Skip to content

Cron model overrides cause LiveSessionModelSwitchError on isolated sessions #57155

Description

@jeremyknows

Bug

Cron jobs with payload.model overrides (e.g., Haiku on a Sonnet-primary agent) fail with LiveSessionModelSwitchError when running as sessionTarget: "isolated".

Reproduction

  1. Configure an agent with primary model anthropic/claude-sonnet-4-6
  2. Create an isolated cron job with payload.model: "anthropic/claude-haiku-4-5"
  3. Wait for the job to fire

Expected: Job runs with Haiku as documented ("We recommend model overrides only for isolated jobs")
Actual: LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-sonnet-4-6

Root Cause

New in v2026.3.28: src/agents/live-model-switch.ts adds live model switch detection. In src/agents/pi-embedded-runner/run.ts:452-457, resolvePersistedLiveSelection() fires on every run loop iteration unconditionally — including for cron/isolated sessions.

For cron jobs: the run starts with the payload model override (Haiku), but resolvePersistedLiveSelection() reads the session entry which has no modelOverride set → falls back to resolveDefaultModelForAgent() → returns the agent's primary (Sonnet) → mismatch detected → error thrown.

The check doesn't distinguish between:

  • Interactive session: user changed model in a live Discord conversation (intended use case)
  • Cron job: payload has a different model than the agent default (should be allowed)

params.trigger === "cron" is available at the call site and could be used to skip the check.

Suggested Fix

In src/agents/pi-embedded-runner/run.ts, guard the live model switch check:

// Line ~451
if (params.trigger !== "cron") {
  const nextSelection = resolvePersistedLiveSelection();
  if (hasDifferentLiveSessionModelSelection(resolveCurrentLiveSelection(), nextSelection)) {
    log.info(`live session model switch detected...`);
    throw new LiveSessionModelSwitchError(nextSelection);
  }
}

Same guard needed at the two other throw sites (~lines 598 and 613).

Impact

All cron jobs with model overrides on agents whose primary model differs. In our deployment: 46 jobs affected, forcing us to remove all Haiku overrides and run everything on Sonnet (~3x cost increase for lightweight maintenance jobs).

Environment

  • OpenClaw 2026.3.28 (9ac1eba)
  • macOS, Node 25.5.0
  • Agents with anthropic/claude-sonnet-4-6 primary model
  • Cron jobs with anthropic/claude-haiku-4-5 payload override
  • sessionTarget: "isolated" on all affected jobs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions