openclaw - ✅(Solved) Fix /new session reset doesn't purge system-events queue — stale events leak into fresh session [1 pull requests, 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#66864Fetched 2026-04-16 06:37:35
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×2referenced ×2commented ×1

Root Cause

Because sessionKey is preserved across /new, any system events enqueued before the reset (e.g., exec failure notifications from maybeNotifyOnExit) survive and get drained by rebuildPromptBodies into the first user message of the fresh session as System (untrusted): ... prefixed text.

Fix Action

Fixed

PR fix notes

PR #66868: fix: drain system events on session reset to prevent cross-session leak

Description (problem / solution / changelog)

Summary

  • Fixes #66864: System events queue not purged on /new session reset
  • Drains system-events Map entries in ensureSessionRuntimeCleanup for each queue key
  • Prevents stale exec failure notifications from leaking into fresh sessions

Problem

When a session is reset via /new, ensureSessionRuntimeCleanup called clearSessionQueues() to purge followup/command lane queues, but did not drain the process-global system-events Map. Because sessionKey is preserved across /new, any system events enqueued before the reset survived and got drained into the first user message of the fresh session.

Solution

Added a loop to call drainSystemEventEntries(key) for each queue key after clearing session queues. This is symmetric with the existing followup/command queue purge.

Test Plan

  • Updated server.sessions.gateway-server-sessions-a.e2e.test.ts to mock and verify drainSystemEventEntries is called for each queue key
  • All 9 session tests pass
  • E2E test suite runs clean

🤖 Generated with Claude Code

Changed files

  • src/gateway/server-methods/sessions.ts (modified, +4/-0)
  • src/gateway/server.sessions.gateway-server-sessions-a.e2e.test.ts (modified, +19/-0)
RAW_BUFFERClick to expand / collapse

Bug

When a session is reset via /new, performGatewaySessionReset → ensureSessionRuntimeCleanup calls clearSessionQueues() to purge followup/command lane queues, but does not drain the process-global system-events Map (keyed by sessionKey).

Because sessionKey is preserved across /new, any system events enqueued before the reset (e.g., exec failure notifications from maybeNotifyOnExit) survive and get drained by rebuildPromptBodies into the first user message of the fresh session as System (untrusted): ... prefixed text.

Impact

  • Fresh sessions can start with stale, unrelated system event text injected into the first user message
  • Exec failure events may contain file paths or truncated command output, creating unintended context leakage across session boundaries
  • Affects all channels, not Telegram-specific

Reproduction

  1. Trigger an exec failure in an active session (any command that exits non-zero)
  2. Run /new
  3. Send any message — inspect the first user row in the session JSONL
  4. The stale exec failure text appears as a System (untrusted): prefix on the first user message

Proposed Fix

In ensureSessionRuntimeCleanup, after clearSessionQueues([...queueKeys]), loop-drain drainSystemEventEntries(key) for each queue key. ~5 lines, no function rewrite. This is symmetric with the existing followup/command queue purge.

Optional Hardening (separate concern)

Consider redacting or truncating raw exec output in maybeNotifyOnExit before enqueuing as system events, since even within a single session, failed commands can surface sensitive paths/content in model context.

extent analysis

TL;DR

Drain the process-global system-events Map in ensureSessionRuntimeCleanup to prevent stale system event text from being injected into fresh sessions.

Guidance

  • To fix the issue, loop-drain drainSystemEventEntries(key) for each queue key in ensureSessionRuntimeCleanup after clearSessionQueues([...queueKeys]).
  • Verify the fix by reproducing the issue using the provided steps and checking that the first user message in the session JSONL no longer contains stale system event text.
  • Consider implementing the proposed hardening measure of redacting or truncating raw exec output in maybeNotifyOnExit to prevent sensitive information from being surfaced in system events.
  • Review the ensureSessionRuntimeCleanup function to ensure that it correctly handles the draining of system event entries for each queue key.

Example

// Example of how to drain system event entries in ensureSessionRuntimeCleanup
for (const key of queueKeys) {
  drainSystemEventEntries(key);
}

Notes

The proposed fix assumes that the drainSystemEventEntries function is correctly implemented and can handle the draining of system event entries for each queue key. Additionally, the hardening measure of redacting or truncating raw exec output in maybeNotifyOnExit is a separate concern and may require additional implementation.

Recommendation

Apply the proposed fix by adding the loop-drain of system event entries in ensureSessionRuntimeCleanup to prevent stale system event text from being injected into fresh sessions. This fix is a targeted solution to the identified issue and does not require any significant changes to the existing codebase.

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