openclaw - 💡(How to fix) Fix Cron isolated sessions fail with LiveSessionModelSwitchError when agent primary model differs from payload.model [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#58592Fetched 2026-04-08 02:00:32
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0

Cron jobs with sessionTarget: "isolated" and payload.kind: "agentTurn" fail immediately with LiveSessionModelSwitchError when the payload.model field specifies a different model than the agent's configured model.primary. This makes the model field in cron payloads effectively non-functional.

Error Message

LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-opus-4-6

Root Cause

The issue stems from a mismatch between how isolated cron sessions are created vs how model overrides are applied:

  1. Session creation uses the agent's model.primary (e.g., anthropic/claude-opus-4-6)
  2. Model override from payload.model (e.g., zai/glm-5.1) triggers resolveLiveSessionModelSelection() which detects the difference
  3. LiveSessionModelSwitchError is thrown in auth-profiles-B5ypC5S-.js at the session runner level
  4. The runner in agent-runner.runtime-C-sR1PRP.js does handle this error gracefully for interactive sessions (it catches it, updates followupRun.run.provider/model, and continues)
  5. However, the cron scheduler treats it as fatal — the run is marked status: "error" and no retry occurs

Fix Action

Workaround

Set the agent's model.primary to the same provider used in cron payloads. This defeats the purpose of per-cron model selection.

Code Example

// Before each attempt, checks if model selection changed
const nextSelection = resolvePersistedLiveSelection();
if (hasDifferentLiveSessionModelSelection(resolveCurrentLiveSelection(), nextSelection)) {
    throw new LiveSessionModelSwitchError(nextSelection);
}

---

if (err instanceof LiveSessionModelSwitchError) {
    params.followupRun.run.provider = err.provider;
    params.followupRun.run.model = err.model;
    params.followupRun.run.authProfileId = err.authProfileId;
    // continues...
}

---

{
  "agents": {
    "list": [{
      "id": "my-agent",
      "model": {
        "primary": "anthropic/claude-opus-4-6",
        "fallbacks": ["zai/glm-5-turbo"]
      }
    }]
  }
}

---

{
  "name": "test-cron",
  "schedule": { "kind": "every", "everyMs": 600000 },
  "sessionTarget": "isolated",
  "payload": {
    "kind": "agentTurn",
    "model": "zai/glm-5.1",
    "message": "Hello world"
  }
}

---

LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-opus-4-6
RAW_BUFFERClick to expand / collapse

Bug Report

Summary

Cron jobs with sessionTarget: "isolated" and payload.kind: "agentTurn" fail immediately with LiveSessionModelSwitchError when the payload.model field specifies a different model than the agent's configured model.primary. This makes the model field in cron payloads effectively non-functional.

Environment

  • OpenClaw version: 2026.3.28 (f9b1079)
  • Runtime: Linux x64, Node v22.22.1
  • Channel: Telegram (primary) + Discord (secondary)

Root Cause Analysis

The issue stems from a mismatch between how isolated cron sessions are created vs how model overrides are applied:

  1. Session creation uses the agent's model.primary (e.g., anthropic/claude-opus-4-6)
  2. Model override from payload.model (e.g., zai/glm-5.1) triggers resolveLiveSessionModelSelection() which detects the difference
  3. LiveSessionModelSwitchError is thrown in auth-profiles-B5ypC5S-.js at the session runner level
  4. The runner in agent-runner.runtime-C-sR1PRP.js does handle this error gracefully for interactive sessions (it catches it, updates followupRun.run.provider/model, and continues)
  5. However, the cron scheduler treats it as fatal — the run is marked status: "error" and no retry occurs

Key Code Paths

Error generation (auth-profiles-B5ypC5S-.js):

// Before each attempt, checks if model selection changed
const nextSelection = resolvePersistedLiveSelection();
if (hasDifferentLiveSessionModelSelection(resolveCurrentLiveSelection(), nextSelection)) {
    throw new LiveSessionModelSwitchError(nextSelection);
}

Interactive runner handles it (agent-runner.runtime-C-sR1PRP.js):

if (err instanceof LiveSessionModelSwitchError) {
    params.followupRun.run.provider = err.provider;
    params.followupRun.run.model = err.model;
    params.followupRun.run.authProfileId = err.authProfileId;
    // continues...
}

But isExpectedNonErrorLaneFailure() marks it as expected non-error, suggesting the cron lane may not have the same retry logic.

Reproduction Steps

  1. Configure an agent with model.primary: "anthropic/claude-opus-4-6" (or any provider A model)
  2. Create a cron job with payload.model: "zai/glm-5.1" (or any provider B model)
  3. Trigger the cron manually or wait for schedule
  4. Observe: run fails immediately with LiveSessionModelSwitchError

Minimal Config

{
  "agents": {
    "list": [{
      "id": "my-agent",
      "model": {
        "primary": "anthropic/claude-opus-4-6",
        "fallbacks": ["zai/glm-5-turbo"]
      }
    }]
  }
}
{
  "name": "test-cron",
  "schedule": { "kind": "every", "everyMs": 600000 },
  "sessionTarget": "isolated",
  "payload": {
    "kind": "agentTurn",
    "model": "zai/glm-5.1",
    "message": "Hello world"
  }
}

Expected Behavior

The cron job's payload.model should be used as the session's initial model, not trigger a model switch after session creation.

Actual Behavior

LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-opus-4-6

Duration: ~2-6 seconds, no actual LLM call is made.

Workaround

Set the agent's model.primary to the same provider used in cron payloads. This defeats the purpose of per-cron model selection.

Impact

  • All cron jobs on agents with cross-provider primary models are broken
  • Affects qa-tester, supply-chain-monitor, clawbbo-sync — 41+ consecutive failures on one job alone
  • The model field in cron payload is documented as functional but silently fails

Suggested Fix

Either:

  1. Apply payload.model before session creation (ideal — prevents the switch entirely)
  2. Add the same retry/switch logic to the cron lane that the interactive runner already has
  3. Clear isExpectedNonErrorLaneFailure handling so the error is retried as a transient failure

extent analysis

TL;DR

Apply the payload.model before session creation or add retry/switch logic to the cron lane to fix the LiveSessionModelSwitchError issue in cron jobs.

Guidance

  • Review the session creation process to determine where the payload.model can be applied before the session is created, potentially in the resolveLiveSessionModelSelection() function.
  • Consider adding a try-catch block in the cron scheduler to catch the LiveSessionModelSwitchError and apply the same retry/switch logic as the interactive runner.
  • Investigate the isExpectedNonErrorLaneFailure() function to understand why it marks the LiveSessionModelSwitchError as an expected non-error and determine if this handling can be cleared or modified.
  • Evaluate the impact of setting the agent's model.primary to the same provider used in cron payloads as a temporary workaround, despite defeating the purpose of per-cron model selection.

Example

// Example of applying payload.model before session creation
const nextSelection = resolvePersistedLiveSelection(payload.model);
if (hasDifferentLiveSessionModelSelection(resolveCurrentLiveSelection(), nextSelection)) {
    // Update the session model selection before throwing the error
    updateSessionModelSelection(nextSelection);
} else {
    throw new LiveSessionModelSwitchError(nextSelection);
}

Notes

The provided code snippets and analysis suggest that the issue is related to the order of operations in the session creation process and the handling of the LiveSessionModelSwitchError in the cron scheduler. However, without further information about the specific requirements and constraints of the system, it is difficult to provide a more detailed solution.

Recommendation

Apply the workaround of setting the agent's model.primary to the same provider used in cron payloads, despite its limitations, until a more permanent fix can be implemented. This will allow cron jobs to function correctly, although it will defeat the purpose of per-cron model selection.

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 Cron isolated sessions fail with LiveSessionModelSwitchError when agent primary model differs from payload.model [1 participants]