Skip to content

fix(agents): apply subagent spawn model selection#72877

Closed
Papilllion wants to merge 2 commits into
openclaw:mainfrom
Papilllion:fix/subagent-model-selection-runtime
Closed

fix(agents): apply subagent spawn model selection#72877
Papilllion wants to merge 2 commits into
openclaw:mainfrom
Papilllion:fix/subagent-model-selection-runtime

Conversation

@Papilllion

Copy link
Copy Markdown

Summary

  • Restore native subagent configured model precedence so agents.defaults.subagents.model wins over the target agent primary model when no per-agent subagents.model is set.
  • Persist the resolved sessions_spawn model onto child sessions as selected model override fields (providerOverride / modelOverride, source auto) before the first child agent run.
  • Align isolated cron agent-turn subagent model precedence with native subagent selection.

Why

Native sessions_spawn could report modelApplied: true while the child run still executed on the target agent/default model. The spawn path persisted only runtime identity fields (model / modelProvider), but agentCommand selects from modelOverride / providerOverride, so the resolved spawn model was visible in some status surfaces without necessarily controlling the actual provider call.

This also covers the default precedence case discussed in #58822 / #58823, and adds the explicit-spawn-model application path related to #6295.

Tests

  • corepack pnpm vitest run src/agents/model-selection.test.ts src/agents/openclaw-tools.subagents.sessions-spawn.model.test.ts src/agents/subagent-spawn.model-session.test.ts src/cron/isolated-agent.model-formatting.test.ts
  • PATH="/tmp/openclaw-pnpm-shim:$PATH" corepack pnpm check:changed

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 27, 2026
@greptile-apps

greptile-apps Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two related model-selection issues in subagent spawning: it reverses the precedence order so agents.defaults.subagents.model beats the target agent's own model field (now the correct order: per-agent subagents.model > global defaults.subagents.model > agent model), and it ensures buildDirectChildSessionPatch writes modelOverride, providerOverride, and modelOverrideSource: "auto" alongside the existing model/modelProvider fields so that agentCommand actually picks up the resolved spawn model.

Confidence Score: 5/5

Safe to merge — changes are focused, self-contained, and covered by targeted tests.

All changes are two-line precedence swaps and three additive field writes. Tests are updated to reflect the new expected behaviour in both the native and cron paths. No P0/P1 findings were identified.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(agents): apply subagent spawn model ..." | Re-trigger Greptile

@clawsweeper

clawsweeper Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

This PR is superseded: current main already has the child-session override persistence piece in a source-aware form, the Yuanbao catalog pin is already present, and the remaining subagent precedence work is tracked by narrower open follow-ups. The PR head also still has a correctness bug around explicit spawn model source handling, so it should not be merged as-is.

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Review details

Best possible solution:

Close this superseded branch and consolidate review on the narrower precedence/runtime follow-up, while keeping current main’s source-aware child-session override persistence rather than reintroducing all-auto model override source handling.

Do we have a high-confidence way to reproduce the issue?

Yes. The code-level reproduction is to spawn with an explicit sessions_spawn.model on the PR head: the plan only passes model, buildDirectChildSessionPatch stores it as auto, and fallback resolution treats auto overrides as eligible for configured fallbacks.

Is this the best way to solve the issue?

No. The intended precedence direction is plausible, but this branch is stale against current main’s override-source handling and duplicates remaining work already covered by #58823 and #72984.

Security review:

Security review cleared: The diff touches supply-chain-sensitive catalog metadata, but the Yuanbao exact npm spec and integrity are already present on current main and the patch does not broaden scripts, permissions, or credential handling.

What I checked:

  • PR head marks all child model overrides as auto: At PR head, buildDirectChildSessionPatch writes modelOverrideSource = "auto" for every patch model, including explicit sessions_spawn.model requests. (src/agents/subagent-spawn.ts:243, 1794e95cb804)
  • Current main already preserves explicit spawn model source: Current main records modelOverride/modelProvider fields while preserving auto versus user source from the initial child-session patch. (src/agents/subagent-spawn.ts:241, 359d871293e8)
  • Current main marks explicit spawn models as user: resolveSubagentModelAndThinkingPlan sets modelOverrideSource to user when the caller supplied an explicit model override and auto otherwise. (src/agents/subagent-spawn-plan.ts:75, 359d871293e8)
  • Model override source changes fallback semantics: resolveEffectiveModelFallbacks returns configured fallbacks only for auto-sourced overrides; user or legacy explicit selections get an empty fallback list. (src/agents/agent-scope.ts:207, 359d871293e8)
  • Current main still has old native precedence: resolveSubagentConfiguredModelSelection still checks per-agent subagents.model, then the agent primary model, then agents.defaults.subagents.model. (src/agents/model-selection.ts:240, 359d871293e8)
  • Current main still has old isolated-cron precedence: The isolated cron model selection path still checks agentConfigOverride.model before cfg.agents.defaults.subagents.model. (src/cron/isolated-agent/model-selection.ts:71, 359d871293e8)

Likely related people:

  • steipete: Recent commits and current-main source show Peter maintained the subagent spawn path and introduced the source-aware child-session override persistence now present on main. (role: recent maintainer; confidence: high; commits: 6c0cdf43e48e, 2e99c1d22726, 343f2d724593; files: src/agents/subagent-spawn.ts, src/cron/isolated-agent/model-selection.ts)
  • neeravmakwana: Merged PR Agents: fix subagent model precedence #58003/commit e394262 changed the precedence toward agent primary before global subagent default, which is the remaining behavior this PR tries to reverse. (role: introduced behavior; confidence: high; commits: e394262bd87e; files: src/agents/model-selection.ts, src/cron/isolated-agent/model-selection.ts)
  • vincentkoc: Recent model-selection and runtime seam history includes several Vincent commits touching model-selection helpers and related agent runtime boundaries. (role: adjacent maintainer; confidence: medium; commits: d13869aab94d, 117ae85bf5c7, 35176f3cb730; files: src/agents/model-selection.ts, src/cron/isolated-agent/model-selection.ts)
  • joeykrug: Joey authored the linked open precedence and runtime-resolution follow-ups that now cover the remaining work from this PR. (role: likely follow-up owner; confidence: medium; commits: 630debe441d3, 5f5e960958c5, 86867e554b05; files: src/agents/model-selection.ts, src/cron/isolated-agent/model-selection.ts, src/gateway/session-utils.ts)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant