fix(server): storage cleanup no longer counts hardlinked files as recovered space #17910
main fromrefs/pull/17910/head·merged by juliusmarminge View on GitHubRemoving a worktree with dependencies hardlinked from a shared store reported those files as recovered space even though the store still owned their disk blocks. Worktree measurement now counts allocated bytes for single-link files, falling back to file length when block metadata is unavailable. Multiply linked files are excluded, so the estimate can undercount when all links are inside the removed tree.
Fixes #17815. Maintainer takeover of #17910, with credit to @tris203 for the report, implementation, and reproduction. Original commits are preserved; current main is merged without rewriting the contributor branch.
Verification on headless Linux / Node 24:
- Before: the real-filesystem regression expected 16,384 recoverable bytes and received 70,098. The external hardlink survives cleanup.
- After:
pnpm exec vp test run apps/server/src/storageCleanup.test.ts— 138 passed. The existing regression covers hardlinks, allocated bytes, and symlinks; one added case covers absent metadata. Current-main suite: 137 → 138 tests in the existing file. - Targeted lint, formatting, and server typecheck passed.
- The cleanup service ran against disposable filesystem fixtures, including actual worktree removal. Screenshots do not prove this accounting change.
Both independent whole-diff reviews found no blockers. Reflink clones are not detected by link counts; their shared blocks remain a limitation.
Not verified: the Storage screen after an interactive cleanup, free-space changes measured with df, other filesystems, macOS, Windows, Electron desktop, iOS, or Android. No contract or client behavior changes.
Implemented with Codex GPT-6.1-Sol; test design by Codex GPT-6-Astra. Independent review by Claude Opus 5.5 and Codex GPT-6-Sol, orchestrated in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
f25cde7Macroscope's review found this PR approvable — This is a narrowly scoped storage-cleanup bug fix that adjusts only recoverable-byte accounting and adds focused hardlink and metadata-fallback tests. No product defaults, schemas, sensitive packages, or static-analysis suppressions change; an unresolved High-severity finding separately flags numeric type handling in the new path.
Notes:
- This verdict was updated automatically after the outstanding correctness findings were resolved. Macroscope did not re-review the code.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2d1d6ae4-72f9-4f34-8652-2ccf4a98ba94
📥 Commits
-
Reviewing files that changed from the base of the PR and between dda7d21a9580aea5660b779320d2e71af3da75d5 and a37e669c72efb79cadd1be03125a29d73a864449.
📒 Files selected for processing: 2
-
apps/server/src/storageCleanup.test.tsapps/server/src/storageCleanup.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
Worktree storage measurement now counts allocated bytes only for files with a single link. Tests cover allocated-size fallback and verify that externally hardlinked files remain after cleanup.
Changes: Worktree storage accounting
Layer / File(s) Summary Reclaimable-byte measurement
apps/server/src/storageCleanup.ts,apps/server/src/storageCleanup.test.tsmeasureWorktreeexcludes multiply linked files and uses allocated blocks when available, falling back to file size. Tests cover nested files, hardlinks, and allocated-size measurements.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Low
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
a37e6-
No actionable merge-blocking risk is supported by the reviewed change context; proceed with normal checks.
Pre-merge checks:
4-
Check name Status Explanation Linked Issues check Issue [ #17815] requires per-worktree and recovered-space accounting to reflect released space or provide a lower bound for hardlinked dependencies.measureWorktreenow excludes files withnlinkgr…Out of Scope Changes check The changes are limited to measureWorktreeaccounting and related storage-cleanup tests. The source change supports issue [#17815]. The tests verify the changed accounting and hardlink behavior. No …Title check The title clearly and concisely describes the main change: storage cleanup no longer counts hardlinked files as recovered space. It uses a conventional commit format and is specific to the server chan… Description check The description covers the problem, implementation, scope, linked issue, maintainer approval context, verification commands and results, limitations, and unverified environments. It does not use the t… Full details: Linked Issues check
-
Explanation
Issue [
#17815] requires per-worktree and recovered-space accounting to reflect released space or provide a lower bound for hardlinked dependencies.measureWorktreenow excludes files withnlinkgreater than 1, usesblocks * 512when available, and falls back to file length. The implementation treats missingnlinkas 1. Updated tests cover hardlinked files and allocated-size accounting. The reported test suite passed.
Full details: Out of Scope Changes check
-
Explanation
The changes are limited to
measureWorktreeaccounting and related storage-cleanup tests. The source change supports issue [#17815]. The tests verify the changed accounting and hardlink behavior. No unrelated behavior, public contract, client, or UI change is included.
Full details: Title check
-
Explanation
The title clearly and concisely describes the main change: storage cleanup no longer counts hardlinked files as recovered space. It uses a conventional commit format and is specific to the server change.
Full details: Description check
-
Explanation
The description covers the problem, implementation, scope, linked issue, maintainer approval context, verification commands and results, limitations, and unverified environments. It does not use the template headings, but the required information is present and the description is complete.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge added labelsmacroscope-review
juliusmarminge assignedjuliusmarminge
Taking over this one as maintainer for batch ssh-relay-remote-02. I’m preserving the hardlink accounting fix, rebuilding it against current main, and validating it with focused tests and independent reviews. I plan to push updates to this PR and leave it unmerged.
- @@ -270,5 +270,6 @@270270 if (isLink) continue;271271 if ((yield* fs.realPath(target)) !== target) return null;272272 const stat = yield* fs.stat(target);273- if (stat.type === "File") bytes += Number(stat.size);274- else if (stat.type === "Directory") {273+ if (stat.type === "File") {274+ // Removing a shared hardlink leaves its blocks allocated.275+ if (Option.getOrElse(stat.nlink, () => 1n) !== 1n) continue;
🟠 High
src/storageCleanup.ts:275Single-link files are excluded from
measureWorktree, so removed worktrees report fewer bytes freed (often0).stat.nlinkandstat.blocksare numbers, but this code compares and multiplies them asbigint; use numeric values for both calculations.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/storageCleanup.ts around line 275: Single-link files are excluded from `measureWorktree`, so removed worktrees report fewer bytes freed (often `0`). `stat.nlink` and `stat.blocks` are numbers, but this code compares and multiplies them as `bigint`; use numeric values for both calculations.This finding does not apply to the current Effect 4 API. In effect@4.0.5, FileSystem.File.Info declares nlink and blocks as Option (FileSystem.ts lines 1028 and 1034); the Node adapter requests bigint stat metadata. Comparing with 1n and multiplying by 512n matches those types. Numeric operands would fail the current server typecheck and would exclude actual single-link files.
The 138-case cleanup suite passes on this head against real filesystem fixtures, including ordinary allocated files, externally hardlinked files, deletion, and missing metadata. Server typecheck also passes. The original contributor patch used numbers against the older API; the takeover deliberately adapted it to current main. No source change is warranted for this finding.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged thiscae5762
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed