Repository navigation
feat(llm-gateway): consolidate safe auto-router - #10934
undivisible wants to merge 20 commits into
Conversation
Co-authored-by: choguun <[email protected]>
Co-authored-by: choguun <[email protected]>
Co-authored-by: choguun <[email protected]> Co-authored-by: Max Carter 祁明思 <[email protected]>
Co-authored-by: choguun <[email protected]>
Co-authored-by: Max Carter 祁明思 <[email protected]> Failure-Class: none
Failure-Class: none
e35fdc4 to
e89106c
Compare
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for consolidating this behind the LLM gateway. The overall direction looks useful: the catalog/serving split, fake-default capability smoke, benchmark-to-proposed-artifact emitter, and mtime-based config reload all help keep the auto-router rollout controlled rather than widening production routing accidentally.
I’m leaving this as maintainer-review feedback rather than approval because the PR is still draft, backend checks are currently failing, and this is product/architecture-sensitive LLM routing work that should get human maintainer sign-off before merge.
A few review notes for the next pass:
- Please get the backend gate green before marking ready. GitHub currently reports failures in Backend unit suite, Hermetic Backend E2E, and the Backend Hermetic Merge Gate. The E2E failure is in the listen/STT language path, so it may be pre-existing or unrelated, but it still needs either a green rerun or a clear note explaining why it is not caused by this head.
- The serving/catalog boundary is the right shape for safe rollout. Before merge, I’d like a maintainer to confirm the exact prod-ready lane set and the behavior where adding/flipping a catalog entry can change the resolver allowlist after config reload.
- The new AA benchmark fetch path is appropriately optional/fallback-based from a quick static review. Please keep validating that no benchmark fetch/cache path can mutate the live serving artifacts directly; the proposed-artifact-only contract is important here.
- Since this changes model-routing infrastructure, please keep the PR validation focused on the real gateway path plus the emitter/smoke path. The added unit coverage is good, but human review should still confirm the rollout policy and operational ownership.
No urgent security/supply-chain issue found in this pass.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the continued work here. I found one concrete blocker in the benchmark refresh path that should be fixed before this is considered ready:
BenchmarksFetcherdefaults its fallback file tobackend/llm_gateway/gateway/_private/benchmarks.example.json, but this PR does not add that file. WithAA_API_KEYunset,BenchmarksFetcher().fetch()logs the intended fallback and then raisesFileNotFoundErrorinstead of returning example data. The same missing file also breaks the successful-AA path when it calls_merge_with_uncovered_tasks(..., self._load_example()), so STT/embedding preservation depends on a file that is not present. I reproduced this on the PR head by directly exercising the fetcher fallback path; it tried to open/workspace/omi-pr-10934-review/backend/llm_gateway/gateway/_private/benchmarks.example.json.
Please either commit the fallback fixture at the path the fetcher uses, point the fetcher at a real committed fallback payload, or make the scheduled/emitter path supply the fallback explicitly, and add a behavioral test that calls fetch() with no AA_API_KEY plus the AA-success merge path. The intended fallback behavior is important because this tooling is supposed to be safe/offline by default rather than failing the scheduled rotation path when the external benchmark key is absent or unavailable.
I am not approving this because the PR is still draft, checks are failing, and this model-routing/rollout path still needs human maintainer review before merge. No urgent security issue found in this pass.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Failure-Class: none Co-authored-by: choguun <[email protected]>
Failure-Class: none Co-authored-by: choguun <[email protected]>
Co-authored-by: choguun <[email protected]>
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the update here. The previous benchmark fallback blocker appears to be resolved on this head because the inactive benchmark proposal/fetcher tooling is no longer present in the final diff.
I found one new blocker in the config reload path that should be fixed before this is ready:
GatewayConfigReloader._load()passesrequired_lane_ids=get_supported_auto_lane_ids()beforeload_gateway_config()reads the changed catalog file. Since the resolver catalog is process-cached, a running gateway can keep using the old prod-ready set whenlanes_catalog.yamlchanges. I reproduced this by priming the resolver catalog, demotingomi:auto:public-shared-conversation-chatin a copied catalog, and callingGatewayConfigReloader.get()again: the reload returned the stale cached config and keptomi:auto:public-shared-conversation-chatincfg.lanesinstead of narrowing the serving set. That means the intended “next request after merge sees the new artifact/catalog” behavior can fail specifically for catalog demotions/removals, leaving a lane servable until process restart.
Please make the reload path derive required lane IDs from the same freshly loaded catalog/config snapshot (or remove the stale resolver-derived requirement) and add a regression test that changes a prod-ready catalog entry to non-prod-ready and verifies the hot-reloaded config narrows the served lane set rather than returning stale.
I’m requesting changes rather than approving because the PR is still draft, the Hygiene check is failing, and this model-routing/config-reload behavior needs human maintainer sign-off before merge. No urgent security issue found.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Failure-Class: none
Resolved on current head; superseded by later automation review.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the update. I re-reviewed the current head and the prior config hot-reload blocker looks resolved: GatewayConfigReloader._load() now loads the changed catalog first, passes that fresh catalog into load_gateway_config(), and only then updates the resolver catalog. The new regression test_reloader_removes_demoted_catalog_lane covers the demotion/removal case that previously kept omi:auto:public-shared-conversation-chat servable until restart.
Validation I ran locally on this head:
.venv/bin/python -m pytest tests/unit/llm/test_lane_catalog.py tests/unit/llm_gateway/test_capability_smoke.py tests/unit/llm_gateway/test_config_reload.py tests/unit/llm_gateway/test_daily_refresh.py -q— 110 passed.venv/bin/python scripts/scan_async_blockers.py --dirs llm_gateway— 0 selected blocking findings
I don't see a remaining automation blocker in this diff, and the category remains backend. I’m not approving because this is still a draft and it changes LLM gateway routing/config reload/smoke behavior, so it still needs human maintainer sign-off before merge. No urgent security issue found.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the latest update. I re-checked this head against the earlier automation feedback:
- The previous benchmark fallback and catalog hot-reload blockers appear resolved in the current diff; the inactive benchmark proposal/fetcher path is gone, and the reloader now loads the changed catalog before refreshing the gateway config/resolver catalog.
- GitHub currently reports the relevant backend and hygiene checks passing on this head, which is good progress.
- I still would not merge this without human maintainer sign-off: it is still a draft, currently carries
needs-rebase, and it changes LLM gateway routing/config reload/capability-smoke behavior. That rollout/operational boundary is a maintainer judgment call even though I do not see a new concrete automation blocker in this pass.
No urgent security/supply-chain issue found.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Resolve the lane-catalog / serving-config conflict in favour of main's
shipped behaviour: `utils.llm.model_config` stays the source of truth for
the feature lanes it generates, and the lane catalog governs the
hand-authored serving YAML only.
Gating generated lanes on the catalog (as this branch previously did)
would have cut the served set from 42 lanes to 2, silently disabling the
chat-agent, translation, memory-l2 and 37 other feature lanes that main
routes through the gateway today. `GatewayConfig.generated_lane_ids`
records which lanes are generated so `validate_serving_config` skips
them; catalog demotion still narrows the hand-authored serving set, which
is the safety property this branch adds.
Verification:
backend/.venv/bin/python -m pytest tests/unit/llm/test_lane_catalog.py \
tests/unit/llm_gateway/ tests/unit/test_llm_gateway_config.py \
tests/unit/test_llm_gateway_readiness.py \
tests/unit/test_llm_gateway_coverage_guardrails.py \
tests/unit/test_llm_gateway_anthropic_passthrough.py \
tests/unit/test_llm_gateway_output_budget.py -q
-> 164 passed
`GatewayConfigReloader` silently returned the last good config whenever a
reload failed. That branch changes correctness (the gateway keeps routing
on a superseded artifact set) and is exactly the fail-open shape
`docs/agents/fallback-telemetry.md` requires the shared helper for, so it
now calls `record_fallback(component='llm_gateway',
to_mode='stale_config', outcome='degraded')`.
`DailyRefreshCache` gains an `on_stale_fallback` hook rather than
importing the emitter itself, keeping the cache generic; the callback is
swallowed on error so telemetry can never break serving.
Verification:
backend/.venv/bin/python -m pytest tests/unit/llm_gateway/test_config_reload.py \
tests/unit/llm_gateway/test_daily_refresh.py -q
-> 31 passed (includes the new
test_reloader_records_fallback_when_serving_stale_config)
`get_gateway_config` became a coroutine when this branch moved the gateway
onto the mtime-watched reloader, but `main.lifespan` still called it
synchronously. Startup therefore handed a coroutine object to
`observe_gateway_config_identity`, which raised
`AttributeError: 'coroutine' object has no attribute 'lanes'` and aborted
the app lifespan — every request against a freshly started gateway failed.
Verification:
backend/.venv/bin/python -m pytest tests/unit/test_llm_gateway_service.py \
tests/unit/test_llm_gateway_openai_compatible.py tests/unit/llm/ \
tests/unit/llm_gateway/ tests/unit/test_llm_gateway_*.py \
tests/unit/test_verify_llm_gateway_serving.py -q
-> 320 passed (was 1 failed, 1 error)
… guard Merging main grew the served lane set from 2 to 42, so the reloader tests that parse the full production gateway config two or three times to prove an mtime change re-reads it now measure 0.12-0.13s CPU against the 0.12s fail ceiling. The cost tracks the served lane count, not the tests, which is the structural case `fast_unit_duration_allowlist.txt` exists for. Verification: BACKEND_UNIT_TEST_FILE_LIST=<11 changed gateway test files> bash test.sh -> all files pass, no duration guard failures
|
Rebased onto current The
Resolved in favour of This means the "narrow the prod-ready lane set" outcome is not in this PR. That is the maintainer call you flagged; happy to do it as a follow-up once the intended prod-ready set is decided. Also fixed:
Verification on this head:
Leaving as draft pending your call on the lane-set question above. |
…ent drops The served lane set stays exactly as it is today unless an operator opts in: with OMI_LLM_GATEWAY_SERVING_LANES unset, resolve_served_lane_ids returns every candidate lane, so all 42 generated + hand-authored lanes keep serving. Opting in names the lane set to serve. Because silently disabling production lanes is the failure mode being guarded against, an allowlist that would drop a currently-served lane refuses to start unless OMI_LLM_GATEWAY_SERVING_LANES_DROP_CONFIRM names exactly the dropped set. A confirmed narrowing emits the shared record_fallback helper (component=llm_gateway, to_mode=allowlisted_lanes, reason=policy, outcome=degraded) so the restricted mode is never silent in ops. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…usal test_default_config_serves_every_generated_lane asserts the served set equals every utils.llm.model_config feature lane plus the two hand-authored lanes, with a >=40 numeric floor. This is the test that would have caught the 42-to-2 collapse: a revision that gates serving on prod_ready catalog entries fails it. Verified by temporarily forcing that narrowing, which failed the test, then reverting. The remaining cases pin the opt-in path: an empty allowlist is a no-op, an allowlist naming every lane is a no-op, unknown lane ids are rejected, a narrowing allowlist refuses without confirmation, a partial confirmation still refuses, and an exact confirmation narrows while recording one degraded llm_gateway fallback. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Adds both env vars to the gateway env table and a section stating the default (every generated lane serves), the refuse-rather-than-drop contract, and the fallback telemetry emitted on a confirmed narrowing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Thanks for the continued iteration here. I re-reviewed the current head and this is moving in a good direction, but I’m still leaving it for human maintainer review rather than approval because it is still a draft and it changes the LLM gateway’s routing/config reload behavior. Specific notes from this pass:
Validation I ran locally on this head:
No blocking implementation issue found in this pass. Remaining merge blockers are qualitative/process: the PR is draft, currently carries rebase/workflow/human-review labels, and changes a security/operations-sensitive model-routing surface. Leaving this for human maintainer review of the LLM-gateway rollout direction and operational risk. — Reviewed by glm-5.2 for Omi maintainer automation. AI disclosure: this feedback was generated by Omi’s AI maintainer-review automation. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
Summary
Merge with main
The lane catalog and main's model_config-derived lanes conflicted. Resolved in favour of
main's shipped behaviour:
utils.llm.model_configstays the source of truth for the featurelanes it generates, and the catalog governs the hand-authored serving YAML only. Gating
generated lanes on the catalog would have cut the served set from 42 lanes to 2.
GatewayConfig.generated_lane_idsrecords which lanes are generated sovalidate_serving_configskips them; catalog demotion still narrows the hand-authoredserving set, which is the safety property this PR adds.
Validation
backend/.venv/bin/python -m pytest tests/unit/llm/test_lane_catalog.py tests/unit/llm_gateway/ tests/unit/test_llm_gateway_config.py tests/unit/test_llm_gateway_readiness.py tests/unit/test_llm_gateway_coverage_guardrails.py tests/unit/test_llm_gateway_anthropic_passthrough.py tests/unit/test_llm_gateway_output_budget.py -q(164 passed)backend/.venv/bin/python scripts/scan_async_blockers.py --dirs backend/llm_gatewaymake preflightProduct invariants affected
Failure class (fixes)
Failure-Class: none