Skip to content

fix(bin): recognize teardown work that landed under rewritten commits - #2586

Closed
IanQiu979 wants to merge 19 commits into
kunchenguid:mainfrom
IanQiu979:fm/fm-teardown-false-refusal-after-rebase
Closed

IanQiu979 wants to merge 19 commits into
kunchenguid:mainfrom
IanQiu979:fm/fm-teardown-false-refusal-after-rebase

Conversation

@IanQiu979

@IanQiu979 IanQiu979 commented Aug 18, 2026 •

Copy link
Copy Markdown

Intent

Fix a false refusal in bin/fm-teardown.sh's landed-work safety check: after a rebase, a branch whose content landed in full under rewritten commits could never be reclaimed, because the check only asked whether the branch's COMMITS were reachable from main. Rebase is the normal path here - bin/fm-merge-local.sh is fast-forward-only, so every second chain landing into a moved default branch must rebase first - so every multi-chain local-only graph ended with parent nodes that ordinary teardown could never reclaim, and the documented remedies (merge again, or --force) were both wrong for work that was not actually at risk.

The fix teaches the check about patch equivalence (the git cherry / patch-id relationship) so content that landed under a rewritten commit is recognised as landed, and removes the NEED for --force in this case rather than making --force easier to reach.

The safety property must NOT weaken. Teardown must still refuse genuinely unlanded work: it keeps refusing when a commit's patch is genuinely absent from main, keeps refusing on uncommitted changes regardless of patch state, and --force stays gated on explicit captain authority.

Decisions made deliberately during this work - please treat these as intended, not as mistakes:

  1. Terminator-aware comparison: a difference that is only a trailing newline must NEVER read as landed. If equivalence cannot be proven including line terminators, it is NOT landed - refuse.
  2. Location-preserving proof: reverse-apply must not match an identical block at the wrong location. If location cannot be established, treat as NOT landed and refuse.
  3. Net-zero sequences are allowed only AFTER per-patch proof that both inverse patches genuinely landed - never inferred from an empty net diff.
  4. Governing invariant: this change may turn a false "landed" into a refusal freely, but may only turn a refusal into an allow on positive proof.
  5. A patch that landed and was later reverted, partially reverted, relocated, replaced, or had one hunk or one added line undone must refuse. A landed patch that main later added unrelated lines on top of (a genuine superset) may allow.
  6. The reference scan is bounded to the paths the subject commits touch and batched through one git log -p | git patch-id pipeline, so cost does not grow with the default branch's history.

Acceptance criteria the change must meet, and the tests that must prove them genuinely distinguishing (no single implementation may pass all three by weakening the check):

  • a test proves teardown allows reclaim when a branch's patch landed under a rewritten commit;
  • a test proves teardown still REFUSES when the branch has a commit whose patch is not on main;
  • a test proves teardown still refuses on uncommitted changes even when all commits landed.

Verified locally before this run: the full tests/fm-teardown.test.sh suite passes (78 assertions, 0 failures); bin/fm-lint.sh is clean including pinned actionlint; bin/fm-doc-audience-check.sh passes. The distinguishing property was proven empirically - the allow test fails against the pre-fix guard from origin/main, and the refuse test fails against a deliberately weakened build whose patch check returns success unconditionally.

The final commit on this branch only clears three shellcheck findings that bin/fm-lint.sh (the repo's canonical lint gate, which CI invokes directly) reported in the new code: it asserts the numstat record carries its path field, gives two locals explicit empty-string initialisers, and checks a diff's exit status directly. All three are behavior-preserving or fail-closed.

This repo is firstmate's own shared tracked material and bin/fm-teardown.sh is a safety-critical guard, so .agents/skills/firstmate-coding-guidelines/SKILL.md applies: one sentence per line in tracked Markdown, plain dashes, shellcheck-clean bin scripts, tests colocated in tests/ as .test.sh, and tests must exercise behavior through an executable interface rather than asserting implementation source bytes.

What Changed

  • bin/fm-teardown.sh's landed-work check no longer relies on commit reachability alone: a new patches_are_in_ref arm accepts a branch when every commit the default branch cannot reach is present there as a patch (the git cherry / patch-id relationship), which is the only way work rewritten by a rebase can be recognized. The reference scan runs through one batched git log -p | git patch-id pipeline bounded to the paths the subject commits touch, and the old content_in_default was split into default_landing_ref plus a ref-parameterized content_in_ref.
  • The patch arm allows only on positive proof: subject_patches_are_in_reference requires every subject patch on the reference side and then a per-path changes_are_represented_in_tree proof that reverse-applies each path's binary/full-index patch against a scratch index of the reference tree, rejecting hunks that matched at an offset (relocation), trailing-newline-only differences, non-blob or mode changes, and any path the tree has since deleted lines from; a net-zero subject range is allowed only after both inverse patches are individually proven and the tip tree still matches over those paths. The merged-PR path keeps its patch-id-only contract, and validate_worktree_teardown_safety still refuses on uncommitted changes with a distinct message when the commits did land.
  • tests/fm-teardown.test.sh adds ~20 behavior-level cases through the teardown executable covering the rebase allow, an absent-patch refusal, dirty-worktree refusal after landing, plus reverted, partially reverted, relocated, replaced, superset, rename, net-zero and patch-history-failure variants; docs/gitlab-merge-watch.md updates its one-line description of teardown's fallback to name the default-branch checks.

Risk Assessment

⚠️ Medium: A 400-line rewrite of a safety-critical destructive-action guard is large in blast radius, but every new arm is fail-closed, the loosening is gated behind a per-commit patch-id match plus a location-preserving tree-representation proof, and 20 new behavior-level tests cover the three required distinguishing criteria plus revert/relocate/replace/newline/net-zero adversarial cases — so it is safe to merge with the informational notes as follow-ups.

Testing

Ran the subject's own suite (tests/fm-teardown.test.sh: 79 assertions, 0 failures) and then exercised bin/fm-teardown.sh directly in sandboxed repos to capture the operator-visible CLI output for each acceptance criterion: teardown now completes for a branch whose patch landed under a rewritten commit, still refuses with 'commits not yet on main' when a commit's patch is absent, and still refuses on uncommitted changes with copy that correctly credits the landed commits. Re-running the same rebase scenario against the pre-fix script from the base commit reproduces the original false REFUSED, so the fix is genuinely distinguishing rather than a weakened check; transcripts and suite results are saved as evidence and the worktree was left clean.

Evidence: Teardown CLI transcript after the fix (three acceptance scenarios)

Source: Teardown CLI transcript after the fix (three acceptance scenarios)

SCENARIO 1 (patch landed under a rewritten commit): * f58ae1b add feature | * f27dbd5 rebased: add feature.txt | * 1938898 unrelated main commit [branch commits are NOT reachable from main - rebase rewrote them] $ fm-teardown.sh task-x1 teardown task-x1 complete (window firstmate:fm-task-x1, worktree .../evid-landed-rebase/wt) [exit status: 0] SCENARIO 2 (a commit's patch never landed): REFUSED: local-only worktree .../evid-unlanded-commit/wt has work not yet merged into main and not on any remote. commits not yet on main: e1ea9f4 add extra a41a0b4 add feature [exit status: 1] SCENARIO 3 (all commits landed, worktree dirty): REFUSED: local-only worktree .../evid-dirty/wt has uncommitted changes; its commits already landed in main. uncommitted changes present Commit the uncommitted changes (or get the captain's explicit OK to discard, then --force). [exit status: 1]


=========================================================
$ SCENARIO 1: branch content landed under a rewritten (rebased) commit -> expect ALLOW
=========================================================

--- git state (branch fm/task-x1 vs local main) ---
    * f58ae1b add feature
    | * f27dbd5 rebased: add feature.txt
    | * 1938898 unrelated main commit
    |/  
    * b605b30 origin baseline
    [branch commits are NOT reachable from main - rebase rewrote them]

=========================================================
$ fm-teardown.sh task-x1
=========================================================
teardown task-x1 complete (window firstmate:fm-task-x1, worktree /var/folders/62/t6ydhgg91f3df0jm3k2r0fh80000gp/T//fm-teardown-tests.9rGZet/evid-landed-rebase/wt)
Backlog: task-x1 just finished. Run tasks-axi done task-x1 --note "local main", then run tasks-axi ready for dependency-cleared candidates, check date gates, and dispatch only work whose blockers are gone and date is due.

[exit status: 0]

=========================================================
$ SCENARIO 2: a second commit's patch never landed on main -> expect REFUSE
=========================================================

--- git state (branch fm/task-x1 vs local main) ---
    * e1ea9f4 add extra
    * a41a0b4 add feature
    | * d25998e rebased: add feature.txt
    | * dda8f3e unrelated main commit
    |/  
    * fb1bf79 origin baseline
    [branch commits are NOT reachable from main - rebase rewrote them]

=========================================================
$ fm-teardown.sh task-x1
=========================================================
REFUSED: local-only worktree /var/folders/62/t6ydhgg91f3df0jm3k2r0fh80000gp/T//fm-teardown-tests.9rGZet/evid-unlanded-commit/wt has work not yet merged into main and not on any remote.
commits not yet on main:
e1ea9f4 add extra
a41a0b4 add feature
Merge the branch into local main first (bin/fm-merge-local.sh after the captain approves), or push to a fork/remote, or get the captain's explicit OK to discard, then --force.

[exit status: 1]

=========================================================
$ SCENARIO 3: every commit landed but the worktree is dirty -> expect REFUSE
=========================================================

--- git state (branch fm/task-x1 vs local main) ---
    * a1dd054 rebased: add feature.txt
    * 61469b2 unrelated main commit
    | * 0386f38 add feature
    |/  
    * cec1200 origin baseline
    [branch commits are NOT reachable from main - rebase rewrote them]

=========================================================
$ fm-teardown.sh task-x1
=========================================================
REFUSED: local-only worktree /var/folders/62/t6ydhgg91f3df0jm3k2r0fh80000gp/T//fm-teardown-tests.9rGZet/evid-dirty/wt has uncommitted changes; its commits already landed in main.
uncommitted changes present
Commit the uncommitted changes (or get the captain's explicit OK to discard, then --force).

[exit status: 1]
Evidence: Same scenarios against the pre-fix script (base commit 038d0f7) — shows the false refusal

Source: Same scenarios against the pre-fix script (base commit 038d0f7) — shows the false refusal

SCENARIO 1 (patch landed under a rewritten commit), pre-fix build: $ fm-teardown.sh task-x1 REFUSED: local-only worktree .../evid-landed-rebase/wt has work not yet merged into main and not on any remote. commits not yet on main: 2899557 add feature Merge the branch into local main first (bin/fm-merge-local.sh after the captain approves), or push to a fork/remote, or get the captain's explicit OK to discard, then --force. [exit status: 1]


=========================================================
$ SCENARIO 1: branch content landed under a rewritten (rebased) commit -> expect ALLOW
=========================================================

--- git state (branch fm/task-x1 vs local main) ---
    * 2899557 add feature
    | * 766c71a rebased: add feature.txt
    | * 0ca7ebe unrelated main commit
    |/  
    * c0ef6a6 origin baseline
    [branch commits are NOT reachable from main - rebase rewrote them]

=========================================================
$ fm-teardown.sh task-x1
=========================================================
REFUSED: local-only worktree /var/folders/62/t6ydhgg91f3df0jm3k2r0fh80000gp/T//fm-teardown-tests.Zt78CS/evid-landed-rebase/wt has work not yet merged into main and not on any remote.
commits not yet on main:
2899557 add feature
Merge the branch into local main first (bin/fm-merge-local.sh after the captain approves), or push to a fork/remote, or get the captain's explicit OK to discard, then --force.

[exit status: 1]

=========================================================
$ SCENARIO 2: a second commit's patch never landed on main -> expect REFUSE
=========================================================

--- git state (branch fm/task-x1 vs local main) ---
    * 487782c add extra
    * 79fcbee add feature
    | * 0dd0879 rebased: add feature.txt
    | * abc57b1 unrelated main commit
    |/  
    * 43f6f9f origin baseline
    [branch commits are NOT reachable from main - rebase rewrote them]

=========================================================
$ fm-teardown.sh task-x1
=========================================================
REFUSED: local-only worktree /var/folders/62/t6ydhgg91f3df0jm3k2r0fh80000gp/T//fm-teardown-tests.Zt78CS/evid-unlanded-commit/wt has work not yet merged into main and not on any remote.
commits not yet on main:
487782c add extra
79fcbee add feature
Merge the branch into local main first (bin/fm-merge-local.sh after the captain approves), or push to a fork/remote, or get the captain's explicit OK to discard, then --force.

[exit status: 1]

=========================================================
$ SCENARIO 3: every commit landed but the worktree is dirty -> expect REFUSE
=========================================================

--- git state (branch fm/task-x1 vs local main) ---
    * 9d48280 add feature
    | * ab98af9 rebased: add feature.txt
    | * f847c56 unrelated main commit
    |/  
    * 50d2f87 origin baseline
    [branch commits are NOT reachable from main - rebase rewrote them]

=========================================================
$ fm-teardown.sh task-x1
=========================================================
REFUSED: local-only worktree /var/folders/62/t6ydhgg91f3df0jm3k2r0fh80000gp/T//fm-teardown-tests.Zt78CS/evid-dirty/wt has work not yet merged into main and not on any remote.
uncommitted changes present
commits not yet on main:
9d48280 add feature
Merge the branch into local main first (bin/fm-merge-local.sh after the captain approves), or push to a fork/remote, or get the captain's explicit OK to discard, then --force.

[exit status: 1]
Evidence: fm-teardown suite results

Source: fm-teardown suite results

ok - local-only worktree whose patch landed under a rewritten commit is torn down ok - local-only worktree with a commit whose patch is absent from main is refused ok - worktree with uncommitted changes is refused even when every commit's patch landed ok - local-only worktree whose landed trailing newline was removed is refused ok - local-only worktree whose landed change moved to an identical block is refused ok - local-only worktree whose rewritten inverse patches net to zero is torn down ... 79 assertions, 0 failures (bash tests/fm-teardown.test.sh, exit 0)

ok - local-only worktree with HEAD on a fork remote is torn down (fix holds)
ok - teardown prompts tasks-axi backlog refresh when compatible
ok - teardown honors config/backlog-backend=manual even when tasks-axi is compatible
ok - local-only worktree with truly unpushed work is refused (safety preserved)
ok - local-only worktree with work merged into local main is torn down (no regression)
ok - local-only worktree whose patch landed under a rewritten commit is torn down
ok - local-only worktree with a commit whose patch is absent from main is refused
ok - local-only worktree whose landed patch was reverted on main is refused
ok - local-only worktree whose patch was reverted with other work is refused
ok - local-only worktree whose landed patch sequence was jointly reverted is refused
ok - local-only worktree whose multi-file patch was partially reverted is refused
ok - local-only worktree whose reverted patch was re-landed is torn down
ok - local-only worktree whose landed change moved to an identical block is refused
ok - local-only worktree whose rewritten inverse patches net to zero is torn down
ok - local-only net-zero worktree whose inverse was later reverted is refused
ok - local-only worktree whose same-file patch was partially reverted is refused
ok - local-only worktree whose added line was reverted is refused
ok - local-only worktree whose added line was replaced is refused
ok - local-only worktree whose added file was fully replaced is refused
ok - local-only worktree whose landed file gained unrelated content is torn down
ok - local-only worktree whose landed trailing newline was removed is refused
ok - worktree with uncommitted changes is refused even when every commit's patch landed
ok - no-mistakes worktree whose landed content was fully replaced is refused
ok - local-only worktree whose rename landed under a rewritten commit is torn down
ok - partial patch-history output cannot authorize teardown
ok - no-mistakes worktree with HEAD on origin is torn down (no regression)
ok - no-mistakes worktree with genuinely unlanded work is refused (safety preserved)
ok - local-only worktree with unpushed work is torn down under --force (escape hatch)
ok - teardown completes when an exact busy-state sidecar is already absent
ok - herdr teardown removes pane-owned escalation dedupe state
ok - herdr flat teardown refuses before returning the isolated copy under lock contention and the retry completes cleanly
ok - herdr flat teardown never erases records when pane presence is unparseable
ok - herdr flat teardown preflight refuses before every destructive change
ok - forced secondmate teardown preflights every Herdr child before cleanup mutation
ok - forced secondmate teardown holds every descendant lifecycle and metadata lock
ok - forced secondmate teardown retains Herdr child identity until exact pane disappearance
ok - forced teardown retains a nested secondmate home and its grandchild's Herdr identity when the grandchild close is unconfirmed
ok - herdr projection teardown retires its journal only after confirming the exact recorded pane is gone
ok - herdr projection teardown retains every record when post-close presence is unknown
ok - herdr projection teardown surfaces failed focus restoration without turning confirmed cleanup into a hard failure
ok - squash-merged + deleted-branch worktree (PR merged) is torn down (the fix)
ok - squash-merged PR accepts a local HEAD that is an ancestor of the final PR head
ok - teardown discovers a merged PR by branch name and tears down when no pr= was ever recorded
ok - squash-merged PR accepts replayed unpushed local patches contained in the PR head
ok - merged-PR path stays patch-id containment when the PR head evolved after the local commit
ok - merged PR does not allow teardown after a later local commit
ok - fm-pr-check does not refresh PR head after HEAD moves
ok - fm-pr-check records the remote PR head when the local worktree lags
ok - worktree whose content already landed in the default branch is torn down (content fallback)
ok - content fallback refreshes origin default before comparing trees
ok - dirty worktree is refused even when its committed work has landed (dirty always wins)
ok - gh lookup error with content not in default refuses (fail-safe)
ok - provably-stale worktree index.lock (old, no live holder) is cleared and teardown succeeds
ok - live-held worktree index.lock is never removed and teardown refuses
ok - lsof errors leave worktree index.lock in place and refuse teardown
ok - stale lock cleanup rechecks and refuses dirty worktree before return
ok - normal repo index.lock is resolved from the worktree and cleared when stale
ok - lock mtime read failures leave worktree index.lock in place and refuse teardown
ok - transient index.lock cleared after first failed return is retried successfully without force-remove
ok - persistent index.lock exhausts retries and refuses without force-removing the lock
ok - empty retry wait overrides use the default without aborting teardown
ok - fractional legacy retry wait remains supported without arithmetic
ok - a task's own parked no-mistakes run is aborted, not orphaned, before the worker is removed
ok - teardown refuses before reap or removal when a task-owned run remains parked
ok - a different run cannot confirm the targeted abort
ok - empty post-abort status is not accepted as confirmation
ok - the CLI's exact run-not-found signal confirms completion
ok - a parked run on another branch is never aborted by this task's teardown (ownership is precise)
ok - a task-owned autonomous running step is left alone rather than aborted
ok - a leaked descendant process rooted under the task's worktree is reaped by teardown, not left surviving
ok - a leaked descendant process rooted under the task's per-task tasktmp is reaped by teardown too
ok - missing lsof falls back to reaping the tmux pane process group
ok - an erroring lsof scan refuses teardown and preserves the task
ok - a reused pid with a different start time is never force-killed
ok - an exec change preserves birth identity and the process is reaped
ok - a process spawned during grace is reaped on a later pass
ok - persistent leaked processes refuse teardown after bounded retries
ok - a process exiting during identity lookup does not block teardown
ok - the run abort and the leaked-process reap both complete before the destructive worktree return

79 assertions, 0 failures (bash tests/fm-teardown.test.sh, exit 0)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 3 infos
  • ℹ️ bin/fm-teardown.sh:1150 - Location-preserving proof rejects any hunk that reverse-applies at a non-zero offset, so the "genuine superset" allowance of decision 5 only actually reaches files the branch ADDED (the pre_entry-empty fallback). Concrete state I verified in a scratch repo: branch changes line 20 of f.txt; main lands the rewritten commit and a later main commit prepends one line to f.txt. git apply --cached --check --reverse --verbose -p0 then prints "Hunk chore: initialize no-mistakes gate #1 succeeded at 18 (offset -1 lines).", the grep at line 1150 matches, and teardown refuses even though the work is fully present in main. This is fail-closed and permitted by governing invariant 4, so it is not a defect — but it is a broader residual false-refusal surface than the header comment implies, and it is reachable in exactly the multi-chain rebase scenario this change targets (chain A edits the same file above chain B's hunk). Worth a line in the patches_are_in_ref comment so a future reader does not read decision 5 as already covered for modified files.
  • ℹ️ bin/fm-teardown.sh:1424 - The script runs under set -eu. Three new sites capture a deliberately-failing command's status as a bare statement rather than in a condition: subject_patches_are_in_reference ...; status=$? (1423-1424), git apply --cached --check --reverse ...; status=$? (1146-1147), and git diff --quiet ...; status=$? (1323-1324). These are correct today only because every entry point is evaluated inside an if/&& condition (if [ -n "$unmerged" ] && patches_are_in_ref ... at 1728, if ! work_is_landed ... at 1756), which suppresses errexit for the whole call subtree. A future caller invoking patches_are_in_ref as a plain statement would make the script exit at the first non-zero git status instead of returning "not landed". Consequence is fail-closed (teardown aborts non-zero), so this is a maintenance hazard rather than a safety hole; an inline note or || status=$? idiom would make the dependency explicit.
  • ℹ️ bin/fm-teardown.sh:1199 - The numstat (pre->post) binary guard at 1199/1210 is unreachable as a distinct case. This arm is only entered after [ -z "$pre_entry" ] succeeded, so pre has no blob for the path and binary-ness of the pre->post diff is decided solely by post. Whenever pre->post is binary, post is binary, so the current_numstat (post->tree) binary guard at 1216 already fires. The check is harmless and fail-closed; it exists mainly to give the numstat local a use for SC2034. Dropping it (and the now-unused local) would remove a branch that no input can reach on its own.
✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-teardown.test.sh — full subject suite for the changed script (79 ok assertions, 0 failures, exit 0)
  • Manual CLI run of bin/fm-teardown.sh task-x1 on a sandbox where the branch's patch landed under a rewritten commit (allow, exit 0)
  • Manual CLI run of bin/fm-teardown.sh task-x1 with a second commit whose patch never reached main (refuse, exit 1, names the missing commits)
  • Manual CLI run of bin/fm-teardown.sh task-x1 with all commits landed but staged uncommitted changes (refuse, exit 1, 'uncommitted changes present')
  • Same three scenarios re-run against git show 038d0f7:bin/fm-teardown.sh (pre-fix) to prove the rebase case previously produced a false REFUSED
  • git status --porcelain — worktree left clean, scratch harness removed
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix: no lint changes needed; fm-lint.sh passes clean
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

@IanQiu979
IanQiu979 force-pushed the fm/fm-teardown-false-refusal-after-rebase branch from 2896c83 to 2c8dc6c Compare August 22, 2026 13:05
@greptile-apps

greptile-apps Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "no-mistakes(document): Document tree-rep..." | Re-trigger Greptile

Comment thread bin/fm-pr-merge.sh Resolved
Comment on lines 648 to 650
while kill -0 "$REPEAT_WORKER_PID" 2>/dev/null && [ "$SECONDS" -lt "$REPEAT_DEADLINE" ]; do
kill -TERM "$REPEAT_WORKER_PID" 2>/dev/null || true
sleep 0.05
done

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unpaced SIGTERM flood

The tight loop now sends SIGTERM continuously throughout worker shutdown. This recreates the documented Bash pending-trap overload that can interrupt or corrupt shutdown, leave temporary ownership state behind, and produce flaky failures unrelated to the worker behavior under test.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

CRITICAL: gh pr diff vs current main REMOVES the GitLab merge path from bin/fm-pr-merge.sh / bin/fm-pr-lib.sh (reverts merged #2779) and drops the -yR short-option-cluster repo-override guard. The teardown rewrite (patches_are_in_ref / patch-id landing proof in bin/fm-teardown.sh) is the intended #2586 fix, but it is not landable on top of that revert. Ahead 23 / behind 1.

VISION (per rule):

  • One captain, one interface — teardown intent aligns (false refusal of rewritten-but-landed work is noise). The GitLab merge deletion is not that intent.
  • Authority is explicit — teardown --force gating is untouched, which aligns. Silently dropping GitLab merge capability does not.
  • Scripts own the mechanics — patch-equivalence as a scripted landed-work proof aligns. Mixing it with an unrelated merge-path revert does not.
  • A restart is a non-event — n/a.
  • Delegation with a spine — "unlanded work is never torn down" is the teardown goal. Reverting GitLab merge is out of scope and risks the fleet's merge surface.
  • The fleet outlives any vendor — regresses. GitLab merge watching/merging on arbitrary instances is deleted.
  • Scope — teardown rewrite is command-layer; deleting GitLab merge is not this task.

Class: corrective (teardown rewrite) but the GitLab merge revert is blocking and must not land.

Security: the -yR / bundled short-option cluster that used to reject --repo overrides is gone; extra merge args can bypass the canonical-repository guard. Combined with the GitLab merge deletion this is not a clean teardown-only diff.

Overlap / do not land together: bin/fm-teardown.sh and tests/fm-teardown.test.sh overlap teardown/spawn holds #2637 / #2692 / #2768 (and #2770 also edits teardown). Sequence separately even after the GitLab path is restored.

CI: no structured no-mistakes-pipeline-attestation:v1 matching THIS HEAD 2c8dc6cfddc3c298f345701b0e49d743730b551d. Require no-mistakes FAILED (run 32574776387). CI 32574776189 in progress after this-pass workflow approval; an Aug 18 CI success is a different HEAD and is not this gate. Greptile is not a merge gate.

Ahead 23, behind 1, mergeable, mergeStateStatus UNSTABLE.

Not merge-eligible. Waiting on the author to restore the GitLab merge path and keep the teardown rewrite on top of current main — not waiting on the captain.

fm-teardown.sh proved landed work by asking whether the branch's own
commits are reachable from the default branch. A rebase gives every
commit a new object id, so once landing rewrote them that question can
never be answered yes again, and teardown refused work that was fully in
main. Because bin/fm-merge-local.sh is fast-forward-only, rebasing onto a
moved default branch is the normal way a local-only chain lands, so every
multi-chain graph left earlier nodes permanently unreclaimable. The
documented remedies were all wrong for that state: merging again is
redundant, and --force would need captain authority to discard work that
was never at risk.

Add patch equivalence - the relationship `git cherry` reports - as an
additional landed-work proof, in the local-only merged check and in
work_is_landed alike. It is deliberately strict so it can only turn a
refusal into an allow on proof: every commit the ref cannot reach must
match a patch id the ref does contribute, an unreadable or empty patch
(an empty commit, or a merge commit whose conflict resolution `git show`
does not emit) never counts as landed, and a ref contributing no patches
at all stays inconclusive. The uncommitted-changes refusal and the
explicit-authority gate on --force are untouched.

Tests cover the three distinguishing cases: a branch whose patch landed
under a rewritten commit is reclaimable; a branch holding a commit whose
patch is absent from main still refuses; and a worktree with uncommitted
changes still refuses even when every commit's patch landed. Mutation
runs confirm each case fails on its own weakening - relaxing the match
from every commit to any commit fails the second, and dropping the
uncommitted check fails the third. A fourth case covers the same rebase
fix on the PR path, where main edited the file after the patch landed so
the whole-tree content check cannot conclude anything.
bin/fm-lint.sh is the repo's canonical lint gate and CI invokes it directly,
so the branch has to leave it clean.

- Assert the numstat record carries its path field instead of parsing a
  partial line, which also uses the field the reader was discarding (SC2034).
- Give the subject-range locals explicit empty-string initialisers (SC1007).
- Check the reference-tree diff's exit status directly (SC2181).

All three are behavior-preserving or fail-closed: the new path assertion can
only turn a proof into a refusal, never a refusal into an allow.
@IanQiu979
IanQiu979 force-pushed the fm/fm-teardown-false-refusal-after-rebase branch from 2c8dc6c to 948e094 Compare August 24, 2026 16:03
@IanQiu979 IanQiu979 changed the title fix(teardown): recognize work that landed under rewritten commits fix(bin): recognize teardown work that landed under rewritten commits Aug 24, 2026
@IanQiu979

Copy link
Copy Markdown
Author

Closing: this PR was opened against upstream by mistake. The captain's firstmate work belongs on his own fork IanQiu979/firstmate, where he has push rights and can merge. Reopening there with the same teardown fix. Apologies for the noise, and thank you for the review - the GitLab merge path and the -yR guard concerns are noted and will be handled on the fork rather than by landing a mixed diff here.

@IanQiu979 IanQiu979 closed this Aug 24, 2026
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.

2 participants