Skip to content

fix(blobstore): honour cancellation while DeletePrefix removes files - #1661

Merged
Quick104 merged 7 commits into
Silo-Server:mainfrom
dannyshafer:fix/1580-deleteprefix-cancellation
Oct 31, 2026
Merged

Quick104 merged 7 commits into
Silo-Server:mainfrom
dannyshafer:fix/1580-deleteprefix-cancellation

Conversation

@dannyshafer

@dannyshafer dannyshafer commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #1580
Related issue: N/A
Validation tasks: none

Filesystem.DeletePrefix ignored 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: like RemoveAll, 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 vet and gofmt: 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.
  • Review fix fbbe627 adds two regression tests: one entry that can't be removed no longer strands its siblings, and deleting a missing prefix leaves its empty parent alone. Both fail on 05de879 and pass on fbbe627. On fbbe627, go test -race -count=3 ./internal/blobstore/..., go build ./internal/..., the blobgc and adminjob tests, and make lint-changed pass.
  • Caller packages (adminjob, metadata) could not be built locally because libvips is not installed; CI built and tested them.
  • Full CI: green on dfebe6f (fbbe627 merged with current main).

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

DeletePrefix can 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

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (desktop app)
  • Tool(s): Claude Code (sub-agents, Bash, Edit), GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: CodeRabbit and Kody reviewed the diff. CodeRabbit had no findings. Kody found three issues in the first version: directory removal errors were ignored, empty-directory cleanup continued after cancellation, and every directory path was kept in memory. All three were fixed by the post-order rewrite, and Kody confirmed each. A maintainer review with Claude Code (claude-opus-5-5) found two more: a stuck entry stranded its siblings, and a missing prefix pruned its parents. Its fix commit, fbbe627, was AI-generated.

🤖 Generated with Claude Code

Note

Fix blobstore.Filesystem.DeletePrefix to honour context cancellation

  • Rewrites DeletePrefix as a cancellation-aware post-order traversal. New helpers deleteTree and deleteChildren in filesystem.go check the context before each removal, delete directory contents before parents, and count only regular files actually removed.
  • Traversal does not descend through symlinks and uses os.Root plus identity checks to reject a symlink or replacement at the traversed name.
  • Directory entries are read in sorted batches of 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.
  • Deleting a missing prefix now returns a zero count and nil error, and keeps the empty parent directory. Tests in filesystem_test.go cover cancellation mid-delete, symlink/swap safety, stuck entries, batched reads, and missing prefixes.
  • Behavioral Change: DeletePrefix can 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.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6beb21cf-ab47-4521-9c8c-9cdec86293d9
📥 Commits

Reviewing files that changed from the base of the PR and between e0f9bf5 and be3a8f8.

📒 Files selected for processing: 1
  • internal/blobstore/filesystem_test.go

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

Walkthrough

Filesystem.DeletePrefix now removes a prefix through a recursive, batched walk. It checks cancellation and directory identity during traversal, returns the count of regular files removed before an error, and prunes empty ancestors after successful deletion.

Changes: Filesystem prefix deletion

Layer / File(s) Summary
Recursive removal and cancellation
internal/blobstore/filesystem.go, internal/blobstore/filesystem_test.go
DeletePrefix delegates removal to a recursive helper that checks cancellation and counts regular files. Tests cover partial deletion after cancellation, retry behavior, and missing prefixes.
Guarded batched traversal and error handling
internal/blobstore/filesystem.go, internal/blobstore/filesystem_test.go
The traversal verifies directory identity and symlink status, sorts entries in batches, and continues after individual removal errors while retaining the first error. Tests cover directory swaps, stuck entries, and batched deletion.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant DeletePrefix
  participant deleteTree
  participant deleteChildren
  DeletePrefix->>deleteTree: Remove prefix entries
  deleteTree->>deleteChildren: Traverse directory entries
  deleteTree-->>DeletePrefix: Return removed-file count and error
Loading

Suggested reviewers: quick104

Merge Risk: Minimal · previous review be3a8

No actionable merge-blocking risk is identified; the change is ready for normal merge checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 1e25b

The filesystem boundary appears unchanged, but cancellation can now leave empty directories for a later cleanup attempt. That may interact with the job’s no-progress limit. No new security exposure was established, though production authorization was not fully verified.

Retained concerns

  • Low · reliability · inferred: Cancellation can leave already-emptied directories for a retry. If directory cleanup repeatedly consumes a job slice without deleting files, the admin job can exhaust its no-progress allowance while cleanup remains unfinished.
Security review details

Security Blast Radius

  • inferred — Any partial deletion is bounded by the configured filesystem root and the prefix supplied by an existing caller; the inspected change does not establish a new caller or broader filesystem authority.

Trust Boundaries and Controls

  • observed — Prefix validation and root-scoped checks precede the changed removal logic. The available evidence does not establish authorization for every production caller or control over every supplied prefix.

Resilience and Maintainability Implications

  • inferred — A later call can recover an interrupted prefix, but the admin job’s zero-deleted-file stall check may not recognize progress consisting only of directory removal.

Hardening Proposals

  • proposed — Verify recovery with repeated cancellations during directory-only cleanup, and ensure that either bounded empty-directory cleanup or job progress accounting prevents a retryable prefix from being declared stalled.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: making blobstore DeletePrefix honor cancellation while removing files.
Description check Passed The description directly explains the DeletePrefix cancellation problem, implementation approach, validation, risks, and test coverage. It is fully related to the changeset.
Linked Issues check Passed Issue #1580 requires Filesystem.DeletePrefix to honor cancellation during removal, return the context error with the number of files removed, and leave remaining files for a later call. The current …
Out of Scope Changes check Passed The changes are limited to internal/blobstore/filesystem.go and internal/blobstore/filesystem_test.go. Symlink and replacement checks, bounded directory reads, removal-error handling, and regressi…
Full details: Linked Issues check

Explanation

Issue #1580 requires Filesystem.DeletePrefix to honor cancellation during removal, return the context error with the number of files removed, and leave remaining files for a later call. The current implementation uses a cancellation-aware post-order traversal, checks the context before removals, counts removed regular files, and returns partial results on cancellation. Tests cover cancellation, remaining files, and follow-up deletion. The implementation also preserves missing-prefix behavior and successful parent pruning.

Full details: Out of Scope Changes check

Explanation

The changes are limited to internal/blobstore/filesystem.go and internal/blobstore/filesystem_test.go. Symlink and replacement checks, bounded directory reads, removal-error handling, and regression tests support the DeletePrefix requirements in issue #1580. No unrelated change is demonstrated.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@kody-ai

kody-ai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Access your configuration settings here.

Comment thread internal/blobstore/filesystem.go Resolved
Comment thread internal/blobstore/filesystem.go Resolved
Comment thread internal/blobstore/filesystem.go Resolved
@macroscopeapp

macroscopeapp Bot commented Sep 29, 2026

Copy link
Copy Markdown

The PR body is missing the required Validation tasks: line. No recorded validation case is affected by this change; please add exactly:

Validation tasks: none

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@kody-ai

kody-ai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Access your configuration settings here.

Quick104 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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 Evidence: none, no user-visible change. This PR was opened before the rule existed, so it hasn't had a chance to meet it yet.

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

@Quick104
Quick104 marked this pull request as draft October 6, 2026 19:25
@dannyshafer

Copy link
Copy Markdown
Contributor Author

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.

@dannyshafer
dannyshafer marked this pull request as ready for review October 10, 2026 16:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-31T04:01:35.267776Z
We couldn’t complete this review. Comment @codex review to try again.
5e1a2c5 New commits
ℹ️ 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" or "@codex security review".

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

silo-kody Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread internal/blobstore/filesystem.go Outdated
return err
}
if isDir {
entries, err := fs.ReadDir(root.FS(), p)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

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

silo-kody Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@dannyshafer

Copy link
Copy Markdown
Contributor Author

Good catch on the swapped-directory case. Before this change, os.Root.RemoveAll removed the tree without following symlinks, so the path-based walk here was a regression. os.Root already kept removals inside the store root, but a symlink could still point them at another key's directory.

Fixed in 0b92171: each directory is entered through its own os.Root, checked with os.SameFile against the Lstat result, and its children are removed relative to that handle. A directory swapped mid-walk is no longer followed. TestFilesystemDeletePrefixDoesNotFollowSwappedDirectory swaps a directory for a symlink to another key's directory after the Lstat and checks that the other key's file survives; it fails with the check disabled. go test ./internal/blobstore/... passes, including with -race.

The Evidence line is now in the PR body as well.

(Change and reply prepared with Claude Code.)

@Quick104 Quick104 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.

Review of 05de879 found two issues, both in DeletePrefix. I'm fixing both in a commit on this branch, so you don't need to change anything yourself. A summary comment follows.

Comment thread internal/blobstore/filesystem.go Resolved
Comment thread internal/blobstore/filesystem.go Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread internal/blobstore/filesystem.go Outdated
if !os.SameFile(want, got) {
return fmt.Errorf("blobstore: %s changed during delete", name)
}
entries, err := fs.ReadDir(sub.FS(), ".")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed 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 findings

Both findings from the review are fixed in fbbe627, and each has a regression test. Both tests fail on 05de879 and pass on fbbe627.

  • Medium, stuck entry strands its siblings. deleteChildren now keeps going past an entry it can't remove and returns the first error at the end, as os.Root.RemoveAll did. A context error still stops the walk at once.
  • Low, missing prefix prunes empty parents. DeletePrefix returns 0, nil early again when the prefix doesn't exist.

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 internal/metadata and internal/catalog) count against this PR. The merge doesn't change the blobstore diff.

Other feedback

  • The Codex thread about directories swapped for symlinks is handled by 0b92171. Each directory is opened through its own os.Root and checked with os.SameFile against the earlier Lstat. TestFilesystemDeletePrefixDoesNotFollowSwappedDirectory covers it. I replied in that thread.
  • The three Kody threads were already fixed and confirmed.
  • The Risks section of the PR body said the avatar and collection handlers return the delete error. They log it or ignore it, so I corrected that sentence. I also updated the Approach and Validation sections for fbbe627 and added the Evidence link.

Verification

On fbbe627, these pass:

  • go test -race -count=3 ./internal/blobstore/...
  • go build ./internal/...
  • the blobgc and adminjob tests
  • make lint-changed (0 issues)

After the merge, the build, the blobstore race tests, the blobgc and adminjob tests, and lint pass again. CI is green on dfebe6f.

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.

  • main: the cancel goes unnoticed once RemoveAll starts. The call deletes everything and returns nil about 0.4 s after the cancel.
  • this PR: the call returns context canceled within 0.2 ms and leaves the rest for a later call.

The evidence page has the commands and the output.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-1661/

Validated features

No 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. Validation tasks: none still holds.

User manual, Apple and Android

The 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

  • Fit 9/10. The PR fixes a correctness bug in the blob store's own delete path, so admin-job time slices hold on local storage. It adds no new surface or setting and stays at the boundary that owns the behavior.
  • Readiness 9/10. Both findings are fixed with regression tests, the earlier bot findings are resolved, and the required checks pass on the current head. No concern remains open.

@dannyshafer

Copy link
Copy Markdown
Contributor Author

Addressed the two remaining Codex findings from Oct 13 in e0f9bf5:

  • Same-inode symlink: os.Root has no no-follow open, so after OpenRoot the code now Lstats the name again and refuses it if it is a symlink or no longer the opened directory. A directory renamed out of the prefix and replaced by a symlink to it now fails with "changed during delete". New test: TestFilesystemDeletePrefixDoesNotFollowSymlinkToSameDirectory, which fails on the previous head.
  • Batched reads: entries are read with ReadDir(256) and the directory is reopened after each batch (the same approach os.RemoveAll uses, since removing entries can make a continued read skip some), reading on past a batch where nothing could be removed. New test: TestFilesystemDeletePrefixReadsInBatches with a batch size of 2 and two stuck entries.

go test ./internal/blobstore/ passes (also as a non-root user so the permission tests run), and golangci-lint reports 0 issues on the package.

Quick104 added a commit that referenced this pull request Oct 16, 2026
…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]>
@macroscopeapp

macroscopeapp Bot commented Oct 16, 2026

Copy link
Copy Markdown

A cancellation during prefix deletion can now leave a partial object count, which the web admin renders in canceled image-cache cleanup history (internal/blobstore/filesystem.go → AdminJobHistory). The private evidence page is described as tests and timing results, not before-and-after captures of that visible result. Please add before-and-after web-admin captures of the same canceled cleanup to the evidence page, including mobile if the result is visible at phone width.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@dannyshafer

Copy link
Copy Markdown
Contributor Author

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

@dannyshafer

Copy link
Copy Markdown
Contributor Author

@Quick104 thanks!

dannyshafer and others added 3 commits October 30, 2026 23:58
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
Quick104 and others added 4 commits October 30, 2026 23:58
…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
@Quick104
Quick104 force-pushed the fix/1580-deleteprefix-cancellation branch from be3a8f8 to 5e1a2c5 Compare October 31, 2026 03:59
@silo-kody

silo-kody Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit 01f6b02 into Silo-Server:main Oct 31, 2026
14 of 15 checks passed
Comment on lines +501 to +503
if read < deleteBatch || failed < read {
break
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Performance medium

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.

​

​

@dannyshafer
dannyshafer deleted the fix/1580-deleteprefix-cancellation branch October 31, 2026 06:03
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.

Local blob store DeletePrefix ignores cancellation while removing files

3 participants