fix(usage): prune stale usage cache temp files#93725
Merged
vincentkoc merged 1 commit intoJun 16, 2026
Merged
Conversation
Member
|
Land-ready maintainer verification:
Known gap: I did not repeat the reporter-class Windows filesystem scenario; the PR's deterministic cleanup proof and focused regression cover the same stale/recent/lock-temp contract. |
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Jun 17, 2026
Co-authored-by: markoub <[email protected]>
crh-code
pushed a commit
to crh-code/openclaw
that referenced
this pull request
Jun 18, 2026
Co-authored-by: markoub <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.usage-cost-cache*.tmpfiles can remain beside the durable usage-cost cache after older cache writers or hard process termination.Change Type
Scope
Linked Issue/PR
Closes #78939
Real behavior proof
OPENCLAW_STATE_DIR.refreshCostUsageCache()andloadCostUsageSummaryFromCache()withnode --import tsx.{ "result": "refreshed", "staleLegacyExists": false, "staleCurrentExists": false, "recentTempExists": true, "lockTempExists": true, "totalTokens": 30, "totalCost": 0.03, "cacheStatus": "fresh" }refreshed, and the cache summary reportedfreshwith the expected totals.Root Cause
Current cache writes use the atomic replacement helper, which cleans up its own active temp path for ordinary failures. It does not sweep temp files left by older builds or hard exits, and the locked refresh path had no stale-temp reclamation step.
Regression Test Plan
src/infra/session-cost-usage.test.tsSecurity Impact
Validation
pnpm install --frozen-lockfilepassed.node scripts/run-vitest.mjs run --config test/vitest/vitest.infra.config.ts src/infra/session-cost-usage.test.ts -t "reclaims stale usage cache temp files before refreshing" --reporter=verbosepassed: 1 test passed.node scripts/run-vitest.mjs run --config test/vitest/vitest.infra.config.ts src/infra/session-cost-usage.test.tspassed: 53 tests passed.node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfopassed.node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfopassed.node scripts/test-projects.mjs --changed origin/mainpassed: infra shard, 53 tests passed.PATH="/opt/homebrew/opt/corepack/bin:$PATH" OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 CI=1 PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN=false node scripts/check-changed.mjspassed locally. The default Testbox delegation could not run because Blacksmith auth is not configured on this machine.git diff --checkpassed..agents/skills/autoreview/scripts/autoreview --mode localpassed: no accepted/actionable findings.AI Assistance
AI-assisted: yes. I used AI assistance to inspect the issue, implement the narrow fix, run local validation, and prepare this PR text. No assistant signature, co-author footer, or generated-by footer is included.