openclaw - 💡(How to fix) Fix sessions_spawn model parameter silently ignored — subagent always uses agents.defaults.model.primary [1 comments, 2 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#73293Fetched 2026-04-29 06:21:22
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
closed ×1commented ×1

Root Cause

I traced through the source code (dist/subagent-spawn--QfZonyO.js):

  1. resolveSubagentSpawnModelSelection (model-selection-GlsOqTDm.js:141) correctly returns the override:

    return normalizeModelSelection(params.modelOverride) ?? resolveSubagentConfiguredModelSelection(...)
  2. persistInitialChildSessionRuntimeModel (subagent-spawn:351) writes to session store:

    store[target.canonicalKey] = mergeSessionEntry(store[target.canonicalKey], {
      model,
      ...provider ? { modelProvider: provider } : {}
    });
  3. modelApplied is set to true and the API response includes modelApplied: true.

  4. However, the child session's session.started trajectory event shows the default model (zai/glm-5.1) instead of the resolved model. This suggests the persisted runtime model is either:

    • Not read during child session initialization, or
    • Overwritten by the default model after persistence, or
    • There's a race between persistence and session startup

Fix Action

Workaround

agents.defaults.subagents.model can set a global subagent default model, but there is no way to override the model per-spawn.

Code Example

{
  "model": "minimax/MiniMax-M2.7-highspeed",
  "spawnMode": "run"
}

---

{
  "type": "session.started",
  "provider": "zai",
  "modelId": "glm-5.1",
  "modelApi": "openai-completions"
}

---

{
  "model": {
    "provider": "zai",
    "name": "glm-5.1",
    "api": "openai-completions"
  }
}

---

return normalizeModelSelection(params.modelOverride) ?? resolveSubagentConfiguredModelSelection(...)

---

store[target.canonicalKey] = mergeSessionEntry(store[target.canonicalKey], {
     model,
     ...provider ? { modelProvider: provider } : {}
   });
RAW_BUFFERClick to expand / collapse

Bug Description

The model parameter in sessions_spawn() is accepted and saved to runs.json (with modelApplied: true in the response), but the child subagent session actually starts with agents.defaults.model.primary instead of the requested model.

Reproduction

Three independent subagent spawns, all on OpenClaw v2026.4.26 (be8c246):

#sessions_spawn({ model: ... })runs.json recorded modelActual runtime model
1minimax/MiniMax-M2.7-highspeedminimax/MiniMax-M2.7-highspeedzai/glm-5.1
2minimax/MiniMax-M2.7-highspeedminimax/MiniMax-M2.7-highspeedzai/glm-5.1
3zai/glm-4.7zai/glm-4.7zai/glm-5.1

Test #3 deliberately used a same-provider model to rule out MiniMax-specific issues — still failed.

Evidence

runs.json (correct)

{
  "model": "minimax/MiniMax-M2.7-highspeed",
  "spawnMode": "run"
}

Child session trajectory — session.started event (wrong)

{
  "type": "session.started",
  "provider": "zai",
  "modelId": "glm-5.1",
  "modelApi": "openai-completions"
}

Child session metadata (from trace.metadata)

{
  "model": {
    "provider": "zai",
    "name": "glm-5.1",
    "api": "openai-completions"
  }
}

Root Cause Analysis

I traced through the source code (dist/subagent-spawn--QfZonyO.js):

  1. resolveSubagentSpawnModelSelection (model-selection-GlsOqTDm.js:141) correctly returns the override:

    return normalizeModelSelection(params.modelOverride) ?? resolveSubagentConfiguredModelSelection(...)
  2. persistInitialChildSessionRuntimeModel (subagent-spawn:351) writes to session store:

    store[target.canonicalKey] = mergeSessionEntry(store[target.canonicalKey], {
      model,
      ...provider ? { modelProvider: provider } : {}
    });
  3. modelApplied is set to true and the API response includes modelApplied: true.

  4. However, the child session's session.started trajectory event shows the default model (zai/glm-5.1) instead of the resolved model. This suggests the persisted runtime model is either:

    • Not read during child session initialization, or
    • Overwritten by the default model after persistence, or
    • There's a race between persistence and session startup

Environment

  • OpenClaw: v2026.4.26 (be8c246)
  • OS: macOS 15.7.5 (arm64)
  • Node: v24.15.0
  • Default model: zai/glm-5.1
  • Configured models: zai, minimax (Anthropic), bailian (OpenAI), lmstudio

Workaround

agents.defaults.subagents.model can set a global subagent default model, but there is no way to override the model per-spawn.

Expected Behavior

Subagent should use the model specified in sessions_spawn({ model: "..." }), as documented: "an explicit sessions_spawn.model still wins".

extent analysis

TL;DR

The issue can be fixed by ensuring the persisted runtime model is correctly read during child session initialization, potentially by reviewing the session store logic in persistInitialChildSessionRuntimeModel.

Guidance

  • Review the persistInitialChildSessionRuntimeModel function to ensure the model is correctly written to the session store and not overwritten by the default model.
  • Verify that the child session initialization logic correctly reads the persisted runtime model from the session store.
  • Investigate potential race conditions between persistence and session startup that may cause the default model to be used instead of the resolved model.
  • Consider adding logging or debugging statements to track the model selection and persistence process to identify where the issue occurs.

Example

// Example of how to add logging to track model selection and persistence
const resolvedModel = resolveSubagentSpawnModelSelection(params.modelOverride);
console.log('Resolved model:', resolvedModel);

// ...

const storedModel = store[target.canonicalKey].model;
console.log('Stored model:', storedModel);

Notes

The issue may be specific to the OpenClaw version (v2026.4.26) or the Node version (v24.15.0) being used. Further investigation is needed to determine the root cause.

Recommendation

Apply a workaround by setting agents.defaults.subagents.model to the desired default model, although this does not address the per-spawn model override issue. A more permanent fix would require resolving the issue with the session store logic.

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

openclaw - 💡(How to fix) Fix sessions_spawn model parameter silently ignored — subagent always uses agents.defaults.model.primary [1 comments, 2 participants]