Skip to content

fix(worktree-reaper): fail closed when /proc cannot be scanned before removal (#5740) - #6731

Merged
dezren39 merged 1 commit into
mainfrom
queue/fallback-5740-reaper-proc-failclosed
Nov 7, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/fallback-5740-reaper-proc-failclosed

Conversation

@dezren39

@dezren39 dezren39 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Fixes #5740

The reaper's /proc scan failed open: proc_cwds() returned an empty list when os.listdir("/proc") raised, and tree_occupied() read that as "unoccupied" — so the fresh pre-removal check in reap_tree could pass on an inspection error and delete a worktree whose occupancy was simply unknown.

  • proc_cwds() now raises ProcScanError (an OSError subclass, so it still reads as an inspection failure) instead of returning []. A successful scan with zero matches still returns [] — the two states are now distinct all the way down.
  • reap_tree catches ProcScanError at the pre-removal re-check: candidate kept with reason occupied-unknown-at-removal, the error recorded on the record, a WARNING printed — and no git worktree remove, branch deletion, or path deletion runs.
  • main() catches it at the run's initial scan: clear ERROR, summary printed, exit 1, nothing evaluated or removed.

Tests (infra/worktree-reaper/tests/test_worktree_reaper.py, the documented command in its docstring): new ProcScanFailClosedTests — injected os.listdir("/proc") failure raises ProcScanError; reap_tree under the same injection returns False, keeps the candidate, asserts run_git was never called and the tree survives; successful-empty-scan and confirmed-matching-process behaviour pinned as controls. 12/12 pass on the laptop.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 7, 2026 03:31
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 80953678-84d1-43c8-a163-e1dde6b7eb2a
Commits

Reviewing files that changed from the base of the PR and between bcc0901 and 0d1f3bf.

Files selected for processing: 2

  • infra/worktree-reaper/bin/worktree_reaper.py
  • infra/worktree-reaper/tests/test_worktree_reaper.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T03:33:24.311209Z 0d1f3bf PR opened
ℹ️ 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.

@dezren39
dezren39 merged commit 5df7c86 into main Nov 7, 2026
3 checks passed
@dezren39
dezren39 deleted the queue/fallback-5740-reaper-proc-failclosed branch November 7, 2026 03:34
@dezren39

dezren39 commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Salvage note from duplicate PR #6733 (lane code-q; closed as duplicate of this PR per the duplicate-PR protocol — diffed against this merged PR before closing, not just compared by file list).

Race context: lanes code-z and code-q claimed issue #5740 in fallback mode 24 seconds apart (03:29:00Z / 03:29:24Z) — the deployed fleet binary has no fallback claim verb to refuse the second claim, so both lanes implemented in parallel. This PR landed first and is canonical.

Diff verdict: the two implementations satisfy the same contract with different mechanics — this PR raises ProcScanError (reap keeps occupied-unknown-at-removal; a failed run-wide scan aborts the run, exit 1, nothing removed), while #6733 returned None and retained per-tree (occupied-unknown at evaluation, run continues). The merged behavior is complete for every acceptance criterion of #5740, and its suite passes on current main (12 tests, verified 2026-11-07 by lane code-q from an origin/main archive).

One unique item in the duplicate, recorded here as the salvage: end-to-end failure-injection coverage through main() on a synthetic repo — /proc failure injected at evaluation and separately at only the removal re-scan, asserting on disk that the candidate tree and branch survive and naming the decision reason. The merged suite covers the removal path at unit level (git-call spy) and the proc_cwds contract, but no test exercises the run-wide-scan abort path in main() end-to-end. Nothing else in #6733 is unique; no code needs porting.

@dezren39
dezren39 restored the queue/fallback-5740-reaper-proc-failclosed branch November 8, 2026 04:30
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.

worktree-reaper: fail closed when /proc cannot be scanned before removal

1 participant