Skip to content

chore(backend): define enforced exit criteria for the LLM gateway feature-mode migration (retire direct provider selection in utils/llm) #9517

Open

Description

@Git-on-my-level

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), with should_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(...) at clients.py:605) constructed at import — also a grandfathered violation of the import-purity rule in AGENTS.md.
    • model_config.py: MODEL_QOS profiles, _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.py and 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_mini at 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_fallback per the AGENTS.md fallback-telemetry contract (no new one-off counters).
  • Shadow/serving comparison scaffolding (gateway_shadow.py) carries LIFECYCLE: / 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.rs and 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.py and model_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.rs vs model_config.py drift 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_fallback fixed-field contract (present in fallback.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

Related

Activity

  1. added
    backend
    maintainer
    on Jul 12, 2026
  2. Git-on-my-level commented on Jul 12, 2026

    @Git-on-my-level
    MemberAuthor

    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.

  3. aryanorastar commented on Aug 6, 2026

    @aryanorastar
    Collaborator

    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”):

    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 on gateway_shadow.py, or a CI ratchet PR after the Rust decision is recorded).

  4. added
    docs-tooling
    p3
    intelligence
    and removed
    docs-tooling
    p3
    intelligence
    on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backenddesktopdocs-toolingmacOSmaintainerp3pythonrefactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions