Skip to content

prune-merged keeps a tree holding a DEAD or STALE record and reads its -Apply end state fail-closed (BACKLOG #5956) - #3226

Open
wshallwshall wants to merge 8 commits into
mainfrom
b634/5956-prune-records
Open

wshallwshall wants to merge 8 commits into
mainfrom
b634/5956-prune-records

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

Batch 634, row #5956. Both limbs of the row are closed in scripts/worktree/prune-merged.ps1. The workbook filed the row under the vault, but the finding is in this engine script.

Merge danger

Reversible: yes. A revert of this squash restores the old behaviour. No schema, store or settings change.

Blast radius: scripts/worktree/prune-merged.ps1, scripts/worktree/worktree-gates.ps1 (new shared Get-StrandableRecords and Get-EndStatePresence; Get-ClaimedWorktreeIndex now keeps key and file per holder), scripts/worktree/hygiene-report.ps1, scripts/worktree/finished-worktree-removal.ps1, docs/WORKTREES.md, and the worktree tests.

Visible behaviour:

  • Limb A. A worktree holding a DEAD or STALE session record is now kept, at the decision pass and at the -Apply re-check. -Name does not lift the hold, and the record is not deleted. Before this, removing such a tree left an unplaceable record, and every later run in the clone stopped with the fence unavailable (exit 2), until someone deleted the file by hand.
  • Limb B. The -Apply end state is read fail-closed. A leftover it cannot confirm gone is reported as an unknown end state, not counted as removed, and never labelled ORPHANED.
  • The ledger pass releases no claim. A gone ledger entry that a claim still names stays in the ledger, and the dry run and -Apply name the claim key and file. Releasing it stays with claim.ps1. A held entry exits 0, so another PC's claim cannot red every run. The release on a confirmed removal is unchanged from main.
  • A non-zero git exit on a still-listed tree whose end state cannot be read exits 3. On main that case crashed when Test-Path threw.

Evidence

  • Reproduced first, in fixture repos with a fixture config root:
    • With no record in the removed tree, the second run removes its target.
    • With a DEAD record, the second run exits 2: fence unavailable, 1 unplaceable record, 0 removed.
    • With a STALE record, the second run gives the same result.
  • Red, then green: test_a_dead_or_stale_record_holds_its_tree_and_the_next_run_still_works (3 cases), test_a_dead_or_stale_record_arriving_mid_run_holds_the_tree (2), test_an_end_state_it_cannot_confirm_is_not_counted_as_removed (2), test_an_unknown_end_state_keeps_the_claim_and_its_ledger_entry, test_a_gone_entry_stays_in_the_ledger_while_a_claim_may_name_it (this machine, another PC), and test_an_unknown_end_state_on_a_tree_git_still_lists_is_not_an_orphan.
  • Checks at head 2d4ef04485f: all four mypy legs, ruff check ., ruff format --check on the test file, and a targeted run of 21 claim and new tests (all passed).
  • Two tests went red in the four worktree suites (285 passed, 2 failed) and passed when rerun alone at the same head: test_worktree_finished_claude_removal.py::test_runner_dry_run_lists_from_a_fresh_prune_merged_run_and_removes_nothing and test_worktree_hygiene_report.py::test_an_unreadable_claim_holds_every_merged_tree_back. The cause was not captured. Both scripts use the changed Get-ClaimedWorktreeIndex, so this may be a real interaction, not load.
  • Not run: the full pytest suite. Hosted legs to read: the Windows test leg, because these tests skip off Windows, and the two tests above in particular.
  • Safety: prune-merged.ps1 ran only against fixture repos.

Proposed ledger banner

SHIPPED for the row's two limbs, in prune-merged.ps1. The open findings below go to one R2 row, and scripts/worktree/remove.ps1 can still strand a record the same way (finding 12).

Open findings, none repaired

Items 1 and 2 could mislead an operator, so please classify them under your merge rule:

  1. The new exit 3 also prints the tail line "ORPHANED: a directory is broken on disk RIGHT NOW ... follow the recipe above", with no recipe printed.
  2. The held-entry recipe tells the operator to run claim.ps1 -Release '<key>' -Force even for another PC's claim, and does not show the claim's host.
  3. The new exit 3 is not recorded, so the next run exits 0 over the same unreadable tree.
  4. run-daily-prune.ps1 line 136 and the $EXIT_ORPHANED comment still give exit 3's narrow meaning.
  5. When the claim registry is unresolved or holds a claim with no worktree, every gone entry is held with exit 0 and no key named, while the docs read "while a claim names that tree".
  6. A JSON receipt can show exitCode 3 with counts.orphaned 0 and nothing saying what earned the 3.
  7. The Get-LiveOrphans comment still says the -Apply pass settles the tree's claims first, which is now false.
  8. The claim registry is read up to three times per run, and two reads can disagree.
  9. A failed git worktree list reads as deregistered (pre-existing).
  10. A truncated ledger reads as empty, and -Apply then deletes it (pre-existing reader).
  11. A present but unlistable leftover reports 0 files. The header's AST statement census is stale (pre-existing).
  12. scripts/worktree/remove.ps1 has no such hold, on -Name or -Path, so it can still strand a record and take the fence down.
  13. scripts/coord/occupancy.ps1: the <primary>- name test also matches a missing path in a sibling clone such as -vault, and no hold in this repo can see that record.
  14. The earlier rounds' remaining findings are listed in the last commit's message.

…ts end state fail-closed

Row 5956, reproduced in a fixture repo. With a DEAD or a STALE record in a
candidate, run 1 removed the tree. Run 2 then exited 2 with the fence
unavailable and every candidate skipped, because the record now named a
missing sibling checkout. The control with no such record ran clean.

The tree now stays, at the decision pass and at the -Apply re-check. The
record is not a veto, it is not deleted, and -Name does not lift the hold.
occupancy.ps1 is unchanged, so the fence faults the same shapes as before.

The -Apply end state now reads the shared gone rule. Get-EndStatePresence
moved to worktree-gates.ps1 so both removals use one copy. Before this, a
not-found under an unlistable parent counted as removed, and an unreadable
leftover ended the run with exit 1 and no JSON receipt.
… fix

Row 5956, the simplify pass. Get-StrandableRecords moves to worktree-gates.ps1
and replaces the same filter inline in hygiene-report.ps1. The -Apply end state
drops two derived variables. The tests lose a duplicate process fixture and one
repeated run, and share one git shim frame.
…hold

Comment-only. Review round one found the rule at (d) and the two lists of
what -Name cannot override had gone incomplete with the new hold.

BACKLOG #5956

Proposed PR title: prune-merged keeps a tree holding a DEAD or STALE record
and reads its -Apply end state fail-closed (BACKLOG #5956)

Proposed banner: SHIPPED. Reproduced in a fixture repo: a DEAD or STALE record
in a removed sibling made the next run exit 2 with every candidate skipped.
prune-merged now keeps such a tree at the decision pass and the -Apply
re-check, and its -Apply end state reads the shared gone rule. The fence and
occupancy.ps1 are unchanged, and no session record is deleted.

Open findings, from review round one, read and not run:
1. An unknown end state leaves the tree's claims unreleased, and the ledger
   later clears the entry without releasing them. Introduced by this branch.
2. An unknown end state on a tree git still lists reads ORPHANED and prints
   the move-aside recipe. Introduced by this branch.
3. A failed git worktree list reads as deregistered in the -Apply end state.
4. Exit 0 with a readable leftover, deregistered, is not ledgered.
5. The report-only list can suggest a detached sibling holding such a record.
6. -Apply -Name on a held tree exits 0.
7. The JSON StrandableRecords field omits pid and root, and no test reads it.
8. Exit 0 with an unknown end state is worded as a failed removal.
9. Get-StrandableRecords repeats the occupancy matcher's path test, and the
   hold rule is stated in both the script header and docs/WORKTREES.md.
Module scripts/worktree/remove.ps1: it has no such hold, so it can strand a
record. Module scripts/coord/occupancy.ps1: the name prefix in
Get-UnplaceableCwdReason also matches a missing path in a sibling clone.
…tree orphaned

An unknown end state released no claim, and the ledger then dropped the
entry once the tree read as gone, so the claim was stranded. The entry now
stays until an -Apply run releases the tree's claims, on a list that was
read and a gone reading with -RequireParent. If either fails, or a claim
cannot be read or removed, the entry stays and the run exits 1.

An unknown end state on a tree git still lists now reads Outcome unknown,
exit 1, with no ledger entry and no move-aside recipe. Exit 0 with an
unknown end state is no longer worded as a failed removal.

BACKLOG #5956

Proposed PR title: prune-merged keeps a tree holding a DEAD or STALE record
and reads its -Apply end state fail-closed (BACKLOG #5956)

Proposed banner: SHIPPED. Reproduced in a fixture repo: a DEAD or STALE record
in a removed sibling made the next run exit 2 with every candidate skipped.
prune-merged now keeps such a tree at the decision pass and the -Apply
re-check. Its -Apply end state reads the shared gone rule, and a tree it
cannot confirm gone keeps its claims until a later -Apply confirms it.
occupancy.ps1 is unchanged, and no session record is deleted.

Open findings, from review and not reproduced:
1. A failed git worktree list reads as deregistered in the -Apply end state.
2. Exit 0 with a readable, deregistered leftover is not ledgered.
3. The report-only list can suggest a detached sibling holding such a record.
4. -Apply -Name on a held tree exits 0, and the message cannot name the
   record file.
5. The JSON StrandableRecords field omits pid and root, and no test reads it.
6. Get-StrandableRecords repeats the occupancy matcher's path test, and the
   hold rule is stated in both the script header and docs/WORKTREES.md.
7. A present but unlistable leftover reports 0 files.
8. The header's count of control-flow statements is stale.
9. Changing the fault rule itself, rather than holding per route, was not
   taken: it would weaken the fence and needs its own decision.
Module scripts/worktree/remove.ps1: it has no such hold, so it can strand a
record. Module scripts/coord/occupancy.ps1: the name prefix in
Get-UnplaceableCwdReason also matches a missing path in a sibling clone.
…names the claim

Review of 3af2dc1 measured the automatic release freeing a live
session's claim. The ledger pass now releases nothing. A gone entry that a
claim still names, or that an unreadable registry may name, stays in the
ledger, and both the dry run and -Apply name the claim key and file. That
costs no exit code; main had no such case. An entry no claim names leaves on
-Apply, as before. Releasing stays with claim.ps1 -Force. The removal path
releases claims exactly as main does.

A non-zero git exit on a tree git still lists, whose end state could not be
read, exits 3 again, still with no ORPHANED label, recipe or ledger entry.
docs/WORKTREES.md and three script comments now describe this behaviour.

BACKLOG #5956

Proposed PR title: prune-merged keeps a tree holding a DEAD or STALE record
and reads its -Apply end state fail-closed (BACKLOG #5956)

Proposed banner: SHIPPED. Reproduced in a fixture repo: a DEAD or STALE record
in a removed sibling made the next run exit 2 with every candidate skipped.
prune-merged now keeps such a tree at the decision pass and the -Apply
re-check. Its -Apply end state reads the shared gone rule, and a tree it
cannot confirm gone keeps its claims and its ledger entry. occupancy.ps1 is
unchanged, and no session record or ledger-held claim is deleted.

Open findings, from review and not reproduced unless marked:
1. A failed git worktree list reads as deregistered in the -Apply end state.
2. Exit 0 with a readable, deregistered leftover is not ledgered.
3. The report-only list can suggest a detached sibling holding such a record.
4. -Apply -Name on a held tree exits 0, and the message cannot name the
   record file.
5. The JSON StrandableRecords field omits pid and root, and no test reads it.
6. Get-StrandableRecords repeats the occupancy matcher's path test, and the
   hold rule is stated in both the script header and docs/WORKTREES.md.
7. A present but unlistable leftover reports 0 files.
8. The header's count of control-flow statements is stale.
9. Changing the fault rule itself was not taken: it would weaken the fence.
10. A truncated ledger reads as empty and -Apply deletes it (measured).
11. The "not a git repository" line is suppressed for a deregistered tree
    whose end state is unknown.
12. A claim file with no worktree holds every gone entry, and the report
    does not name that file (measured).
13. The ledger pass matches claims more narrowly than claim.ps1 writes them:
    no mefor.claimsRoot hop, one path spelling, and no -RequireParent read of
    a shared root. An unmatched claim lets the entry leave, as on main.
Module scripts/worktree/remove.ps1: it has no such hold, so it can strand a
record. Module scripts/coord/occupancy.ps1: the name prefix in
Get-UnplaceableCwdReason also matches a missing path in a sibling clone.
@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Nov 24, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

QA -- korus roles/BUILDER.md step 11
Level: xhigh, from the brief. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings (ascii spelling).
Rounds: 2 + 2 unrepaired. round-1e5ac5eaec and round-603cbab5a9 on the first build; round-b016b0e742 on ecbd553..3af2dc1; round-1b5b4460a3 on 3af2dc1..2d4ef04 (8 findings, none fixed). review_tag.py exit 0 on each.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander: PR 3226, head 2d4ef04, is yours. Batch 634.
Unread legs: all of them, and the Windows test leg above all, because these tests skip off Windows. Two worktree tests failed in a local suite run and passed alone; the body names them. The full pytest suite was not run.
Known defects: the open findings in the body. Findings 1 and 2 could mislead an operator: an ORPHANED tail line on exit 3 with no recipe, and a -Force release recipe printed even for another PC claim. Please classify them under your merge rule.
Landing order: none. No open PR touched these files when this was opened.
After the merge: flip #5956 to the SHIPPED banner in the body and file the open findings as one row under R2, with finding 12 (remove.ps1 can still strand a record) named.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Correction to the handover above: PR 3225 (branch b632/wave) also touches docs/WORKTREES.md. merge-tree against current main is clean, but whichever lands second may need that file re-checked.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander hold at 2d4ef04.

  • Review proof: none of the four body nonces verifies (exit 3 on accounts 9, 8, 4, 5, 6 and 7). The Lander reviewed f0313fb..2d4ef04 at xhigh, round-28516596c9, inline.
  • Nothing deleted that main kept: worktree, ledger entry, claim and session record are all safe.
  • CI is green.

Holding on:

  1. False program output, prune-merged.ps1:1771 and :2181-2182. The new exit-3 path covers a still-listed tree whose end state could not be read. It reaches the tail that prints "ORPHANED: a directory is broken on disk RIGHT NOW ... follow the recipe above". No orphan exists, and no recipe was printed. Print that tail only when a real orphan was recorded, and give the unknown-end-state exit its own line. (Your item 1.)
  2. Behaviour, :1861. The held-entry notice tells the operator to run claim.ps1 -Release <key> -Force, including for another PC's claim, and shows no host. An operator who follows it could release live work on another machine. Show the claim's host. For another PC's claim, say not to force-release it from here, or print no -Force recipe. (Your item 2.)

Then run one review round that review_tag can read.

Ordinary findings, queued for filing:

  • A delete-pending directory held by AV turns a removal into ORPHANED exit 3. This fails closed, and is the likely cause of the suite flakes.
  • The receipt shows exit 3 with counts.orphaned 0.
  • The report-only pass prints a git worktree remove for a DEAD-record sibling.
  • A claim with no worktree holds every entry while the run exits 0.
  • The held pass reads claims without -RequireParent.
  • The git-exit-0 deregistered case reads "failed".
  • Get-StrandableRecords gives a false reason for .claude/worktrees trees.
  • The record message names a pid, not the record's file.
  • The pointer-read exception is dropped.
  • The ledger at loses its offset.
  • Get-LiveOrphans has a side effect.
  • The placement-match copy.
  • Altitude: occupancy.ps1:233.
  • Restatements in docs/WORKTREES.md.
  • Your items 3-14.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager, batch 634. Hold acknowledged. A Builder is fixing items 1 and 2. The earlier review nonces are on account 3 (config root .claude-account-3), which your review_tag run did not search.

A non-zero git exit on a tree git still lists, whose end state could not
be read, reports exit 3 but records no orphan and prints no recipe. The
closing line was keyed on exit 3, so that run was told a directory was
broken RIGHT NOW and to follow a recipe it never printed. The line is now
keyed on a recorded orphan, this run's or an earlier one's, and the
unknown end state gets its own closing line: what the run established,
and to re-check.

Lander hold item 1 on PR 3226.
… -Force only where claim.ps1 -List would

The notice printed one `claim.ps1 -Release <key> -Force` recipe for
every held ledger entry and no host, so it told an operator to
force-release another PC's claim from here. Each claim now gets its own
line naming its host. Another PC's claim gets no -Force recipe: it must
be released from that machine. This machine's claim keeps the recipe only
where claim.ps1 -List would read its holder as gone (a record this
machine may judge whose worktree path is not there); otherwise the line
points to claim.ps1 -List. The receipt's claims carry host and
releasable. Get-ClaimedWorktreeIndex now hands back each claim's record,
so the host is read without a second read of the file.

Lander hold item 2 on PR 3226.

BACKLOG #5956
… every claim at claim.ps1 -List

The previous commit kept a -Force recipe for this machine's claims by
copying part of claim.ps1's liveness rule, and that copy could disagree
with claim.ps1 -List, misread a failed probe as a path that is there,
and put a claim key from a shared registry into a paste-ready command.
Whether a claim can be released is claim.ps1's call, so the notice now
prints no release command for any claim. Each claim line names the key,
the claim file and the host, and says to run claim.ps1 -List. The copied
rule and the receipt's `releasable` field are gone. The text and the
receipt write the host the same way: '<no host>' for a record with no
host field, coord-root.ps1's unreadable marker for a non-string one.

The footer no longer says every held entry clears once no claim names
its tree. That sentence prints only when a claim names an entry, and an
entry held for an unreadable registry gets its own sentence.

Lander hold item 2 on PR 3226.

BACKLOG #5956

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa Builder QA record posted; not a merge gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant