Skip to content

fix: sweep orphaned atomic-write .temp files after a crashed run - #160

Open
ig-imanish wants to merge 2 commits into
Nano-Collective:mainfrom
ig-imanish:main
Open

fix: sweep orphaned atomic-write .temp files after a crashed run#160
ig-imanish wants to merge 2 commits into
Nano-Collective:mainfrom
ig-imanish:main

Conversation

@ig-imanish

Copy link
Copy Markdown

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:

  • Clean up stale .tmp- files when nanotune starts.
  • Clean up stale temp files before writeFileAtomic writes to the same path.
  • Reuse the existing isProcessAlive check to make sure we only remove files from processes that are no longer running.
  • Live process temp files are left untouched, so concurrent runs should be safe.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

Automated Tests

  • All existing tests pass (pnpm test:all completes successfully)
  • New tests added for new functionality (if applicable)

Manual Testing

  • Tested nanotune init
  • Tested nanotune data commands (add/import/list/validate)
  • Tested nanotune train
  • Tested nanotune export
  • Tested nanotune benchmark

Checklist

  • Code follows project style guidelines (pnpm format)
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)

Copilot AI lite review requested due to automatic review settings September 5, 2026 04:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 isProcessAlive so it can be reused outside model-cache.ts.
  • Added sweeping logic to remove dead-pid .tmp-<pid> files both at CLI startup (benchmarks dir) and per-target before writeFileAtomic writes.
  • 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.

Comment thread src/lib/config.spec.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants