Skip to content

fix: verify task branch cleanup before completing teardown - #7929

Open
WTF-Am-ID wants to merge 20 commits into
kunchenguid:mainfrom
WTF-Am-ID:fm/up-fm-4374
Open

WTF-Am-ID wants to merge 20 commits into
kunchenguid:mainfrom
WTF-Am-ID:fm/up-fm-4374

Conversation

@WTF-Am-ID

@WTF-Am-ID WTF-Am-ID commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • Updated fm-teardown.sh to check recorded task-branch work independently of HEAD and verify local branch removal across ordinary and Orca cleanup, with explicit retained-ref reporting when the task repository is unavailable.
  • Preserved branch identity and task records for retries, blocked completion replay while branch cleanup is unresolved, and added generation-safe recovery for manual and no-backlog homes.
  • Added regression coverage for cleanup failures, interrupted completion, reassigned worktrees, and task ID reuse, and updated recovery documentation and diagnostics.

Risk Assessment

⚠️ Medium: The change matches issue 4374. Swallowed detach and delete failures are replaced by a postcondition that must prove the ref absent or name the retained ref. Generation-bound retry identity and the branch_cleanup_pending replay barrier are correct as traced, and staging and recovery refs are never touched. Risk is medium, not low, because the diff reworks a large, lifecycle-critical part of teardown, the marker format and bootstrap recovery in exempt homes. Three earlier concerns (duplicate conclude/reap, a stuck teardown when a ref is unprovable, the records-only recovery subsystem) were ruled no-fix and are not raised again. This review is static and did not run the closure test.

Testing

Inspected the candidate, testing rules, CI-box procedure, and seven closure scenarios. No functional or baseline tests ran, and no product artifacts were produced. Earlier CI-box results are supplied historical evidence, not live execution in this run. No files were changed or background jobs started.

  • Live validation: ⚠️ inconclusive - 0 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Ordinary and fake-Orca cleanup remove the recorded task branch before reporting completion ⏸️ untested no CI-box-only testing requires remote fixture writes, which this phase's workspace boundary prohibits. Local disposable fixtures cannot satisfy that restriction. An authorized outer CI-box execution can…
Already-detached cleanup removes the branch identified by task metadata ⏸️ untested no The permitted CI-box route requires prohibited remote fixture writes. Local execution would violate the CI-box-only testing requirement. Needs authorized outer CI-box execution.
Failed detach names the retained ref and preserves retry records without reporting completion ⏸️ untested no Remote fixture creation is outside this phase's workspace authority, and local functional testing is excluded by the CI-box requirement. Needs authorized outer CI-box execution.
Failed or ineffective deletion refuses completion even with force and preserves retry records ⏸️ untested no The CI-box runner needs remote fixture writes that this phase cannot perform. A local substitute would violate the required testing location. Needs authorized outer CI-box execution.
Unavailable task copies finish only with a proven named retained ref ⏸️ untested no CI-box fixture provisioning is prohibited by the workspace boundary. Local fixtures cannot meet the CI-box-only requirement. Needs authorized outer CI-box execution.
Interrupted cleanup retries the same task identity and startup preserves unresolved branch records ⏸️ untested no Driving cleanup and startup requires disposable records on the CI box, outside this phase's write authority. Needs authorized outer CI-box execution.
Cleanup protects unlanded recorded-branch work and preserves staging and recovery refs ⏸️ untested no The required CI-box execution needs remote scratch repositories that this phase cannot create. Local execution cannot satisfy the location requirement. Needs authorized outer CI-box execution.
  • Outcome: ⚠️ 1 warning across 1 run (1m19s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (0 of 7 scenarios were driven live against the product); untested: Ordinary and fake-Orca cleanup remove the recorded task branch before reporting completion, Already-detached cleanup removes the branch identified by task metadata, Failed detach names the retained ref and preserves retry records without reporting completion, Failed or ineffective deletion refuses completion even with force and preserves retry records, Unavailable task copies finish only with a proven named retained ref, Interrupted cleanup retries the same task identity and startup preserves unresolved branch records, Cleanup protects unlanded recorded-branch work and preserves staging and recovery refs
  • Live validation: ⚠️ inconclusive - 0 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Ordinary and fake-Orca cleanup remove the recorded task branch before reporting completion ⏸️ untested no CI-box-only testing requires remote fixture writes, which this phase's workspace boundary prohibits. Local disposable fixtures cannot satisfy that restriction. An authorized outer CI-box execution can…
Already-detached cleanup removes the branch identified by task metadata ⏸️ untested no The permitted CI-box route requires prohibited remote fixture writes. Local execution would violate the CI-box-only testing requirement. Needs authorized outer CI-box execution.
Failed detach names the retained ref and preserves retry records without reporting completion ⏸️ untested no Remote fixture creation is outside this phase's workspace authority, and local functional testing is excluded by the CI-box requirement. Needs authorized outer CI-box execution.
Failed or ineffective deletion refuses completion even with force and preserves retry records ⏸️ untested no The CI-box runner needs remote fixture writes that this phase cannot perform. A local substitute would violate the required testing location. Needs authorized outer CI-box execution.
Unavailable task copies finish only with a proven named retained ref ⏸️ untested no CI-box fixture provisioning is prohibited by the workspace boundary. Local fixtures cannot meet the CI-box-only requirement. Needs authorized outer CI-box execution.
Interrupted cleanup retries the same task identity and startup preserves unresolved branch records ⏸️ untested no Driving cleanup and startup requires disposable records on the CI box, outside this phase's write authority. Needs authorized outer CI-box execution.
Cleanup protects unlanded recorded-branch work and preserves staging and recovery refs ⏸️ untested no The required CI-box execution needs remote scratch repositories that this phase cannot create. Local execution cannot satisfy the location requirement. Needs authorized outer CI-box execution.
  • git rev-parse HEAD confirmed a6533fb682b2705ad2f6181af65c53be122aa716.
  • git diff --stat bf05a4fcd69b8bb27f261177eac4abb57f98aa1b a6533fb682b2705ad2f6181af65c53be122aa716 and targeted source/fixture inspection established scenario scope.
  • git diff 6bc0085065c722cebc4ff7d8fbd51bc2f4d16afa HEAD -- bin/fm-bootstrap.sh docs/captain-hold-lifecycle.md confirmed only comments and documentation differ from the cited behavior candidate.
  • bash bin/fm-test-run.sh --list tests/fm-teardown.test.sh tests/fm-backend-orca.test.sh tests/fm-pr-check-security.test.sh selected the three focused scripts without executing them.
  • git status --short confirmed no working-tree changes.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Issues

Closes #4374

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The documentation update appears safe to merge, with no new blocking issue found.

Reviews (8) · Last reviewed commit: "no-mistakes(document): Correct Gerrit br..." · Reviewed by Greptile

Comment thread bin/fm-teardown.sh Resolved
Comment thread bin/fm-teardown.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @WTF-Am-ID. #4374 is a real honesty gap. Teardown printing "complete" while the task branch survives is exactly what this should end, and the eight live scenarios cover it thoroughly.

What I checked (head 18e629eb, main b04154bd): the new teardown_task_branch saves the branch name and Git common dir to state/<id>.teardown-branch, bound to the meta hash and spawn_gen, before the destructive steps. On both the Orca and ordinary paths it deletes refs/heads/<branch> and proves it gone, or names the retained ref and keeps the task records, even under --force. A new --branch-cleanup-pending marker flag holds back startup replay until that's proven, and fm_backlog_teardown_branch_retire retires the identity by generation. No workflow, network or credential changes.

Before this can merge:

  1. Greptile's two P1s match my reading. (a) The saved meta_hash requires the whole task record to stay byte-identical, so an unrelated meta edit between attempts, like fm-control.sh exit dropping busy_gen, leaves every retry stuck. Matching the stable branch, Git and spawn_gen identity would avoid that. (b) On the manual-backlog and no-backlog paths, the meta is removed before the identity is retired, and no pending-close marker exists to replay it. An interruption there leaves a stale identity that blocks teardown of a later task reusing the ID.
  2. A new dead end under --force. When the task's copy is already gone (or the slot was reassigned) and meta still records branch=, capture returns "task repository identity is unavailable" and teardown exits 1, with or without --force. Main completes that cleanup today, and --force is what the captain reaches for when a discard is already authorized. With no path to finish, those records would be stranded. The same goes for the new "worktree is on " refusal. Please either give these cases a finish path that names the retained ref (which is what fm-teardown.sh --force reports complete while the task branch ref survives #4374's suggested shape asks for), or show how a captain gets out of them.
  3. CI: Behavior portable parallel 1 and serial 4 fail on run 40732633810. The logs aren't readable yet because the run is still in progress, so please check them once it finishes.

Overlap, FYI: this edits the same teardown block as your #7932 (post-reap re-check) and #7927 (Orca absent-worktree --force), and all three touch the pending backlog-close marker on refusal. #7932's refusal exit would now leave a teardown-branch identity behind, so whichever lands second needs that interaction covered by a test. It's also related to open ready-for-pr #2997 (fail closed when branch deletion fails). tests/fm-teardown.test.sh now conflicts with main after #7915 landed. That conflict is ours to fix, and you don't need to rebase.

contract-class: new-default. The honest "complete" line is a restore. But this also changes what --force does on the default path (it can now refuse where it used to complete), and it adds a new durable record and a replay barrier. So once it's otherwise ready, this goes to the captain rather than auto-merging. VISION: One captain aligns (no false "complete"). Authority: cannot tell yet, because of the --force dead end in point 2 (a captain-authorized discard should be able to finish). Scripts/agents aligns (exact ref proof). Restart aligns (durable identity), apart from the P1 replay gaps. Delegation aligns (strengthens a refusal path). Vendor aligns (plain git, Orca and tmux both covered). Scope aligns.

This is waiting on you for the points above, then a git push no-mistakes re-raise. Thanks again!

Comment thread bin/fm-teardown.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @WTF-Am-ID. ad5da37b takes care of both earlier P1s. The retry identity is now bound to branch, Git identity, paths and spawn_gen instead of the whole meta hash. The records-only path also writes a generation-bound completion marker before the meta goes away, so startup can retire the identity after an interruption.

Three things are left, so this is still waiting on you:

  1. --force dead ends (point 2 from my last note, still open). capture still refuses with "worktree is on " and "task repository identity is unavailable", with or without --force (bin/fm-teardown.sh ~3899/3912). Greptile's new P1 is a concrete case of the first one: a launch that fails before the agent creates the task branch now can't be torn down at all, because the endpoint never gets closed and the copy is never returned. Main finishes both cases today. Please check the recorded ref without needing it checked out. Where the ref can't be checked, a finish path that names the retained ref would cover both cases.
  2. CI: Behavior portable serial 10 fails on run 40787340372 with not ok - teardown could not finish a valid crash-left retirement receipt. That's teardown code this PR changes, so I'm not treating it as a flake.
  3. no-mistakes: the attestation still binds 18e629eb. Please re-raise with git push no-mistakes once the above is in.

Contract-class stays new-default: this changes what --force does on the default teardown path. Once it's green and the attestation binds the head, it goes to the captain for the merge call. It doesn't need anything more from you after that, and any conflict is ours to fix.

@WTF-Am-ID WTF-Am-ID changed the title fix: verify task branch removal before completing teardown fix: report retained task branches during teardown Oct 29, 2026
Comment thread bin/fm-teardown.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @WTF-Am-ID, this round closes a lot. I re-read head 0f9250b8 against main. 439c76c1/ad46f56c give a failed launch a finish path: branch lookup no longer needs the branch checked out, and a missing namespace finishes only after show-ref proves the retained ref exists. The PR-poll receipt fix makes serial 10 pass. CI run 40830136530 is green and the no-mistakes attestation binds this head.

One thing is left, and it's a real one, so this is still waiting on you:

  • Greptile's new P1 (bin/fm-teardown.sh ~3917): ordinary teardown can now delete unlanded work. On main, cleanup only deletes the branch the worktree is currently on, and that's the same HEAD validate_worktree_teardown_safety just checked. Capture now prefers the recorded branch= from meta. So if the worktree has been switched to a clean, landed branch while the recorded task branch still has unpushed commits, the safety check passes on HEAD and cleanup then branch -Ds the recorded branch without --force. Please run the same unlanded-work check on the recorded branch before deleting it. If it has work, retain it and name the ref. A branch that never existed should still finish. A regression test for "switched to a clean branch, recorded branch has unpushed commits" would cover it.

Once that's in, please re-raise with git push no-mistakes. Contract-class stays new-default (it changes what teardown and --force do on the default path). When it's green with the attestation on the head, it goes to the captain for the merge call, and any conflict is ours to fix.

@WTF-Am-ID WTF-Am-ID changed the title fix: report retained task branches during teardown fix: verify task branch cleanup before reporting teardown complete Oct 29, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @WTF-Am-ID. 9958e5ce closes the last real gap, and this is now with the captain.

What I re-read at head 9df287f2 against main. validate_worktree_teardown_safety now takes a work ref. After the HEAD check, if the meta-recorded branch= differs from the checked-out branch, it runs the same unlanded-work check again on refs/heads/<branch>, covering unpushed commits, merged-PR proof and content-in-default. If that branch has work that hasn't landed, teardown refuses before anything is closed or returned. A recorded branch that never existed (a failed launch) still finishes, and any other show-ref error refuses and keeps the records. --force keeps its explicit-discard meaning. The new test_recorded_task_branch_work_is_checked_before_cleanup covers the exact case Greptile raised, plus the pushed-work and --force controls. Greptile now says the earlier finding is fixed (5/5, no new findings).

VISION, per rule. One captain / peace of mind: aligns (teardown no longer reports "complete" while the task ref survives). Authority: aligns (--force stays the captain's explicit discard, and failed launches have an honest finish path). Scripts own mechanics: aligns (exact show-ref/ref checks, refusals with reasons). Restart: aligns (records are kept on unresolved branch cleanup so a later run can retry). Delegation with a spine: now aligns, because unlanded work on the recorded branch is never torn down. Vendor: aligns (Orca/backends unchanged in kind). Scope: aligns.

contract-class: new-default. This changes what ordinary teardown and --force do on the default path (branch verification before "complete", retained-ref finishes), so it's a captain decision and not an auto-merge.

Readiness. CI is 21/21 green on 9df287f2 (run 40862692720), the no-mistakes attestation binds this head, live validation is 11/11, and Greptile is 5/5. #7909 just landed and touched the same test file, so this branch now conflicts in tests/fm-teardown.test.sh. That conflict is ours to fix once the captain says merge, so you don't need to rebase. Overlap note: #7932 (late worker changes) and #7927 (absent Orca worktrees) also change teardown. They're separate fixes, and we'll sequence them.

This isn't waiting on you. It's with Kun now.

@WTF-Am-ID WTF-Am-ID changed the title fix: verify task branch cleanup before reporting teardown complete fix: report retained task branches during teardown Oct 29, 2026
@WTF-Am-ID WTF-Am-ID changed the title fix: report retained task branches during teardown fix: verify task branch cleanup before completing teardown Nov 6, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: noting the new tip 600f3582 (re-raise since the Oct 29 captain card). Greptile is still 5/5 with prior P1s resolved, and the branch merges cleanly. The attestation on this head shows rebase: skipped. This PR is still waiting on Kun, not on you — no action needed from your side while that captain card is open.

@WTF-Am-ID WTF-Am-ID changed the title fix: verify task branch cleanup before completing teardown fix: verify task branch cleanup before retiring task records Nov 7, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: tip moved again to a6533fb6 (from the Nov 6 note on 600f3582, and well past the Oct 29 captain card on 9df287f2). I re-read this head against main bf05a4fc.

Gates: coverage guard, repo invariants and the no-mistakes check pass. Greptile is 5/5 with all prior P1 threads resolved. It merges cleanly and closes #4374. The red Full suite row is only our unlabelled gate, not a failure in your code. Rockets: none.

Blocking: no-mistakes attestation has rebase: skipped on this head. The branch already contains main (MERGEABLE, no conflict), so this is not the conflict-only rebase-skip case. Per our no-skipped-steps rule I need one clean git push no-mistakes re-raise that completes every step, including rebase, and binds the new tip. Until then this cannot stay with the captain or take full-ci.

Contract-class remains new-default (ordinary teardown / --force change on the default path). Live validation on this raise is inconclusive 0/7 because of the CI-box fixture boundary — that is a note for the later re-flag, not today's ask.

Waiting on you for that clean re-raise. After it lands green with the attestation bound and no skips, this goes back to Kun for the merge-or-leave call (any conflict then is ours to fix).

@WTF-Am-ID WTF-Am-ID changed the title fix: verify task branch cleanup before retiring task records fix: verify task branch cleanup before completing teardown Nov 8, 2026
@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Nov 8, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @WTF-Am-ID. Tip moved to f31df9ab (from a6533fb6 on the last note). I re-read this head against main bf05a4fc.

Gates: the no-mistakes attestation now binds f31df9ab with every step completed and no skipped steps, including rebase — that clears the ask from the last pass. Coverage guard, repo invariants and the no-mistakes check pass. Greptile is 5/5 with all prior P1 threads resolved. It merges cleanly and closes #4374 (fm-teardown.sh --force reporting complete while the task branch survived: the tip verifies local branch removal or names the retained ref before completion). The red Full suite row is only our unlabelled gate, not a failure in your code. Live validation on this raise is inconclusive 0/7 because of the CI-box fixture boundary — a note for the later captain card, not something you need to redo. Rockets: none.

Contract-class remains new-default (ordinary teardown and --force change on the default path). Once Full is green this goes to Kun for the merge-or-leave call, not auto-merge. Any conflict then is ours to fix.

Nothing more is needed from you. The full suite is queued, and this waits on that run.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: the full suite is green on f31df9ab (labelled run 42443013741), and every other gate still holds. The no-mistakes attestation binds this head with no skipped steps. Coverage guard, repo invariants and the no-mistakes check pass. Greptile is 5/5 with no open threads. It merges cleanly with current main 5c935cfb and closes #4374. Rockets: none on this PR or #4374.

This is now with the captain for a merge-or-leave decision. It is not waiting on you, @WTF-Am-ID. Contract-class stays new-default (teardown and --force behave differently on the default path), so it doesn't auto-merge. If a conflict shows up before the decision, it's ours to fix on a merge word. Thank you for the clean re-raise.

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

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fm-teardown.sh --force reports complete while the task branch ref survives

2 participants