Skip to content

fix(agents): subagent model precedence — global default shadowed by parent agent's own model #58822

@joeykrug

Description

@joeykrug

Bug

PR #58003 (commit e394262, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions