Repository navigation
fix(blobstore): honour cancellation while DeletePrefix removes files - #1661
Conversation
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Providing Context (Files & MCPs)Add these hints in your PR description (or a comment) to unlock deeper checks:
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
The PR body is missing the required
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Providing Context (Files & MCPs)Add these hints in your PR description (or a comment) to unlock deeper checks:
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
Silo's pull request guidance changed today (#2016). A PR that changes what a user sees now needs before-and-after evidence in its Evidence section, and a PR with no visible change says Missing here: Needs the line 'Evidence: none, no user-visible change'. The rules are in Show visible changes, and the PR template shows the Evidence section layout. I've converted this PR to draft for now. Mark it ready for review once the Evidence section is filled in. Generated by Claude Code |
|
Thanks for the pointer to the updated guidance. Evidence for this one: Evidence: none, no user-visible change The change only affects how the blobstore's DeletePrefix reacts to context cancellation inside background jobs. No page, field or API response changes. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e25bc4ec3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return err | ||
| } | ||
| if isDir { | ||
| entries, err := fs.ReadDir(root.FS(), p) |
There was a problem hiding this comment.
Avoid following directories swapped to symlinks
When another process replaces a directory (including prefix itself) with a symlink to a sibling inside the blob root after Lstat or the parent ReadDir, the stale isDir value remains true and fs.ReadDir(root.FS(), p) follows that contained symlink. The recursive root.Remove(p/child) calls then remove the sibling's files even though they are outside the requested prefix; os.Root only prevents escaping the store root, and the previous root.RemoveAll(prefix) removed the link rather than traversing it. Open each directory through a no-follow, descriptor-anchored traversal before deleting its children.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
0b92171 addresses this. Each directory is now opened through its own os.Root (parent.OpenRoot(name)), and its children are removed relative to that handle. Before reading the directory, deleteChildren compares the opened directory with the earlier Lstat result using os.SameFile. A directory that was swapped for a symlink fails that check, and the walk leaves it alone. TestFilesystemDeletePrefixDoesNotFollowSwappedDirectory covers the swap, and it still passes on fbbe627.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Good catch on the swapped-directory case. Before this change, Fixed in 0b92171: each directory is entered through its own The Evidence line is now in the PR body as well. (Change and reply prepared with Claude Code.) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fbbe62708e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| prune(root, path.Dir(prefix)) | ||
| return n, nil | ||
| if !os.SameFile(want, got) { |
There was a problem hiding this comment.
Reject same-inode symlinks before descending
When another process renames the directory to a sibling and replaces its old name with a symlink to that moved directory between Lstat and OpenRoot, OpenRoot follows the link and os.SameFile(want, got) returns true because the target is still the same inode; the loop then deletes files that are no longer under the requested prefix. Fresh evidence in this revision is that the new identity guard explicitly accepts this same-inode target, while the added test only links to a different inode. Open the child with no-follow semantics, including for the final component, rather than validating the followed target.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dfebe6f92c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !os.SameFile(want, got) { | ||
| return fmt.Errorf("blobstore: %s changed during delete", name) | ||
| } | ||
| entries, err := fs.ReadDir(sub.FS(), ".") |
There was a problem hiding this comment.
Read directory entries in cancellable batches
When a local prefix contains a very large directory, fs.ReadDir reads and sorts every entry before control reaches the cancellation-aware loop. If the five-minute image-cache cleanup context expires during that enumeration, DeletePrefix continues scanning and allocating until the directory is exhausted, so the runner can still overrun the slice this change is meant to enforce. Open the directory and consume bounded ReadDir(n) batches, checking ctx between batches.
AGENTS.md reference: AGENTS.md:L13-L18
Useful? React with 👍 / 👎.
Review summaryReviewed head: dfebe6f. That is review fix fbbe627 with current main merged in. The review itself was of 05de879. Fit: 9/10 · Readiness: 9/10 — ready Addressed findingsBoth findings from the review are fixed in fbbe627, and each has a regression test. Both tests fail on 05de879 and pass on fbbe627.
dfebe6f merges current main into the branch. CI lints the PR merged with main but compared lines against the old merge base. After the fix push, that made nine findings already on main (in Other feedback
VerificationOn fbbe627, these pass:
After the merge, the build, the blobstore race tests, the A cancellation timing check exercises the behavior #1580 describes. It deletes 40,000 files in 400 hash directories and cancels the context 300 ms in.
The evidence page has the commands and the output. Validated featuresNo validated case is affected. On a successful delete the behavior matches main: the same files are removed, parents are pruned, and a missing prefix returns 0 and nil. What changes is that cancellation is now honored, and a failed delete can now report a partial count. The callers on the Collections (#193) and artwork (#1210) paths log or ignore that error. User manual, Apple and AndroidThe manual is unaffected: this changes no setting, label, or documented behavior. This is a server-only change with no API or client-visible change, so neither app needs a follow-up. Scores
|
|
Addressed the two remaining Codex findings from Oct 13 in e0f9bf5:
|
…2591) A pull request's size-ratchet and migration checks compared its merge commit with the payload's base.sha. That SHA can be older than the target tip the merge was built on, so a PR opened before main moved was charged with every file main grew since. #1661 failed the size ratchet on eight files it never touched. Both steps now pass origin/<target branch>, and the make targets take its merge base with HEAD, which is the commit the PR was merged onto. The contract checks already compare this way, and Go lint uses the merge commit's first parent since #2521. Closes #2404 Co-authored-by: Claude Opus 5.5 <[email protected]>
|
A cancellation during prefix deletion can now leave a partial object count, which the web admin renders in canceled image-cache cleanup history ( Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
Hi! This PR looks ready to go from my side, could a maintainer with merge rights take a look and merge it when you get a chance? Status:
Happy to rebase or adjust anything if needed. Thanks! Generated by Claude Code |
|
@Quick104 thanks! |
Remove each file during the walk after checking the context, then drop the emptied directories, instead of a context-free RemoveAll. On cancellation return the count removed so far with the context error. Fixes Silo-Server#1580 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lation Directories are removed as soon as their children are gone, so only the current path's entries are held in memory. Directory removal errors other than not-exist are returned, and the walk stops with ctx.Err() before any further removal once the context is canceled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The post-order walk resolved each child by path from the store root, so a directory replaced by a symlink after Lstat could redirect removals to another key's directory inside the store. Each directory is now entered through its own os.Root, checked with os.SameFile against the Lstat result, and its children are removed relative to that handle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Uj5ANjmwiWfx36d1AEHjKH
…fixes DeletePrefix stopped at the first entry it could not remove, so every sibling after it stayed on disk and a retry stopped at the same place. Keep going past such an entry and return the first error at the end, as RemoveAll did; a context error still stops the walk at once. Deleting a prefix that does not exist pruned its empty parent directories again, which could race a concurrent publish. Return early for a missing prefix, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es in batches A directory renamed out of the prefix and replaced by a symlink to it passed the SameFile check, because OpenRoot follows the symlink to the same inode. Lstat the name again after opening it and refuse a symlink or a different file. Read directory entries in bounded batches instead of listing the whole directory up front, so cancellation is seen during enumeration of a very large directory. Reopen after each batch, as os.RemoveAll does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HTTGRebY77TfMpmRyQy744
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HTTGRebY77TfMpmRyQy744
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HTTGRebY77TfMpmRyQy744
be3a8f8 to
5e1a2c5
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| if read < deleteBatch || failed < read { | ||
| break | ||
| } |
There was a problem hiding this comment.
Repeated failed subtree traversals in internal/blobstore/filesystem.go occur because every successful full batch reopens the directory from the beginning and recursively retries all previously failed children. With S unremovable children preceding R removable children, cleanup performs roughly S × ceil(R / deleteBatch) failed subtree traversals instead of S, causing large partially undeletable prefixes to consume their cleanup time slices retrying the same failures.
Prompt for LLM
File internal/blobstore/filesystem.go:
Line 501 to 503:
Repeated failed subtree traversals in internal/blobstore/filesystem.go occur because every successful full batch reopens the directory from the beginning and recursively retries all previously failed children. With S unremovable children preceding R removable children, cleanup performs roughly S × ceil(R / deleteBatch) failed subtree traversals instead of S, causing large partially undeletable prefixes to consume their cleanup time slices retrying the same failures.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
Problem
Closes #1580
Related issue: N/A
Validation tasks: none
Filesystem.DeletePrefixignored cancellation once it started removing files, so deleting a large leftover prefix could keep the admin job runner busy past its time slice. With this change the delete stops when the context ends and a later call finishes the job.Approach
The context was checked only during a counting walk; removal then went through
root.RemoveAll, which takes no context. The delete is now a single post-order walk that checks the context at every entry and before each directory removal, removes each directory once its children are gone, and counts the regular files it removed. Only the current path is held in memory.On a context error it returns the count so far with
ctx.Err(). Errors removing a directory are returned rather than ignored. An entry that can't be removed doesn't stop the walk: likeRemoveAll, it removes the remaining entries and returns the first error at the end, while a context error stops it at once. A missing entry is not an error, and a missing prefix still returns 0 and nil without pruning its parents. Parents are pruned as before on success.Validation
go test ./internal/blobstore/...,go vetandgofmt: pass locally. A new test cancels partway through and checks the partial count, the context error, the remaining files, and that a follow-up call completes.go test -race -count=3 ./internal/blobstore/...,go build ./internal/..., theblobgcandadminjobtests, andmake lint-changedpass.adminjob,metadata) could not be built locally because libvips is not installed; CI built and tested them.No user-visible change. The evidence page holds the regression-test results and a cancellation timing check against main.
Evidence: https://evidence.siloserver.org/r/silo-server/pr-1661/
Risks
DeletePrefixcan now return a nonzero count together with an error (a partial delete). Existing callers handle that: the image cache cleanup adds the count to its deleted-object total, logs the error and does not count the prefix as done; the blob collector returns the error; the avatar and collection handlers and the stale-image cleanup log it or ignore it; the scanner discards the result.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Fix
blobstore.Filesystem.DeletePrefixto honour context cancellationDeletePrefixas a cancellation-aware post-order traversal. New helpersdeleteTreeanddeleteChildrenin filesystem.go check the context before each removal, delete directory contents before parents, and count only regular files actually removed.os.Rootplus identity checks to reject a symlink or replacement at the traversed name.deleteBatch(default 256); the directory is revisited when a full batch removes nothing. Ordinary deletion errors are skipped while retaining the first error; cancellation stops immediately.DeletePrefixcan now return a partial file count and a cancellation error instead of deleting everything; failure of one entry no longer aborts deletion of siblings.Macroscope summarized 5e1a2c5.