Repository navigation
fix(disk-hygiene): inventory an empty directory at the scan depth boundary - #2661
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
Claude finished @kyle-sexton's task in 3m 3s —— View job Code review complete
No blocking findings. This is a well-scoped, well-tested fix. What I checked:
Not independently verified: this sandbox's Bash tool requires approval for any Python invocation (even One non-blocking style observation, left out of the diff since it's a nit, not a defect: |
|
Claude finished @kyle-sexton's task in 2m 16s —— View job Security review — PR #2661
No security issues found. This PR touches only What I verified:
Net: the change is a reporting/planning correctness fix (lets a genuinely-empty boundary directory become plannable instead of stuck behind a rescan cycle), and the existing multi-layered identity/emptiness re-verification at both |
|
Last security-reviewed head: |
|
Claude has reviewed this PR 2 times. The lane skips further automatic reviews after 5; deleting this comment resets the count. |
51740f0 to
540552d
Compare
Treat empty --max-depth boundary directories as walked size 0 instead of truncated, via a fail-closed first-child probe. Bump to 0.20.1. Closes #2618 Co-authored-by: Kyle Sexton <[email protected]>
540552d to
7fabb4a
Compare
|
Claude finished @cursor[bot]'s task in 1m 49s —— View job Code review — skip gate applied
No new findings — skip gate criteria 3/4 apply to this sync. This lane already reviewed this PR at
Both are correct, self-consistent, and outside the code-review lane's remit (no logic, no test coverage implications). This is a "trivial/automated, no meaningful review surface" sync per the skip gate — no inline comments posted. |
No linked issue
Summary
scan_tree's depth cut was evaluated before any read of the child, so emptinesswas unobservable at the scan boundary: every directory at
depth == max_depthwas marked
walked=Falseregardless of what it held. That nulled itslogical_size, appended thenot-walkedqualifier, and put it intruncated_paths, wherepreviewrefuses it astruncated-not-inventoried.For an empty directory both effects are wrong in the same direction. It is
vacuously fully inventoried — there are no descendants left uncounted — and its
size is genuinely
0, not unknown. The consequence in a real run (#2618 F2) wasthat no directory at depth N could ever be planned from a
--max-depth Nscan;clearing one cost a delete-child → rescan-at-depth+1 → delete-parent cycle, two
extra approval-gated rounds per directory.
Fix
At the depth boundary only, probe for a first child before marking anything:
directory_has_child()— oneos.scandir, first entry only, no recursionand no count. Deliberately not
top_level_entry_count(), which iterates everychild to produce a number; a boundary directory with hundreds of thousands of
entries is exactly the cost
--max-depthexists to avoid. The question is"any?", not "how many?".
True(assumecontent), so emptiness is proven, never assumed. The read sits inside the
trybecause Windows surfaces an access denial on the first iteration steprather than on
os.scandiritself. No newerrorsentry is recorded: the oldcode did no
scandirthere at all, so silence preserves prior behavior exactly.walked=True,logical_size=0, nonot-walkedqualifier, and does not entertruncated_paths. With nothing leftunwalked,
target_identityalso stops carrying anot-walkedqualifier it didnot earn.
Scoped to the depth branch only (constraint (a) of the issue's fix note). The
VCS_NAMESandprotectionsbranches wear the identicalsubtotal = None; walked = False; truncated.append(...)shape, but they refuse awalk for reasons emptiness does not answer — an empty protected directory or an
empty VCS root must still land in
truncated. Two regression tests assert that,and both were confirmed to fail when the probe is applied to those branches.
The four
truncated_pathsconsumers, checked (constraint (b))previewblocker (overlaps_truncated→truncated-not-inventoried)truncated-not-inventoriedprotects an uninventoried subtree, and an empty directory has none. It also arms the drift check rather than weakening it — see the TOCTOU note below.previewunverifiedshort-circuitcurrent_descendants/tracked_blocker/candidate_handle_state. Those short-circuits exist to avoid unbounded live walks on candidates that can never become approvable; an empty directory's walk is onescandirand it can be approvable, so running them is correct.handoff_verifycontestedsethandoff_verify, the read-only manual-handoff revalidation lane.applyitself never readstruncated_paths; it consumes preview's verdicts.scan-completepassthroughFifth consumer, not in the audit's list:
annotate_trackedsubtracts eachtruncated path from the
git ls-filespathspec via:(exclude). A cleared emptydirectory is no longer excluded, so the pathspec is marginally larger. No
behavior change:
ls-files --cachedreads the index, so a directory empty ondisk can still return index entries, but those paths were never scanned, so
by_path.get(relative)isNoneand no annotation changes.TOCTOU. If a child appears between scan and preview, the directory is no
longer short-circuited, so
current_descendantsruns andcurrent_paths != expected_pathsraiseschanged-since-scan. Asserted bytest_cleared_boundary_directory_that_gains_a_child_is_caught.Rungs 2 and 3 of the issue's ladder (documenting the constraint; a separate
empty-verifiedqualifier) are deliberately not taken here.Verification
Covering suite, run in full on this branch and on its merge base (
b7e56070)for comparison:
The 282 − 275 = 7 added tests all pass. The three failures on this branch are a
strict subset of the baseline's four and are pre-existing and environmental on
this Windows workstation —
test_stash_must_exist_in_an_independent_checkout(8.3 short-path
KYLESE~1vsKyleSexton),test_preview_allows_root_children_os_managed_snapshot, andtest_deny_emits_blocked_telemetry_when_sink_wired. The baseline's extratest_every_local_branch_head_is_confirmederror did not recur. None are in thisdiff's blast radius; CI runs the suite on a clean Linux runner.
The seven new tests, run in isolation — all
ok:test_empty_directory_at_scan_depth_is_inventoried_not_truncated— size0,no qualifier,
truncated_paths == [], target roll-up exact.test_non_empty_directory_at_scan_depth_stays_truncated— unchanged behavior.test_empty_protected_directory_at_scan_depth_stays_truncated— regression guard.test_empty_vcs_directory_at_scan_depth_stays_truncated— regression guard;hard_protectionis stubbed so the VCS branch is the only thing that cantruncate, otherwise
.git's ownvcs-metadataprotection would keep theassertion green even if the probe had leaked into that branch.
test_directory_has_child_fails_closed_when_unreadable— fail-closed contract.test_empty_directory_at_scan_depth_is_previewable— the payoff, at consumer 1.test_cleared_boundary_directory_that_gains_a_child_is_caught— TOCTOU.Mutation check on the regression guards. With the probe deliberately applied
to the
VCS_NAMESandprotectionsbranches, both guards fail(
Lists differ: ['.git'] != []); reverted before commit. The guards discriminate.Lint:
Both files in this diff are among the already-formatted two; the three
reformat candidates (
destructive_guard.py,guard_launch_monitor.py,test_guard_launch_monitor.py) are pre-existing and untouched here.scripts/affected-tests.shselects seven suites for this diff.hygiene.test.shis the one that covers the change and is reported above;kill_switch_probe.test.shandpython3_alias_probe.test.shalso pass. Theremaining four are transitive dependents that do not touch the traversal branch
and blow the local wall-clock budget on Windows (the README's spawn-bound
caveat) — CI runs them.
Related
disk-hygiene:clean: frontmatter Bash belt is session-lifetime, not skill-scoped (+6 findings from a post-use audit) #2618 (F2) — the post-use audit umbrella. Already closed as completedwhile other findings from it were merged, so this PR carries no closing
keyword; F2's traversal fix had not landed. F5 (belt scope) and other findings
are covered separately.
plugins/disk-hygiene/skills/clean/scripts/hygiene.pyand its testsonly. The audit's markdown findings and
destructive_guard.pyare out of scopehere and are being handled in parallel.
Not for auto-merge. This changes traversal logic that feeds a deletion
preview; it wants a human read of the four-consumer analysis above before it
lands.