Skip to content

fs: add uncancelable delete variants - #696

Merged
lalinsky merged 1 commit into
mainfrom
uncancelable-deletes
Aug 21, 2026
Merged

lalinsky merged 1 commit into
mainfrom
uncancelable-deletes

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

deleteFile/deleteDir/deleteTree gain *Uncancelable siblings, for the cleanup paths that must run even when the task is being canceled — a delete skipped by a cancellation leaves the file or directory behind for good, with nothing left to retry it.

The two single-op ones go through waitForIoUncancelable, the same primitive close() uses. deleteTreeUncancelable walks the tree with many operations, so it runs under a cancellation shield instead, to keep a canceled task from abandoning it half done.

Each has an error set with no Canceled in it, which is the real point. Wrapping a delete in beginShield()/endShield() already worked and is only two lines, but it leaves error.Canceled in the signature, so every cleanup site either writes a branch that cannot be taken or quietly reports a cancellation as a failed delete. DeleteTreeError is now DeleteTreeUncancelableError || Cancelable.

TempFile/TempDir/AtomicFile were doing this by hand already: removeTempTree was exactly deleteTreeUncancelable and is gone, and removeTempFile is down to the log.warn it wraps. TempDir.CleanupError drops Canceled as a result.

The test covers the contract that matters for a deinit: with a cancellation pending, both deletes complete, and neither swallows the cancellation — it is still there for the next cancellation point. It self-cancels with getCurrentTask().cancel() rather than handle.cancel(), which blocks until the task finishes.

One thing that came up writing it: cancellation is delivered once (the pending_errors count), and Waiter.waitTask returns early without a cancel check when the signal already arrived, so a plain deleteFile with a cancel pending often succeeds anyway. It reports Canceled only when the op genuinely parks and the backend cancels it — intermittent rather than absent, which is the argument for having these.

Cleanup that a cancellation can skip leaves the file or directory behind
for good, with nothing left to retry it. deleteFileUncancelable and
deleteDirUncancelable run the unlink through waitForIoUncancelable, like
close() does, and deleteTreeUncancelable walks the tree under a
cancellation shield so a canceled task cannot abandon it half done.

Each comes with an error set that has no Canceled in it, which is the
point: a deinit handling error.Canceled from a delete either writes a
branch that cannot be taken, or quietly reports a cancellation as a
failed delete. DeleteTreeError is now that set plus Cancelable.

The temporary file and directory cleanup paths were already doing this by
hand, so removeTempTree is gone and removeTempFile is down to the log
call it wraps; AtomicFile.deinit goes through the same helper.
@coderabbitai

coderabbitai Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fa3a6d81-87d3-4f7f-b8b3-2e6373e579b6

📥 Commits

Reviewing files that changed from the base of the PR and between 227c016 and dfa89ce.

📒 Files selected for processing (1)
  • src/fs.zig

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The filesystem module adds uncancelable deletion APIs for files, directories, and trees. Temporary resource cleanup uses these APIs. Tests verify that cleanup completes while cancellation remains pending and is observed by the next cancelable wait.

Changes

Filesystem cleanup

Layer / File(s) Summary
Deletion error contracts
src/fs.zig
Directory, file, and tree deletion now separate uncancelable filesystem errors from Cancelable and expose uncancelable deletion methods.
Cancellation-shielded tree deletion
src/fs.zig
deleteTreeUncancelable performs recursive deletion under a cancellation shield and uses uncancelable I/O waits.
Temporary cleanup integration and validation
src/fs.zig
Temporary directories and files use the uncancelable deletion APIs. Tests verify that pending cancellation remains pending during cleanup and is observed afterward.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to dfa89

The PR adds uncancelable delete operations for cleanup paths so cancellation cannot leave files or directories behind; no actionable merge-blocking risk remains beyond normal checks and review.

Poem

Files descend, the shield holds tight,
Cancellation waits outside.
Trees are gone, temp files too,
The next safe wait still sees it through.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding uncancelable filesystem deletion variants.
Description check ✅ Passed The description explains the new deletion APIs, cancellation behavior, cleanup migration, and tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch uncancelable-deletes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lalinsky
lalinsky merged commit a01355b into main Aug 21, 2026
31 checks passed
@lalinsky
lalinsky deleted the uncancelable-deletes branch August 21, 2026 06:00
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.

1 participant