openclaw - 💡(How to fix) Fix [Bug]: Context overflow reset can map sessionFile to nonexistent transcript, orphaning real session history [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#75151Fetched 2026-05-01 05:37:40
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
2
Author
Timeline (top)
commented ×1cross-referenced ×1mentioned ×1subscribed ×1

A long-lived Telegram direct agent session hit context-overflow / compaction failure, then the active sessions.json mapping was rotated to a new sessionId whose transcript file was never created. As a result, chat.history / session lookup returned an empty history even though the real prior transcript still existed on disk under the previous session id.

From the user perspective this looked like the agent was "cut off without compaction" and had forgotten all recent work. Manual forensic recovery showed the prior transcript was intact, but orphaned from the active session mapping.

This appears related to the existing context overflow / compaction / session mapping issue family, but this case adds a specific failure mode:

  • reset/rotation chooses a new sessionId
  • sessions.json points the direct session key at that new id and sessionFile
  • the new .jsonl transcript file does not exist
  • the real active/recent work remains in the previous large .jsonl
  • history lookup for the session key returns empty or stale data

Error Message

promptError: "Context overflow: prompt too large for the model (precheck)" promptErrorSource: "precheck" context.compiled events truncated at trajectory-event-size-limit originalBytes often ~273K-515K+

Root Cause

For long-lived agents, this becomes a practical "memory wipe" even though the data is still present on disk. It is especially painful for tool-heavy business/ops agents where compaction is supposed to preserve working state.

Fix Action

Fix / Workaround

Suggested fixes / mitigations

Code Example

{
  "sessionId": "6855a9b8-...",
  "sessionFile": ".../agents/<agent>/sessions/6855a9b8-....jsonl",
  "compactionCount": 10,
  "authProfileOverrideCompactionCount": 10,
  "systemSent": false,
  "abortedLastRun": false
}

---

.../agents/<agent>/sessions/6855a9b8-....jsonl -> ENOENT / exists false

---

.../agents/<agent>/sessions/59eb5fe8-....jsonl
size: ~14 MB
rows: ~5356
latest content: recent successful user/assistant/tool turns

---

promptError: "Context overflow: prompt too large for the model (precheck)"
promptErrorSource: "precheck"
context.compiled events truncated at trajectory-event-size-limit
originalBytes often ~273K-515K+
RAW_BUFFERClick to expand / collapse

Summary

A long-lived Telegram direct agent session hit context-overflow / compaction failure, then the active sessions.json mapping was rotated to a new sessionId whose transcript file was never created. As a result, chat.history / session lookup returned an empty history even though the real prior transcript still existed on disk under the previous session id.

From the user perspective this looked like the agent was "cut off without compaction" and had forgotten all recent work. Manual forensic recovery showed the prior transcript was intact, but orphaned from the active session mapping.

This appears related to the existing context overflow / compaction / session mapping issue family, but this case adds a specific failure mode:

  • reset/rotation chooses a new sessionId
  • sessions.json points the direct session key at that new id and sessionFile
  • the new .jsonl transcript file does not exist
  • the real active/recent work remains in the previous large .jsonl
  • history lookup for the session key returns empty or stale data

Environment

  • OpenClaw: 2026.4.26
  • Runtime: Node v22.22.0
  • OS: Darwin arm64
  • Channel: Telegram direct agent session
  • Provider/model: openai-codex/gpt-5.5
  • Affected pattern: long-lived tool-heavy agent session with many compactions / summaries

Observed state

The session index entry for the Telegram direct agent key pointed to a new session id similar to:

{
  "sessionId": "6855a9b8-...",
  "sessionFile": ".../agents/<agent>/sessions/6855a9b8-....jsonl",
  "compactionCount": 10,
  "authProfileOverrideCompactionCount": 10,
  "systemSent": false,
  "abortedLastRun": false
}

But the referenced file did not exist:

.../agents/<agent>/sessions/6855a9b8-....jsonl -> ENOENT / exists false

Meanwhile, the real recent transcript existed and contained the latest user/assistant/tool work:

.../agents/<agent>/sessions/59eb5fe8-....jsonl
size: ~14 MB
rows: ~5356
latest content: recent successful user/assistant/tool turns

Trajectory evidence for the real transcript showed repeated context/precheck failures:

promptError: "Context overflow: prompt too large for the model (precheck)"
promptErrorSource: "precheck"
context.compiled events truncated at trajectory-event-size-limit
originalBytes often ~273K-515K+

Some runs succeeded, but several subsequent runs failed before assistant output. This created brittle behavior around compaction/recovery and eventually produced the bad mapping to a missing transcript.

Actual behavior

  1. Long-lived session grows very large.
  2. Context precheck overflows repeatedly.
  3. Compaction/truncation attempts occur, but the active transcript is not reliably rotated/shrunk enough.
  4. Runtime resets/rotates the active session mapping to a new session id.
  5. The new transcript file is not created / prewarmed.
  6. sessions.json points at the missing file.
  7. chat.history / session lookup returns no useful messages.
  8. The agent appears to have lost continuity even though the old transcript still exists.

Expected behavior

If OpenClaw rotates/resets a session after compaction/precheck failure, it should guarantee one of these safe outcomes:

  1. The session key points to a real transcript containing a compacted continuity summary, or
  2. The new transcript file is created/prewarmed before the session store is updated, or
  3. The old transcript remains mapped until the new transcript is durable, or
  4. Recovery uses the last valid transcript/checkpoint instead of returning empty history.

At minimum, sessions.json should not point sessionFile at a nonexistent .jsonl.

Why this matters

For long-lived agents, this becomes a practical "memory wipe" even though the data is still present on disk. It is especially painful for tool-heavy business/ops agents where compaction is supposed to preserve working state.

Related issues

Possibly related / same bug family:

  • #70472
  • #70744
  • #50620
  • #65564
  • #72676
  • #60213
  • #66360

Suspected root cause

Based on local forensics, likely a combination of:

  • oversized append-only transcript
  • compaction target / precheck budget mismatch
  • no active transcript rotation/shrink after compaction in this path
  • reset path updating session metadata before the new transcript exists
  • queued/nested followups possibly retaining stale sessionFile references

Suggested fixes / mitigations

  • Ensure compaction-success path can rotate/shrink active transcript when it remains too large.
  • Add a guard: never persist a sessionFile path in sessions.json unless the file exists or has just been durably created.
  • In reset/rotation path, prewarm/write the new transcript before switching the session key mapping.
  • If new transcript creation fails, keep mapping to the previous valid transcript and surface an explicit recovery warning.
  • Consider a max active transcript byte cap for individual .jsonl files, not only session index maintenance.
  • Add a repair command/check that detects sessions.json entries pointing at missing transcript files and suggests/remaps to the most recent valid transcript/checkpoint.

extent analysis

TL;DR

To fix the issue, ensure that the new transcript file is created and exists before updating the sessions.json mapping, and consider implementing a guard to prevent pointing to non-existent files.

Guidance

  • Verify that the compaction-success path can rotate/shrink the active transcript when it remains too large.
  • Add a check to ensure the new transcript file exists before updating the sessionFile path in sessions.json.
  • In the reset/rotation path, prewarm/write the new transcript before switching the session key mapping.
  • Consider implementing a max active transcript byte cap for individual .jsonl files to prevent oversized transcripts.

Example

No code example is provided as the issue does not contain sufficient information to create a specific code snippet.

Notes

The issue appears to be related to a combination of oversized transcripts, compaction target/precheck budget mismatch, and incorrect session metadata updates. The suggested fixes aim to address these issues, but further investigation and testing may be necessary to ensure a complete resolution.

Recommendation

Apply the suggested fixes, particularly ensuring that the new transcript file is created and exists before updating the sessions.json mapping, to prevent the "memory wipe" issue and ensure continuity for long-lived agents.

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

If OpenClaw rotates/resets a session after compaction/precheck failure, it should guarantee one of these safe outcomes:

  1. The session key points to a real transcript containing a compacted continuity summary, or
  2. The new transcript file is created/prewarmed before the session store is updated, or
  3. The old transcript remains mapped until the new transcript is durable, or
  4. Recovery uses the last valid transcript/checkpoint instead of returning empty history.

At minimum, sessions.json should not point sessionFile at a nonexistent .jsonl.

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]: Context overflow reset can map sessionFile to nonexistent transcript, orphaning real session history [1 comments, 2 participants]