openclaw - ✅(Solved) Fix [Bug]: sessions_spawn with runtime="subagent" does not respect agent's model.primary config [1 pull requests, 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#57428Fetched 2026-04-08 01:49:49
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×2cross-referenced ×1referenced ×1

Bug Description When spawning a subagent using sessions_spawn with runtime="subagent", the spawned session does not use the agent's configured model.primary, instead falling back to the global default model.

Configuration

{
  "id": "sidekick",
  "name": "小跟班",
  "model": {
    "primary": "bailian/qwen3.5-plus"
  }
}

Root Cause

Bug Description When spawning a subagent using sessions_spawn with runtime="subagent", the spawned session does not use the agent's configured model.primary, instead falling back to the global default model.

Configuration

{
  "id": "sidekick",
  "name": "小跟班",
  "model": {
    "primary": "bailian/qwen3.5-plus"
  }
}

Fix Action

Fixed

PR fix notes

PR #57440: fix(agents): forward resolved model to agent gateway call in sessions_spawn

Description (problem / solution / changelog)

Summary

Fixes #57428

sessions_spawn with runtime="subagent" resolves the target agent's model.primary config correctly via resolveSubagentSpawnModelSelection and patches it onto the child session, but never passes it in the actual agent gateway call. This causes spawned subagents to use the global default model instead of the configured per-agent model.

Changes

src/agents/subagent-spawn.ts

  • Added model: resolvedModel || undefined to the callSubagentGateway({ method: "agent", params: {...} }) call so the resolved model is forwarded to the gateway when spawning the subagent.

src/agents/openclaw-tools.subagents.sessions-spawn.model.test.ts

  • Added test: "sessions_spawn forwards resolved model to the agent gateway call" — verifies that an explicit model override is forwarded in the agent call params (not just sessions.patch).
  • Added test: "sessions_spawn forwards config-resolved model to the agent gateway call" — verifies that a config-resolved model.primary from the target agent is forwarded in the agent call params.

Root Cause

In spawnSubagentDirect, the resolved model was:

  1. ✅ Computed correctly at line 483 via resolveSubagentSpawnModelSelection
  2. ✅ Patched onto the child session via sessions.patch
  3. ✅ Persisted via persistInitialChildSessionRuntimeModel
  4. Not passed in the callSubagentGateway({ method: "agent" }) params

The gateway agent method uses its own model resolution when no model is provided in the call, falling back to the global default rather than respecting the session-patched value.

Testing

  • All 11 tests pass (9 existing + 2 new):
    ✓ sessions_spawn applies a model to the child session
    ✓ sessions_spawn forwards thinking overrides to the agent run
    ✓ sessions_spawn rejects invalid thinking levels
    ✓ sessions_spawn applies default subagent model from defaults config
    ✓ sessions_spawn falls back to runtime default model when no model config is set
    ✓ sessions_spawn prefers per-agent subagent model over defaults
    ✓ sessions_spawn prefers target agent primary model over global default
    ✓ sessions_spawn fails when model patch is rejected
    ✓ sessions_spawn forwards resolved model to the agent gateway call (NEW)
    ✓ sessions_spawn forwards config-resolved model to the agent gateway call (NEW)
    ✓ sessions_spawn supports legacy timeoutSeconds alias

Changed files

  • src/agents/openclaw-tools.subagents.sessions-spawn.model.test.ts (modified, +55/-0)
  • src/agents/subagent-spawn.ts (modified, +1/-0)

Code Example

{
  "id": "sidekick",
  "name": "小跟班",
  "model": {
    "primary": "bailian/qwen3.5-plus"
  }
}

### Steps to reproduce

**Steps to reproduce:**


1. Configure an agent with a non-default model in `openclaw.json`:

---

2. Restart OpenClaw gateway to load the new configuration

3. Verify agent config shows correct model:

---

4. Spawn a subagent using `sessions_spawn` with `runtime="subagent"`:

---

5. Check the actual model used by the subagent:
   - Either via `subagents list` API
   - Or have the subagent report its model name

6. **Expected**: Subagent uses `bailian/qwen3.5-plus`
   
   **Actual**: Subagent uses global default `moonshot/kimi-k2.5`

---

1. Configure agent "sidekick" with `model.primary: "bailian/qwen3.5-plus"`
2. Restart gateway
3. Spawn subagent: `sessions_spawn({runtime: "subagent", agentId: "sidekick", task: "..."})`
4. Observe subagent uses `moonshot/kimi-k2.5` instead of configured `bailian/qwen3.5-plus`

---
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Bug Description When spawning a subagent using sessions_spawn with runtime="subagent", the spawned session does not use the agent's configured model.primary, instead falling back to the global default model.

Configuration

{
  "id": "sidekick",
  "name": "小跟班",
  "model": {
    "primary": "bailian/qwen3.5-plus"
  }
}

### Steps to reproduce

**Steps to reproduce:**


1. Configure an agent with a non-default model in `openclaw.json`:
   ```json
   {
     "id": "sidekick",
     "model": {
       "primary": "bailian/qwen3.5-plus"
     }
   }
  1. Restart OpenClaw gateway to load the new configuration

  2. Verify agent config shows correct model:

    openclaw agents list
    # Output shows: Model: bailian/qwen3.5-plus
  3. Spawn a subagent using sessions_spawn with runtime="subagent":

    {
      "task": "Test task",
      "runtime": "subagent",
      "agentId": "sidekick"
      // Note: no "model" parameter specified
    }
  4. Check the actual model used by the subagent:

    • Either via subagents list API
    • Or have the subagent report its model name
  5. Expected: Subagent uses bailian/qwen3.5-plus

    Actual: Subagent uses global default moonshot/kimi-k2.5


---


```markdown
1. Configure agent "sidekick" with `model.primary: "bailian/qwen3.5-plus"`
2. Restart gateway
3. Spawn subagent: `sessions_spawn({runtime: "subagent", agentId: "sidekick", task: "..."})`
4. Observe subagent uses `moonshot/kimi-k2.5` instead of configured `bailian/qwen3.5-plus`

Expected behavior

Subagent should use bailian/qwen3.5-plus as configured in agent's model.primary.

Actual behavior

Subagent uses global default moonshot/kimi-k2.5.

OpenClaw version

2026.3.24

Operating system

Linux (WSL2)

Install method

npm

Model

moonshot/kimi-k2.5

Provider / routing chain

manager → sidekick (subagent)

Additional provider/model setup details

|------|----------| | Provider | bailian (或 moonshot) | | Routing chain | manager → sidekickagent:manager:main → agent:sidekick:subagent |

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

Fix Plan

To fix the issue, we need to modify the sessions_spawn function to inherit the model.primary configuration from the parent agent when spawning a subagent with runtime="subagent".

Here are the steps:

  • Modify the sessions_spawn function to check if the runtime parameter is set to "subagent".
  • If it is, retrieve the parent agent's configuration and extract the model.primary value.
  • Pass the extracted model.primary value to the subagent's configuration.

Example code:

// sessions_spawn function
if (params.runtime === 'subagent') {
  const parentAgentConfig = await getAgentConfig(params.agentId);
  const primaryModel = parentAgentConfig.model.primary;
  // Pass the primary model to the subagent's configuration
  subagentConfig.model.primary = primaryModel;
}

Alternatively, you can also modify the getAgentConfig function to return the model.primary value for the subagent if it's not explicitly specified.

Verification

To verify the fix, follow these steps:

  • Configure an agent with a non-default model in openclaw.json.
  • Restart the OpenClaw gateway to load the new configuration.
  • Spawn a subagent using sessions_spawn with runtime="subagent" and the agent ID.
  • Check the actual model used by the subagent using the subagents list API or by having the subagent report its model name.
  • Verify that the subagent uses the configured model.primary value instead of the global default model.

Extra Tips

  • Make sure to update the documentation to reflect the changed behavior of the sessions_spawn function.
  • Consider adding a test case to ensure that the fix works as expected.
  • If you're using a version control system, create a new branch for the fix and merge it into the main branch after verification.

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…

FAQ

Expected behavior

Subagent should use bailian/qwen3.5-plus as configured in agent's model.primary.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING