Skip to content

fix(gateway): use default agent model for session defaults#50210

Closed
lc708 wants to merge 3 commits into
openclaw:mainfrom
lc708:codex/fix-session-default-agent-model
Closed

fix(gateway): use default agent model for session defaults#50210
lc708 wants to merge 3 commits into
openclaw:mainfrom
lc708:codex/fix-session-default-agent-model

Conversation

@lc708

@lc708 lc708 commented Mar 19, 2026

Copy link
Copy Markdown

Summary

Fixes #50156.

sessions.list.defaults was resolving the fallback model from the global hardcoded default path, which ignored the default agent's effective model.primary. In Control UI this surfaced as a misleading extra "Default (...)" choice when a single configured agent had its own primary model.

This changes getSessionDefaults() to resolve through resolveDefaultModelForAgent() using the repo's default agent id, so the gateway reports the same primary model the default agent will actually run.

Changes

  • src/gateway/session-utils.ts: resolve session defaults from the default agent's effective model instead of the hardcoded global fallback path.
  • src/gateway/session-utils.test.ts: add a regression test covering a default agent with model.primary = minimax/MiniMax-M2.5 and no global agents.defaults.model.primary.

Test plan

  • pnpm exec oxfmt --check src/gateway/session-utils.ts src/gateway/session-utils.test.ts
  • Attempted: pnpm test -- src/gateway/session-utils.test.ts -t "getSessionDefaults prefers the default agent primary model over the hardcoded fallback"
    • Blocked locally by an existing dependency skew in this checkout: node_modules/@mariozechner/pi-ai is still linked to 0.54.1, so the suite fails during import on @mariozechner/pi-ai/oauth before the test runs.

AI-assisted

This PR was authored with AI assistance. I reviewed the change and verified the root cause in code before submitting.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Mar 19, 2026
@greptile-apps

greptile-apps Bot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug in getSessionDefaults() where the session defaults were resolving the model through the hard-coded global fallback path (resolveConfiguredModelRef with DEFAULT_PROVIDER/DEFAULT_MODEL) rather than through the default agent's effective primary model. The result was that the Control UI showed a misleading extra "Default (...)" entry when a single configured agent had its own model.primary.

The fix is a focused one-liner: resolveConfiguredModelRef(…) is replaced with resolveDefaultModelForAgent({ cfg, agentId: resolveDefaultAgentId(cfg) }). Because resolveDefaultModelForAgent already falls back to DEFAULT_PROVIDER/DEFAULT_MODEL when no agent is configured or the agent carries no primary model, repos without any agent configuration continue to behave identically.

Key changes:

  • src/gateway/session-utils.ts: getSessionDefaults now delegates to resolveDefaultModelForAgent using the repo's resolved default agent id, aligning the reported defaults with what the agent will actually run.
  • src/gateway/session-utils.test.ts: Regression test added for a default agent with model.primary = "minimax/MiniMax-M2.5" and no global agents.defaults.model.primary, verifying the correct provider/model are surfaced. The PR author notes the test could not be executed locally due to an existing unrelated dependency skew (@mariozechner/pi-ai version mismatch), so CI validation is important before merging.

Confidence Score: 4/5

  • This PR is safe to merge after CI confirms the new regression test passes.
  • The change is minimal and tightly scoped — a single call-site swap in getSessionDefaults. The replacement function (resolveDefaultModelForAgent) already exists and is exercised elsewhere in the codebase, and its internal fallback path preserves backwards-compatible behavior for repos without explicit agent configs. A targeted regression test is included. The only reason this isn't a 5 is that the PR author explicitly states the test was not executed locally due to a dependency skew, so CI validation is the remaining gating step.
  • No files require special attention beyond CI confirming the new test in src/gateway/session-utils.test.ts passes.

Last reviewed commit: "Gateway: use default..."

@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: 3799485f90

ℹ️ 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 thread src/gateway/session-utils.ts Outdated

@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: 2d0e254a91

ℹ️ 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 899 to 900
const contextTokens =
cfg.agents?.defaults?.contextTokens ??

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 Resolve session default contextTokens from the selected agent

This now resolves defaults.model from the requested/default agent, but defaults.contextTokens still comes from cfg.agents?.defaults?.contextTokens. In configs where the selected agent overrides model.primary (or has its own context cap), sessions.list will return a mixed pair: agent B's model with the global/default-agent context window. src/tui/tui-status-summary.ts:54-59 renders these fields together as the “Default model” line, so filtered views and single-agent installs can advertise the wrong context size. The runtime path already resolves caps as agentCfg?.contextTokens ?? lookupContextTokens(model) in src/auto-reply/reply/model-selection.ts:603-609, so getSessionDefaults() should derive the cap from the same effective agent config.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 28, 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 open: this targets a real gateway/UI default-model bug, but the branch is stale, conflicted, lacks real behavior proof, and now misses current-main sessions.list paths and default metadata behavior.

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, source-level. Current main still builds sessions.list defaults from global configured defaults while Control UI uses those defaults for its Default (...) model label and option list; I did not run a live Control UI repro in this read-only review.

Is this the best way to solve the issue?

No. The main direction is right, but the branch needs a current-main rebase, complete default metadata handling, async sessions.list coverage, hook-scope split, and real behavior proof before it is the best fix.

Security review:

Security review needs attention: The gateway fix itself is not security-sensitive, but the PR also changes hook handler path selection in a command-execution boundary.

  • [medium] Unrelated hook handler path boundary change — src/hooks/workspace.ts:132
    src/hooks/workspace.ts changes handlerPath to a constructed canonical-base path rather than preserving the path returned by the boundary-open helper; this should be split or proven before merging with a gateway model fix.
    Confidence: 0.72

What I checked:

  • stale F-rated PR: PR was opened 2026-03-19T04:45:19Z, is older than 60 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: Introduced and refactored core model-selection, gateway sessions, and hook infrastructure used by this path. (role: feature owner and adjacent maintainer; confidence: high; commits: 15e5bb3459b0, dc5d23484854, 310d2db31241; files: src/agents/model-selection.ts, src/gateway/server-methods/sessions.ts, src/hooks/workspace.ts)
  • gumadeiras: Merged TUI/Gateway model display and session model resolver work that overlaps the affected sessions list and UI surfaces. (role: recent gateway/TUI model-display contributor; confidence: high; commits: 38e6da1fe0fe, e75638aa5f3b, ba54c5a351f7; files: src/gateway/session-utils.ts, src/tui/tui-session-actions.ts, src/agents/model-selection.ts)
  • vincentkoc: Current blame and recent merged history touch model normalization and hook loader hardening, including the security-sensitive hook boundary affected by the unrelated commit. (role: recent model and hook-boundary contributor; confidence: high; commits: 0a4b30191df0, d13869aab94d, d4f535b20302; files: src/gateway/session-utils.ts, src/agents/model-selection.ts, src/hooks/workspace.ts)
  • robbyczgw-cla: Authored merged work to display the correct model for sub-agents in sessions list, directly adjacent to this default-model behavior. (role: adjacent sessions-list model contributor; confidence: medium; commits: 5c69e625f58d, 0fd0de121841; files: src/gateway/session-utils.ts, src/gateway/session-utils.test.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against ff79299d68e3.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. labels May 17, 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 17, 2026
@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. 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. and removed impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. labels May 18, 2026
@clawsweeper

clawsweeper Bot commented May 19, 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.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label May 22, 2026
@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 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.

Control UI shows two "default" model options when only one agent is configured[Bug]:

1 participant