-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Usage-cost cache leaves orphaned .usage-cost-cache.json.*.tmp files in agent session stores #78939
Copy link
Copy link
Closed
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automationExclude from stale automation
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automationExclude from stale automation
Type
Fields
Priority
None yet
Repo: https://github.com/openclaw/openclaw
Observed OpenClaw version:
2026.5.6Summary
I found a real disk-leak issue in OpenClaw's session usage-cost cache.
In production, agent session directories accumulated orphaned temp files named like:
.usage-cost-cache.json.<pid>.<timestamp>.tmpThese files were not being cleaned up and built up over time.
On one live system, I found:
303leaked temp files1.877 GBconsumed by those temp files aloneThis was separate from other session artifacts such as reset/checkpoint/trajectory files.
Why this looks like a real current bug
The current bundled code in
2026.5.6appears to write the usage-cost cache via:Observed local file/line range:
dist/session-cost-usage-CoJqCXu7.js:191-195The important problem is that this path does not appear to remove
tmpPathin afinallyblock if the rename fails, the process is interrupted, or the write path aborts after the temp file is created.In the same module, the lock writer does clean up its temp file in a
finallyblock:Observed local file/line range:
dist/session-cost-usage-CoJqCXu7.js:103-109So the temp-file-cleanup pattern already exists nearby, but the main usage-cost cache write path does not appear to use it.
Impact
This can silently bloat agent session directories over time, especially on busy systems.
In my case, these leaked temp files were found across multiple agent session stores and had to be deleted manually.
This is easy to miss because the real cache file still exists and works, while the orphaned temp files just pile up beside it.
What I observed
Relevant production evidence:
.usage-cost-cache.json.*.tmp3031.877 GB0The leak was found inside agent session directories under paths like:
D:\Mr_OC\.openclaw\agents\viggo\sessionsD:\Mr_OC\.openclaw\agents\tom\sessionsD:\Mr_OC\.openclaw\agents\jeff\sessionsD:\Mr_OC\.openclaw\agents\doc\sessionsExpected behavior
Temporary usage-cost cache files should not remain on disk indefinitely after interrupted or failed writes.
Suggested fix directions
writeUsageCostCache()clean up its temp file in afinallyblock when appropriate..usage-cost-cache.json.*.tmpfiles.Notes
I am not reporting the normal session archive/checkpoint growth here.
This issue is specifically about the orphaned usage-cost-cache temp files.