Repository navigation
fix(gateway): judge a rewritten model by the name it sends; tell Codex and Gemini conversations apart - #215
Merged
Merged
Conversation
…x and Gemini conversations apart Model admission, skipping candidates that cannot serve a request, and cheapest-group pricing all looked at the model the client wrote, before any routing rule rewrote it. A rule that renames claude-* to glm-* (which Claude Desktop needs for any non-Claude upstream) was therefore rejected whenever the target upstream publishes a model list: "No upstream serves model ...". - Admission now runs after the rule decision and checks the model each candidate will actually be asked for, including per-upstream (phase-two) rewrites. New codes gw.model.no_upstream_rewritten and gw.model.not_allowed_rewritten name both the requested and the rewritten model. - The serving filter, cheapest pricing and the routing dry run use the same per-candidate models (Engine::models_asked, Engine::phase_two_with). Session fingerprints only read Anthropic/Chat bodies (system + messages), so every Codex (Responses) and Gemini request had none: session-affine groups pinned all of them to the first member, and traffic never grouped them into sessions. The fingerprint now reads instructions/input and systemInstruction/contents, and prefers the request's own prompt_cache_key (Codex sends one per conversation), since Codex conversations in the same repository start with identical text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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.
Two gateway bugs
1. A routing rule that rewrites the model never worked against an upstream with a model list
Model admission (
admit), the serving filter (models::serving) and cheapest-group pricing all used the model the client wrote, before any rule rewrote it. So a rule such asclaude-* → set model glm-5, to zhipuwas rejected withNo upstream serves model claude-…(or the candidate was skipped as "does not offer this model") whenever the target upstream publishes/v1/models. It only worked with upstreams that have no list.This matters because Lite tells users to write exactly this rule: Claude Desktop only accepts Claude-like model names, so any non-Claude upstream needs it; the Antigravity CLI and DeepSeek Harness takeover notes suggest it too.
Fix:
Engine::models_askedlists the model each candidate will actually be asked for: phase-two (provider_would_be) rewrites over phase-one rewrites over the request's own model.Engine::phase_two_withtakes a rule table so the dry run can evaluate drafts.gw.model.no_upstream_rewritten/gw.model.not_allowed_rewrittenname both models.serving,unit_pricesand the routing dry run take the per-candidate models.2. Codex and Gemini requests had no session fingerprint
session::fingerprintonly readsystem+messages. Responses bodies (instructions+input) and Gemini bodies (systemInstruction+contents) gotNone, so:The fingerprint now reads all four formats and prefers the request's own
prompt_cache_key(Codex sends its conversation id there). Text alone would merge Codex conversations started in the same repository, whose opening instructions and environment context are identical.Tests
tw-gateway/tests/models.rs: a phase-one rename against a listed upstream; a phase-two rename for one member of a group; a rename to a model nobody serves names both models.tw-control/tests/models.rs: the dry run judges a candidate by the rewritten model.session.rs: Responses and Gemini conversations keep their fingerprint as they grow;prompt_cache_keyseparates conversations with identical openings.cargo fmt --check,cargo clippy --workspace --all-targets -D warningsandcargo test --workspacepass locally. No control-protocol change;tw-dialect/tw-guard/tw-breakerare untouched.🤖 Generated with Claude Code