Skip to content

[Bug] Cron isolated jobs created from chat sessions may persist current sessionKey and lose true isolation #58083

Closed as duplicate

Description

@jrsdhr

Summary

When creating a cron job from a Discord/chat session with sessionTarget: "isolated", OpenClaw appears to persist the current chat sessionKey onto the job even when sessionKey was not explicitly provided.

That makes the job run against the chat-bound session instead of the expected isolated cron:<jobId> session, which can leak session/model state into a background script-style cron and cause runtime failures such as LiveSessionModelSwitchError.

Expected behavior

For cron jobs with:

  • sessionTarget: "isolated"
  • no explicit sessionKey provided

OpenClaw should run the job in an isolated cron session (cron:<jobId>) and should not implicitly persist the creating chat/session sessionKey onto the job.

Actual behavior

Creating the cron job from a Discord session produced a stored job like this (abridged):

{
  "sessionTarget": "isolated",
  "payload": {
    "kind": "agentTurn",
    "model": "anthropic/claude-sonnet-4-6"
  },
  "sessionKey": "agent:cron-lite:discord:channel:1475102142951067682"
}

Because sessionKey is present, the isolated runner uses that session key instead of cron:<jobId>.

Why this seems wrong

From the runtime code path, isolated cron execution uses roughly:

const baseSessionKey = params.sessionKey?.trim() || `cron:${params.job.id}`;

So if a job gets a sessionKey injected during creation, it no longer behaves like a clean isolated cron run.

This is especially problematic for script-style jobs that:

  • do not need chat history
  • do not need current-session binding
  • use delivery.mode = "none"
  • are intended to run as clean background tasks

Observed failure mode

The affected job started failing with model-switch conflicts like:

LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-haiku-4-5

and earlier also:

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

This strongly suggests the cron run was inheriting/contending with model state from the chat-bound session.

Reproduction

  1. From a Discord/OpenClaw chat session, create a cron job using the cron tool/API with:
    • sessionTarget: "isolated"
    • payload.kind: "agentTurn"
    • no explicit sessionKey
  2. Inspect the stored/listed cron job.
  3. Observe that the job may contain the current chat sessionKey.
  4. Run the job and observe that it does not behave like a clean cron:<jobId> isolated session.

Workaround

Manually clearing the stored sessionKey fixes the issue:

{
  "patch": {
    "sessionKey": null
  }
}

After patching sessionKey to null, the job no longer shows the chat-bound session key and behaves as expected.

Additional notes

This does not look like a problem with the isolated cron execution core itself.
The likely issue seems to be in the cron creation/request path, where the creating session's sessionKey is being implicitly forwarded/persisted onto the job even for sessionTarget: "isolated" jobs.

That may be reasonable for sessionTarget: "current", but it seems incorrect for plain isolated jobs.

Activity

  1. changed the title [-]Cron isolated jobs created from chat sessions may persist current sessionKey and lose true isolation[/-] [+][Bug] Cron isolated jobs created from chat sessions may persist current sessionKey and lose true isolation[/+] on Mar 31, 2026
  2. jrsdhr commented on Mar 31, 2026

    @jrsdhr
    Author

    Additional evidence from a second reproduction path (another Discord channel context):

    New findings

    This is not limited to one specific cron payload or delivery flow.

    I reproduced the problem with minimal isolated jobs created from a Discord channel context:

    A. Minimal job with Discord delivery

    • sessionTarget: isolated
    • payload model: anthropic/claude-opus-4-6
    • payload body: send one fixed text message only
    • result: failed with
      • LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-haiku-4-5

    B. Minimal job with delivery.mode = none

    • sessionTarget: isolated
    • payload model: anthropic/claude-opus-4-6
    • payload body: reply with exact fixed text, no tools, no delivery
    • result: failed with the same error
      • LiveSessionModelSwitchError: Live session model switch requested: anthropic/claude-haiku-4-5

    Important implication

    This strongly suggests the bug is not only in Discord delivery / announce.

    Even a minimal isolated job with delivery.mode = none created from the chat session is still inheriting / binding to the current Discord live session context.

    Stronger evidence: sessionKey injection still happens at creation time

    When creating both minimal jobs from the Discord channel context, the returned job objects already contained:

    • sessionTarget: "isolated"
    • but also an unexpected sessionKey shaped like:
      • agent:cron-lite:discord:channel:<channel-id>

    That means:

    1. the contamination happens at cron job creation time, not only at run time
    2. it happens even when delivery.mode = none
    3. isolated is therefore not truly isolated for chat-created jobs

    Why this matters

    This explains why unrelated isolated cron jobs can fail before doing any real work:

    • not a script problem
    • not a TTS problem
    • not necessarily a delivery problem
    • but a session inheritance bug / design flaw in chat-created cron jobs

    Suggested clarification / fix

    For jobs with:

    • sessionTarget = "isolated"
    • and no explicit sessionKey

    OpenClaw should never automatically persist the current chat sessionKey into the job, regardless of delivery mode.

    Instead it should always run on a clean cron session like:

    • cron:<jobId>
    • or a per-run isolated session

    Right now, chat-created isolated jobs appear to silently bind to the originating Discord session, which then causes cross-model live-session conflicts.

  3. vincentkoc commented on Apr 25, 2026

    @vincentkoc
    Member

    Closing this as a duplicate of #70619. Persisting the current session key into isolated cron jobs is part of the same isolation/state-contamination family.

  4. added
    dedupe:child
    close:duplicate
    on Apr 25, 2026
  5. locked as resolved and limited conversation to collaborators on Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    close:duplicatededupe:child

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions