Skip to content

feat(gateway): infer provider from configured model families - #64988

Closed
neofdezf-cloud wants to merge 1 commit into
openclaw:mainfrom
neofdezf-cloud:neo/model-family-provider-routing
Closed

neofdezf-cloud wants to merge 1 commit into
openclaw:mainfrom
neofdezf-cloud:neo/model-family-provider-routing

Conversation

@neofdezf-cloud

Copy link
Copy Markdown

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

  • adds a normalization step on top of resolveSessionModelRef()
  • infers provider from configured model families when a canonical model name maps uniquely in config
  • preserves explicit providerOverride selections from the user
  • preserves fully-qualified provider/model refs without rewriting them
  • adds focused tests for canonical-model inference and explicit-provider preservation

Why

OpenClaw already resolves default/session model refs, but canonical model names like gpt-5.4 can 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" + configured openai-codex/gpt-5.4
    → resolves to openai-codex/gpt-5.4
  • providerOverride: "openai" + modelOverride: "gpt-5.4"
    → stays on openai/gpt-5.4
  • modelOverride: "anthropic/claude-opus-4-1"
    → preserved as-is

Tests

  • src/gateway/session-utils.model-family-routing.test.ts
  • src/gateway/session-utils.search.test.ts

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Apr 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1049 to +1051
if (normalizedModel.includes("/")) {
const parsed = parseModelRef(normalizedModel, params.ref.provider || DEFAULT_PROVIDER);
if (parsed) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +1079 to +1083
if (!params.ref.provider || params.ref.provider === DEFAULT_PROVIDER) {
return {
provider: inferredProvider,
model: normalizedModel,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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-apps

greptile-apps Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds normalizeResolvedSessionModelRef to resolveSessionModelRef so that a bare canonical model name (e.g. gpt-5.4) routes to the unique configured provider when the config makes the mapping unambiguous. The inference logic and explicit-override preservation work correctly for fresh sessions with no stored state.

Two untested edge cases are worth addressing before merging:

  • When entry.modelProvider is set (common for any session that has run at least once), the runtimeProvider early-return at lines 1073-1078 bypasses inference entirely — the new feature silently doesn't apply to existing sessions.
  • When both a providerOverride and a fully-qualified modelOverride (e.g. \"openai/gpt-5.4\") are present, the slash-parse path re-parses the model and discards the providerOverride.

Confidence Score: 4/5

Safe 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 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.

---

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

Comment on lines +1065 to +1078
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,
};
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Comment on lines +1049 to +1054
if (normalizedModel.includes("/")) {
const parsed = parseModelRef(normalizedModel, params.ref.provider || DEFAULT_PROVIDER);
if (parsed) {
return parsed;
}
return params.ref;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

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 details

Best 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:

  • stale F-rated PR: PR was opened 2026-04-11T19:53:23Z, is older than 30 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Recent commits separated selected session model resolution, added bare configured-provider inference for defaults, and refactored shared model-selection helpers adjacent to this PR's target contract. (role: recent model-selection contributor; confidence: high; commits: 1fb44f0aadd4, 1392a78c757a, 310d2db31241; files: src/gateway/session-utils.ts, src/agents/model-selection.ts, src/agents/model-selection-shared.ts)
  • dndodson: The selected-model compatibility behavior for vendor-prefixed models appears to date to the merged wrapper-provider preservation commit. (role: introduced wrapper-provider preservation; confidence: high; commits: 4cad67438784; files: src/gateway/session-utils.ts, src/gateway/session-utils.test.ts)
  • luoyanglang: Authored adjacent session-status work that inferred custom runtime providers from config and added tests near this provider inference surface. (role: adjacent provider-inference contributor; confidence: medium; commits: 40b24dfa6b6c; files: src/agents/model-selection.ts, src/agents/model-selection.test.ts, src/gateway/session-utils.test.ts)
  • vincentkoc: Recent commits hardened malformed persisted model handling and gateway session metadata near the selected-model path. (role: recent gateway/session contributor; confidence: medium; commits: 96886381a3b5, a0e0bf58486d, 92492ecdd00e; files: src/gateway/session-utils.ts, src/gateway/session-utils.test.ts, src/agents/model-selection.test.ts)

Codex review notes: model internal, reasoning high; reviewed against 6c88811b4bba.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels May 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 19, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@RomneyDa

Copy link
Copy Markdown
Member

Heads up: this PR needs to be updated against current main before the new required Dependency Guard check can pass.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 13, 2026
@clawsweeper

clawsweeper Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants