Skip to content

fix(analyze): deduplicate Home hard links across children - #2014

Merged
tw93 merged 2 commits into
tw93:mainfrom
r266-tech:codex/home-overview-hardlink-accounting
Nov 16, 2026
Merged

tw93 merged 2 commits into
tw93:mainfrom
r266-tech:codex/home-overview-hardlink-accounting

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Summary

Home overview sizes count a 1 MiB file twice when its hard links sit in different immediate children, or directly in Home and a child. Each child previously used an independent du, while direct files were added separately.

Measure all included children in one du invocation and use its combined total. Keep only the immediate ~/Library excluded, retain mount-point filtering and physical symlink handling, and invalidate older cached totals. If the operand list cannot fit in exec, the existing bounded Go fallback shares the scanner's file-identity accounting.

Safety Review

This changes read-only size accounting. The existing deletion, Trash and authorization paths are untouched. Top-level Library and mounted children remain outside the Home measurement; nested Library directories remain included. Permission-only failures retain a partial subtotal, and cancellation keeps the existing measurement deadline.

Home now uses one du process for shared hardlink accounting. Large real user homes have not been benchmarked; the existing overview deadline remains in force.

Tests

  • New real-hardlink regression: same-child control passes on unchanged main@5dd93fe3; sibling, root/child, newline-name and fallback cases fail there and pass with the fix.
  • Partial-permission results, sole ordinary/dangling symlinks, mount exclusion, Library accounting and measurement independence.
  • go test ./....
  • ./scripts/check.sh --format and ./scripts/check.sh --no-format.
  • TERM=xterm-256color MOLE_TEST_NO_AUTH=1 MOLE_TEST_TIMING=1 BATS_FORMATTER=tap ./scripts/test.sh, with an isolated TMPDIR: exit 0, All tests passed! (1938.49 s). Main Bats batch 2508 cases and all nine serial files complete, followed by Go build/vet/tests, module loading and integration.

The local check uses its supported go vet fallback because golangci-lint is not installed. The full runner skips the shallow-clone commit-resolution case, the CLI check for an unbuilt analyze binary, and its Homebrew installation probe. The new Go regressions and the runner’s Go build/tests do run; no live cleanup or large real-user HOME scan was performed.

The Linux consumer has the same per-child structure; unchanged source was reproduced through the real CLI on Ubuntu 25.10 with uutils and GNU du. Its current contribution policy accepts issues, so that consumer is tracked in #2013. The Windows Home consumer uses its own walker; #2012 remains the separate NTFS work.

AI assistance was used for the investigation, implementation and validation.

Safety-related changes

Read-only measurement and cache invalidation only.

Measure included Home entries in one du process so siblings and top-level
files share its hardlink accounting. Keep the immediate Library and mounted
children excluded, and reject stale cached totals.

Reuse scan-wide file identities in the bounded Go fallback when exec cannot
fit all operands. Preserve partial permission results and physical symlinks.

Verified the real-hardlink regression red on unchanged main and green here,
format/check, go test ./..., and the full scripts/test.sh runner (exit 0).
Record the regression against the fix commit, the native Linux reproduction
in tw93#2013, and the separate Windows consumer. Keep package and app delivery
status unverified.

Verified the incident audit, new commit and catcher references, and diff
whitespace. Production code is unchanged from the passing full test run.
@r266-tech
r266-tech requested a review from tw93 as a code owner November 15, 2026 20:02
@tw93
tw93 merged commit 3c4f01d into tw93:main Nov 16, 2026
12 checks passed
tw93 added a commit that referenced this pull request Nov 16, 2026
The Home overview ran one du per child after skipping ~/.cache, so each
process kept its own hardlink set and a file linked across two children,
or between Home and a child, was counted once per link. Mole CLI (macOS)
fixed this in #2014 by passing every child to one du -c, but uutils du
0.2.2, Ubuntu 25.10's default, still counts links per operand, so Linux
runs a single du over Home and excludes the literal ~/.cache path, the
same way it already excludes foreign mounts. The bounded Go fallback now
shares the scan's identity set, and overview cache schema 13 drops older
totals.

Verified on the devbox: TestHomeOverviewCountsHardlinksAcrossChildrenOnce
reads 6291456 B on the old code under GNU du 9.1 and uutils du 0.2.2 and
passes on the new code under both; go test ./... passes as user mole.
tw93 added a commit that referenced this pull request Nov 16, 2026
…inux port

Squash merging #2014 replaced 7c83bad with 3c4f01d, so I-77 and the SYNC
source now name the merged commit (audit_incidents.py passes, 77 rows). The
Linux row moves from Pending to Implemented at linux 644a643 (#2013), with
why it uses one du over Home instead of the operand list: uutils du 0.2.2
counts hard links per operand.
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