openclaw - 💡(How to fix) Fix [Bug]: Inbound DM creates new isolated session that inherits a closed cron run's sessionKey, causing the cron task to re-execute [1 comments, 2 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#78074Fetched 2026-05-06 06:17:10
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
2
Author
Timeline (top)
labeled ×2commented ×1

After a sessionTarget=isolated cron job finishes, an inbound DM that arrives within ~1 minute is materialized as a brand-new isolated session whose sessionKey is the just-closed cron's run key (agent:<id>:cron:<jobId>:run:<runId>); the new session interprets the DM under the closed cron's "Your Role" task and re-executes it, causing duplicate side effects (in our case, a duplicate monthly report email).

Root Cause

After a sessionTarget=isolated cron job finishes, an inbound DM that arrives within ~1 minute is materialized as a brand-new isolated session whose sessionKey is the just-closed cron's run key (agent:<id>:cron:<jobId>:run:<runId>); the new session interprets the DM under the closed cron's "Your Role" task and re-executes it, causing duplicate side effects (in our case, a duplicate monthly report email).

Code Example

=== 1. Closed cron run ===
File: ~/.openclaw/agents/youtube/sessions/703dd922-dde2-4f32-8ef7-b51d204cf606.trajectory.jsonl
session.started ts: 2026-05-01T05:00:13.228Z
sessionKey: agent:youtube:cron:b5e2cfe3-78ef-43cc-9b06-8501f762d1fd:run:703dd922-dde2-4f32-8ef7-b51d204cf606
runId: 703dd922-dde2-4f32-8ef7-b51d204cf606
data.trigger: "cron"
session.ended (closed normally): 2026-05-01T05:08:25.609Z  -- email delivered, summary OK

=== 2. New session created 53 seconds later, reusing the closed run's sessionKey ===
File: ~/.openclaw/agents/youtube/sessions/cac575da-2edc-4871-a8ad-0f8b29d0dccf.trajectory.jsonl
session.started ts: 2026-05-01T05:09:18.450Z
sessionId:  cac575da-2edc-4871-a8ad-0f8b29d0dccf  <-- NEW
runId:      1fdaa485-1669-4b24-be55-c0ec7de46619  <-- NEW
sessionKey: agent:youtube:cron:b5e2cfe3-78ef-43cc-9b06-8501f762d1fd:run:703dd922-dde2-4f32-8ef7-b51d204cf606  <-- REUSED FROM CLOSED RUN
data.trigger: "user"
data.messageChannel: "webchat"
data.toolCount: 20
data.workspaceDir: /home/ubuntu/.openclaw/workspace-youtube

prompt.submitted text:
  "[Fri 2026-05-01 07:08 GMT+2] Buenas noches, Juli. Que descanses 👁️"

systemPrompt -> "Your Role" block (excerpt): contains the full cron task verbatim:
  "# Tarea: Informe Mensual AnalyticsMayo 2026
   **Trigger:** Cron día 1 de mayo (7:00 CEST). Ejecutar SO-7 completo.
   ..."

Result: the model re-executed the monthly report, sending a duplicate email to
the user (Gmail Message-ID <69f43739.d40a0220.4a776.a452@mx.google.com> at
07:10 CEST, ~10 min after the original 07:00 CEST report).

=== 3. Pattern is not isolated ===
A grep over the last 30 days of trajectories
  (filter: session.started.sessionKey contains ":cron:<uuid>:run:<uuid>"
   AND data.trigger == "user")
returned 12 matches across both agents (main and youtube) and 7 distinct cron job IDs:

  2026-05-01T03:05  agent:main:cron:36ed96ea:run:4301eba2     trigger=user
  2026-05-01T05:09  agent:youtube:cron:b5e2cfe3:run:703dd922  trigger=user   <-- duplicate email
  2026-05-01T05:31  agent:main:cron:74768b89:run:577da363     trigger=user
  2026-05-01T08:04  agent:main:cron:c89b99e9:run:81ea4e14     trigger=user
  2026-05-01T16:10  agent:youtube:cron:9fc2ec57:run:283bf2e6  trigger=user
  2026-05-01T19:51  agent:main:cron:33a23856:run:22fb867c     trigger=user
  2026-05-03T05:31  agent:main:cron:74768b89:run:36058d36     trigger=user
  2026-05-04T05:11  agent:youtube:cron:9fc2ec57:run:0a524142  trigger=user
  2026-05-04T05:31  agent:main:cron:74768b89:run:66e9bc58     trigger=user
  2026-05-04T06:01  agent:main:cron:0954482f:run:8224e358     trigger=user
  2026-05-05T03:04  agent:main:cron:36ed96ea:run:253acfb7     trigger=user
  2026-05-05T05:31  agent:main:cron:74768b89:run:27e8e524     trigger=user

Most of these resolved to NO_REPLY (the model recognized the mismatch); one
(2026-05-01 05:09) re-executed a side-effecting task and produced the duplicate
email described above.
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

After a sessionTarget=isolated cron job finishes, an inbound DM that arrives within ~1 minute is materialized as a brand-new isolated session whose sessionKey is the just-closed cron's run key (agent:<id>:cron:<jobId>:run:<runId>); the new session interprets the DM under the closed cron's "Your Role" task and re-executes it, causing duplicate side effects (in our case, a duplicate monthly report email).

Steps to reproduce

  1. Start OpenClaw 2026.4.27 with session.dmScope: "main", a single-owner Telegram allowlist, and a non-default agent (agentId: youtube) configured.
  2. Configure an isolated cron job for that agent (payload.kind: agentTurn, sessionTarget: isolated, payload.model: claude-sonnet-4-6) whose payload.message contains a substantive task in a "# Tarea / Your Role" block — e.g. a monthly analytics report that ends by sending an email.
  3. Let the cron fire and finish normally. Confirm the run closes (session.ended in the trajectory) and the side effect (e.g. report email) is delivered.
  4. Within ~1 minute of the run closing, send any inbound DM from the parent agent's main session that, under dmScope=main, would normally route to agent:main:main (in our case a one-line "Buenas noches, Juli." emitted automatically from a different cron a few seconds later).
  5. Inspect ~/.openclaw/agents/<agentId>/sessions/ for new *.trajectory.jsonl files created in that minute.

Expected behavior

The inbound DM lands in agent:main:main (per dmScope=main). No new session is created in agents/<other-agentId>/sessions/. Closed cron run sessionKeys are not reusable as targets for inbound user messages. The cron task does not re-execute.

Actual behavior

A brand-new session file is created under the cron's agent (agents/youtube/sessions/<new-uuid>.jsonl + matching .trajectory.jsonl). Its session.started event has:

  • sessionId: a fresh UUID (different from the closed run).
  • runId: a fresh UUID.
  • sessionKey: literally agent:youtube:cron:<jobId>:run:<closed-runId> — i.e. the closed cron run's key, reused.
  • data.trigger: "user", data.messageChannel: "webchat".
  • spawnedBy: null, requesterSessionKey: null.
  • data.toolCount: 20 (the cron's tool profile, not the parent main's profile).
  • The compiled system prompt contains the cron's full "Your Role" / "# Tarea" block verbatim.

The DM text is delivered as the prompt.submitted payload to that fresh session. The model interprets the combination (inbound user text + cron task in system prompt) as a re-trigger of the cron task and re-executes it (in our case re-sending the monthly report email to the user).

The same pattern shows up across multiple agents and crons over a 5-day window — see "Logs and evidence".

OpenClaw version

2026.4.27

Operating system

Ubuntu 24.04 (arm64) — Oracle Cloud VPS

Install method

npm global

Model

anthropic/claude-sonnet-4-6 (cron payload). Inbound DM that triggered the reuse came from a different agent running anthropic/claude-opus-4-7.

Provider / routing chain

openclaw -> anthropic (direct)

Additional provider/model setup details

  • Two agents on the same gateway: main (Opus 4.7) and youtube (Sonnet 4.6, separate workspace ~/.openclaw/workspace-youtube/).
  • Top-level session.dmScope: "main", single-owner Telegram allowlist (one user id).
  • The cron is agentId: youtube, sessionTarget: isolated, schedule.kind: cron, payload.kind: agentTurn, delivery.mode: announce, delivery.channel: telegram.
  • Cross-agent message delivery from main to youtube was triggered from the main session via the runtime's normal DM path (not via sessions_send); the messageChannel: webchat on the new session is what the runtime recorded.

Logs, screenshots, and evidence

=== 1. Closed cron run ===
File: ~/.openclaw/agents/youtube/sessions/703dd922-dde2-4f32-8ef7-b51d204cf606.trajectory.jsonl
session.started ts: 2026-05-01T05:00:13.228Z
sessionKey: agent:youtube:cron:b5e2cfe3-78ef-43cc-9b06-8501f762d1fd:run:703dd922-dde2-4f32-8ef7-b51d204cf606
runId: 703dd922-dde2-4f32-8ef7-b51d204cf606
data.trigger: "cron"
session.ended (closed normally): 2026-05-01T05:08:25.609Z  -- email delivered, summary OK

=== 2. New session created 53 seconds later, reusing the closed run's sessionKey ===
File: ~/.openclaw/agents/youtube/sessions/cac575da-2edc-4871-a8ad-0f8b29d0dccf.trajectory.jsonl
session.started ts: 2026-05-01T05:09:18.450Z
sessionId:  cac575da-2edc-4871-a8ad-0f8b29d0dccf  <-- NEW
runId:      1fdaa485-1669-4b24-be55-c0ec7de46619  <-- NEW
sessionKey: agent:youtube:cron:b5e2cfe3-78ef-43cc-9b06-8501f762d1fd:run:703dd922-dde2-4f32-8ef7-b51d204cf606  <-- REUSED FROM CLOSED RUN
data.trigger: "user"
data.messageChannel: "webchat"
data.toolCount: 20
data.workspaceDir: /home/ubuntu/.openclaw/workspace-youtube

prompt.submitted text:
  "[Fri 2026-05-01 07:08 GMT+2] Buenas noches, Juli. Que descanses 👁️"

systemPrompt -> "Your Role" block (excerpt): contains the full cron task verbatim:
  "# Tarea: Informe Mensual Analytics — Mayo 2026
   **Trigger:** Cron día 1 de mayo (7:00 CEST). Ejecutar SO-7 completo.
   ..."

Result: the model re-executed the monthly report, sending a duplicate email to
the user (Gmail Message-ID <[email protected]> at
07:10 CEST, ~10 min after the original 07:00 CEST report).

=== 3. Pattern is not isolated ===
A grep over the last 30 days of trajectories
  (filter: session.started.sessionKey contains ":cron:<uuid>:run:<uuid>"
   AND data.trigger == "user")
returned 12 matches across both agents (main and youtube) and 7 distinct cron job IDs:

  2026-05-01T03:05  agent:main:cron:36ed96ea:run:4301eba2     trigger=user
  2026-05-01T05:09  agent:youtube:cron:b5e2cfe3:run:703dd922  trigger=user   <-- duplicate email
  2026-05-01T05:31  agent:main:cron:74768b89:run:577da363     trigger=user
  2026-05-01T08:04  agent:main:cron:c89b99e9:run:81ea4e14     trigger=user
  2026-05-01T16:10  agent:youtube:cron:9fc2ec57:run:283bf2e6  trigger=user
  2026-05-01T19:51  agent:main:cron:33a23856:run:22fb867c     trigger=user
  2026-05-03T05:31  agent:main:cron:74768b89:run:36058d36     trigger=user
  2026-05-04T05:11  agent:youtube:cron:9fc2ec57:run:0a524142  trigger=user
  2026-05-04T05:31  agent:main:cron:74768b89:run:66e9bc58     trigger=user
  2026-05-04T06:01  agent:main:cron:0954482f:run:8224e358     trigger=user
  2026-05-05T03:04  agent:main:cron:36ed96ea:run:253acfb7     trigger=user
  2026-05-05T05:31  agent:main:cron:74768b89:run:27e8e524     trigger=user

Most of these resolved to NO_REPLY (the model recognized the mismatch); one
(2026-05-01 05:09) re-executed a side-effecting task and produced the duplicate
email described above.

Impact and severity

  • Affected: OpenClaw operators running 2+ agents with isolated cron jobs and dmScope=main. Both agent:main and a separate agent:youtube were affected on the same install.
  • Severity: Medium-high. Mostly silent (NO_REPLY), but on tasks with external side effects (email send, posting to a third-party API) it causes duplicates. We observed one duplicate monthly-report email delivered to the end user.
  • Frequency: 12 occurrences observed across 5 days on a single install with 7 distinct cron jobs, so it is not a one-off; it triggers whenever a DM lands wi ...(truncated)...

Additional information

No response

extent analysis

TL;DR

The issue can be mitigated by ensuring that the sessionKey for a new session is not reused from a recently closed cron run, potentially by introducing a delay or a unique identifier.

Guidance

  • Investigate the sessionKey generation logic to prevent reuse of recently closed cron run sessionKeys.
  • Consider introducing a delay between the closure of a cron run and the creation of a new session to prevent immediate reuse of the sessionKey.
  • Review the logic for handling inbound DMs to ensure that they are correctly routed to the intended agent and session.
  • Analyze the data.trigger and data.messageChannel fields to understand how the new session is being triggered and how the message is being delivered.

Example

No code snippet is provided as the issue is related to the logic and configuration of the OpenClaw system, and the exact code changes required are not clear from the provided information.

Notes

The issue appears to be related to the interaction between the OpenClaw system, the cron jobs, and the handling of inbound DMs. The provided logs and evidence suggest that the issue is not isolated to a single agent or cron job, but rather a more systemic issue.

Recommendation

Apply a workaround by introducing a delay or a unique identifier to prevent the reuse of recently closed cron run sessionKeys, as this is the most likely cause of the issue. This will help prevent duplicate side effects, such as duplicate emails, until a more permanent fix can be implemented.

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…

FAQ

Expected behavior

The inbound DM lands in agent:main:main (per dmScope=main). No new session is created in agents/<other-agentId>/sessions/. Closed cron run sessionKeys are not reusable as targets for inbound user messages. The cron task does not re-execute.

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]: Inbound DM creates new isolated session that inherits a closed cron run's sessionKey, causing the cron task to re-execute [1 comments, 2 participants]