Repository navigation
Report Codex cache write failures and clean up orphaned files - #1764
Open
levelupself wants to merge 1 commit into
Open
levelupself wants to merge 1 commit into
levelupself wants to merge 1 commit into
Conversation
Keep the last complete cache on persistence errors, warn with the affected path, and remove owned temporary files after write, sync, close, or rename failures. Reclaim abandoned legacy and PID-tagged temporary files without deleting live writers. Cover result and project-index failures, retry recovery, source fingerprint validation, and a cache larger than 60 MB.
iamtoruk
requested changes
Oct 31, 2026
iamtoruk
left a comment
Member
There was a problem hiding this comment.
Thanks, the leak is real: a write, fsync or close failure leaves the temp behind and nothing sweeps it. Numbers are identical with your branch, so the fix itself is safe.
The shape is more than the bug needs, and two parts fight the codebase:
- Warnings. CodeBurn is silent on stderr unless CODEBURN_VERBOSE is set, because serve turns stderr into progress frames. Your sweep warns on every cold load and flush, and it warns about any fresh temp from another writer before the age check, so a second CodeBurn process mid-write gets reported as stale every run.
- PID tagging. The Flatpak CLI shares ~/.cache/codeburn with a host CLI but not its PID namespace, so a host writer's temp looks dead from inside the sandbox and gets deleted at once, and that save is lost. A reused PID keeps a dead writer's leftover forever.
What I would merge: unlink the temp on any failure after open (a few lines in writeFileAtomic), and sweep leftovers by age only, the same rule the session cache already uses, with no warnings. The 60 MB test passes on main and can go, and temp dirs belong under tmpdir() like the other tests. Happy to take that version quickly.
This branch has not been deployed
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.
A Codex cache write that fails before the final rename currently leaves the previous disk snapshot in place without a warning, and can leave an empty or partial temporary file behind. Subsequent reports still work, but the persistence failure is hard to diagnose.
This change keeps persistence best effort while warning with the destination path and underlying error. It cleans up owned temporary files after write, sync, close, and rename failures for both the result cache and project index. It also reports abandoned temporary files and reclaims them on a cold result-cache load or flush. New files use exclusive creation and include the writer PID; live writers are left alone, and legacy files without a PID get a 24-hour grace period.
The regression tests cover injected failures, preservation of the last complete snapshot, successful retry, orphan cleanup, live-writer protection, source fingerprint validation, and a cache larger than 60 MB.
Validation used Node 22.23.1 and clean committed trees:
npm test -- --run --maxWorkers=3): upstream9a40cc603fcd194caca9daa8c5134a61ea7e0e2bhad 5,209 passed, 3 failed, 7 skipped; this branch atbc675005f8edd27b5030935cb6858be47d896b25had 5,223 passed, 2 failed, 7 skipped. There are no new failures. Both branch failures are the samedashboard never entered background hydrationfailures intests/dashboard-process-exit.test.tsseen on upstream. Upstream also failed the degraded-read assertion intests/session-cache-status-snapshot.test.ts, which passed on the branch.bc675005f8edd27b5030935cb6858be47d896b25: all 13 new tests and 16 related cache tests passed;npm run test:lockspassed all 37 tests;npx tsc --noEmitandnpm run buildpassed.The new regression assertions are in
tests/codex-cache-write.test.ts, exercisingsrc/codex-cache.ts,src/cache-dir.ts, andsrc/wsl.ts. The related suites cover cache-directory switching, versioned cache adoption, concurrent loads, and WSL flushing. The full-suite commands use the repository'spackage.json,vitest.config.ts, and test environment isolation setup.