Repository navigation
fix(embedding): a model that fails to load fails only the requests that name it (#236) - #240
Conversation
…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
There was a problem hiding this comment.
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
MLXEmbeddingModule.swift:188— the one load-failure exit the fix doesn't cover. Theguard let dir = localDirectory(for: id) else { throw ... }early return throws withoutplan.loadFailed(), socoldTargetsurvives that failure. Reachable when a model is pruned between the live store scan inresolveand the load. Impact is small (the next request re-stages), butEmbeddingSlotPlan's own doc comment claims "a failed load clears the staged target" without qualification. Adefer, or moving the guard inside thedo, closes it.MLXEmbeddingModule.swift:172— stalecoldTargetcan outlive an explicit rebind.rebindno longer stages the target, and its no-op early return (residentId == target, container != nil) leaves whatever a prior request staged. A request that stagedXand then 503'd before any load, followed by an operator rebind to the already-residentY, leavescoldTarget == X— so the next governor evict→reload bindsX, not the operator's choice.- The new message names a model for load failures that aren't that model's.
classified(_:module:model:)rewrites everymodule_load_failedon 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 insideembedSerialized(which fire on a successfully loaded model mid-forward). Combined with the consume-oncelastLoadError[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 insideAthenaError(e.g.moduleLoadFailed(module, model:, reason:)) would keep the NE7 message SSOT in one place and limit the model name to genuine load failures. - The unit tests pin the plan, not the fix.
coldRequeststages a target before every request — which is the fix — sotestColdLoadBindsRequestedModelNotDefaultandtestFailedModelDoesNotWedgeLaterRequestsreturn 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 —governedEmbedcallingselectColdLoadModelbeforeawaitLoad— has no test, sinceAthenaServeris in the executable target (the ADR 008 seam is still incomplete there). - The stub tier still can't reproduce #236.
StubEmbeddingModulekeeps its owndesiredNamewith no failure semantics, so stub and MLX module now diverge on rebind/failed-load staging. Moving the stub ontoEmbeddingSlotPlanwould restore the ADR 009 mirror. selectColdLoadModelis now declared on bothLLMModuleandEmbeddingModule.ModelSelectable— which both conform to, and which the server already reaches viaselectable(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.
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
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>
Closes #236
Root cause (code trace, before the fix)
Request path:
governedEmbed→governor.awaitLoad(.textEmbedding)→performLoad→MLXEmbeddingModule.load(reservation:)→loadContainer(desiredName ?? residentId ?? default). ThenauditedRebind→rebind(to:), thenembed→embedSerialized.load(reservation:)which model the request named (the LLM path hasselectColdLoadModel; embeddings had no equivalent). A cold slot therefore loaded the configured default, which isembeddinggemma-300mwhen it is listed first. That is the v0.11.0 symptom: a bge request loaded the 300m model.rebindandembedSerializedsetdesiredName = targetbeforeloadContainerran. After one failed load the staged choice was the broken model, and every later coldload(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
EmbeddingSlotPlan(new, MLX-free):lastServedandcoldTargetare recorded only when a load succeeds; a failed load clears the staged target.EmbeddingModule.selectColdLoadModel(_:)(stub + MLX), called fromgovernedEmbedbeforeawaitLoad, mirroring the LLM path (/healthz per-moduleresidentBytesdoes not track the resident model (stuck value, exceeds physFootprint); one over-budget footprint observed #206/M62).module_load_failedfrom/v1/embeddingsnames the requested model (Module textEmbedding failed to load model '<id>'.). The sharedAthenaErrormessage stays detail-free (NE7).Verification
swift formatclean.EmbeddingSlotPlanTests(testColdLoadBindsRequestedModelNotDefault,testFailedModelDoesNotWedgeLaterRequests,testFailureOnFirstRequestDoesNotStageTheBrokenModel,testEvictReloadRestoresLastSuccessfullyServedModel) andStubEmbeddingColdLoadTests.testColdLoadBindsStagedModel.lastServedat stage time,loadFaileda no-op): 3 of 4EmbeddingSlotPlanTestsgo red.--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):
coldTargetafter admission. Real, but the same design as the LLMselectColdLoadModeland not introduced here (main'sdesiredNamehad the same race). The fix is binding an immutable model id to each governor load operation. Follow-up.lastLoadErroris 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
appVersionbump.🤖 Generated with Claude Code