Repository navigation
Conversation
2896c83 to
2c8dc6c
Compare
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (2): Last reviewed commit: "no-mistakes(document): Document tree-rep..." | Re-trigger Greptile |
| 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 |
There was a problem hiding this comment.
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.
|
Speaking as Kun's firstmate: CRITICAL: VISION (per rule):
Class: corrective (teardown rewrite) but the GitLab merge revert is blocking and must not land. Security: the Overlap / do not land together: CI: no structured 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.
2c8dc6c to
948e094
Compare
|
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. |
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:
git log -p | git patch-idpipeline, 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):
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 newpatches_are_in_refarm accepts a branch when every commit the default branch cannot reach is present there as a patch (thegit cherry/ patch-id relationship), which is the only way work rewritten by a rebase can be recognized. The reference scan runs through one batchedgit log -p | git patch-idpipeline bounded to the paths the subject commits touch, and the oldcontent_in_defaultwas split intodefault_landing_refplus a ref-parameterizedcontent_in_ref.subject_patches_are_in_referencerequires every subject patch on the reference side and then a per-pathchanges_are_represented_in_treeproof 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, andvalidate_worktree_teardown_safetystill refuses on uncommitted changes with a distinct message when the commits did land.tests/fm-teardown.test.shadds ~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.mdupdates its one-line description of teardown's fallback to name the default-branch checks.Risk Assessment
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]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]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)Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
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 -p0then 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 underset -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), andgit diff --quiet ...; status=$?(1323-1324). These are correct today only because every entry point is evaluated inside anif/&&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 invokingpatches_are_in_refas 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- Thenumstat(pre->post) binary guard at 1199/1210 is unreachable as a distinct case. This arm is only entered after[ -z "$pre_entry" ]succeeded, soprehas no blob for the path and binary-ness of the pre->post diff is decided solely bypost. Whenever pre->post is binary,postis binary, so thecurrent_numstat(post->tree) binary guard at 1216 already fires. The check is harmless and fail-closed; it exists mainly to give thenumstatlocal 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 ofbin/fm-teardown.sh task-x1on a sandbox where the branch's patch landed under a rewritten commit (allow, exit 0)Manual CLI run ofbin/fm-teardown.sh task-x1with a second commit whose patch never reached main (refuse, exit 1, names the missing commits)Manual CLI run ofbin/fm-teardown.sh task-x1with all commits landed but staged uncommitted changes (refuse, exit 1, 'uncommitted changes present')Same three scenarios re-run againstgit show 038d0f7:bin/fm-teardown.sh(pre-fix) to prove the rebase case previously produced a false REFUSEDgit status --porcelain— worktree left clean, scratch harness removed✅ **Document** - passed
✅ No issues found.
🔧 **Lint** - 1 issue found → auto-fixed ✅
🔧 Fix: no lint changes needed; fm-lint.sh passes clean
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.