openclaw - 💡(How to fix) Fix [Bug]: Spawned subagent with explicit model can fail before first attempt with LiveSessionModelSwitchError [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#58539Fetched 2026-04-08 02:01:22
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Error Message

Child completion error: LiveSessionModelSwitchError: Live session model switch requested: openai-codex/gpt-5.4

Observed child result: (no output)

Code Example

Child completion error:
LiveSessionModelSwitchError: Live session model switch requested: openai-codex/gpt-5.4

Observed child result:
(no output)

---

const nextSelection = shouldTrackPersistedLiveSelection
  ? resolvePersistedLiveSelection()
  : null;
if (hasDifferentLiveSessionModelSelection(resolveCurrentLiveSelection(), nextSelection)) {
  throw new LiveSessionModelSwitchError(nextSelection);
}

---

export class LiveSessionModelSwitchError extends Error {
  constructor(selection: LiveSessionModelSelection) {
    super(`Live session model switch requested: ${selection.provider}/${selection.model}`);
  }
}
RAW_BUFFERClick to expand / collapse

Title: [Bug]: Spawned subagent with explicit model can fail before first attempt with LiveSessionModelSwitchError

Bug type: Behavior bug (incorrect output/state without crash) Beta release blocker: No

Summary A spawned runtime="subagent" run with an explicit model (openai-codex/gpt-5.4) failed immediately with LiveSessionModelSwitchError instead of running the child session or surfacing a provider/model error.

Steps to reproduce

  1. Start a normal OpenClaw session on 2026.3.28.
  2. From that session, call sessions_spawn with runtime: "subagent", mode: "run", and model: "openai-codex/gpt-5.4".
  3. Wait for the child run to complete.
  4. Observe that the child returns a completion event with status: failed and no model output.

Expected behavior A spawned subagent should run as its own session. With an explicit model, it should either:

  • execute on that model successfully, or
  • surface the underlying provider/model failure for that child session. It should not fail with a live-session model-switch error before the child produces any model output.

Actual behavior The spawned child failed immediately and the only surfaced error was:

LiveSessionModelSwitchError: Live session model switch requested: openai-codex/gpt-5.4

No child model output was produced, and no provider-level rate-limit/quota error was surfaced in the child completion event.

OpenClaw version 2026.3.28 (f9b1079)

Operating system macOS Darwin 25.3.0 arm64

Install method npm global

Model openai-codex/gpt-5.4

Provider / routing chain openclaw -> openai-codex (ChatGPT Plus OAuth path)

Additional provider/model setup details

  • The parent session was running on openai/gpt-5.4 via API key when the subagent was spawned.
  • The child run was explicitly requested with model: "openai-codex/gpt-5.4".
  • The observed failure happened on a one-shot spawned subagent (runtime: "subagent", mode: "run"), not on a reused existing child session.

Logs, screenshots, and evidence

Child completion error:
LiveSessionModelSwitchError: Live session model switch requested: openai-codex/gpt-5.4

Observed child result:
(no output)

Local source inspection on current main shows a matching error path in src/agents/pi-embedded-runner/run.ts:

const nextSelection = shouldTrackPersistedLiveSelection
  ? resolvePersistedLiveSelection()
  : null;
if (hasDifferentLiveSessionModelSelection(resolveCurrentLiveSelection(), nextSelection)) {
  throw new LiveSessionModelSwitchError(nextSelection);
}

And src/agents/live-model-switch.ts defines the error and persisted-selection lookup:

export class LiveSessionModelSwitchError extends Error {
  constructor(selection: LiveSessionModelSelection) {
    super(`Live session model switch requested: ${selection.provider}/${selection.model}`);
  }
}

Impact and severity Affected: users spawning subagents with an explicit model selection Severity: High (blocks the spawned run entirely) Frequency: Observed on the reproduced run described above Consequence: child tasks fail before first model attempt and can surface a session/model-switch error instead of the underlying provider/model failure

Additional information

  • Related reports that appear adjacent in symptom area: #20002, #28925, #49491, #10375.
  • A separate contemporaneous direct Codex surface reported a ChatGPT Plus usage cap, but that provider error did not appear in the child completion event here.
  • Based on source inspection, one code path worth checking is whether newly spawned child sessions with explicit model selection are being enrolled in persisted live-session model tracking too early, or are reading a persisted session-store selection that does not belong to the freshly spawned child state.
  • Possible fix to evaluate: when a spawned subagent has an explicit model, do not throw LiveSessionModelSwitchError unless the child session has first established its own persisted session-store entry; alternatively, have resolveLiveSessionModelSelection() return null when no persisted entry exists instead of synthesizing a default selection.

extent analysis

TL;DR

The most likely fix is to modify the resolveLiveSessionModelSelection() function to return null when no persisted entry exists, instead of synthesizing a default selection, to prevent the LiveSessionModelSwitchError from being thrown prematurely.

Guidance

  • Review the src/agents/pi-embedded-runner/run.ts file to understand the error path that leads to the LiveSessionModelSwitchError being thrown.
  • Investigate the resolveLiveSessionModelSelection() function to determine why it is returning a selection that does not belong to the freshly spawned child state.
  • Consider modifying the resolveLiveSessionModelSelection() function to return null when no persisted entry exists, as suggested in the additional information section.
  • Verify that the hasDifferentLiveSessionModelSelection() function is correctly checking for differences in live session model selections.

Example

// Modified resolveLiveSessionModelSelection function
function resolveLiveSessionModelSelection(): LiveSessionModelSelection | null {
  // Check if a persisted entry exists for the child session
  const persistedEntry = getPersistedSessionStoreEntry();
  if (!persistedEntry) {
    return null; // Return null if no persisted entry exists
  }
  // Return the persisted selection
  return persistedEntry.selection;
}

Notes

The provided code snippets and additional information suggest that the issue is related to the handling of persisted live session model selections for newly spawned child sessions. However, without further information about the getPersistedSessionStoreEntry() function and the LiveSessionModelSelection class, it is difficult to provide a more detailed solution.

Recommendation

Apply the suggested modification to the resolveLiveSessionModelSelection() function to return null when no persisted entry exists, and verify that this change resolves the issue. This approach is recommended because it addresses the potential root cause of the problem and prevents the premature throwing of the LiveSessionModelSwitchError.

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 [Bug]: Spawned subagent with explicit model can fail before first attempt with LiveSessionModelSwitchError [1 participants]