Skip to content

Session context compaction deletes active session transcripts #15404

@Chris0x88

Description

@Chris0x88

alias: GitHub-Issue-Session-Compaction-Bug
created: 2026-02-13T21:31+10:00
status: submitted
tags: [openclaw, bug-report, github, session-compaction]

GitHub Issue: Session Context Compaction Bug

Status: submitted
Created: 2026-02-13 21:31 AEST
Target: https://github.com/openclaw/openclaw/issues

Copy the contents below into a new GitHub issue.


Description

During an active session, the "Reduce Context" compaction process deleted the session transcript file (*.jsonl) while the session was still alive, causing session corruption and complete loss of conversation history. The session remained registered in the system but became unusable because the transcript file was missing.

System Details

  • OpenClaw Version: 2026.2.12 (runtime) / 2026.2.9 (wizard last run)
  • Default Model: openrouter/stepfun/step-3.5-flash:free
  • Compaction Mode: safeguard (from openclaw.json)
  • Platform: Mac Mini 16GB (Apple Silicon), Darwin 25.2.0, Node v25.6.0
  • Channel: webchat (primary), also configured for Telegram
  • Compaction Config:
"compaction": {
  "mode": "safeguard"
}

Steps to Reproduce

  1. Start a new session (via webchat or Telegram)
  2. Have a conversation spanning multiple turns
  3. Wait for automatic "Reduce Context" compaction to trigger (appears to run periodically)
  4. Observe that the session transcript file is deleted while session is still active
  5. Attempt to continue conversation - agent fails with ENOENT errors when trying to read session history
  6. Session becomes unresponsive; gateway restart required

Expected Behavior

  • Compaction should only process sessions that are completed or aborted, never sessions in processing or idle state
  • Active sessions should never have their transcript files deleted
  • The safeguard mode should provide strong protection against this

Observed Behavior

  • Session transcript file deleted 45 seconds after session creation
  • Session registry still listed the session as active
  • Log errors: ENOENT: no such file or directory, access '/Users/cdi/.openclaw/workspace/<session-id>.jsonl'
  • Session becomes corrupted and unusable
  • Gateway restart required to recover

Log Evidence

2026-02-13T10:33:55 - Session 2d204cc2-e0b6-431a-9ec2-ace99d6b0e53 created
2026-02-13T10:33:59 - First run completed successfully
2026-02-13T10:34:27 - Second run started
2026-02-13T10:34:38 - sessions_list tool executed successfully
2026-02-13T10:34:40.457 - ERROR: read failed: ENOENT: no such file or directory, access '/Users/cdi/.openclaw/workspace/2d204cc2-e0b6-431a-9ec2-ace99d6b0e53.jsonl'
2026-02-13T10:34:45 - Gateway restart triggered

# Compaction runs logged just before session creation:
2026-02-13T10:32:27 - embedded run compaction start: runId=2d78a865...
2026-02-13T10:33:08 - embedded run compaction start: runId=7a35987b...
2026-02-13T10:33:24 - embedded run compaction start: runId=f7f1136d...

Root Cause

The compaction logic does not adequately check session state or age before deleting transcript files. Despite being in safeguard mode, the process deleted a session that was:

  • Less than 60 seconds old
  • In idle state (between runs)
  • Still registered and used by the webchat channel

The compaction likely incorrectly classified the session as "expired" due to a bug in age calculation or state checking.

Impact

  • High severity: complete loss of conversation history within affected sessions
  • Session corruption requires manual intervention (gateway restart)
  • User experience: agent appears to stop responding with no clear error
  • Potential data loss if important context was in the transcript

Proposed Fix

  1. Add minimum age threshold: Never compact sessions younger than 10 minutes (configurable)
  2. Check session state explicitly: Only compact sessions with state completed or aborted, exclude processing and idle
  3. Add file lock/check: Verify transcript file is not currently in use before deletion
  4. Add safety logging: Log warning if attempting to delete a session that appears active
  5. Consider compaction.mode implementations:
    • safe: Only compact completed/aborted sessions older than threshold
    • safeguard: Current behavior appears broken; review implementation
    • disabled: No automatic compaction (manual cleanup only)

Workaround

As an immediate measure, users can disable compaction:

openclaw config.patch agents.defaults.compaction.mode disabled
openclaw gateway restart

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    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