You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A failed Review or skill worktree acquisition leaves an empty temp directory behind #1975
SkillWorktree::on_pull_request (src/worktree/skill.rs) creates its temp directory and calls .keep() before acquisition::add_review:
let path = tempfile::Builder::new().prefix("thirdshift-review-").tempdir()?
.keep();
acquisition::add_review(launch, branch,&path, commit)?
When add_review fails, for example because the pull request's branch is checked out in a retained worktree (Occupied checkout … on refs/heads/<branch>), the ? returns and the empty directory is never removed. SkillWorktree::checkout has the same shape for thirdshift-skill-* directories.
Observed on a Linux host: before #1780, a scheduled Review Pass failed this way every two minutes on 2026-11-05. Seven empty /tmp/thirdshift-review-* directories, two minutes apart, were still there on 2026-11-10. #1780 stopped the scheduled retries, but the leak remains:
thirdshift review <PR URL> on an occupied branch, and
the window between conflicts::eligible's read-only pull_request_conflict check and acquisition.
Expected
A failed acquisition leaves no new directory behind. For example, remove the directory if add_review / add returns an error and the directory is still empty, or keep the TempDir guard until acquisition succeeds.
Verification
A test in the existing worktree acquisition tests: acquiring a Review checkout on a branch occupied by another worktree fails as today, and leaves no thirdshift-review-* directory under the temp root. Add the same test for SkillWorktree::at.
Confirmed against main at 6bcde72. Keep #1975 as one bounded bug fix.
Diagnosis: src/worktree/skill.rs:48-52 and :65-74 create a TempDir, call keep(), then propagate acquisition errors. Acquisition records that directory as pre-existing (src/worktree/acquisition.rs:155), so recovery permits it to remain when Git creates no registration (:285-297, :431-435). No SkillWorktree is returned to perform cleanup.
Reproduction: a scratch harness using the unchanged repository modules exercised real local Git. Running python3 target/triage-1975/run-repro.py twice produced identical results: invalid commits through SkillWorktree::at and SkillWorktree::on_pull_request each left one empty directory; a Git wrapper that occupied the Review branch immediately before worktree add also left one empty thirdshift-review-* directory. Each no-leak assertion failed. Logs are target/triage-1975/repro.log and repro-repeat.log.
Correction to the original example: a branch already occupied before on_pull_request starts is now rejected by recover_pull_request at skill.rs:43, before allocation, and leaves no directory. The later occupation race still reproduces.
Implementation: clean up the attempt-owned empty allocation when either acquisition call fails. Preserve the original acquisition error, occupied checkouts, branches, and partial checkouts containing work or uncertain ownership. Respect the existing directory-identity checks and ADR 0014. Simply retaining TempDir's recursive cleanup through acquisition is unsafe: a failing post-checkout hook can leave work that must survive.
Acceptance: add regressions at the actual SkillWorktree entry points for invalid-commit failures under an isolated temp root and for branch occupation after Review preflight. Assert no new empty directory remains, while the occupied checkout and branch remain intact. Keep controls for rejection before allocation, hook-created work, and normal successful cleanup. The existing acquisition test enum's Review variant uses ReviewWorktree, so it does not cover these allocation paths. Run the focused worktree tests and scripts/affected-tests main.
Activity
JacobStephens2 commentedon Nov 11, 2026
Agent Brief
Confirmed against main at 6bcde72. Keep #1975 as one bounded bug fix.
Diagnosis: src/worktree/skill.rs:48-52 and :65-74 create a TempDir, call keep(), then propagate acquisition errors. Acquisition records that directory as pre-existing (src/worktree/acquisition.rs:155), so recovery permits it to remain when Git creates no registration (:285-297, :431-435). No SkillWorktree is returned to perform cleanup.
Reproduction: a scratch harness using the unchanged repository modules exercised real local Git. Running
python3 target/triage-1975/run-repro.pytwice produced identical results: invalid commits through SkillWorktree::at and SkillWorktree::on_pull_request each left one empty directory; a Git wrapper that occupied the Review branch immediately before worktree add also left one empty thirdshift-review-* directory. Each no-leak assertion failed. Logs are target/triage-1975/repro.log and repro-repeat.log.Correction to the original example: a branch already occupied before on_pull_request starts is now rejected by recover_pull_request at skill.rs:43, before allocation, and leaves no directory. The later occupation race still reproduces.
Implementation: clean up the attempt-owned empty allocation when either acquisition call fails. Preserve the original acquisition error, occupied checkouts, branches, and partial checkouts containing work or uncertain ownership. Respect the existing directory-identity checks and ADR 0014. Simply retaining TempDir's recursive cleanup through acquisition is unsafe: a failing post-checkout hook can leave work that must survive.
Acceptance: add regressions at the actual SkillWorktree entry points for invalid-commit failures under an isolated temp root and for branch occupation after Review preflight. Assert no new empty directory remains, while the occupied checkout and branch remain intact. Keep controls for rejection before allocation, hook-created work, and normal successful cleanup. The existing acquisition test enum's Review variant uses ReviewWorktree, so it does not cover these allocation paths. Run the focused worktree tests and scripts/affected-tests main.