fix: sweep orphaned atomic-write .temp files after a crashed run - #160
Open
ig-imanish wants to merge 2 commits into
Open
fix: sweep orphaned atomic-write .temp files after a crashed run#160ig-imanish wants to merge 2 commits into
ig-imanish wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new tests rely on a “dead PID” value that is not guaranteed to be dead on all systems, which can create rare but real test flakiness.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR addresses orphaned atomic-write temp files (.tmp-<pid>) left behind when a process is killed before writeFileAtomic’s finally cleanup runs, preventing .nanotune/benchmarks from accumulating stale intermediates across runs.
Changes:
- Exported
isProcessAliveso it can be reused outsidemodel-cache.ts. - Added sweeping logic to remove dead-pid
.tmp-<pid>files both at CLI startup (benchmarks dir) and per-target beforewriteFileAtomicwrites. - Added tests covering startup sweep behavior and per-target pre-write cleanup.
File summaries
| File | Description |
|---|---|
| src/lib/model-cache.ts | Exports isProcessAlive for reuse by other modules. |
| src/lib/config.ts | Adds stale-temp sweeping helpers and integrates cleanup into writeFileAtomic. |
| src/lib/config.spec.ts | Adds tests for sweeping stale atomic-write temp files. |
| src/cli.tsx | Runs a startup sweep for benchmarks temp files on every CLI invocation. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Description
writeFileAtomic creates a .tmp- file while writing and normally removes it in the finally block. The problem is that if the process gets killed with something like SIGKILL, the cleanup never runs, so the temp file is left behind in .nanotune/benchmarks/.
This PR adds cleanup for those leftover files:
Type of Change
Testing
Automated Tests
pnpm test:allcompletes successfully)Manual Testing
nanotune initnanotune datacommands (add/import/list/validate)nanotune trainnanotune exportnanotune benchmarkChecklist
pnpm format)