Repository navigation
fix(backend): degrade embeddings to direct when the gateway has no route - #12444
Merged
Merged
Conversation
The prod LLM gateway was last deployed 2026-08-20 (48bb6e7); the /v1/embeddings route landed 2026-08-28 in fe3df5a (#12337). The backend half of that PR auto-deploys on merge, the gateway is workflow_dispatch-only, so the client shipped and the server did not. From 2026-08-30 the gateway answered every embeddings call with a Starlette 404, embed_query raised it, find_similar_action_items failed, and conversation finalization dead-lettered ~1,300/h in prod. A working direct embeddings path was sitting right behind that 404 the whole time. _gateway_mode already trades ledger accounting for availability when a rollout is misconfigured (it catches RuntimeError), but it could not see this skew: the gateway is healthy, it is simply older than its client. So treat route-absence as its own condition. The status alone cannot carry it -- the gateway also answers 404 for model_not_found -- but the bodies differ: a route the app never registered gets Starlette's bare {"detail": "Not Found"}, while a gateway-owned rejection is OpenAI-shaped {"error": {...}}. is_gateway_route_absent discriminates on the body, so deploy skew degrades to direct while lane misconfiguration still raises. Applied to all four OpenAI embedding methods and to gemini_embed_query, which reaches the same route for screen-activity search and had the identical defect. The skew is logged once per process, not per call. This does not remove the need to redeploy the gateway; it removes the gateway's ability to take embeddings down when it is behind. Failure-Class: FC-ship-before-required-route
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The outage
Since 2026-08-30 the prod pusher failed every conversation finalization:
~1,300/h, 100% in the pusher container. Live voice captures dead-lettered to
processing_failed; "Conversation processed by pusher" went to ~0/h.Root cause: the client shipped, the server didn't
48bb6e799f/v1/embeddingsroute addedfe3df5ac00(#12337, SCA-365)fe3df5ac00is an ancestor of48bb6e799f?#12337added both halves of the hop: the gateway route and the backend clientthat calls it. The backend auto-deploys on merge to main;
gcp_llm_gateway.ymlis
workflow_dispatch-only. So the caller reached prod and the callee never did.Ruled out, not assumed:
main.pydoesapp.include_router(embeddings.router)on main./v1/chat/completions200and
/v1/embeddings404 in the same 30-minute window, from the same pods.Feature mode is on; the route is what's missing.
answer, not a
GatewayError.What this PR changes
It does not redeploy the gateway — that is still required, and is tracked
separately. It removes the gateway's ability to take embeddings down when it is
behind.
_gateway_modealready trades ledger accounting for availability when a rolloutis misconfigured — it catches
RuntimeErrorand degrades to direct, becauseembeddings are load-bearing for memory and vector search. It could not see this
skew: the gateway is healthy, it is simply older than its client. Meanwhile a
working direct embeddings path sat three lines behind that 404 the entire outage.
Status alone cannot carry route-absence — the gateway also returns 404 for
model_not_found(_status_code_for_error). The bodies differ, sois_gateway_route_absentdiscriminates on the body:{"detail": "Not Found"}(Starlette, unrouted){"error": {...}}(OpenAI-shaped)Applied to all four
_OpenAIEmbeddingsProxyembedding methods and togemini_embed_query, which reaches the same/v1/embeddingsroute forscreen-activity search and had the identical defect.
The skew is logged once per process rather than per call: the condition holds
until the gateway is redeployed, the callers behind it run thousands of
embeddings an hour, and the gateway's own access log keeps counting the 404s.
Tests
backend/tests/unit/test_embeddings_gateway.py, driven through the real seam(
clients.embeddings/clients.gemini_embed_query) with realhttpxresponses:(
httpx.HTTPStatusError: Client error 404escapingembed_query), pass with the fix.model_not_foundstill raises, so the fallback cannot widen into masking lane drift.Follow-ups (not in this PR)
not restore the embeddings ledger rows, which stay unaccounted while the gateway
is behind.
dependency has no equivalent of the release-lane probe that this failure class's
canonical prevention installed for the Windows update feed.
Failure-Class: FC-ship-before-required-route