Skip to content

fix(backend): degrade embeddings to direct when the gateway has no route - #12444

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix-embeddings-gateway-route-absent
Aug 31, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix-embeddings-gateway-route-absent

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

The outage

Since 2026-08-30 the prod pusher failed every conversation finalization:

ERROR:database.vector_db:find_similar_action_items failed uid=...: Client error '404 Not Found'
for url 'http://prod-omi-llm-gateway.prod-omi-backend.svc.cluster.local:8080/v1/embeddings'

~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

Prod gateway last deployed 2026-08-20, run 32428978705, SHA 48bb6e799f
/v1/embeddings route added 2026-08-28, fe3df5ac00 (#12337, SCA-365)
fe3df5ac00 is an ancestor of 48bb6e799f? No — the deployed gateway is 800 commits behind main

#12337 added both halves of the hop: the gateway route and the backend client
that calls it. The backend auto-deploys on merge to main; gcp_llm_gateway.yml
is workflow_dispatch-only. So the caller reached prod and the callee never did.

Ruled out, not assumed:

  • Route not mounted — main.py does app.include_router(embeddings.router) on main.
  • Feature-mode mismatch — the gateway is serving /v1/chat/completions 200
    and /v1/embeddings 404 in the same 30-minute window, from the same pods.
    Feature mode is on; the route is what's missing.
  • A route the gateway declines to serve — the 404 is Starlette's unrouted-path
    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_mode already trades ledger accounting for availability when a rollout
is misconfigured — it catches RuntimeError and degrades to direct, because
embeddings 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, so
is_gateway_route_absent discriminates on the body:

404 body Meaning Behaviour
{"detail": "Not Found"} (Starlette, unrouted) server predates client degrade to direct, log once
{"error": {...}} (OpenAI-shaped) gateway owns the route, rejected the request raise, unchanged

Applied to all four _OpenAIEmbeddingsProxy embedding methods and to
gemini_embed_query, which reaches the same /v1/embeddings route for
screen-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 real httpx responses:

  • 6 new tests fail on the unfixed tree with exactly the production symptom
    (httpx.HTTPStatusError: Client error 404 escaping embed_query), pass with the fix.
  • 2 of the new tests pass both before and after — deliberately: they pin that
    model_not_found still raises, so the fallback cannot widen into masking lane drift.
17 passed  tests/unit/test_embeddings_gateway.py
521 passed  all 41 gateway/embedding test files

Follow-ups (not in this PR)

  • The gateway still needs redeploying. This PR restores availability; it does
    not restore the embeddings ledger rows, which stay unaccounted while the gateway
    is behind.
  • The 800-commit gateway drift is the standing risk. A backend↔gateway route
    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

Review in cubic

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
@Git-on-my-level
Git-on-my-level merged commit 0e2bd09 into main Aug 31, 2026
43 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix-embeddings-gateway-route-absent branch August 31, 2026 00:13
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.

1 participant