@feigi/fleet-ctl 3.24.6 → 3.24.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.24.6",
3
+ "version": "3.24.7",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/scripts/reap.sh CHANGED
@@ -1397,10 +1397,12 @@ for b in $gone_branches; do
1397
1397
  # not read (#622). The dry run — printing `would reap` unconditionally
1398
1398
  # here — cannot predict any of those keeps either.
1399
1399
  #
1400
- # A window remains between this re-read and the delete, per the ruling on
1401
- # #1330 (Q2, ADR 0018): a checkout landing in it breaks that worktree but
1402
- # cannot lose a commit — a commit made there moves the ref off `$tip`, and
1403
- # the compare-and-swap refuses.
1400
+ # A window remains between this re-read and the delete. A commit landing
1401
+ # in it moves the ref off `$tip`, and the compare-and-swap refuses. A
1402
+ # `git worktree add` of this branch landing in it moves nothing, so the
1403
+ # delete goes through under it — and `wt_recheck_delete`, right after the
1404
+ # delete, finds that worktree and restores the branch rather than leaving
1405
+ # it broken and unreported.
1404
1406
  if ! wt_listing; then
1405
1407
  keep "$b" "cannot re-read the worktree list to check $b before the delete — not deleted: $(printf '%s' "$wt_err" | tr '\n' ' ')"
1406
1408
  continue
@@ -1437,6 +1439,21 @@ for b in $gone_branches; do
1437
1439
  keep "$b" "branch delete failed: $(printf '%s' "$err" | tr '\n' ' ')"
1438
1440
  continue
1439
1441
  fi
1442
+ # The add that raced the delete, caught after it: a worktree that checked
1443
+ # this branch out while the delete ran. Ahead of the config removal below,
1444
+ # so a restored branch keeps its upstream and is selected again next pass.
1445
+ if wt_recheck_delete "refs/heads/$b" "$tip"; then race_rc=0; else race_rc=$?; fi
1446
+ case $race_rc in
1447
+ 0) ;;
1448
+ 2)
1449
+ keep "$b" "$b $wt_restore_why, and restoring it at $tip failed — $wt_restore_out: $(printf '%s' "$wt_err" | tr '\n' ' ')"
1450
+ continue
1451
+ ;;
1452
+ *)
1453
+ keep "$b" "$b $wt_restore_why — branch restored, not deleted"
1454
+ continue
1455
+ ;;
1456
+ esac
1440
1457
  # The `[branch "<b>"]` config section, which `-D` removed with the ref and
1441
1458
  # ref-only `update-ref` leaves behind. Measured, git 2.50.1: a later
1442
1459
  # `git branch --no-track <b>` inherits the stale upstream and reads
@@ -1524,6 +1541,20 @@ elif ! detached=$(printf '%s\n' "$wt_list" |
1524
1541
  END{if (p != "" && !skip) print h" "p}'); then
1525
1542
  keep "" "could not read the worktrees git listed — a branchless one would go unreported"
1526
1543
  else
1544
+ # Read off this listing before the loop below, which re-reads it into the
1545
+ # same `$wt_list` whenever a removal refuses: the worktrees checked out on a
1546
+ # branch that no longer exists, for the backstop after that loop. A
1547
+ # `branch` line with the null object id as its `HEAD` is that shape, and
1548
+ # the backstop then asks git whether the ref really is gone. Status taken,
1549
+ # for the reason given for `$detached` above.
1550
+ if ! broken=$(printf '%s\n' "$wt_list" |
1551
+ awk '/^worktree /{if (p != "" && b != "" && h ~ /^0+$/) print b" "h" "p; p=substr($0,10); h=""; b=""; next}
1552
+ /^HEAD /{h=$2}
1553
+ /^branch /{b=substr($0,8)}
1554
+ END{if (p != "" && b != "" && h ~ /^0+$/) print b" "h" "p}'); then
1555
+ keep "" "could not read the worktrees git listed — one checked out on a deleted branch would go unreported"
1556
+ broken=
1557
+ fi
1527
1558
  while IFS= read -r entry; do
1528
1559
  [ -n "$entry" ] || continue
1529
1560
  head=${entry%% *}
@@ -1735,6 +1766,41 @@ else
1735
1766
  removed="${removed}$(jfield "$wt"),"
1736
1767
  done <<EOF
1737
1768
  $detached
1769
+ EOF
1770
+
1771
+ # Backstop for a branch deleted under a worktree that checked it out: the
1772
+ # delete raced a `git worktree add` that `wt_recheck_delete` could not see,
1773
+ # or something outside this script deleted the ref. git lists such a
1774
+ # worktree with its `branch` line forever, so the sweep above never sees it,
1775
+ # and its `HEAD` does not resolve. Reported, never acted on: a worktree made
1776
+ # with `git worktree add --orphan` looks the same, and only fleet worktrees,
1777
+ # under `.worktrees/`, are reported — a fleet claim always branches from
1778
+ # `origin/main`, so one of those on a ref that does not exist was broken.
1779
+ # The likely tip is read from the worktree's own `HEAD` reflog, which
1780
+ # survives the delete, and named as unverified: nothing here can prove it
1781
+ # was the branch's tip.
1782
+ while IFS= read -r entry; do
1783
+ [ -n "$entry" ] || continue
1784
+ ref=${entry%% *}
1785
+ entry=${entry#* }
1786
+ null=${entry%% *}
1787
+ wt=${entry#* }
1788
+ case "$wt" in
1789
+ */.worktrees/*) ;;
1790
+ *) continue ;;
1791
+ esac
1792
+ git rev-parse -q --verify "$ref" >/dev/null && continue
1793
+ likely=
1794
+ if ! nl_path "$wt" && admin=$(git -C "$wt" rev-parse --absolute-git-dir 2>/dev/null); then
1795
+ likely=$(awk '$2 !~ /^0+$/ {t = $2} END {print t}' "$admin/logs/HEAD" 2>/dev/null) || likely=
1796
+ fi
1797
+ if [ -n "$likely" ]; then
1798
+ keep "" "worktree $wt is checked out on $ref, which no longer exists — its HEAD reflog last named $likely (unverified); if that was the tip, restore it with: git update-ref $ref $likely $null"
1799
+ else
1800
+ keep "" "worktree $wt is checked out on $ref, which no longer exists — no tip could be read from its HEAD reflog; restore it with: git update-ref $ref <tip> $null"
1801
+ fi
1802
+ done <<EOF
1803
+ $broken
1738
1804
  EOF
1739
1805
  fi
1740
1806
 
@@ -1646,14 +1646,14 @@ else
1646
1646
  # separate git invocation, and nothing here can ask `update-ref` to verify
1647
1647
  # it atomically with the delete the way `-D` verified its own.
1648
1648
  #
1649
- # What that window can cost, per the maintainer's ruling: a checkout
1650
- # landing in it leaves that worktree holding a deleted branch, which
1651
- # breaks the worktree. It cannot lose a commit. A commit made there before
1652
- # the delete moves the ref off $tip, and the compare-and-swap below then
1653
- # refuses. Measured, git 2.50.1: with a commit made in the window,
1654
- # `update-ref -d` exits 1 on `is at <new> but expected <tip>` and the
1655
- # branch keeps the commit; with none, the delete lands and that worktree
1656
- # reads `No commits yet` on its branch.
1649
+ # What that window can cost: a commit made there before the delete moves
1650
+ # the ref off $tip, and the compare-and-swap below refuses. A checkout
1651
+ # landing in it moves nothing — `git worktree add` of an existing branch
1652
+ # writes only the new worktree's `HEAD` — so the delete goes through and
1653
+ # leaves that worktree on a branch that no longer exists. That is what
1654
+ # `wt_recheck_delete` after the delete catches: it finds the worktree and
1655
+ # restores the branch at $tip, and the release halts exactly as it does
1656
+ # on a holder caught before the delete.
1657
1657
  #
1658
1658
  # Held by either route `-D` refused on, not only the porcelain `branch`
1659
1659
  # line: a worktree stopped mid `rebase -i` or mid `git bisect` on this
@@ -1693,6 +1693,15 @@ else
1693
1693
  if ! err=$(git update-ref -d "refs/heads/$branch" "$tip" 2>&1); then
1694
1694
  halt "git update-ref -d refused $branch: $(printf '%s' "$err" | tr '\n' ' ')"
1695
1695
  fi
1696
+ if wt_recheck_delete "refs/heads/$branch" "$tip"; then race_rc=0; else race_rc=$?; fi
1697
+ case $race_rc in
1698
+ 0) ;;
1699
+ 2)
1700
+ [ -n "$wt_now" ] || done_branch=true
1701
+ halt "$branch $wt_restore_why, and restoring it at $tip failed — $wt_restore_out: $(printf '%s' "$wt_err" | tr '\n' ' ')"
1702
+ ;;
1703
+ *) halt "$branch $wt_restore_why — branch restored, not deleted" ;;
1704
+ esac
1696
1705
  done_branch=true
1697
1706
  fi
1698
1707
 
@@ -468,3 +468,131 @@ wt_h_settle() {
468
468
  wt_h_check_op "$1" 1
469
469
  return $?
470
470
  }
471
+
472
+ # How many times `wt_recheck_delete` re-reads a listing that still shows a
473
+ # `git worktree add` in progress, 0.1s apart, before it stops waiting.
474
+ wt_init_waits=20
475
+
476
+ # After `git update-ref -d` has deleted branch ref $1 (`refs/heads/<b>`) at
477
+ # tip $2: did a `git worktree add` check that branch out while the delete
478
+ # ran? If so, or if that cannot be ruled out, put the ref back at $2.
479
+ #
480
+ # The holder check before a delete and the delete itself are two git calls,
481
+ # and git has no lock that stops a `worktree add` of an existing branch
482
+ # between them. Measured, git 2.50.1: such an add writes only the new
483
+ # worktree's `HEAD` symref and never touches `refs/heads/<b>`, so the
484
+ # compare-and-swap still succeeds and the new worktree is left on a branch
485
+ # that no longer exists — `HEAD` unresolvable, and listed with a `branch` line
486
+ # forever, so nothing that reads the listing later sees a stray. Once the ref
487
+ # is gone a new add fails on `invalid reference`, so only an add that
488
+ # resolved the branch before the delete can land this way, and this re-read
489
+ # after the delete sees it.
490
+ #
491
+ # While an add runs, git lists its worktree `detached` and `locked
492
+ # initializing`, with no `branch` line. Measured, git 2.50.1: while the add has
493
+ # resolved the branch but not yet written the worktree's `HEAD`, `wt_holding`
494
+ # answers "cannot tell" (the admin dir has no `HEAD` yet), so a check made
495
+ # then would restore the ref under rc 3 with a reason that names no holder.
496
+ # So the listing is re-read while any such entry is listed, up to
497
+ # `wt_init_waits` times, until the add settles and `wt_holding` can name it; a
498
+ # wait that runs out, or a `sleep` that fails, restores the ref.
499
+ # `wt_holding` itself has no rule for a `locked initializing` entry: every
500
+ # concurrent `claim-ticket.sh` add is listed that way while it runs, and
501
+ # reading all of them as "cannot tell" would halt deletes under ordinary fleet
502
+ # churn.
503
+ #
504
+ # The restore is create-only — the null id as the old value — so it never
505
+ # overwrites a ref someone else created since. Measured, git 2.50.1: it fully
506
+ # heals a worktree whose add finished before the delete (`HEAD` resolves,
507
+ # status clean). The branch's reflog does not come back.
508
+ #
509
+ # 0: no worktree holds the branch; the delete stands.
510
+ # 1: a worktree held it — `wt_holder`/`wt_holder_how` as `wt_holding` sets
511
+ # them — and the ref is restored.
512
+ # 2: the restore failed — `wt_err` carries git's message. `wt_restore_out` says
513
+ # what state the branch is left in, as a clause to follow the failed
514
+ # restore in a message: deleted, with `wt_repair` the command that restores
515
+ # the ref by hand, or recreated by something else since the delete, in
516
+ # which case `wt_now` is the commit it resolves to and nothing was
517
+ # overwritten. `wt_now` is empty when the branch is deleted.
518
+ # 3: no holder could be ruled out — an add still in progress when the wait
519
+ # ran out (`wt_holder` names that entry), a holder check that could not
520
+ # tell, or a listing that would not re-read — and the ref is restored.
521
+ # On 1, 2 and 3, `wt_restore_why` says why, as a clause to follow the branch
522
+ # name in a message.
523
+ #
524
+ # Condition context only, like `wt_holding`.
525
+ # shellcheck disable=SC2034
526
+ wt_recheck_delete() {
527
+ wt_restore_why=
528
+ wt_restore_out=
529
+ wt_now=
530
+ wt_rd_waits=0
531
+ while :; do
532
+ if ! wt_listing; then
533
+ wt_holder=
534
+ wt_restore_why="could not be checked against the worktree list after the delete: $(printf '%s' "$wt_err" | tr '\n' ' ')"
535
+ wt_rd_rc=3
536
+ break
537
+ fi
538
+ wt_rd_path=
539
+ wt_rd_init=
540
+ while IFS= read -r wt_rd_line; do
541
+ case $wt_rd_line in
542
+ "worktree "*) wt_rd_path=${wt_rd_line#worktree } ;;
543
+ "locked initializing") wt_rd_init=$wt_rd_path ;;
544
+ esac
545
+ done <<EOF
546
+ $wt_list
547
+ EOF
548
+ if [ -z "$wt_rd_init" ]; then
549
+ if wt_holding "$1"; then wt_rd_held=0; else wt_rd_held=$?; fi
550
+ case $wt_rd_held in
551
+ 0)
552
+ wt_restore_why="was ${wt_holder_how#is } in worktree $wt_holder during the delete"
553
+ wt_rd_rc=1
554
+ ;;
555
+ 1) return 0 ;;
556
+ *)
557
+ wt_restore_why="could not be checked against worktree $wt_holder after the delete"
558
+ wt_rd_rc=3
559
+ ;;
560
+ esac
561
+ break
562
+ fi
563
+ if [ "$wt_rd_waits" -ge "$wt_init_waits" ]; then
564
+ wt_holder=$wt_rd_init
565
+ wt_restore_why="could not be checked after the delete: worktree $wt_rd_init was still being added (locked initializing) when the wait ran out"
566
+ wt_rd_rc=3
567
+ break
568
+ fi
569
+ if ! sleep 0.1; then
570
+ wt_holder=$wt_rd_init
571
+ wt_restore_why="could not be checked after the delete: could not wait for worktree $wt_rd_init to finish being added (locked initializing)"
572
+ wt_rd_rc=3
573
+ break
574
+ fi
575
+ wt_rd_waits=$((wt_rd_waits + 1))
576
+ done
577
+ # The null id as long as the tip itself, so a SHA-256 repository gets its
578
+ # own width.
579
+ wt_rd_null=
580
+ wt_rd_t=$2
581
+ while [ -n "$wt_rd_t" ]; do
582
+ wt_rd_null=${wt_rd_null}0
583
+ wt_rd_t=${wt_rd_t#?}
584
+ done
585
+ wt_repair="git update-ref $1 $2 $wt_rd_null"
586
+ if ! wt_err=$(git update-ref "$1" "$2" "$wt_rd_null" 2>&1); then
587
+ [ -n "$wt_err" ] || wt_err="git update-ref failed"
588
+ if wt_now=$(git rev-parse -q --verify "$1" 2>/dev/null); then
589
+ wt_restore_out="the branch now exists at $wt_now, recreated by something else and left as it is"
590
+ else
591
+ wt_now=
592
+ wt_restore_out="the branch is deleted, restore it with: $wt_repair"
593
+ fi
594
+ return 2
595
+ fi
596
+ wt_err=
597
+ return "$wt_rd_rc"
598
+ }
@@ -24,6 +24,7 @@ Every precondition recomputed **inside** same command as delete:
24
24
  - **`git cherry origin/main`, not `git diff main..`.** Against `origin/main` — local `main` you never fast-forwarded reads every merged branch as unmerged. Any `+` line is commit that exists nowhere else.
25
25
  - **The delete is `git update-ref -d`'s compare-and-swap on a tip read once (ADR 0018), authorized by that cherry check and by a fresh check, re-read immediately before the delete, that no worktree holds the branch.** Tip read before the cherry, cherry runs against that SHA, delete refuses unless ref still equals it — commit landing between check and delete is kept with git's own `cannot lock ref`, never force-deleted, as it was under `git branch -D` until #2219. `--no-deref`, so symref branch deletes the symref, not its target (measured). Branch's config section removed after, as `-D` did — left behind, re-created branch of same name inherits dead upstream and reads `[gone]` at once. `git branch -d` would refuse everything here: upstream gone, so falls back to comparing against `HEAD`, a possibly-behind local `main`. Never delete branch whose cherry output you did not just read.
26
26
  - **A branch any worktree holds is a KEEP, checked right before the delete.** `update-ref` consults no worktree; `-D` did. So listing is re-read and worktree.sh's `wt_holding` asks: held by a `branch` line, or by detached worktree stopped mid `rebase -i` / mid `bisect` on it (admin dir's `head-name` / `BISECT_START`) — both routes `-D` refused on (#2218). Worktree it cannot resolve, or listing that will not re-read, is a KEEP. `--apply` only, like the delete: dry run cannot predict this refusal — not the same limitation `-D`'s dry run had, since an unrelated worktree elsewhere in the listing that this check cannot resolve keeps every `[gone]` branch in the pass (see below), a repo-wide case `-D` never produced.
27
+ - **A worktree that checked the branch out while the delete ran is caught after it, and the branch is put back.** git has no lock that stops `git worktree add <p> <b>` between that holder check and the delete, and such an add writes only the new worktree's `HEAD` — the ref does not move, so the compare-and-swap succeeds and leaves the worktree on a branch that no longer exists (measured, git 2.50.1). So worktree.sh's `wt_recheck_delete` re-reads the listing right after the delete — and again, up to 20 times 0.1s apart, while an add in progress is listed `locked initializing` — and when a worktree holds the branch, or the wait runs out, recreates it at the tip with a create-only `git update-ref`. The branch is a KEEP naming the worktree or the entry, and its config section stays. A restore that fails is a KEEP naming the tip, git's error and the command that restores it by hand — or, when something recreated the branch since the delete, the commit it now sits at, left as it is, since the create-only restore never overwrites it. The branch's reflog does not come back.
27
28
  - **A cherry that cannot answer is a KEEP.** Capture git's output; never pipe git itself: `cmd | grep -q` takes grep's exit status, never cmd's, so a `git cherry` that dies (rc 128 — one unreadable loose object is enough) prints nothing, grep exits 1, and a dead probe reads identical to "nothing unmerged" (verified, git 2.50.1). Unanswerable probe authorizes no delete — same fail-closed shape as `worktree remove` below. Read the `+` anchored, too: the capture folds stderr in, so an unanchored match reads a `+` in a diagnostic as a commit. Pinned by a test.
28
29
  - **A worktree registry that cannot be read is a KEEP, for every `[gone]` branch in that pass.** The lookup decides whether the dirty, ignored-files and removal checks run at all; an unread registry reads identical to "no worktree", and `-D`, the delete then, needed no answer from the registry to delete a branch that has none — so failing open force-deleted merged branches blind (#622). The holder check before the delete asks only whether a worktree holds the branch, never those other questions, so the lookup still fails closed on its own. The listing is re-read per branch, so one repo-level failure keeps every `[gone]` branch in the pass, each with git's own cause. Reap runs after every merge pass, so the next one retries: nothing is lost, nothing is reaped blind.
29
30
  - **A registry the listing does not match is a KEEP for the whole pass, not just one branch — if the fault is standing.** Eight real admin-directory faults leave `git worktree list` at rc 0 while the held entry loses its `branch` line (admin `HEAD` garbage, empty, missing or chmod 000) or leaves the listing (`gitdir` missing or chmod 000, admin dir chmod 000, `.git/worktrees` replaced by a file) — and git's own "used by worktree" `-D` refusal read the same admin state, so it deleted the branch a live worktree held (measured, git 2.50.1, #2078). The holder check that replaced that refusal reads the same listing and answers "not held" for seven of the eight (measured; "cannot tell" only for `HEAD` missing), so it is no backstop either. So before the lookup is trusted, linked entries listed are counted against entries under `<git-common-dir>/worktrees/` (inflight.sh's `count_registry`/`count_linked`, recount-before-refuse included), and any linked entry with a null `HEAD` and no `branch` line fails it too — the HEAD faults keep the counts equal. A dropped or nameless entry says nothing about which branch it held. The check re-reads the listing per branch, so a standing fault — one still there on every branch's own read — keeps every `[gone]` branch in the pass, the healthy ones included; a transient one, healed before the next branch's read, keeps only the branches whose listing it touched. Either way nothing is reaped blind, and the next pass retries once the registry reads consistent again.
@@ -42,6 +43,7 @@ So `reap.sh` enumerates worktrees git lists with **no `branch` line at all** and
42
43
  - **Absent `branch` line is not by itself detached HEAD.** git prints none for worktree whose HEAD it cannot resolve either, reporting null object id instead — four measured corruption routes for admin `HEAD` (#179). Nothing about such worktree decidable, so report and leave. Null id alone is not the test: unborn branch is legitimate null id and DOES carry `branch` line.
43
44
  - **A git operation in progress is a keep, and git is no backstop for it.** Measured, git 2.50.1 (Apple Git-155): `worktree remove` *without* `--force` removes worktree holding interrupted rebase, and one holding bisect, at rc 0. Both detach, both leave `status --porcelain` empty — so every other check passes them and sequencer state, todo list and original head go with directory. Interrupted rebase is exactly how fleet worktree wanders off its branch (see `release-ticket.sh`'s own stray guard).
44
45
  - **Every decline is a `kept` entry, `branch` null.** No branch to name. Gap was invisible precisely because nothing was reported.
46
+ - **A fleet worktree whose branch no longer exists is reported, never acted on.** It keeps its `branch` line, so the enumeration above never sees it, and its `HEAD` reads as the null object id. Under `.worktrees/` only, a `kept` entry names the worktree, the missing ref, the tip its own `HEAD` reflog last named (unverified) and the `git update-ref` command that restores it. Never removed: a `git worktree add --orphan` checkout looks the same.
45
47
  - **Removals join `worktreesRemoved[]`, from both sweeps.** One meaning, no qualifier: a key naming only removals no branch accounted for would leave reader unable to tell absent removal from unreported one.
46
48
  - **Not fixed in merge bot.** Re-attaching worktree after rebase puts invariant where it only helps paths that remember to do it, and next permitted-command change moves problem again.
47
49
 
@@ -60,6 +62,8 @@ So nothing in the run cleans it up. Next run, the in-flight probe's local-worktr
60
62
 
61
63
  **The delete is `git update-ref -d`'s compare-and-swap (ADR 0018) here too, and for reap's reason** — authorized by the `ahead` and `git cherry` checks above, plus the `ahead` recount re-run against `origin/main` immediately before the delete itself (a commit can land across the `gh issue view` between the checks and the delete; `git cherry` is not re-run, because such a commit is ahead of `origin/main` by construction), plus a fresh check, re-read immediately before the delete, that no worktree holds the branch (`update-ref` consults no worktree, where `-D` refused a held branch; a worktree it cannot resolve, or a listing that will not re-read, stops the delete too), and by nothing else. A claim used to carry `origin/main` as its upstream, so `-d` compared against *that* and forgave a behind local main; since #760 `claim-ticket.sh` passes `--no-track` (so `@{u}` cannot silently answer about main), a claim has no upstream until its first `push -u`, and `-d` falls back to comparing against local `HEAD`. Measured: with local `main` behind `origin/main`, `-d` refuses a pristine claim — half-releasing it, worktree deleted and branch stranded with `in-progress` still on the ticket. The two checks above are strictly stronger than what `-d` would have asked, and both measure against `origin/main` rather than a local ref.
62
64
 
65
+ **A checkout that lands between that fresh check and the delete halts the release after it.** `git worktree add` of an existing branch does not move the ref, so the compare-and-swap succeeds under it. The same `wt_recheck_delete` reap uses then finds the worktree, recreates the branch at the tip, and the release halts with exit 2, `released:false` and a blocker naming that worktree — the shape of a holder caught before the delete. A restore that fails halts the same way, with the tip and the repair command in the blocker.
66
+
63
67
  **`worktree remove` without `--force`** refuses on modified and untracked files and deletes ignored files silently (verified, git 2.50.1). Ignored-silently is what is wanted: `claim-ticket.sh` writes an `agent-test` into each fresh worktree it claims of a repository that tracks none, and ignores it through the repository's exclude file, so treating ignored files as dirt would strand every such release. The same asymmetry is why a claim never writes over a tracked `agent-test`: that write would leave a modified tracked path, which this refusal does not forgive. Its refusal is the dirty check recomputed by git at the moment of the delete — for the live-directory case ONLY. `worktree remove` gates that clean check on the same `stat` the guard does, so it is not an independent second opinion: where the path cannot be stat'ed git reaches the same "gone" by the same means, accepts the entry at rc 0 and deregisters a worktree whose files are still on disk (measured, git 2.50.1: an untracked file in a worktree under a `chmod 000` parent). There the `gone` guard is sole arbiter — which is why it establishes absence instead of inferring it from a failed `-e`, and why the fail-open fixed in `1e54bac` survived being reasoned about: guard and backstop fail on the same inputs.
64
68
 
65
69
  **A worktree that wandered off the branch blocks too.** The worktree is located by the branch it has checked out, and it does not stay there — an interrupted rebase leaves it detached, a member can switch it. The lookup then finds nothing, which reads as "no worktree of ours": the dirty check is skipped entirely and the release reports success while the worktree stands with the member's work in it, so the next run's probe still reads the ticket as taken. So a linked worktree at `claim-ticket.sh`'s `.worktrees/<issue>-<slug>` that is *not* on the branch is its own blocker — which remedy it names is the next paragraph, and is not always a hand-release. The path is read as the whole rest of the `worktree list --porcelain` line, never the first whitespace field, or every checkout under a directory with a space in its name reads as a different path.