Repository navigation
Description
Summary
Give the in-flight LLM gateway feature-mode migration an enforced exit: define the end state in which direct client construction and per-call-site provider decisions in backend/utils/llm/ are deleted, and a single profile resolver owns feature→(provider, model, lane, credential scope). Without this, the gateway becomes a new canonical serving plane sitting next to the old selection logic — exactly the migration-without-an-exit failure mode diagnosed in #9515 and being fixed for conversations in #9516.
This is an exit-criteria / tracking issue, not a new refactor competing with the gateway work. The gateway migration continues as planned; this issue pins what "done" means.
Current state (verified in tree)
- The migration is real and gated:
OMI_LLM_GATEWAY_FEATURE_MODE(utils/llm/gateway_client.py:23), withshould_route_features_through_gateway()blocked outside dev/local without explicit override. utils/llm/is the highest-churn backend package (120 commits since 2026-05-15) and splits provider decisions across:clients.py(~25K): BYOK client creation branches,should_route_features_through_gateway()conditionals at ~lines 205/448/628/642, and module-level eager clients (llm_mini = ChatOpenAI(...)atclients.py:605) constructed at import — also a grandfathered violation of the import-purity rule in AGENTS.md.model_config.py:MODEL_QOSprofiles,_PINNED_FEATURES,_ANTHROPIC_ONLY_FEATURES,_PERPLEXITY_ONLY_FEATURES, structured-output feature sets.gateway_client.py/gateway_byok.py/gateway_shadow.py/gateway_serving.py/gateway_anthropic.py,providers.py,fair_use_classifier.py.
- The gateway absorbs the serving half (client construction, provider calls). The selection policy half (feature→model/lane mapping, BYOK scoping, pinned features) lives in
model_config.py/clients.pyand will not move on its own.
Exit criteria (the definition of "migration complete")
- One profile resolver owns feature→execution profile:
{provider, model, lane, credential scope}. Every LLM call site consumes a resolved profile; none re-derive provider/model/BYOK/gateway decisions inline. -
should_route_features_through_gateway()and its call-site branches are deleted once feature mode is the default — not left as a permanent dual path. - Module-level eager LLM clients in
clients.py(e.g.llm_miniat line 605) are removed or made lazy per the import-purity rule; the import-purity guard baseline shrinks accordingly. - Direct provider client construction outside the resolver/gateway path is deleted; a CI guard fails on new
ChatOpenAI(/anthropic.constructions outside the sanctioned modules. Ratchet to zero. - Lane/provider fallbacks flow through
record_fallbackper the AGENTS.md fallback-telemetry contract (no new one-off counters). - Shadow/serving comparison scaffolding (
gateway_shadow.py) carriesLIFECYCLE:/DELETE-AFTER:headers per the rollout-scaffolding rule, or is deleted at exit. - AGENTS.md service map +
docs/doc/developer/updated to describe the final single-resolver architecture, not migration phases. - The desktop Backend-Rust lane decision below is recorded and implemented — the migration is not "exited" while a fourth policy authority can silently drift.
Desktop Backend-Rust lane (fourth policy authority)
LLM provider/model/BYOK policy currently lives in four places, not two: (1) backend/utils/llm/ selection policy, (2) backend/llm_gateway/ serving plane, (3) desktop/macos/Backend-Rust/src/ — verified in tree: llm/model_qos.rs (12.6K) is a hand-maintained second implementation of the MODEL_QOS profiles in model_config.py, alongside independent BYOK (byok.rs, 23.7K), Vertex routing (vertex.rs), provider fallback (fallback.rs), and the desktop serving lane (routes/chat_completions.rs ~100K, routes/proxy.rs ~82K) — and (4) desktop bridge/harness modes, being converged by #9515 domain 6. Backend-Rust has 75 commits since 2026-05-15, so the drift surface between model_qos.rs and model_config.py is live and only caught by human review.
Decision required (pick one, record it here):
- (a) Gateway as the single serving/policy plane for desktop too. The Rust backend proxies LLM traffic to
llm-gateway;model_qos.rsand duplicated BYOK/provider policy are deleted. Rust keeps only transport/auth/paywall concerns it genuinely owns. - (b) Rust lane as a declared bounded owner for desktop. The policy artifact is shared, not duplicated: QoS profiles / pinned features / provider constraints generated from one canonical source consumed by both
model_config.pyandmodel_qos.rs, with a CI drift check that fails when either side diverges.
Evaluation inputs: desktop latency budget for an extra gateway hop, BYOK key locality (keys that must not transit the gateway), offline/local-model paths, and paywall/rate-limit coupling in routes/rate_limit.rs.
Rust-lane exit criteria:
- Decision (a) or (b) recorded with the evaluation inputs above.
- Zero hand-maintained duplicate policy tables:
model_qos.rsvsmodel_config.pydrift is mechanically impossible (deleted, or generated + CI drift check) — not just reviewed for. - BYOK/credential-scope policy has one authoritative definition; the other lane consumes or proxies it.
- Rust-lane provider fallbacks flow through the existing
fallback::record_fallbackfixed-field contract (present infallback.rs; verify byok/vertex branch coverage). - Non-goal preserved: the Rust backend's non-LLM concerns (auth, updates, webhooks, screen activity) and realtime voice transport selection stay put.
Cross-stack note
The resolved profile concept is the same shape as SessionExecutionProfile in #9515 (domain 6, desktop). Where practical, align the schema so desktop session profiles and backend feature profiles are one concept end-to-end rather than two vocabularies.
Non-goals
- Accelerating or redesigning the gateway rollout itself.
- Changing model/provider policy — only making existing policy canonical and singly-owned.
- Touching realtime voice transport provider selection (desktop-owned; see refactor(macOS): converge chat, PTT, agents, tools, and continuity onto single owners #9515).
Related
- refactor(macOS): converge chat, PTT, agents, tools, and continuity onto single owners #9515 — macOS convergence (execution-profile domain and the "no compatibility seam survives merge" rule).
- refactor(backend): converge conversation lifecycle onto a single mutation owner #9516 — backend conversation lifecycle convergence (same governing rule, different subsystem).
- refactor(cross-stack): one LLM policy source of truth — retire hand-duplicated model_qos.rs vs model_config.py (follow-up to #9517) #9531 — closed, consolidated into this issue (Rust-lane scope now lives here).
Activity
Git-on-my-level commentedon Jul 12, 2026
Update: this scope now lives in the issue body ("Desktop Backend-Rust lane" section) — decision options, evaluation inputs, and exit criteria included. #9531 was briefly split out and then consolidated back here; it is closed.
aryanorastar commentedon Aug 6, 2026
VERIFY — PARKED (maintainer tracking / decision gate)
Re-checked 2026-08-06 on
origin/main.What this issue is: exit-criteria / tracking for the LLM gateway feature-mode migration (label:
maintainer), not a standalone contributor refactor. The body already pins the exit checklist and the Desktop Backend-Rust fourth-authority decision (a/b/…).Tree pulse (not “done”):
should_route_features_through_gateway()still branches inbackend/utils/llm/clients.py.llm_miniconstruction appears partially addressed (_LazyClientProxy/_create_legacy_llm_mini) — progress, not exit.No PR from me: executing the exit (delete dual path, ratchet CI guards, retire shadow scaffolding, pick/implement desktop policy plane) is migration ownership + an explicit maintainer architecture decision. Happy to take a narrow follow-up if maintainers pick a slice (e.g.
LIFECYCLE:/DELETE-AFTER:headers ongateway_shadow.py, or a CI ratchet PR after the Rust decision is recorded).