Repository navigation
Conversation
…, zero-drift day-one) Expands the gateway's lane catalog from 1 (omi:auto:chat-structured) to 16, covering every AI capability in Omi. Read-review-only — no behavior change. - lanes.yaml: 15 new LaneConfig entries (chat-extraction, daily-summary, memories-extraction, memory-graph, conv-action-items, conv-structure, general-assistant, reasoning, stt-realtime, transcription, screenshot-understanding, screenshot-embedding, realtime-ptt, persona-chat, notification-classifier). - route_artifacts.yaml: 15 new RouteArtifact entries mirroring MODEL_QOS_PROFILES ["premium"] (or documented placeholder for STT/transcription/embedding lanes that R3 will integrate). All shadow mode (rollout.percent: 0), all evidence.dev_only: false (is_prod_eligible() passes). - resolver.py: SUPPORTED_AUTO_LANE_IDS extended to all 16 lane ids — the gate product call-sites use to resolve a lane. - tests: 16 new tests cover objective sum-to-1.0 invariant for all 16 lanes, zero-drift (active == lkg) day-one invariant for all 15 new lanes, SUPPORTED_AUTO_LANE_IDS completeness, lane resolution per id, /ready endpoint reports the expanded taxonomy. Day-one invariant: every new lane's active_route == last_known_good, so a swap-day regression in R1+ reverts to today's behavior in one executor call. 224 gateway unit tests pass. Per PLAN.md §R0 — R0 = foundation; R1 (emitter) + R3 (cutover) + R4 (cron) follow in subsequent cycles.
(R0) Four findings from cubic-dev-ai on the R0 PR: 1. P2 (lanes.yaml:32): comment referenced .aidlc/spec.md which is gitignored and not in the repo. Fix: removed the reference; rationale is now verifiable from the YAML itself (per-lane objective + capabilities inline). 2. P2 (route_artifacts.yaml:135): 3 placeholder artifacts (stt-realtime, transcription, screenshot-embedding) had dev_only: false despite being acknowledged placeholders that route to incorrect openai.chat_completions surfaces. Fix: dev_only: true so Evidence.is_prod_eligible() returns False for them. The 3 artifact_digest values were recomputed to match the new body. 3. P3 (lanes.yaml:31): inline comment said '14 new lanes' but 15 were added. Fix: corrected to '15 new LaneConfig entries'. 4. P3 (test_llm_gateway_config.py:14): same '14 new lanes' typo. Fix: '15'. Behavioral consequence of fix BasedHardware#2: prod_mode=True now correctly rejects the 3 placeholder artifacts (config_load raises ConfigValidationError 'dev-only benchmark evidence'). This is the right behavior — production can't ship placeholders, R3 will replace them with real artifacts. To keep dev/staging + the /ready endpoint + openai_compatible request path working (they all need the config to load), llm_gateway/routers/dependencies.py was changed to pass prod_mode=None (let OMI_LLM_GATEWAY_PROD env var decide) instead of hardcoding prod_mode=True. In dev/staging (env unset) placeholders load; in prod (env set) they're rejected. Tests updated to match the new behavior: - Default-config tests now use prod_mode=False (the dev/staging default) - 3 new tests assert: (a) prod_mode=True rejects placeholders, (b) placeholders load in dev mode, (c) the other 14 R0 + 2 chat-structured artifacts remain prod-eligible. 227 gateway unit tests pass (was 224 pre-fix; +3 new placeholder tests).
… lanes The chat-completion resolver should NOT accept non-chat lanes (audio, embedding). Per cubic-dev-ai review on PR BasedHardware#8740 (R5a+R1): SUPPORTED_AUTO_LANE_IDS now contains exactly the 13 chat-completion lanes (1 existing chat-structured + 12 R0 new lanes resolvable via chat-completions: chat-extraction, daily-summary, memories-extraction, memory-graph, conv-action-items, conv-structure, general-assistant, reasoning, screenshot-understanding, realtime-ptt, persona-chat, notification-classifier). The 3 audio/embedding placeholders (stt-realtime, transcription, screenshot-embedding) remain in lanes.yaml + route_artifacts.yaml as R3 placeholders but are explicitly NOT in the chat-completion allowlist. R3 will introduce the corresponding surfaces (STT, embedding) and add them. Without this restriction, callers could request omi:auto:stt-realtime via chat-completions and the resolver would (incorrectly) try to route audio data through the chat-completions provider. Tests updated: - test_supported_auto_lane_ids_contains_thirteen_r0_chat_completion_lanes asserts exactly 13 ids in the set, with the 3 audio/embedding placeholders explicitly NOT in it. - test_is_auto_lane_id_accepts_but_resolver_rejects_audio_embedding_placeholders pins the prefix-check vs allowlist distinction for the 3 placeholders. - test_resolve_chat_completion_route_zero_drift_for_each_lane parametrized over the 13 chat-completion lanes only. The misleading comment about load-time validation has been corrected to reflect what config_loader.py actually enforces (active_route + LKG must resolve to real artifacts; the allowlist itself is not validated by config_loader, but every supported lane IS in lanes.yaml).
…ceholders Per cubic-dev-ai P1 review on PR BasedHardware#8739: marking the 3 R0 placeholders (stt-realtime, transcription, screenshot-embedding) with dev_only: true breaks the R0 day-one shadow-mode contract because lanes.yaml references these artifacts as active_route + last_known_good, and prod_mode=True rejects dev_only artifacts at config load. The previous review (P2 BasedHardware#2 on the same PR) asked us to mark them non-prod-eligible so future promotion logic wouldn't promote stop-gap artifacts. Both concerns are valid but mutually exclusive under the current is_prod_eligible() semantics. Resolution: introduce a new Evidence.placeholder: bool = False field. Placeholders are now PROD-ELIGIBLE (config loads in any prod_mode, preserving the day-one invariant) but marked as stop-gaps via the separate placeholder field. Future promotion logic (R1 emitter, R4 cron) reads evidence.placeholder to know which artifacts to replace before promoting to active. evidence.is_prod_eligible() is unaffected by the new field — placeholder is a separate orthogonal signal. Schema change: Evidence.placeholder: bool = False in backend/llm_gateway/gateway/schemas.py. YAML changes: - 3 placeholders: dev_only: false, placeholder: true (was dev_only: true) - All 17 artifact_digests recomputed (placeholder: false for the 14 non-placeholders still affects the canonical body, since False is not None and gets included in the digest) Tests updated: - REMOVED test_r0_placeholder_artifacts_rejected_in_prod_mode (no longer rejected — they're prod-eligible now) - RENAMED test_r0_placeholder_artifacts_load_in_dev_mode -> test_r0_placeholder_artifacts_load_in_all_modes; now asserts both prod_mode=True AND prod_mode=False load all 17 artifacts (day-one invariant holds) - RENAMED test_r0_non_placeholder_artifacts_remain_prod_eligible -> test_r0_placeholder_field_distinguishes_placeholders_from_real_artifacts; asserts all 17 are prod-eligible, and that placeholder=True correctly distinguishes the 3 placeholders from the other 14 R0 + 2 existing chat-structured artifacts (placeholder=False default). Tests: 223 pass (was 227 pre-fix; net -4 from removed/renamed tests).
…tale-fallback) Cherry-picks v3's DailyRefreshCache primitive verbatim into the gateway as a public module on the request path: - backend/llm_gateway/gateway/daily_refresh.py (159 LOC, sha256 6e6897f5f0490417dd06924b32a79b0b6d2cd44b14079a20fdb37c75baf84d74) Verbatim copy of v3's backend/utils/auto_router/daily_refresh.py. Stdlib imports only (asyncio, logging, time, datetime, typing). Same as R5a's scoring.py cherry-pick discipline (byte-equivalent, verified). - backend/llm_gateway/gateway/config_loader.py Wrap yaml.safe_load in try/except yaml.YAMLError; raise ConfigValidationError. The gateway's contract is now: any YAML load failure raises ConfigValidationError. Previously a malformed YAML leaked yaml.parser.ParserError to callers. - backend/tests/unit/llm_gateway/test_daily_refresh.py (11 tests) Parity tests mirroring v3's test_auto_router_daily_refresh.py (focused subset): TTL refresh, lock contention (double-checked locking), stale fallback on loader error, invalidate(), TTL validation, and a public-namespace lint check confirming daily_refresh.py is at gateway/ (NOT _private/) since the request path uses it. Public location: daily_refresh.py lives at gateway/daily_refresh.py (not _private/) because the R5b config_reload.py uses it on the request path. This differs from R5a's scoring.py which is in _private/ (emitter-only). Per PLAN.md §R5b + §Sequencing: this is the foundation for the hot- reload cache; T-003 (config_reload.py + dependencies.py wiring) lands in the next commit.
Wraps DailyRefreshCache with mtime polling so the gateway picks up
YAML changes on the next request after merge — no pod restart required.
- backend/llm_gateway/gateway/config_reload.py
GatewayConfigReloader class:
- get() (async): check max mtime across the 3 config files; on
change, invalidate DailyRefreshCache + reload. Otherwise return
the cached GatewayConfig instance (same identity, no reload).
- _load(): called by DailyRefreshCache.get_or_refresh under the
cache lock. Reads from config_dir + sets self._cached on success.
On ConfigValidationError, raises — DailyRefreshCache does the
stale-fallback (returns last good value if cached, propagates if
first-call).
- invalidate(): test helper + admin path; clears mtime + cached +
cache.
- last_loaded_config property: diagnostic accessor.
- _max_mtime() helper: returns max st_mtime across lanes.yaml +
route_artifacts.yaml + feature_bundles.yaml (0.0 if none exist).
- backend/tests/unit/llm_gateway/test_config_reload.py (14 tests):
- _max_mtime() helper: zero on empty dir, max of existing files,
ignores unrelated files
- First-call load: 16 lanes + 17 artifacts (R0 placeholder fix)
- Cached on unchanged mtime: same object identity
- Reload on mtime change: bumps mtime, gets new instance
- Reload on any of 3 files' mtime change
- Stale fallback on ConfigValidationError (post-success)
- First-call error propagation (no cached value)
- Recovery after first-call error
- Concurrency: 5 concurrent get() calls produce 1 loader invocation
- invalidate() forces reload + clears last_loaded_config
- End-to-end: reloader works against the real default config
Per PLAN.md §R5b: 'the cache invalidation path is what makes nightly
rotation mean the next request after merge sees the new artifact
instead of restart the pod.'
T-003 (dependencies.py + route handlers) lands in the next commit.
…ready
Replaces the @lru_cache(maxsize=1) pattern on get_gateway_config with
the mtime-watched GatewayConfigReloader. The gateway now picks up YAML
changes on the next request after merge — no pod restart.
- backend/llm_gateway/routers/dependencies.py
- Module-level singleton _config_reloader pointing at DEFAULT_CONFIG_DIR.
- get_gateway_config() is now ASYNC; awaits _config_reloader.get().
- prod_mode=None (env-driven): dev/staging loads all configs;
prod rejects dev_only artifacts. R0 day-one invariant preserved.
- reset_gateway_config_reloader() helper for tests + admin paths.
- backend/llm_gateway/routers/health.py
- get_ready() is now ASYNC; awaits get_gateway_config(). The /ready
endpoint still returns 200 with sorted lane list + artifact count.
- 503 on ConfigValidationError (unchanged behavior).
TestClient transparently handles async handlers (Starlette's TestClient
calls async endpoints via asyncio.run internally), so the readiness +
openai_compatible tests pass without TestClient changes.
Tests: 248 pass (was 224 pre-R5b; +24 new: 11 daily_refresh parity +
13 config_reload behavior).
Per PLAN.md §R5b: this completes the R5b hot-reload cycle. R2
(capability smoke) and R3/R4 (gated) are next.
There was a problem hiding this comment.
5 issues found across 16 files
Confidence score: 2/5
- In
backend/llm_gateway/gateway/schemas.py, adding a default forevidence.placeholdercan change artifact content digests for existing configs that omitted the field, which can triggerartifact_digestmismatches during config load and break route startup behavior — preserve backward-compatible digest inputs (or version/migrate digest computation) before merging. - In
backend/llm_gateway/gateway/daily_refresh.py(DailyRefreshCache[T]), usingNoneas the empty-cache sentinel means realNonepayloads are treated as missing/stale, causing incorrect freshness checks and fallback behavior at runtime; thelast_loaded_atdocstring formula is also misleading and could cause incorrect maintenance assumptions — switch to a dedicated sentinel object and align the docstring/tests with the actual time semantics before merging. - In
backend/llm_gateway/gateway/resolver.py, expandingSUPPORTED_AUTO_LANE_IDSwithout validating those IDs againstlanes.yamlrisks referencing lanes that do not exist, leading to misrouting or failed auto-lane resolution when configs drift — add load-time validation that every supported ID is present (and fail fast with a clear error) before merging. - In
backend/llm_gateway/gateway/config_reload.py, synchronous config loading inside async_load()can block the event loop during reloads, which may increase latency or stall concurrent async work under load — move blocking I/O/CPU work off the loop (e.g., thread executor) or make the loader fully async before merging.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/llm_gateway/gateway/resolver.py">
<violation number="1" location="backend/llm_gateway/gateway/resolver.py:33">
P2: The hardcoded `SUPPORTED_AUTO_LANE_IDS` frozenset was expanded from 1 to 13 lane IDs, but `load_gateway_config` does not validate that all entries are actually present in `lanes.yaml`. The comment in `resolver.py` misleadingly claims `load_gateway_config` enforces this invariant, but the loader only validates `lane -> route artifact` resolution for lanes present in YAML, not that all `SUPPORTED_AUTO_LANE_IDS` members exist in YAML. If a lane is added to the frozenset but omitted from `lanes.yaml`, config loading succeeds and the failure is deferred to runtime. Add cross-file validation in `load_gateway_config` (or a parity test) to ensure every lane in `SUPPORTED_AUTO_LANE_IDS` has a corresponding config entry and valid route artifacts.</violation>
</file>
<file name="backend/llm_gateway/gateway/schemas.py">
<violation number="1" location="backend/llm_gateway/gateway/schemas.py:117">
P1: New default `evidence.placeholder` will silently change route artifact content digests for existing artifacts that omit the field, causing `artifact_digest` mismatches at config load time.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| # Distinct from `dev_only` (which excludes the artifact from production | ||
| # loading entirely). A placeholder is fully servable — it just shouldn't | ||
| # be the long-term primary. See R0 spec + PR #8739 review (cubic P1). | ||
| placeholder: bool = False |
There was a problem hiding this comment.
P1: New default evidence.placeholder will silently change route artifact content digests for existing artifacts that omit the field, causing artifact_digest mismatches at config load time.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/llm_gateway/gateway/schemas.py, line 117:
<comment>New default `evidence.placeholder` will silently change route artifact content digests for existing artifacts that omit the field, causing `artifact_digest` mismatches at config load time.</comment>
<file context>
@@ -109,8 +109,18 @@ class Evidence(StrictBaseModel):
+ # Distinct from `dev_only` (which excludes the artifact from production
+ # loading entirely). A placeholder is fully servable — it just shouldn't
+ # be the long-term primary. See R0 spec + PR #8739 review (cubic P1).
+ placeholder: bool = False
def is_prod_eligible(self) -> bool:
</file context>
| # (it validates active_route + last_known_good resolve to real artifacts). | ||
| # Adding a lane here that is missing from config is a hard error at config | ||
| # load. | ||
| SUPPORTED_AUTO_LANE_IDS = frozenset( |
There was a problem hiding this comment.
P2: The hardcoded SUPPORTED_AUTO_LANE_IDS frozenset was expanded from 1 to 13 lane IDs, but load_gateway_config does not validate that all entries are actually present in lanes.yaml. The comment in resolver.py misleadingly claims load_gateway_config enforces this invariant, but the loader only validates lane -> route artifact resolution for lanes present in YAML, not that all SUPPORTED_AUTO_LANE_IDS members exist in YAML. If a lane is added to the frozenset but omitted from lanes.yaml, config loading succeeds and the failure is deferred to runtime. Add cross-file validation in load_gateway_config (or a parity test) to ensure every lane in SUPPORTED_AUTO_LANE_IDS has a corresponding config entry and valid route artifacts.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/llm_gateway/gateway/resolver.py, line 33:
<comment>The hardcoded `SUPPORTED_AUTO_LANE_IDS` frozenset was expanded from 1 to 13 lane IDs, but `load_gateway_config` does not validate that all entries are actually present in `lanes.yaml`. The comment in `resolver.py` misleadingly claims `load_gateway_config` enforces this invariant, but the loader only validates `lane -> route artifact` resolution for lanes present in YAML, not that all `SUPPORTED_AUTO_LANE_IDS` members exist in YAML. If a lane is added to the frozenset but omitted from `lanes.yaml`, config loading succeeds and the failure is deferred to runtime. Add cross-file validation in `load_gateway_config` (or a parity test) to ensure every lane in `SUPPORTED_AUTO_LANE_IDS` has a corresponding config entry and valid route artifacts.</comment>
<file context>
@@ -15,7 +15,46 @@
+# (it validates active_route + last_known_good resolve to real artifacts).
+# Adding a lane here that is missing from config is a hard error at config
+# load.
+SUPPORTED_AUTO_LANE_IDS = frozenset(
+ {
+ 'omi:auto:chat-structured', # existing — pilot lane
</file context>
(R5b) Four findings from cubic-dev-ai on the R5b PR. P1 #1 was a false positive (digests already correct after the R0 placeholder fix in 7c82adf). The remaining 4 (P1 BasedHardware#2 + P2 BasedHardware#3/4/5) are addressed as follows: P2 BasedHardware#3 (resolver.py:33) — Add cross-validation that every lane in SUPPORTED_AUTO_LANE_IDS exists in lanes.yaml. Fix: - backend/llm_gateway/gateway/config_loader.py: load_gateway_config() now accepts an optional required_lane_ids parameter. When provided, missing lane ids raise ConfigValidationError at load time (no longer deferred to runtime). - backend/llm_gateway/gateway/config_reload.py: passes SUPPORTED_AUTO_LANE_IDS to load_gateway_config so the cross-check fires on every reload (startup AND mtime-driven reloads). - backend/llm_gateway/routers/dependencies.py: imports SUPPORTED_AUTO_LANE_IDS (no circular import — resolver imports config_loader but not dependencies). - 3 new tests: missing-id raises, satisfied-id succeeds, default-None skips cross-validation. P2 BasedHardware#4 (config_reload.py:88) — Sync config loading blocks the event loop. Fix: - backend/llm_gateway/gateway/config_reload.py: _load() now wraps the sync load_gateway_config() call in asyncio.to_thread() so the ~10-50ms yaml.safe_load + Pydantic validation runs in a threadpool instead of blocking the event loop. P1 BasedHardware#2 (daily_refresh.py:59) + P2 BasedHardware#5 (daily_refresh.py:77) — Both findings are inside the cherry-picked daily_refresh.py file. Per PLAN.md §R5a discipline, the cherry-pick is byte-equivalent to v3 (sha256 6e6897f5f0490417dd06924b32a79b0b6d2cd44b14079a20fdb37c75baf84d74 verified). Modifying it to fix the bugs would break byte-equivalence and conflict with future re-cherry-picks. DEFERRED to v3 (documented as advisory in .aidlc/review.md): - P1 BasedHardware#2: None sentinel — DailyRefreshCache uses 'None' as the cache-empty sentinel, so legitimate None payloads can't be cached (loader is re-invoked on every call; stale fallback never triggers). Real v3 bug. Our usage (DailyRefreshCache[GatewayConfig]) never has None values, so the bug doesn't manifest in our path. - P2 BasedHardware#5: docstring math is wrong — last_loaded_at + (monotonic_now() - last_loaded_at) simplifies to monotonic_now(). Just misleading docstring; doesn't affect behavior. P1 #1 (schemas.py:117) — false positive. The reviewer is concerned that adding the Evidence.placeholder field (default False) will silently change route artifact content digests for existing artifacts that omit the field. This was already addressed in commit 7c82adf ('fix: use placeholder flag instead of dev_only for R0 placeholders') which recomputed all 17 artifact_digests after adding the field. Verified post-rebase: all 17 digests in route_artifacts.yaml match the canonical body computed via RouteArtifact.model_validate(...).content_digest. Tests: 251 pass (was 248 pre-fix; +3 new cross-validation tests).
|
Thanks for the review — 4 of 5 findings addressed in commit P1 #1 (schemas.py:117) — False positive. The reviewer is concerned that adding P1 #2 (daily_refresh.py:59) — Deferred to v3. The P2 #3 (resolver.py:33) — Fixed. Added a
P2 #4 (config_reload.py:88) — Fixed. Sync config loading inside async P2 #5 (daily_refresh.py:77) — Deferred to v3. The docstring math is wrong ( Cherry-pick disciplineThe plan's R5a/R5b discipline keeps cherry-picked files byte-equivalent to v3. Two of cubic's findings (P1 #2 + P2 #5) are inside
If v3 fixes P1 #2 / P2 #5 upstream, this branch's cherry-pick will diverge and need to be re-applied. The sha256 verification at cherry-pick time catches drift; this branch's Tests251 pass (was 248 pre-fix; +3 cross-validation tests). |
…ring Per cubic-dev-ai review on PR BasedHardware#8744 (the same bug exists on v3): 1. None-sentinel bug (P1): DailyRefreshCache used None as the empty- cache sentinel, so legitimate None payloads couldn't be cached (loader was re-invoked on every call, stale fallback never triggered). Fix: introduce a private _MISSING = object() sentinel; update has_value, _is_fresh, the loader's success path, and the stale- fallback check to use `is _MISSING` / `is not _MISSING`. 2. Docstring math (P2): last_loaded_at property had a misleading formula 'last_loaded_at + (monotonic_now() - last_loaded_at)' which simplifies to `monotonic_now()` — still monotonic, not wall-clock. Fix: rewrite the docstring to honestly describe the limitation (use last_loaded_wall_time() for approximation, or have the loader record time.time() for exact wall-clock). Tests: 18 pass (was 15; +3 regression tests for None-payload caching, stale fallback with None, and the empty-cache sentinel). Note: the cherry-pick on feat/auto-router-hot-reload (PR BasedHardware#8744) will need a re-cherry-pick or the same fix applied to keep parity. v3 is the source of truth; auto-router-hot-reload was previously a verbatim copy (sha256 6e6897f5) and will diverge with this fix.
…bic fixes Propagates the cubic-dev-ai P1 BasedHardware#2 + P2 BasedHardware#5 fixes from v3 (commit `84e690464`) into the R5b cherry-pick. The cherry-pick is no longer byte-equivalent to v3's pre-fix state — it's now sourced from v3's post-fix state (sha256 `f9fed285e7d446224c19b9393f137f40591381726642e8eb084f164c204c06c1`). What's in the fix: - backend/llm_gateway/gateway/daily_refresh.py (now 168 LOC, was 159): - P1: `None` sentinel bug — introduce private `_MISSING = object()` sentinel. `has_value`, `_is_fresh`, the loader's success path, and the stale-fallback check now use `is _MISSING` / `is not _MISSING` instead of `is None` / `is not None`. Legitimate None payloads can now be cached; stale fallback correctly fires when a previously- cached None value is preserved across a failed refresh. - P2: `last_loaded_at` docstring math — the misleading formula 'last_loaded_at + (monotonic_now() - last_loaded_at) = monotonic_now()' is replaced with an honest description: monotonic clock has no wall-clock meaning; use `last_loaded_wall_time()` for approximation or have the loader record `time.time()` for exact wall-clock. - backend/tests/unit/llm_gateway/test_daily_refresh.py: - +3 regression tests for None-payload caching (TestNonePayloadCaching class): cache a None, stale-fallback a None, and the empty-cache sentinel. These tests would have failed against the pre-fix code. - Updated module docstring: documents the new sha256 + the fact that a previous verbatim copy (sha256 6e6897f5) predates this fix. Tests: 254 pass (was 251 pre-fix; +3 None-payload regressions). Cross-branch consistency: v3 source-of-truth now matches the cherry-pick. Future re-cherry-picks from v3 will be conflict-free. Per cubic-dev-ai review on PR BasedHardware#8744 (R5b).
|
Update on the P1 #2 + P2 #5 fixes — both landed (in v3 and re-cherry-picked into this PR). P1 #2 (None sentinel bug) — Fixed.
P2 #5 (docstring math) — Fixed.
Cross-branch consistency Both v3 and this branch now contain the same fix. Future re-cherry-picks from v3 are conflict-free. Tests
Cherry-pick discipline (revised) The plan's R5a/R5b discipline is to keep cherry-picked files byte-equivalent to v3. With the v3 source-of-truth fix, the cherry-pick on this branch is now in sync (both at sha256 All 5 findings on PR #8744 are now resolved. |
kodjima33
left a comment
There was a problem hiding this comment.
backend feature: llm_gateway R5b config hot-reload — approve only
|
Maintainer Review — R5b (mtime-watched config hot-reload) Thanks @choguun for the thorough work. The hot-reload design is sound — mtime polling, A few observations for human maintainer attention before merge: 1. Stacked dependency on R0 (#8739) 2. Model/provider routing surface 3. 4. Stale-fallback edge case 5. Scope expansion in config_loader.py Labels added: Not formally approving — this is a large architectural PR touching model routing with a stacked dependency. Needs human maintainer judgment on the lane taxonomy and PR sequencing. |
|
Independent Review — R5b (mtime-watched config hot-reload) Thanks @choguun for the high-quality work. The hot-reload architecture is well-designed: mtime polling via One technical finding the existing reviews haven't flagged: Test fragility: sync mock for now-async Confirmations:
Not formally approving. This is a large (2540-line) architectural PR that bundles R0 lane-taxonomy expansion (15 new lanes touching model/provider routing) alongside the R5b hot-reload mechanism, with a stacked dependency on #8739. Needs human maintainer judgment on PR sequencing and the lane taxonomy itself. |
|
Consolidated into #10089 — all 6 auto-router PRs merged sequentially with co-authorship preserved. |
|
Hey @choguun 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
Consolidates #8739 #8758 #8740 #8744 #8746 #8748. - Unified auto-router with lane catalog, serving config, route artifacts - Config reload, benchmark scoring, capability smoke checks - Lazy-loading lane catalog (no import-time I/O in request-path modules) - Cataloged public-shared-conversation-chat as prod_ready Failure-Class: none
Consolidates #8739 #8758 #8740 #8744 #8746 #8748. - Unified auto-router with lane catalog, serving config, route artifacts - Config reload, benchmark scoring, capability smoke checks - Lazy-loading lane catalog (no import-time I/O in request-path modules) - Cataloged public-shared-conversation-chat as prod_ready Failure-Class: none
Consolidates #8739 #8758 #8740 #8744 #8746 #8748. - Unified auto-router with lane catalog, serving config, route artifacts - Config reload, benchmark scoring, capability smoke checks - Lazy-loading lane catalog (no import-time I/O in request-path modules) - Cataloged public-shared-conversation-chat as prod_ready Failure-Class: none
Summary
R5b of the auto-router-on-LLM-gateway feature. Replaces the
@lru_cache(maxsize=1)pattern onget_gateway_configwith an mtime-watched config reloader. The gateway now picks up YAML changes on the next request after merge — no pod restart required. : "the cache invalidation path is what makes 'nightly rotation' mean 'the next request after merge sees the new artifact' instead of 'restart the pod.'"This branch is independent of R5a+R1 (PR #8740, in review) and can land in parallel. Rebased onto the latest R0 fixes from PR #8739.
What this PR delivers
backend/llm_gateway/gateway/daily_refresh.py(NEW, 159 LOC)Verbatim cherry-pick of v3's
backend/utils/auto_router/daily_refresh.py(sha2566e6897f5f0490417dd06924b32a79b0b6d2cd44b14079a20fdb37c75baf84d74verified). ProvidesDailyRefreshCache[T]— a generic TTL +asyncio.Lock+ stale-fallback primitive.Public module (lives at
gateway/daily_refresh.py, NOT_private/). The request path uses it viaconfig_reload.py, so it must be public. A lint test enforces this constraint — seeTestPublicNamespace.test_daily_refresh_NOT_in_private_namespace. This differs from R5a's scoring.py which IS in_private/(only emitter uses it).backend/llm_gateway/gateway/config_reload.py(NEW)GatewayConfigReloader— wrapsDailyRefreshCachewith mtime polling:async get()— checks max mtime acrosslanes.yaml+route_artifacts.yaml+feature_bundles.yaml; on change, invalidates the cache + reloads; otherwise returns the cached instance (same identity, no reload)ConfigValidationError— serves the last good config (DailyRefreshCache handles this)invalidate()— admin/test helperlast_loaded_config— diagnostic accessorbackend/llm_gateway/routers/dependencies.py(MODIFY)Replaced
@lru_cache(maxsize=1)with the module-level_config_reloadersingleton pointing atDEFAULT_CONFIG_DIR.get_gateway_config()is now async; awaits_config_reloader.get().prod_mode=None(env-driven: OMI_LLM_GATEWAY_PROD env var decides) — preserves R0's day-one invariant.backend/llm_gateway/routers/health.py(MODIFY)get_ready()is now async; awaitsget_gateway_config(). Returns 200 with sorted lane list + artifact count, 503 onConfigValidationError(unchanged behavior).backend/llm_gateway/gateway/config_loader.py(MODIFY — small hardening)Wrap
yaml.safe_loadintry/except yaml.YAMLErrorand re-raise asConfigValidationError. The gateway's error contract is now: any YAML load failure raisesConfigValidationError. Previously malformed YAML leakedyaml.parser.ParserErrorto callers — which broke the reloader's stale-fallback semantics (it can't fallback on an exception type it doesn't know about).Tests (24 new tests, 248 total)
backend/tests/unit/llm_gateway/test_daily_refresh.py(11 tests) — parity tests mirroring v3'stest_auto_router_daily_refresh.py(focused subset): TTL refresh, lock contention (double-checked locking), stale fallback on loader error,invalidate(), TTL validation, public-namespace lint.backend/tests/unit/llm_gateway/test_config_reload.py(14 tests) — behavior tests:_max_mtime()helper, first-call load, cached on unchanged mtime, reload on mtime change (any of 3 files), stale fallback, first-call error propagation, recovery, concurrency,invalidate(), end-to-end against real config.Day-one invariants
daily_refresh.pysha256 matches v3's exactly. Drift would be silent breakage; future re-cherry-picks must update both file and parity tests.daily_refresh.pyis atgateway/daily_refresh.py(public),scoring.pyis atgateway/_private/scoring.py(private to emitter). The boundary is enforced by a lint test._private/scoring.py.os.stat()calls (microseconds); only on mtime change does it reload (~10-50ms cold). On hot path, returns the sameGatewayConfiginstance (verified byassert cfg1 is cfg2).ConfigValidationError, serves the last good config. Operations team sees a WARNING log; gateway stays up.Validation gates (all met)
daily_refresh.pybyte-equivalent to v3 (sha256 verified)_private/invariant still holdsget()ConfigValidationErrorpost-success → serve last goodConfigValidationErrorfirst call → propagateget()→ 1 loader invocation/readyendpointHow to test locally
Risks
config_loader.pymodification: I wrappedyaml.safe_loadto convertyaml.YAMLErrortoConfigValidationError. This is a behavior change beyond R5b's strict scope but necessary for the reloader to surface YAML errors uniformly (otherwise the reloader can't do stale-fallback on YAML parse errors — they'd be uncaught). The change is small and adds clarity to the gateway's error contract.get_readyasync cascading: makingget_gateway_configasync requiredget_readyto also be async. TestClient (Starlette) handles async-from-sync bridging transparently — no test client changes needed.Next PRs after this merges
cc: gateway owners team for review