Repository navigation
fix(backend): address Gemini 3.x at its real endpoint, and give every model a fallback chain - #11826
Merged
Git-on-my-level merged 4 commits intoAug 18, 2026
Merged
Conversation
No gemini-3.x model is callable by based-hardware: every one 404s on the project-scoped endpoint while appearing in the global publisher catalog, on both v1 and v1beta1 and in both us-central1 and global. #11823 routes server-paid Pro and Flash overflow to gemini-3.1-flash-lite, so Pro would have 404'd outright and peak spillover would have turned a working degraded path into a hard failure under exactly the load that triggers it. The availability check that missed this listed the global catalog, which enumerates models that exist in Vertex rather than models a project may call. Only the project-scoped path answers that, and it needs credentials that can invoke inference. Availability is now a routing state rather than an error. A 404 from the target latches the observation, re-serves the in-flight request on a model that works, and clears the prepaid-capacity flag, because a model the project cannot call cannot be holding a reservation. Overflow resolves to a ladder instead of a single pin so a dead rung is skipped and a reachable rung always remains, still never returning the reservation itself. The latch is re-checked on the same TTL as capacity, so enabling 3.x access later restores the intended routing with no deploy. Also records the measured thinking contract: 2.5 models honor thinkingBudget and reject thinkingLevel with a 400, so the family split is required in both directions rather than defensive. Failure-Class: FC-platform-grant-record-as-live-capability Co-Authored-By: Claude Opus 5 <[email protected]>
… model a fallback chain The 404s that #11826 routed around were never a project access gap. Gemini 3.x has no regional endpoint: it is served on plain `aiplatform.googleapis.com` with a multi-region `locations/{loc}` segment. `_vertex_url()` built one regional URL for every model, so no 3.x request could ever succeed. Measured 2026-08-18 on based-hardware with credentials that can invoke inference: locations/us gemini-3.1-flash-lite -> 200 ON_DEMAND locations/global gemini-3.1-flash-lite -> 200 ON_DEMAND locations/us gemini-3.1-flash-lite + dedicated -> 429 provisioned throughput us-central1 / us-east5 / us-west1 / europe-west4 / asia-northeast1 -> 404 Endpoint is now resolved per model, by family, in the pure policy module. The default multi-region is `us`, not `global`: both answer, but `global` may serve from anywhere in the world, and this path carries users' conversations and transcripts while every other server-paid call runs in us-central1. `OMI_VERTEX_GLOBAL_LOCATION` makes widening that an explicit operator flip. gemini-2.5-flash also answers multi-region, and must not go there: the 5 GSU Provisioned Throughput order is regional, so a multi-region call bypasses it and bills on-demand while the reservation keeps charging — the 2026-08-04 double-pay incident. The rule is by family, never by what happens to answer. Generalizing the reachability work from #11826, now as defense in depth: * MODEL_FALLBACKS declares an explicit chain for every routable model, as one reviewable data table. Chains never route onto the live PT model (tested at both PT states), never climb in output price, and never contain their own head. gemini-2.5-flash-lite is terminal, which is what keeps the client-pinned lanes off the 3.75x-costlier model. * Reachability is learned per model, only from real generateContent attempts. No startup probe: the metadata endpoint 404s for gemini-2.5-flash-lite, which works, so it is not an oracle, and Cloud Run churns instances too fast to afford one inference call per model per instance. Absence of an entry, never 0.0, means "never observed" — monotonic() has an arbitrary origin. BYOK responses never teach the table. * Both the streaming and non-streaming paths get it; every refused streaming attempt is still closed and its provider slot released. Deletes the thinking family split rather than inverting it. Measured: gemini-3.1-flash-lite honors thinkingBudget (0 -> 0 thoughts, 1024 -> 278), while 2.5 models reject thinkingLevel with HTTP 400. thinkingBudget is the one option both families accept, so _retarget_thinking() and the branch in thinking_config_for() are gone and a cross-family fallback rewrites nothing. Verification: backend $ .venv/bin/python -m pytest tests/unit/test_desktop_proxy.py \ tests/unit/test_vertex_pt_routing.py -q -> 128 passed $ .venv/bin/python -m pyright backend/routers/desktop_proxy.py \ backend/utils/llm/vertex_pt_routing.py -> 0 errors, 0 warnings Failure-Class: FC-platform-grant-record-as-live-capability Co-Authored-By: Claude Opus 5 <[email protected]>
Failure-Class: FC-platform-grant-record-as-live-capability
MODEL_FALLBACKS lists a chain for gemini-2.5-pro, which reads as though Pro is still a route. It is not: _serving_model remaps it to gemini-3.1-flash-lite before dispatch, and over the daily soft limit metering demotes it to gemini-2.5-flash-lite first. The table lists models a client may request, not models server-paid traffic is served by, and nothing said so. Adds a parametrised guarantee across both reservation states and both reachability states that no server-paid request reaches dispatch as Pro ($10.00/1M out, 6.7x the target and 25x the floor), a companion test that BYOK Pro is still honoured because the user pays for it, and the distinction in the doc table that prompted this. Co-Authored-By: Claude Opus 5 <[email protected]>
Git-on-my-level
force-pushed
the
fix/vertex-target-model-availability-fallback
branch
from
August 18, 2026 22:14
f74d589 to
b756276
Compare
Git-on-my-level
deleted the
fix/vertex-target-model-availability-fallback
branch
August 18, 2026 22:43
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 defect
gemini-3.1-flash-litereturns 404 forbased-hardware. #11823 routes server-paid Pro and Flash overflow onto it, so that routing could not work.The first diagnosis in this PR was wrong, and is corrected here. The original claim was "no Gemini 3.x model is callable by this project". It is not an access gap:
Measured 2026-08-18 on
based-hardwarewith credentials that can invoke inference:gemini-3.1-flash-liteaiplatform.googleapis.com+locations/usaiplatform.googleapis.com+locations/globalaiplatform.googleapis.com+locations/us+dedicatedheaderus-central1/us-east5/us-west1/europe-west4/asia-northeast1eu-aiplatform.googleapis.com+locations/euThe host is always plain
aiplatform.googleapis.com;us-aiplatform.googleapis.comis not a valid host (400Invalid hostname). Only thelocations/{loc}segment changes.The
dedicated429 is the "no PT order for this model" answer, expected while we own no 3.1 order. It also proves the capacity header is honored multi-region, so the existing auto-detect probe works there. Note it reads lowercaseprovisioned throughputwhere the regional endpoint uses title case — the matcher casefolds, and a regression test now pins that.How it got through: availability was checked with
GET /publishers/google/models— the global catalog, no project in the path. That enumerates models that exist in Vertex; it says nothing about whether the URL you are about to build will reach one. Only a realgenerateContentattempt answers that.Blast radius had it deployed
bc7f7657c9is merged but prod still servesc5b0b5d14b, so this never reached production traffic.is_model_unavailableis not_overflow_triggered, so there was no retry: hard failure to the client.Failure class
Failure-Class: FC-platform-grant-record-as-live-capability
Same contract, new subsystem: a platform record was treated as proof the running process can exercise the capability it names. There it was
CGPreflightScreenCaptureAccess()readingtruewhile ScreenCaptureKit refused the same process; here it is the global publisher catalog listing a model while the request the proxy actually builds 404s. Correcting the root cause from "access gap" to "wrong endpoint" does not move the class — the defect is still that a catalog entry was accepted in place of an invocation. The class's canonical prevention prescribes the shape used here: resolve the capability from the refusal reported by the subsystem that actually performs the work, and latch that in memory rather than persisting it, because it is a fact about this process and this deployment rather than a durable truth.Fix 1 — address each model at its real endpoint
ptr.vertex_endpoint()resolves(host, location)per model, by family, in the pure policy module:gemini-3.*aiplatform.googleapis.comus(OMI_VERTEX_GLOBAL_LOCATION){loc}-aiplatform.googleapis.comGCP_LOCATION, defaultus-central1Why
usand notglobal. Both answer.globalmay serve a request from anywhere in the world;usis the US multi-region. This path carries users' personal conversations, transcripts and memories, and every other server-paid Gemini call in this service runs inus-central1, souspreserves the existing residency posture. Widening it is a deliberate operator decision, not a side effect of a routing change — hence a named default and an env flip rather than a literal in a URL builder.Why the rule is by family and not "whatever answers".
gemini-2.5-flashalso returns 200 onlocations/usandlocations/global. Sending it there would bypass the 5 GSU us-central1 Provisioned Throughput order and bill on-demand while the reservation kept charging ~$290/day — paying twice for the same tokens, which is the 2026-08-04 double-pay incident.test_the_reservation_model_is_never_routed_off_its_regionexists specifically to stop that "simplification", and cites the incident in its docstring.Location being per-model also means nothing assumes the reservation and the model absorbing its overflow share a location. Unresolved and not encoded anywhere: whether a PT order for a 3.x model is purchased multi-region, and how that interacts with the existing regional order.
Fix 2 — every routable model gets a declared fallback chain
Generalized from the single migration target in the first revision of this PR. Now defense in depth rather than the headline fix: a model that 404s degrades instead of erroring, whatever the reason.
MODEL_FALLBACKSin the policy module is one reviewable data table:gemini-2.5-progemini-3.1-flash-lite,gemini-2.5-flash-litegemini-2.5-flashgemini-3.1-flash-lite,gemini-2.5-flash-litegemini-3.1-flash-litegemini-2.5-flash-litegemini-2.5-flash-litegemini-embedding-001gemini-2.5-prois not a route in normal use. It appears in the table because it stays proxy-allowlisted and BYOK users pay for it on their own key, but no server-paid request is dispatched as Pro:_serving_model()remaps it togemini-3.1-flash-litebefore dispatch, and over the daily soft limit the metering path demotes it togemini-2.5-flash-litefirst.test_server_paid_traffic_never_dispatches_gemini_2_5_proasserts this across both reservation states and both reachability states — 4 parametrised cases — and a companion test asserts BYOK Pro is still honoured.Three invariants, each enforced by a test rather than by convention:
PRICE_PER_MTOK_OUT, so a degraded request cannot cost more than the one it replaces. This is also whygemini-2.5-flash-liteis terminal — it is the floor of the ladder and the model the desktop clients pin directly (ModelQoS.lightweight, Windowsmemory/goals/insight).test_client_pinned_flash_lite_is_never_promotedstill holds.Fix 3 — reachability is learned, per model, from traffic only
GET .../publishers/google/models/{m}is not an oracle: it 404s forgemini-2.5-flash-lite, which works fine. The only honest signal is a realgenerateContentattempt, and burning one per model per instance is unaffordable on Cloud Run, which churns instances constantly.0.0— means "never observed".time.monotonic()has an arbitrary origin, so a zero-seeded observation would mark every model dead for the first 10 minutes of each new instance's life. Regression test included, alongside the existing one for the probe timestamp.Quota exceeded for requests per minute) is still backpressure and never triggers fallback. Only a PT-exhaustion 429 or a model-unavailable 404 does.Both the streaming and non-streaming paths get all of this;
test_streaming_unreachable_model_falls_back_and_leaks_no_provider_slotasserts every refused attempt is closed and its provider slot released, matching the existing overflow-ladder guarantee.The thinking contract: measured, and it deleted a branch
The 3.x half of the table was unmeasurable before, because those models were unreachable. With the endpoint fixed:
gemini-2.5-flash-litethinkingBudget: 0gemini-2.5-flash-litethinkingBudget: 1024gemini-2.5-flash-litethinkingLevel: minimalgemini-2.5-flashgemini-3.1-flash-litethinkingBudget: 0gemini-3.1-flash-litethinkingBudget: 1024gemini-3.1-flash-litethinkingLevel: minimalgemini-3.1-flash-litethinkingLevel: highgemini-3.1-flash-liteThis reverses the earlier conclusion. #11823 split
thinkingConfigby family on the documented claim that 3.x ignoresthinkingBudgetand cannot disable thinking. Measured,gemini-3.1-flash-litehonorsthinkingBudget— 0 really is 0 thoughts, 1024 spends 278 — while 2.5 models rejectthinkingLevelwith HTTP 400. SothinkingBudgetis the one option both families accept andthinkingLevelis the one that works on neither universally.The split is therefore deleted rather than inverted:
ptr.thinking_config_for()is a single path and_retarget_thinking()is gone, so a fallback that crosses families rewrites nothing. Net removal of a branch and a body-rewriting function.It still justifies injecting a budget at all:
gemini-2.5-flashwith no thinking config spent 516 thinking tokens on a trivial prompt, all billed as output.Testing
Behavioral coverage added for each claim above:
test_gemini_3_x_is_routed_to_the_us_multi_region_endpoint— the actual production defecttest_the_reservation_model_is_never_routed_off_its_region— the 2026-08-04 double-pay guardtest_the_multi_region_residency_pin_is_us_and_is_operator_flippable— residency default and its escape hatchtest_a_fallback_across_families_also_crosses_endpoints— per-model location, end to end through_upstreamtest_no_fallback_chain_ever_routes_onto_the_reservation/test_no_recovery_plan_ever_routes_onto_the_reservation— parametrized over every model at both PT statestest_every_chain_is_non_increasing_in_output_price,test_the_cheapest_text_model_is_terminal— the cost invariantstest_reachability_is_learned_per_model_not_globally,test_byok_traffic_never_teaches_the_reachability_tabletest_a_new_instance_believes_every_model_reachable_regardless_of_uptime— themonotonic()origin traptest_a_404_on_any_model_falls_back_and_latches_it,test_streaming_unreachable_model_falls_back_and_leaks_no_provider_slottest_thinking_budget_is_the_one_option_both_families_accept— cites the measurement above, per the rule that a test rewritten alongside its code must cite an external sourcebackend/docs/vertex-pt-flash.mdcarries the corrected endpoint finding, the residency reasoning, the fallback table, and the full measured thinking contract;test_migration_contract_is_documentednow asserts every declared model and both endpoint constants appear there.Operator note
The earlier note here said enabling Gemini 3.x access for
based-hardwarewas a prerequisite for any of this. That was wrong — there is nothing to enable. 3.x is reachable today at the multi-region endpoint, so the routing and the PT migration are unblocked. What remains genuinely open is whether a 3.x PT order is purchased multi-region and how it interacts with the existing regionalgemini-2.5-flashorder; no code here assumes an answer.