openclaw - ✅(Solved) Fix fix(agents): subagent model precedence — global default shadowed by parent agent's own model [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#58822Fetched 2026-04-08 02:32:19
View on GitHub
Comments
1
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

Root Cause

In src/agents/model-selection.ts, resolveSubagentConfiguredModelSelection:

// After PR #58003 (buggy):
agentConfig?.subagents?.model   // per-agent subagent config → null for main
?? agentConfig?.model           // agent's OWN model → Opus (shadows global default)
?? cfg.agents.defaults.subagents.model  // global subagent default → never reached

An agent's own model (what model runs the agent) is conceptually different from what model its subagents should use. The agent's own model should only be a last-resort fallback, not take priority over an explicitly configured global subagent default.

The same issue exists in src/cron/isolated-agent/model-selection.ts.

Fix Action

Fixed

PR fix notes

PR #58823: fix(agents): restore global subagent model default priority over agent own model

Description (problem / solution / changelog)

Summary

Fixes #58822.

  • Restores correct subagent model precedence in resolveSubagentConfiguredModelSelection: global agents.defaults.subagents.model now takes priority over the parent agent's own model.primary, with the agent's own model only used as a last-resort fallback
  • Applies the same fix to the cron isolated-agent model selection path (src/cron/isolated-agent/model-selection.ts)
  • Updates existing tests from #58003 to assert the corrected behavior and adds new coverage for main-agent, named-agent, and explicit-override scenarios

Background

PR #58003 reordered resolveSubagentConfiguredModelSelection to prefer agentConfig.model over agents.defaults.subagents.model. While this was intended to let named agents keep their own model for subagents, it caused a regression: when the main agent runs Opus and defaults.subagents.model is GPT-5.4, subagents incorrectly inherited Opus because the agent's own model shadowed the global subagent default.

The correct precedence is:

  1. agentConfig.subagents.model — explicit per-agent subagent config (highest)
  2. agents.defaults.subagents.model — global subagent default
  3. agentConfig.model — agent's own model (last-resort fallback)

Test plan

  • pnpm test -- src/agents/model-selection.test.ts — 71 tests pass
  • pnpm test -- src/cron/isolated-agent.subagent-model.test.ts — 5 tests pass
  • pnpm test -- src/gateway/sessions-patch.test.ts — 27 tests pass
  • New test: main agent (Opus) with global subagent default (GPT-5.4) → subagents use GPT-5.4
  • New test: named agent without per-agent subagents.model → uses global default
  • New test: falls back to agent own model when no global default set
  • New test: explicit model override in spawn always wins

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 [email protected]

Changed files

  • src/agents/model-selection.test.ts (modified, +94/-3)
  • src/agents/model-selection.ts (modified, +2/-2)
  • src/cron/isolated-agent.subagent-model.test.ts (modified, +3/-3)
  • src/cron/isolated-agent/model-selection.ts (modified, +2/-2)

Code Example

agents:
  defaults:
    model:
      primary: anthropic/claude-opus-4-6
    subagents:
      model:
        primary: openai/gpt-5.4
  list:
    - id: main
      model:
        primary: anthropic/claude-opus-4-6

---

// After PR #58003 (buggy):
agentConfig?.subagents?.model   // per-agent subagent config → null for main
?? agentConfig?.model           // agent's OWN model → Opus (shadows global default)
?? cfg.agents.defaults.subagents.model  // global subagent default → never reached
RAW_BUFFERClick to expand / collapse

Bug

PR #58003 (commit e394262bd8, merged 2026-03-31) reordered the fallback chain in resolveSubagentConfiguredModelSelection to prefer agentConfig.model (the agent's own model) over agents.defaults.subagents.model (the global subagent default).

This is correct for named agents with an explicit subagents.model override, but it introduces a regression for the common case: the main agent.

Reproduction

Config:

agents:
  defaults:
    model:
      primary: anthropic/claude-opus-4-6
    subagents:
      model:
        primary: openai/gpt-5.4
  list:
    - id: main
      model:
        primary: anthropic/claude-opus-4-6

Expected: subagents spawned from the main agent use openai/gpt-5.4 (the global subagent default).

Actual: subagents use anthropic/claude-opus-4-6 (the main agent's own model), because the agent's own model is checked before the global subagent default.

Root cause

In src/agents/model-selection.ts, resolveSubagentConfiguredModelSelection:

// After PR #58003 (buggy):
agentConfig?.subagents?.model   // per-agent subagent config → null for main
?? agentConfig?.model           // agent's OWN model → Opus (shadows global default)
?? cfg.agents.defaults.subagents.model  // global subagent default → never reached

An agent's own model (what model runs the agent) is conceptually different from what model its subagents should use. The agent's own model should only be a last-resort fallback, not take priority over an explicitly configured global subagent default.

The same issue exists in src/cron/isolated-agent/model-selection.ts.

Correct precedence

  1. agentConfig.subagents.model — explicit per-agent subagent config (highest priority)
  2. cfg.agents.defaults.subagents.model — global subagent default
  3. agentConfig.model — agent's own model (last-resort fallback only)

Related

  • #58003 (introduced the regression)
  • #48255 (original subagent model resolution issue)

extent analysis

TL;DR

Reorder the fallback chain in resolveSubagentConfiguredModelSelection to prioritize the global subagent default over the agent's own model.

Guidance

  • Verify the issue by checking the model used by subagents spawned from the main agent, ensuring it matches the expected global subagent default openai/gpt-5.4.
  • Update src/agents/model-selection.ts and src/cron/isolated-agent/model-selection.ts to reflect the correct precedence:
    1. agentConfig.subagents.model
    2. cfg.agents.defaults.subagents.model
    3. agentConfig.model
  • Test the changes with the provided reproduction config to ensure subagents use the correct model.

Example

// Corrected resolveSubagentConfiguredModelSelection:
agentConfig?.subagents?.model
?? cfg.agents.defaults.subagents.model
?? agentConfig?.model

Notes

This fix assumes the intention is to prioritize the global subagent default over the agent's own model for subagent model selection.

Recommendation

Apply the workaround by reordering the fallback chain as described, to ensure correct subagent model selection.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING