Skip to content

LiveSessionModelSwitchError crashes all isolated cron sessions #57862

@opendorai

Description

@opendorai

Bug: LiveSessionModelSwitchError crashes all isolated cron sessions

Version

OpenClaw 2026.3.28 (f9b1079, latest on npm)

Description

All cron jobs with sessionTarget: "isolated" crash immediately with LiveSessionModelSwitchError. The error occurs regardless of model configuration, payload settings, or agent setup.

Error Pattern

LiveSessionModelSwitchError: Live session model switch requested: zai/glm-4.7

The "requested" model in the error message always matches the agent's configured primary model — no actual model switch is happening.

Affected Jobs

All jobs with sessionTarget: "isolated" fail. Jobs using other session targets (e.g., main with kind: "systemEvent") work fine.

Job Agent Agent Primary Error Model Result
twitter-research scout glm-4.7 glm-4.7 crash (3.2s)
web-research scout glm-4.7 glm-4.7 crash (0.4s)
memory-consolidation archivist glm-4.7-flashx glm-4.7-flashx crash (6.9s)
morning-brief dora glm-5-turbo glm-5-turbo crash (1.9s)

What We Tested (none fixed it)

  1. Removed model from job payload → still crashes
  2. Set model in payload to match agent primary exactly → still crashes
  3. Removed lightContext, thinking, fallbacks from payload → still crashes
  4. Gateway restart (clean, single instance) → still crashes
  5. Deleted all stale session files for affected agents → still crashes
  6. Reset job state (removed cached sessionId, reset consecutiveErrors) → still crashes
  7. Verified single gateway process (found and killed duplicate) → still crashes
  8. All 6 model APIs respond correctly when tested directly
  9. All agent API keys are valid (unique per-agent keys)
  10. Provider configs are complete in each agent's models.json

Source Code Analysis

Examined the bundled source in dist/auth-profiles-B5ypC5S-.js:

// These are the SAME function — both read from LIVE_MODEL_SELECTIONS Map
function resolveCurrentLiveSelection(sessionKey) {
    const current = LIVE_MODEL_SELECTIONS.get(sessionKey);
    return current ?? void 0;
}
function resolvePersistedLiveSelection(sessionKey) {
    return resolveCurrentLiveSelection(sessionKey);
}

The check in agent-runner.runtime:

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

Since both functions are identical and called without arguments, both should return undefinedhasDifferentLiveSessionModelSelection(undefined, undefined) returns false → error should never trigger. Yet it does.

This suggests either:

  • An async operation modifies LIVE_MODEL_SELECTIONS between the two calls
  • Or the resolveModelSelectionForSession() call earlier in the run sets a selection that conflicts with itself
  • Or the functions are being called WITH different session keys in the actual runtime (the minified code may behave differently than the source suggests)

Reproduction

  1. Create a cron job with sessionTarget: "isolated" and payload.kind: "agentTurn"
  2. Manually trigger it: via the cron API/tool
  3. Observe immediate crash with LiveSessionModelSwitchError

Environment

  • OS: WSL2 (Linux 6.6.87.2-microsoft-standard-WSL2, x64)
  • Node: v22.22.1
  • Agents: 6 configured agents (main/dora, scout, forge, archivist, watchman, rainmaker) with per-agent API keys and models
  • Global default model: zai/glm-5-turbo
  • Provider: ZAI (first-party, 6 models registered)

Workaround

Disable all isolated cron jobs and run them manually from an interactive session when needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions