openclaw - ✅(Solved) Fix Bug: LiveSessionModelSwitchError not handled in subagent runner — cross-provider model switches fail [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#57998Fetched 2026-04-08 01:55:04
View on GitHub
Comments
0
Participants
1
Timeline
8
Reactions
0
Author
Participants
Timeline (top)
referenced ×4cross-referenced ×2closed ×1locked ×1

Error Message

Problem: When a subagent is configured with a model from a different provider than its parent session, the subagent fails immediately with LiveSessionModelSwitchError. The main agent runner has retry logic for this error (catches the exception and retries with the new provider/model), but the subagent execution path does not — it surfaces the error as a task failure.

  • The model parameter on sessions_spawn does not help — same error. In agent-runner.runtime, the main runner catches LiveSessionModelSwitchError and retries with the switched provider/model (around line 522 in the bundled JS). The subagent execution path does not have equivalent retry logic — the error propagates as a task failure.

Root Cause

Root cause (from source inspection)

Fix Action

Fixed

PR fix notes

PR #58062: fix(agents): handle LiveSessionModelSwitchError in subagent execution

Description (problem / solution / changelog)

Summary

  • Problem: When a subagent is configured with a different provider/model than the parent agent (e.g., parent uses Anthropic, subagent uses OpenAI), the subagent fails immediately with a LiveSessionModelSwitchError. This occurs in src/agents/agent-command.ts where the error is caught but not handled, causing it to be rethrown and aborting the execution.
  • Root Cause: The runWithModelFallback function throws a LiveSessionModelSwitchError when it detects a live session model switch (e.g., when the persisted session targets a different provider/model). While the main auto-reply runner (src/auto-reply/reply/agent-runner-execution.ts) has a while loop and a catch block to handle this error by updating the provider/model and retrying, the subagent execution path (agentCommandInternal in src/agents/agent-command.ts) lacks this retry mechanism. Consequently, the error escapes the fallback loop and crashes the subagent.
  • Fix: Introduced a while (true) retry loop around the runWithModelFallback call in agentCommandInternal (src/agents/agent-command.ts), mirroring the exact logic used in the main runner. When LiveSessionModelSwitchError is caught, the provider and model variables are updated, the lifecycleEnded flag is reset, and the loop continues to retry the execution with the correct model. This ensures subagents can seamlessly switch models just like the main agent.
  • What changed:
    • src/agents/agent-command.ts: Added LiveSessionModelSwitchError import. Wrapped the runWithModelFallback execution in a while (true) loop. Added a catch branch specifically for LiveSessionModelSwitchError to update model state and continue.
    • src/agents/agent-command.live-model-switch.test.ts: Added comprehensive unit tests to verify the retry logic, error propagation, and lifecycle event emission.
  • What did NOT change (scope boundary): The core model fallback logic (runWithModelFallback) and the main agent runner (agent-runner-execution.ts) remain untouched. The fix is strictly localized to the subagent command execution path.

Reproduction

  1. Configure a parent agent to use anthropic/claude.
  2. Configure a subagent to use openai/gpt-4o.
  3. Trigger the subagent from the parent agent.
  4. Observe the subagent crash with LiveSessionModelSwitchError before the fix. After the fix, it successfully switches models and replies.

Risk / Mitigation

  • Risk: Infinite loops if the model switch error is thrown repeatedly without making progress.
  • Mitigation: The LiveSessionModelSwitchError carries the target provider and model, which are explicitly applied to the next iteration. The underlying runWithModelFallback and runAgentAttempt logic ensures that once the correct model is applied, the switch error is not thrown again. Unit tests specifically verify that the retry loop terminates successfully after the switch.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Agents

Linked Issue/PR

Fixes #57998

Changed files

  • src/agents/agent-command.live-model-switch.test.ts (added, +463/-0)
  • src/agents/agent-command.ts (modified, +132/-98)
RAW_BUFFERClick to expand / collapse

Bug Report

Version: openclaw 2026.3.28

Problem: When a subagent is configured with a model from a different provider than its parent session, the subagent fails immediately with LiveSessionModelSwitchError. The main agent runner has retry logic for this error (catches the exception and retries with the new provider/model), but the subagent execution path does not — it surfaces the error as a task failure.

Reproduction

  1. Main agent running on anthropic/claude-opus-4-6
  2. Subagent configured with openai-codex/gpt-5.4 (via agents.list[].model.primary and agents.list[].subagents.model)
  3. Spawn subagent via sessions_spawn with agentId and explicit model parameter
  4. Subagent fails: LiveSessionModelSwitchError: Live session model switch requested: openai-codex/gpt-5.4

What works

  • Same-provider model switches (e.g., parent on anthropic/claude-opus-4-6, subagent on anthropic/claude-sonnet-4-5) succeed.
  • The main agent runner correctly handles LiveSessionModelSwitchError with a retry loop that applies the new provider/model.

What fails

  • Cross-provider switches (Anthropic → OpenAI, Anthropic → Google) fail in the subagent runner.
  • Tested with both openai-codex/gpt-5.4 and google-gemini/gemini-2.5-flash as subagent models under an Anthropic parent — both fail identically.
  • The model parameter on sessions_spawn does not help — same error.

Root cause (from source inspection)

In agent-runner.runtime, the main runner catches LiveSessionModelSwitchError and retries with the switched provider/model (around line 522 in the bundled JS). The subagent execution path does not have equivalent retry logic — the error propagates as a task failure.

Expected behavior

Subagents should be able to run on any configured provider/model, as documented:

"Default model: inherits the caller unless you set agents.defaults.subagents.model (or per-agent agents.list[].subagents.model); an explicit sessions_spawn.model still wins."

Environment

  • OS: WSL2 / Linux 6.6.87.2
  • Node: v22.22.1
  • OpenClaw: 2026.3.28

extent analysis

Fix Plan

To resolve the LiveSessionModelSwitchError in subagents, we need to implement retry logic for cross-provider model switches in the subagent execution path.

Step-by-Step Solution

  1. Modify agent-runner.runtime: Add a try-catch block around the subagent execution code to catch LiveSessionModelSwitchError.
  2. Implement Retry Logic: Upon catching the error, retry the subagent execution with the new provider/model.
  3. Update Subagent Configuration: Ensure the subagent configuration allows for cross-provider model switches.

Example Code

// agent-runner.runtime (around line 522)
try {
  // Subagent execution code
} catch (error) {
  if (error instanceof LiveSessionModelSwitchError) {
    // Retry with new provider/model
    const newModel = error.newModel;
    const newProvider = error.newProvider;
    // Update subagent configuration with new model and provider
    subagentConfig.model = newModel;
    subagentConfig.provider = newProvider;
    // Retry subagent execution
    await executeSubagent(subagentConfig);
  } else {
    throw error;
  }
}

Verification

To verify the fix, follow the reproduction steps and check that the subagent executes successfully with a cross-provider model switch.

Extra Tips

  • Ensure the agents.list[].subagents.model and agents.defaults.subagents.model configurations are correctly set to allow for cross-provider model switches.
  • Test the fix with different provider/model combinations to ensure it works as expected.

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

Subagents should be able to run on any configured provider/model, as documented:

"Default model: inherits the caller unless you set agents.defaults.subagents.model (or per-agent agents.list[].subagents.model); an explicit sessions_spawn.model still wins."

Still need to ship something?

×6

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

Back to top recommendations

TRENDING