Repository navigation
feat(gateway): infer provider from configured model families - #64988
neofdezf-cloud wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cfb1e861ae
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (normalizedModel.includes("/")) { | ||
| const parsed = parseModelRef(normalizedModel, params.ref.provider || DEFAULT_PROVIDER); | ||
| if (parsed) { |
There was a problem hiding this comment.
Preserve wrapper provider for slash-prefixed override models
normalizeResolvedSessionModelRef reparses any model containing / before checking explicit overrides, so a selected wrapper provider can be silently replaced by the vendor prefix embedded in the model string. For a session like providerOverride: "openrouter" with modelOverride: "anthropic/claude-haiku-4.5", this now returns anthropic/claude-haiku-4.5 instead of keeping openrouter as the provider, which changes routing behavior for wrapper providers and contradicts the existing wrapper-preservation contract.
Useful? React with 👍 / 👎.
| if (!params.ref.provider || params.ref.provider === DEFAULT_PROVIDER) { | ||
| return { | ||
| provider: inferredProvider, | ||
| model: normalizedModel, | ||
| }; |
There was a problem hiding this comment.
Infer provider regardless of which default provider is configured
The new inference path only applies when params.ref.provider is empty or equal to DEFAULT_PROVIDER (openai). If an agent’s default provider is something else (for example anthropic) and the override model is an unqualified canonical id that uniquely maps to another configured provider, the inference is skipped and the session remains pinned to the wrong default provider. This makes model-family routing fail for non-OpenAI default setups.
Useful? React with 👍 / 👎.
Greptile SummaryAdds Two untested edge cases are worth addressing before merging:
Confidence Score: 4/5Safe to merge with low risk for fresh sessions; existing sessions with a stored modelProvider silently won't benefit from the new routing. Both findings are P2 — no production breakage, but the runtimeProvider branch limits the feature's real-world coverage in a non-obvious way that is untested. The slash-providerOverride conflict is a regression for a narrow edge case. No security concerns found. src/gateway/session-utils.ts — normalizeResolvedSessionModelRef's runtimeProvider branch and slash-parse path Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/gateway/session-utils.ts
Line: 1065-1078
Comment:
**`runtimeProvider` branch may silently suppress inference for existing sessions**
When a session has a stored `modelProvider` (i.e. `entry.modelProvider` is non-empty — common for any session that has executed at least once), the `runtimeProvider` branch fires before the `DEFAULT_PROVIDER` check, preventing model-family inference from ever kicking in. The feature described in the PR only applies to sessions without a stored provider.
This is also likely redundant: `resolvePersistedSelectedModelRef` is called with `overrideProvider` taking priority; if no `overrideProvider` is set, `ref.provider` will already equal `runtimeProvider`, so the final `else` branch at line 1086 would return the same value anyway.
Consider whether inference should be allowed to override a stale `modelProvider` (fallback-default provider), and add a test that covers `entry.modelProvider` being set alongside `modelOverride`.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/gateway/session-utils.ts
Line: 1049-1054
Comment:
**Slash-qualified `modelOverride` silently drops a concurrent `providerOverride`**
When both `providerOverride` (e.g. `"azure-openai"`) and a fully-qualified `modelOverride` (e.g. `"openai/gpt-5.4"`) are set, `resolvePersistedSelectedModelRef` returns `{ provider: "azure-openai", model: "openai/gpt-5.4" }`. This function then re-parses `"openai/gpt-5.4"` and returns `{ provider: "openai", model: "gpt-5.4" }` — silently discarding the `providerOverride`. Before this PR, the function returned the raw persisted ref without re-parsing.
The `entry?.providerOverride` check at lines 1065–1071 is never reached for slash refs. If the intent is to honour `providerOverride` uniformly, the check should guard the slash-parse path too — or the slash path should only run when `providerOverride` is absent.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Infer provider from configured model fam..." | Re-trigger Greptile |
| const explicitOverrideProvider = params.entry?.providerOverride?.trim(); | ||
| const runtimeProvider = params.entry?.modelProvider?.trim(); | ||
| if (explicitOverrideProvider) { | ||
| return { | ||
| provider: explicitOverrideProvider, | ||
| model: normalizedModel, | ||
| }; | ||
| } | ||
| if (runtimeProvider) { | ||
| return { | ||
| provider: runtimeProvider, | ||
| model: normalizedModel, | ||
| }; | ||
| } |
There was a problem hiding this comment.
runtimeProvider branch may silently suppress inference for existing sessions
When a session has a stored modelProvider (i.e. entry.modelProvider is non-empty — common for any session that has executed at least once), the runtimeProvider branch fires before the DEFAULT_PROVIDER check, preventing model-family inference from ever kicking in. The feature described in the PR only applies to sessions without a stored provider.
This is also likely redundant: resolvePersistedSelectedModelRef is called with overrideProvider taking priority; if no overrideProvider is set, ref.provider will already equal runtimeProvider, so the final else branch at line 1086 would return the same value anyway.
Consider whether inference should be allowed to override a stale modelProvider (fallback-default provider), and add a test that covers entry.modelProvider being set alongside modelOverride.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/session-utils.ts
Line: 1065-1078
Comment:
**`runtimeProvider` branch may silently suppress inference for existing sessions**
When a session has a stored `modelProvider` (i.e. `entry.modelProvider` is non-empty — common for any session that has executed at least once), the `runtimeProvider` branch fires before the `DEFAULT_PROVIDER` check, preventing model-family inference from ever kicking in. The feature described in the PR only applies to sessions without a stored provider.
This is also likely redundant: `resolvePersistedSelectedModelRef` is called with `overrideProvider` taking priority; if no `overrideProvider` is set, `ref.provider` will already equal `runtimeProvider`, so the final `else` branch at line 1086 would return the same value anyway.
Consider whether inference should be allowed to override a stale `modelProvider` (fallback-default provider), and add a test that covers `entry.modelProvider` being set alongside `modelOverride`.
How can I resolve this? If you propose a fix, please make it concise.| if (normalizedModel.includes("/")) { | ||
| const parsed = parseModelRef(normalizedModel, params.ref.provider || DEFAULT_PROVIDER); | ||
| if (parsed) { | ||
| return parsed; | ||
| } | ||
| return params.ref; |
There was a problem hiding this comment.
Slash-qualified
modelOverride silently drops a concurrent providerOverride
When both providerOverride (e.g. "azure-openai") and a fully-qualified modelOverride (e.g. "openai/gpt-5.4") are set, resolvePersistedSelectedModelRef returns { provider: "azure-openai", model: "openai/gpt-5.4" }. This function then re-parses "openai/gpt-5.4" and returns { provider: "openai", model: "gpt-5.4" } — silently discarding the providerOverride. Before this PR, the function returned the raw persisted ref without re-parsing.
The entry?.providerOverride check at lines 1065–1071 is never reached for slash refs. If the intent is to honour providerOverride uniformly, the check should guard the slash-parse path too — or the slash path should only run when providerOverride is absent.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/session-utils.ts
Line: 1049-1054
Comment:
**Slash-qualified `modelOverride` silently drops a concurrent `providerOverride`**
When both `providerOverride` (e.g. `"azure-openai"`) and a fully-qualified `modelOverride` (e.g. `"openai/gpt-5.4"`) are set, `resolvePersistedSelectedModelRef` returns `{ provider: "azure-openai", model: "openai/gpt-5.4" }`. This function then re-parses `"openai/gpt-5.4"` and returns `{ provider: "openai", model: "gpt-5.4" }` — silently discarding the `providerOverride`. Before this PR, the function returned the raw persisted ref without re-parsing.
The `entry?.providerOverride` check at lines 1065–1071 is never reached for slash refs. If the intent is to honour `providerOverride` uniformly, the check should guard the slash-parse path too — or the slash path should only run when `providerOverride` is absent.
How can I resolve this? If you propose a fix, please make it concise.|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep this PR open, but not merge-ready: the requested provider inference is still not fully implemented on current main, and the branch introduces source-confirmed selected-model routing regressions plus missing real behavior proof. Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. So I’m closing this here because the remaining work is already tracked in the canonical issue. Review detailsBest possible solution: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. Do we have a high-confidence way to reproduce the issue? Yes for the PR defects: source inspection of the proposed helper and current resolver contracts shows the providerOverride, stored-provider, and non-OpenAI-default cases. No live configured OpenClaw run was performed in this read-only review. Is this the best way to solve the issue? No. The requested behavior is useful, but a gateway-only post-processor is not the best current shape until it is reconciled with shared selected-model resolution and current wrapper-provider/runtime semantics. Security review: Security review cleared: The diff touches gateway model-selection TypeScript and tests only, with no dependency, workflow, secret-handling, script, or package changes. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 6c88811b4bba. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
Heads up: this PR needs to be updated against current |
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper applied the proposed close for this PR.
|
Adds a small model-family routing normalization step to
resolveSessionModelRef()so canonical model names can resolve to the correct configured provider when that mapping is unique.What changed
resolveSessionModelRef()providerOverrideselections from the userprovider/modelrefs without rewriting themWhy
OpenClaw already resolves default/session model refs, but canonical model names like
gpt-5.4can still rely too heavily on the default provider when the config already makes the intended provider unambiguous.This PR improves that specific case without redesigning the broader model fallback system.
Examples
modelOverride: "gpt-5.4"+ configuredopenai-codex/gpt-5.4→ resolves to
openai-codex/gpt-5.4providerOverride: "openai"+modelOverride: "gpt-5.4"→ stays on
openai/gpt-5.4modelOverride: "anthropic/claude-opus-4-1"→ preserved as-is
Tests
src/gateway/session-utils.model-family-routing.test.tssrc/gateway/session-utils.search.test.ts