LearnNewsExamplesServices
Frontmatter
titlefix(ai): prevent embedding context truncation (#13944)
authorneo-gpt
stateMerged
createdAtJun 24, 2026, 12:24 PM
updatedAtJun 24, 2026, 12:47 PM
closedAtJun 24, 2026, 12:47 PM
mergedAtJun 24, 2026, 12:47 PM
branchesdevcodex/13944-embedding-context-truncation
urlhttps://github.com/neomjs/neo/pull/13945
contentTrust
projected
quarantined0
signals[]
Merged
neo-gpt
neo-gpt commented on Jun 24, 2026, 12:24 PM

Resolves #13944

This prevents local OpenAI-compatible embedding calls from accepting vectors after LM Studio silently truncates input. TextEmbeddingService now verifies the resident LM Studio embedding model context before posting to /v1/embeddings, refuses below-config or over-loaded-context requests with bounded diagnostics, and emits consumer friction when an input would overflow the observed loaded context. The guard is scoped to the configured LM Studio endpoint, so CI/cloud/generic OpenAI-compatible endpoints do not require an lms CLI. The orchestrator supervisor now reruns a task-owned readiness hook even when a fire-and-exit service is already live, so the existing LMS preload/replacement path runs after an "endpoint is up" liveness result instead of only after a child spawn.

Evidence: L2 (focused unit coverage for stale loaded context, no provider request posted, and liveness-up readiness execution) -> L2 required for #13944 code gate. Residual: L3 local LMS smoke after merge/restart.

Deltas from ticket

  • Added the provider-boundary guard in TextEmbeddingService, so Memory Core and KB callers share the same truncation stop.
  • Reused the existing LMS preload/readiness hook from the supervisor liveness-up path, covering the restart race where lms server is already healthy.
  • Removed hidden fallback defaults in the touched LMS/stuck-runner task config path and read typed AiConfig leaves directly.

Test Evidence

  • node --check ai/services/memory-core/TextEmbeddingService.mjs
  • node --check ai/daemons/orchestrator/services/ProcessSupervisorService.mjs
  • node --check ai/daemons/orchestrator/services/ConfiguredTaskDefinitionsService.mjs
  • npm run test-unit -- test/playwright/unit/ai/services/memory-core/TextEmbeddingService.retry.spec.mjs — 17 passed
  • npm run test-unit -- test/playwright/unit/ai/daemons/orchestrator/services/ProcessSupervisorService.spec.mjs — 34 passed
  • npm run test-unit -- test/playwright/unit/ai/daemons/orchestrator/Orchestrator.spec.mjs — 55 passed
  • npm run test-integration-unified -- test/playwright/integration/healthcheck.spec.mjs — 2 skipped locally by fixture gate
  • git diff --cached --check

Post-Merge Validation

  • Restart the harness/orchestrator with LM Studio models ejected; confirm the embedding model is resident at localModels.embedding.contextLimitTokens or higher before KB sync accepts embeddings.
  • Confirm the KB sync log no longer shows provider-side truncation warnings for embedding requests.

Authored by Euclid (GPT-5, Codex Desktop). Session cd2b88d7-8134-4ef8-a10f-0b1e80c03db4.

neo-gpt
neo-gpt commented on Jun 24, 2026, 12:38 PM

Red integration-unified addressed on head df8b68453e.

Root cause: the first guard keyed LM Studio context verification only on orchestrator.lms.enabled, so generic OpenAI-compatible integration fixtures without an lms CLI failed during the Memory Core embedding write canary (spawn lms ENOENT).

Fix: TextEmbeddingService now runs the lms ps loaded-context probe only when the OpenAI-compatible host is the configured LM Studio endpoint (orchestrator.lms.port) or when a test probe seam is explicitly installed. LM Studio still fails before provider-side truncation; CI/cloud/generic OpenAI-compatible endpoints no longer require lms.

Validation:

  • node --check ai/services/memory-core/TextEmbeddingService.mjs -> passed
  • npm run test-unit -- test/playwright/unit/ai/services/memory-core/TextEmbeddingService.retry.spec.mjs -> 17 passed
  • npm run test-integration-unified -- test/playwright/integration/healthcheck.spec.mjs -> 2 skipped locally by fixture gate
  • npm run agent-preflight -- --no-fix --pr-body /private/tmp/pr-13944.md ai/services/memory-core/TextEmbeddingService.mjs test/playwright/unit/ai/services/memory-core/TextEmbeddingService.retry.spec.mjs -> passed
  • git diff --cached --check -> passed before amend

CI is running again on the pushed head.


tobiu
tobiu APPROVED reviewed on Jun 24, 2026, 12:47 PM

No review body provided.