openclaw - 💡(How to fix) Fix Sessions: orphan transcript files accumulate on failed/interrupted runs, no per-failure cleanup [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#78027Fetched 2026-05-06 06:17:44
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Timeline (top)
closed ×1commented ×1

When a session fails mid-run (API error, timeout, gateway saturation), the partial transcript file is written to the agent's sessions directory but never cleaned up. These "orphan" files accumulate indefinitely until a manual or scheduled maintenance pass removes them.

Error Message

When a session fails mid-run (API error, timeout, gateway saturation), the partial transcript file is written to the agent's sessions directory but never cleaned up. These "orphan" files accumulate indefinitely until a manual or scheduled maintenance pass removes them. OpenClaw writes the session transcript file when a session starts, but only removes/archives it on clean completion. There is no cleanup path in the error/interrupt exit branch. The openclaw sessions cleanup --fix-missing command removes them post-hoc, but it's not called automatically on failure. 2. Trigger an Anthropic API error (or simply run many short sessions in a high-load environment). On session exit via error or unclean interrupt, run the equivalent of sessions cleanup --fix-missing for that agent's store, or at minimum delete/archive the partial transcript for the failed session ID. This would prevent unbounded accumulation without needing a scheduled external cleanup.

Root Cause

OpenClaw writes the session transcript file when a session starts, but only removes/archives it on clean completion. There is no cleanup path in the error/interrupt exit branch. The openclaw sessions cleanup --fix-missing command removes them post-hoc, but it's not called automatically on failure.

Fix Action

Fix / Workaround

Workaround in place

RAW_BUFFERClick to expand / collapse

Summary

When a session fails mid-run (API error, timeout, gateway saturation), the partial transcript file is written to the agent's sessions directory but never cleaned up. These "orphan" files accumulate indefinitely until a manual or scheduled maintenance pass removes them.

Observed impact

Running OpenClaw 2026.5.4 with haiku-utility and main agents:

  • haiku-utility: 53 orphan session files / 276 MB accumulated in a single afternoon (2026-05-05). Root: haiku-utility has no fallback model — surface_error on every Anthropic API hiccup writes a partial transcript and exits without cleanup.
  • main agent: 259 orphan session files / 322 MB accumulated in roughly the same window, driven by plugin-load timeouts (12–17s) causing in-flight sessions to fail before completing.

Without intervention, these orphan files consume several hundred MB per day and inflate the session index, making sessions.list slow (we observed 5s list calls under load).

Root cause

OpenClaw writes the session transcript file when a session starts, but only removes/archives it on clean completion. There is no cleanup path in the error/interrupt exit branch. The openclaw sessions cleanup --fix-missing command removes them post-hoc, but it's not called automatically on failure.

Steps to reproduce

  1. Run an agent with a model that has no fallback (e.g. haiku-utility with claude-haiku-4-5, no gemini fallback configured).
  2. Trigger an Anthropic API error (or simply run many short sessions in a high-load environment).
  3. Observe orphan .jsonl files in the agent's sessions directory whose names do not appear in sessions.json.

Suggested fix

On session exit via error or unclean interrupt, run the equivalent of sessions cleanup --fix-missing for that agent's store, or at minimum delete/archive the partial transcript for the failed session ID. This would prevent unbounded accumulation without needing a scheduled external cleanup.

Workaround in place

Nightly cron at 3:10 AM CT running openclaw sessions cleanup --all-agents --enforce --fix-missing. This keeps accumulation bounded but does not prevent multi-hundred-MB intraday buildup.

Environment

  • OpenClaw 2026.5.4 (325df3e)
  • Agents: main (claude-sonnet-4-6, gemini fallback), haiku-utility (claude-haiku-4-5, no fallback)
  • session.maintenance.maxEntries = 50

extent analysis

TL;DR

Run a cleanup command equivalent to openclaw sessions cleanup --fix-missing on session exit via error or unclean interrupt to prevent orphan file accumulation.

Guidance

  • Identify and implement an automatic cleanup mechanism for partial transcript files when a session fails or is interrupted, potentially by integrating the sessions cleanup --fix-missing command into the error handling branch.
  • Verify the effectiveness of the cleanup mechanism by monitoring the accumulation of orphan files in the agent's sessions directory after implementing the fix.
  • Consider adjusting the session.maintenance.maxEntries setting to optimize session management, although this may not directly address the orphan file issue.
  • Review the current nightly cron job running openclaw sessions cleanup --all-agents --enforce --fix-missing to ensure it remains effective in bounding accumulation, even after implementing the proposed fix.

Example

No specific code snippet is provided due to the lack of direct code references in the issue, but the solution involves calling a cleanup command or function similar to openclaw sessions cleanup --fix-missing when a session exits abnormally.

Notes

The proposed solution focuses on addressing the root cause of orphan file accumulation by ensuring cleanup occurs even on session failure or interrupt. However, the exact implementation details may vary depending on the internal workings of OpenClaw and its session management mechanisms.

Recommendation

Apply a workaround by integrating an automatic cleanup command into the session exit handling, as upgrading to a potentially fixed version is not mentioned in the provided issue context. This approach directly addresses the identified root cause and prevents further accumulation of orphan files.

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

openclaw - 💡(How to fix) Fix Sessions: orphan transcript files accumulate on failed/interrupted runs, no per-failure cleanup [1 comments, 2 participants]