openclaw - ✅(Solved) Fix sessions_spawn model parameter triggers LiveSessionModelSwitchError instead of setting initial model [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#57306Fetched 2026-04-08 01:51:14
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

Error Message

[agent/embedded] live session model switch detected before attempt for <session>: anthropic/claude-sonnet-4-6 -> anthropic/claude-opus-4-6 [ws] ⇄ res ✗ agent errorCode=UNAVAILABLE errorMessage=LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-opus-4-6

Fix Action

Workaround

Currently unknown. Looking for a config-level fix to set the initial subagent model correctly.

PR fix notes

PR #64508: fix(agents): persist subagent spawn model to override fields

Description (problem / solution / changelog)

Summary

  • Problem: When spawning a subagent with a model override (via sessions_spawn or subagents.model config), the child session runs on the default model instead of the requested model, despite modelApplied: true in the spawn response.
  • Why it matters: Subagent model routing is broken. Users are billed for expensive models (Opus) when they configured cheaper ones (Sonnet/Gemma). The modelApplied: true response is misleading.
  • What changed: persistInitialChildSessionRuntimeModel() now writes to modelOverride/providerOverride/modelOverrideSource instead of model/modelProvider. Secondary fix: live-switch path uses agent-resolved defaults instead of global constants.
  • What did NOT change (scope boundary): agentCommand startup logic is unchanged - it already reads override fields correctly.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #48271
  • Closes #43768
  • Related #57306, #62755, #62562, #63221
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: persistInitialChildSessionRuntimeModel() writes to runtime fields (model, modelProvider), but agentCommandInternal() reads from override fields (modelOverride, providerOverride) for startup model selection.
  • Missing detection / guardrail: Tests expected runtime field persistence, which locked in the buggy behavior.
  • Contributing context: The distinction between runtime fields ("what actually ran") and override fields ("what should run") was not enforced at the spawn boundary.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/agents/subagent-spawn.model-override.test.ts (new), updated assertions in subagent-spawn.model-session.test.ts
  • Scenario the test should lock in: Spawn persistence writes override fields, and first-run model selection reads those override fields.
  • Why this is the smallest reliable guardrail: The bug is a field-contract mismatch between spawn and startup; unit tests at both boundaries are the minimal coverage.

AI disclosure

  • AI-assisted (Claude Opus 4.5 via Claude Code)
  • Tested (build + check + unit tests pass)
  • I understand what the code does

Co-Authored-By: Claude [email protected]

Changed files

  • src/agents/pi-embedded-runner/run.ts (modified, +11/-3)
  • src/agents/subagent-spawn.model-override.test.ts (added, +157/-0)
  • src/agents/subagent-spawn.model-session.test.ts (modified, +5/-4)
  • src/agents/subagent-spawn.test-helpers.ts (modified, +15/-3)
  • src/agents/subagent-spawn.test.ts (modified, +3/-2)
  • src/agents/subagent-spawn.ts (modified, +3/-2)

Code Example

[agent/embedded] live session model switch detected before attempt for <session>: anthropic/claude-sonnet-4-6 -> anthropic/claude-opus-4-6
[ws] ⇄ res ✗ agent errorCode=UNAVAILABLE errorMessage=LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-opus-4-6
RAW_BUFFERClick to expand / collapse

Bug Description

When spawning a subagent via sessions_spawn with a model parameter (e.g., model: "opus"), the subagent does not start on the requested model. Instead, it boots on the fallback model (Sonnet), then detects a model mismatch and attempts a live session model switch. This switch throws LiveSessionModelSwitchError and the subagent dies with 0 tokens generated.

Expected Behavior

The model parameter on sessions_spawn should set the initial model for the subagent session, not trigger a post-launch model switch.

Actual Behavior

Gateway logs show this pattern on every spawn attempt:

[agent/embedded] live session model switch detected before attempt for <session>: anthropic/claude-sonnet-4-6 -> anthropic/claude-opus-4-6
[ws] ⇄ res ✗ agent errorCode=UNAVAILABLE errorMessage=LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-opus-4-6

The subagent starts on Sonnet (the fallback model), detects it should be on Opus (the requested model), tries to hot-swap, and the swap fails. Result: 0 tokens, immediate death.

This happens consistently — tested 5+ times with the same result.

Reproduction Steps

  1. Configure default model as anthropic/claude-opus-4-6 with fallback anthropic/claude-sonnet-4-6
  2. Run the main agent session on Opus
  3. Use sessions_spawn with model: "opus" (or model: "anthropic/claude-opus-4-6")
  4. Observe the subagent dies immediately with LiveSessionModelSwitchError

Also reproduced when the main session was switched to Sonnet and spawning with model: "opus" — same error.

Environment

  • OpenClaw version: 2026.3.28
  • OS: macOS 25.4 (arm64)
  • Node: v22.22.2
  • Auth: Anthropic OAuth
  • Config: single agent (main), model primary anthropic/claude-opus-4-6, fallback anthropic/claude-sonnet-4-6

Impact

This completely blocks spawning subagents on a specific model. The model parameter on sessions_spawn is non-functional — subagents always start on the fallback model and fail if a different model is requested.

Workaround

Currently unknown. Looking for a config-level fix to set the initial subagent model correctly.

extent analysis

Fix Plan

To fix the issue with the model parameter on sessions_spawn, we need to modify the configuration to correctly set the initial model for subagent sessions.

Here are the steps:

  • Update the sessions_spawn function to accept an optional initialModel parameter.
  • Modify the subagent spawn logic to use the initialModel parameter instead of the fallback model.
  • Add a check to ensure the initialModel is valid and supported.

Example code changes:

// Update sessions_spawn function
function sessions_spawn(options) {
  const { model, initialModel } = options;
  // ...
  if (initialModel) {
    // Set the initial model for the subagent session
    subagent.model = initialModel;
  }
  // ...
}

// Modify subagent spawn logic
subagent.spawn = async (options) => {
  const { initialModel } = options;
  if (initialModel) {
    // Use the initialModel instead of the fallback model
    await subagent.loadModel(initialModel);
  }
  // ...
}

Verification

To verify the fix, follow these steps:

  • Configure the default model as anthropic/claude-opus-4-6 with fallback anthropic/claude-sonnet-4-6.
  • Run the main agent session on Opus.
  • Use sessions_spawn with model: "opus" (or model: "anthropic/claude-opus-4-6").
  • Check the subagent logs to ensure it starts with the correct model and does not attempt a live session model switch.

Extra Tips

  • Ensure the initialModel parameter is properly validated and handled in the sessions_spawn function.
  • Consider adding additional logging to track the subagent's model usage and any potential errors.
  • Review the OpenClaw documentation to ensure the model parameter on sessions_spawn is correctly documented and supported.

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 - ✅(Solved) Fix sessions_spawn model parameter triggers LiveSessionModelSwitchError instead of setting initial model [1 pull requests, 1 participants]