Skip to content

fix(embedding): a model that fails to load fails only the requests that name it (#236) - #240

Merged
goodolclint-claude[bot] merged 1 commit into
mainfrom
issue-236
Oct 14, 2026
Merged

goodolclint-claude[bot] merged 1 commit into
mainfrom
issue-236

Conversation

@goodolclint-claude

Copy link
Copy Markdown
Contributor

Closes #236

Root cause (code trace, before the fix)

Request path: governedEmbed → governor.awaitLoad(.textEmbedding) → performLoad → MLXEmbeddingModule.load(reservation:) → loadContainer(desiredName ?? residentId ?? default). Then auditedRebind → rebind(to:), then embed → embedSerialized.

  • (b) confirmed. Nothing told load(reservation:) which model the request named (the LLM path has selectColdLoadModel; embeddings had no equivalent). A cold slot therefore loaded the configured default, which is embeddinggemma-300m when it is listed first. That is the v0.11.0 symptom: a bge request loaded the 300m model.
  • (a) confirmed. rebind and embedSerialized set desiredName = target before loadContainer ran. After one failed load the staged choice was the broken model, and every later cold load(reservation:) retried it, failing for every model.

I traced this from the source. I did not reproduce it on a main binary in this session; the issue's own repro matches the trace.

Fix

Verification

  • Unit suite: 850 run, 34 skipped, 0 failures. swift format clean.
  • Tests: EmbeddingSlotPlanTests (testColdLoadBindsRequestedModelNotDefault, testFailedModelDoesNotWedgeLaterRequests, testFailureOnFirstRequestDoesNotStageTheBrokenModel, testEvictReloadRestoresLastSuccessfullyServedModel) and StubEmbeddingColdLoadTests.testColdLoadBindsStagedModel.
  • Mutation (stage lastServed at stage time, loadFailed a no-op): 3 of 4 EmbeddingSlotPlanTests go red.
  • Live (Release build, loopback port 7991, empty temp --data-dir, --embedding-model embeddinggemma-300m): bge-small 200, embeddinggemma-300m 500 (failed to load model 'embeddinggemma-300m'), embeddinggemma-2 200, bge-small 200, embeddinggemma-2 200.

Codex adversarial review

Two findings, both rejected as out of scope (they need governor changes beyond the embedding admission/reload seam, which the kickoff says to report rather than widen):

  1. Concurrent requests can overwrite coldTarget after admission. Real, but the same design as the LLM selectColdLoadModel and not introduced here (main's desiredName had the same race). The fix is binding an immutable model id to each governor load operation. Follow-up.
  2. lastLoadError is module-wide. A broken model that finishes failing after its caller stopped waiting can surface to the next request for a different model, and the new message would then name the wrong model. Needs per-model failure tracking in the governor. Follow-up.

Size: 6 files, +124/−19, one coherent change. No appVersion bump.

🤖 Generated with Claude Code

…at name it (#236)

- /v1/embeddings stages the requested model before the cold load (selectColdLoadModel), as the LLM path does (M62).
- The slot's last-served/staged choice is recorded only after a load succeeds (EmbeddingSlotPlan), so a failed model is never retried for other requests.
- A module_load_failed envelope from /v1/embeddings names the requested model.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YTAGUw9Rzsd5jJy88FcrsV

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — no blockers. The fix is a faithful mirror of the LLM selectColdLoadModel seam (#206/M62) onto the embedding slot, the decision logic lands in an MLX-free unit-tested type, and no hard constraint is touched: no new routes (so no OpenAPISpec.swift edit owed), error envelope preserved via Self.error(...), no outbound calls, no appVersion bump, no private references.

Scope: one coherent change — 6 files, +124/−19. Body claims check out against the diff.

CI at review time: Unit tier (swift test) pass, Lint (swift-format) pass, Classify diff pass.

Correctness trace I verified: container != nil ⇒ residentId == plan.lastServed, because loadContainer is the only writer of all three and unload() nils the container without touching the plan — so dropping desiredName = target from rebind/embedSerialized does not lose NI3. admissionEstimate(forModel: nil) and load(reservation:) now share plan.loadTarget, so the admitted model and the bound model can no longer disagree.

Follow-ups

  1. MLXEmbeddingModule.swift:188 — the one load-failure exit the fix doesn't cover. The guard let dir = localDirectory(for: id) else { throw ... } early return throws without plan.loadFailed(), so coldTarget survives that failure. Reachable when a model is pruned between the live store scan in resolve and the load. Impact is small (the next request re-stages), but EmbeddingSlotPlan's own doc comment claims "a failed load clears the staged target" without qualification. A defer, or moving the guard inside the do, closes it.
  2. MLXEmbeddingModule.swift:172 — stale coldTarget can outlive an explicit rebind. rebind no longer stages the target, and its no-op early return (residentId == target, container != nil) leaves whatever a prior request staged. A request that staged X and then 503'd before any load, followed by an operator rebind to the already-resident Y, leaves coldTarget == X — so the next governor evict→reload binds X, not the operator's choice.
  3. The new message names a model for load failures that aren't that model's. classified(_:module:model:) rewrites every module_load_failed on the embed path, including causes where no load of that model was attempted: MemoryGovernor.slotLost ("slot was unloaded while the rebind waited"), and the zero-length-vector / dim-mismatch checks inside embedSerialized (which fire on a successfully loaded model mid-forward). Combined with the consume-once lastLoadError[id] the body already flags, the message can confidently name the wrong model. ADR 013 §"issue #4 is one instance" already calls out this exact class of misleading text. Deriving it inside AthenaError (e.g. moduleLoadFailed(module, model:, reason:)) would keep the NE7 message SSOT in one place and limit the model name to genuine load failures.
  4. The unit tests pin the plan, not the fix. coldRequest stages a target before every request — which is the fix — so testColdLoadBindsRequestedModelNotDefault and testFailedModelDoesNotWedgeLaterRequests return the staged id under both described mutations and cannot go red; only tests 3 and 4 discriminate. The body's "3 of 4 go red" reads as 2 of 4. Separately, the half that actually unwedges #236 — governedEmbed calling selectColdLoadModel before awaitLoad — has no test, since AthenaServer is in the executable target (the ADR 008 seam is still incomplete there).
  5. The stub tier still can't reproduce #236. StubEmbeddingModule keeps its own desiredName with no failure semantics, so stub and MLX module now diverge on rebind/failed-load staging. Moving the stub onto EmbeddingSlotPlan would restore the ADR 009 mirror.
  6. selectColdLoadModel is now declared on both LLMModule and EmbeddingModule. ModelSelectable — which both conform to, and which the server already reaches via selectable(module) — is its natural home.

The concurrency caveats the body defers (immutable model id per governor load op; per-model failure tracking) are correctly scoped out; both predate this change.

@goodolclint-claude
goodolclint-claude Bot merged commit 5d47dec into main Oct 14, 2026
7 checks passed
goodolclint-claude Bot added a commit that referenced this pull request Oct 14, 2026
Prerelease cut for embeddinggemma-2 on /v1/embeddings (substrate integration-2026-10-14, #237) and the embedder load-failure fix (#240).

- Athena.appVersion 0.11.0 -> 0.12.0-dev1 (ADR 040 S8 release commit).
- release.yml publishes a tag containing a hyphen as a GitHub prerelease, so a dev tag never becomes Latest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WD2bc4rWu67xtvnZ7uba6H
goodolclint-claude Bot added a commit that referenced this pull request Oct 15, 2026
Prerelease cut for embeddinggemma-2 on /v1/embeddings (substrate integration-2026-10-14, #237) and the embedder load-failure fix (#240).

- Athena.appVersion 0.11.0 -> 0.12.0-dev1 (ADR 040 S8 release commit).
- release.yml publishes a tag containing a hyphen as a GitHub prerelease, so a dev tag never becomes Latest.


Claude-Session: https://claude.ai/code/session_01WD2bc4rWu67xtvnZ7uba6H

Co-authored-by: goodolclint-claude[bot] <323206664+goodolclint-claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One embedder that fails to load wedges /v1/embeddings for every model (500 module_load_failed until restart)

0 participants