Skip to content

fix(classify): refuse to close a task on an unbacked done: - #1802

Closed
Nikita-Guzenko wants to merge 6 commits into
kunchenguid:mainfrom
Nikita-Guzenko:fm/brief-done-means-pr
Closed

Nikita-Guzenko wants to merge 6 commits into
kunchenguid:mainfrom
Nikita-Guzenko:fm/brief-done-means-pr

Conversation

@Nikita-Guzenko

Copy link
Copy Markdown

Intent

Make it MECHANICALLY IMPOSSIBLE for a crewmate to close a task with a bare done: on a local commit that has no PR behind it. Seven sessions had already failed that way: hero-studio-restore, ci-merge-group-trigger and a third on 2026-07-31, then call-sales-script, tg-pricelist-capture and call-sales-script again on 2026-08-06, and finally the crew that implemented this very rule, which reported done: on its own unpushed commit hours after writing the refusal. Each time firstmate read the line, closed the task, and told the owner it had shipped; the costliest left branch fm/call-sales-prepayment never pushed to origin at all.

The user explicitly ruled out a wording fix. bin/fm-brief.sh already stated the correct order in prose before every one of those cases, and the no-mistakes brief hands the worker the SAME word done for its intermediate "implemented and committed" gate as for the final shipped one, so no reader can tell the two apart from the line alone. The seventh case proves memory cannot carry it: the rules author broke the rule the same day. The user named bin/fm-classify-lib.sh as the anchor point, required exactly one added condition rather than a rewrite of event classification, and set three acceptance conditions: (1) a fake done must not close the task, (2) the worker must learn immediately rather than be silently reclassified, (3) delivery modes must differ because local-only has no PR by design. They also forbade bloating AGENTS.md beyond a one-line pointer and forbade touching paused/blocked/needs-decision.

Design decisions I made and why, so they do not read as mistakes in the diff:

  • fm-classify-lib.sh owns ONE new condition (status_done_is_unbacked) plus the single refusal text, scoped by the tasks recorded delivery mode from state/.meta. no-mistakes and direct-PR require a full https://.../pull/ or /merge_requests/ URL; local-only, scout, secondmate and an absent/unrecognized mode are deliberately NOT constrained, because a false refusal on a scout report would be worse than the failure being closed.
  • Under mode=no-mistakes an unbacked done: is the crews legitimate INTERMEDIATE report, so the refusal text names a different next action there (instruct /no-mistakes) than under direct-PR (push and open the PR). Both are equally "not a completion".
  • Three consumers act on it, deliberately: fm-crew-state.sh reports blocked instead of done so everything derived from it (fleet snapshot, bearings) is covered; fm-wake-drain.sh prints a REJECTED DONE section on EVERY drain including the empty-queue path, carrying a ready-to-send steer so the worker is corrected within one wake and the rejection cannot be seen once and forgotten; scan_captain_relevant_statuses still surfaces the line but renders the refusal with it.
  • fm-teardown.sh also refuses, because teardown is what actually CLOSES a task: a branch merely pushed with no PR still passes the landed-work check. It refuses only when kind=ship AND the last line is an unbacked done AND no pr= was recorded by fm-pr-check.sh, so a genuinely shipped task is never refused; --force still bypasses like every other teardown gate.
  • Known and deliberate limit: the rule checks that a PR link is PRESENT, not that the PR is green. Greenness stays with fm-pr-check.sh and the no-mistakes CI step; verifying it in a pure classifier would mean a network call from a side-effect-free read.

Evidence: both new test files were confirmed RED against the pre-change scripts (an unbacked done: reported state: done) and are green now. bin/fm-lint.sh exits 0, --check-coverage is ok at 124 scripts, and the doc audience check passes. The full behavior suite was run twice; every remaining failure was compared against a clean clone of the pre-change tree and traced to this box (tasks-axi 0.2.3 vs the 0.2.4 floor, and a tangle banner that fires for any checkout on a feature branch), not to this change. Two regressions this change did cause were found that way and fixed in their own commits: the fm-bearings-snapshot fixture used an unbacked done: complete for a mode=no-mistakes child, and tests/fm-gotmp.test.sh did not link fm-classify-lib.sh into its fake teardown roots.

What Changed

  • Added a single status_done_is_unbacked condition (plus its refusal text) to bin/fm-classify-lib.sh, scoped by the task's recorded delivery mode from state/<id>.meta: no-mistakes and direct-PR require a real pull/<N> / merge_requests/<N> URL, while local-only, scout, secondmate and unknown modes are deliberately not constrained; the no-mistakes refusal names a different next action (/no-mistakes) than direct-PR (push and open the PR).
  • Wired three consumers to the new predicate: fm-crew-state.sh now reports blocked instead of state: done for an unbacked done (covering fleet snapshot and bearings), fm-wake-drain.sh emits a REJECTED DONE section with a ready-to-send steer on every drain including the empty-queue path, and fm-teardown.sh refuses to tear down a kind=ship task whose last line is an unbacked done with no recorded pr= (genuinely landed work still tears down; --force still bypasses).
  • Added tests/fm-done-requires-pr.test.sh and tests/fm-crew-state.test.sh, fixed two regressions this change caused (the fm-bearings-snapshot terminal-child fixture and linking fm-classify-lib.sh into fm-gotmp fake teardown roots), and updated AGENTS.md/docs with a one-line pointer.

Risk Assessment

✅ Low: Additive, well-bounded change adding a single classifier condition wired into four consumers exactly as the intent specifies, with verified sourcing, no reachable false-refusal path, stable dedup signatures, and RED→GREEN tests; no source-verifiable defects found.

Testing

Exercised the classifier, drain, crew-state reader and teardown paths that implement the rule. The decisive product-level evidence is a CLI transcript driving the real bin/fm-classify-lib.sh: a fake done: on the never-pushed fm/call-sales-prepayment branch is refused under mode=no-mistakes ("instruct the crew to run /no-mistakes") and mode=direct-PR ("steer the crew to push and open the PR"), and accepted only for local-only/scout/unrecorded modes and for a done: line carrying a real pull/1800 URL — satisfying all three author acceptance conditions (fake done doesn't close, worker learns immediately, delivery modes differ). The teardown test confirms the same refusal at the point that actually closes a task. No UI surface is involved (shell classifier/CLI change), so evidence is CLI transcripts and test output rather than screenshots. All targeted tests pass; the full suite was intentionally not run per the targeted-validation boundary.

Evidence: Classifier e2e: fake done: refused across delivery modes, PR-backed done: accepted

### Fake done: on unpushed local commit (target commit) mode=no-mistakes -> REJECTED: not a completion - ... instruct the crew to run /no-mistakes and expect "done: PR <url> checks green". mode=direct-PR -> REJECTED: not a completion - mode=direct-PR delivers through a PR and this line carries none ... steer the crew to push and open the PR. mode=local-only -> ACCEPTED (closes task) mode=scout -> ACCEPTED (closes task) mode= -> ACCEPTED (closes task) ### done: carrying the PR URL is NOT refused mode=no-mistakes -> ACCEPTED mode=direct-PR -> ACCEPTED

### Fake done: on unpushed local commit, across delivery modes (target commit)

mode=no-mistakes  -> REJECTED: not a completion - the crew reported its implementation, validation has shipped no PR yet. Do not close the task or report it to the captain; instruct the crew to run /no-mistakes and expect "done: PR <url> checks green".
mode=direct-PR    -> REJECTED: not a completion - mode=direct-PR delivers through a PR and this line carries none, so the branch may not even be pushed. Do not close the task; steer the crew to push and open the PR, then re-report "done: PR <url>".
mode=local-only   -> ACCEPTED (closes task)
mode=scout        -> ACCEPTED (closes task)
mode=             -> ACCEPTED (closes task)

### A genuinely shipped done: (carries the PR URL) is NOT refused
mode=no-mistakes  -> ACCEPTED (closes task)
mode=direct-PR    -> ACCEPTED (closes task)
- Evidence: fm-done-requires-pr test log (local file: /tmp/no-mistakes-evidence/01KZBAND6Y2PQBR0ZVBZF24XQK/fm-done-requires-pr.log)
Evidence: fm-teardown test log (ship-refuse path)
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 - 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 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 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

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-done-requires-pr.test.sh — all pass (predicate across all modes, drain REJECTED DONE section, re-surface-until-PR)
  • bash tests/fm-crew-state.test.sh — all pass (unbacked done reported as blocked, never state: done)
  • bash tests/fm-teardown.test.sh — all pass (ship task with unbacked done + no PR is refused; genuinely landed work still tears down)
  • bash tests/fm-bearings-snapshot.test.sh — all pass (terminal-child fixture regression fix)
  • bash tests/fm-gotmp.test.sh — all pass (classify lib linked into fake teardown roots)
  • Manual e2e probe sourcing bin/fm-classify-lib.sh: ran status_done_is_unbacked + fm_unbacked_done_reason over the full delivery-mode matrix for a fake unpushed done: and a PR-backed done:; confirmed baseline commit 2cf0283 has no predicate (a done: line was a clean completion)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Six sessions closed a task on a `done:` line that had no PR behind it:
hero-studio-restore, ci-merge-group-trigger and a third on 2026-07-31,
then call-sales-script, tg-pricelist-capture and call-sales-script again
on 2026-08-06. Each time firstmate read the line, closed the task, and
reported it to the captain. The costliest left branch
fm/call-sales-prepayment unpushed to origin - the change existed only in
the worker's worktree, and was found by a chance check.

Wording was never the missing piece. bin/fm-brief.sh already stated the
correct order before all six, and the no-mistakes brief hands the worker
the same word `done` for its INTERMEDIATE implementation-committed report
as for the final shipped one. From the line alone no reader can tell
"landed" from "committed locally", so a reminder cannot separate them and
six repetitions proved it.

So this adds a machine test instead. bin/fm-classify-lib.sh gains one
condition - a `done:` in a PR-delivering mode (state/<id>.meta mode=)
that carries no https://.../pull/<N> or .../merge_requests/<N> URL is not
a completion - plus the single refusal text every surface reuses:

  - bin/fm-crew-state.sh, the authoritative current-state reader, reports
    `blocked` with the refusal instead of `done`, so nothing derived from
    it (fleet snapshot, bearings, heartbeat review) can read completion.
  - bin/fm-wake-drain.sh prints a REJECTED DONE section on every drain,
    including the empty-queue path session start relies on, naming the
    task and carrying the ready-to-send steer - so the crew is corrected
    within one wake, and the rejection keeps re-surfacing until the PR
    actually exists rather than being seen once and forgotten.
  - scan_captain_relevant_statuses still SURFACES the line (it is work
    firstmate must act on) but renders it with the refusal attached, so
    no supervision surface presents it as a clean completion.

Modes differ by design and are respected: `local-only` lands on a branch
and has no PR, scouts deliver a report, and a charter has no delivery
contract - none is constrained. An unrecognized or missing mode is
deliberately left alone too, because a false refusal on a scout report
would be worse than the failure this closes.

Nothing else changed: no verb was added or removed, the absorb rules are
untouched, and paused/blocked/needs-decision behave exactly as before.

Tests: tests/fm-done-requires-pr.test.sh covers the predicate over every
mode and near-miss claim (bare "kunchenguid#123", branch name, "PR to follow"), the
captain-relevant rendering, and the drain section including that it
persists across drains and clears once the PR is reported.
tests/fm-crew-state.test.sh gains the reader half. Both were confirmed
RED against the pre-change scripts: an unbacked done: reported
`state: done`.
The supervision surfaces now refuse to render an unbacked `done:` as a
completion, but teardown is the step that actually closes the task, so
the same rule belongs at the irreversible end too. Without it a branch
that was merely pushed - no PR ever opened, nothing merged - still passes
the landed-work check (its commits are reachable from a remote) and the
task closes on a claim nobody can verify.

The gate refuses only when all three hold: the task is kind=ship, its
last status line is a `done:` in a PR-delivering mode with no PR URL, and
no `pr=` was recorded for it by bin/fm-pr-check.sh. A recorded PR is
equally good proof, so a genuinely shipped task is never refused, and
local-only, scouts, and secondmates are outside the rule by construction.
`--force` bypasses it exactly like the other teardown gates and still
requires explicit discard authority.

fm-classify-lib.sh remains the one owner of the test and the refusal
text; this adds no second definition.
The terminal-child-state case wrote `done: complete` for a fixture whose
meta says mode=no-mistakes. Under the new rule that line is not a
completion at all, so the child rendered `blocked` and the case stopped
exercising what it asserts. The fixture now reports a real shipped
completion with its PR URL.

Caught by comparing against a clean clone of the pre-change tree: this
file passed there and failed here, unlike the tasks-axi-version failures
on this box, which fail identically on both.
bin/fm-teardown.sh now sources bin/fm-classify-lib.sh for the
done-requires-a-PR gate. Both fake roots in this suite link every sibling
teardown needs, so they need this one too; without it teardown could not
source it and exited non-zero, which the fixtures read as a tasktmp
cleanup failure.
The crew that implemented this refusal finished the work and reported
`done:` on its own commit, with no PR and nothing pushed, on the same day
it had read all six earlier cases and written the refusal text itself.

That is the strongest evidence in the whole set, so it belongs next to the
rule rather than in a chat log. It rules out the two explanations that
would have kept this a wording problem: not knowing the rule, and not
having thought about it recently. Neither applied. The word `done`
attaches to whatever the worker just finished, and no amount of having
just written the opposite prevents it - which is exactly why the check has
to be mechanical and enforced at every surface that can close a task.
@kunchenguid

kunchenguid commented Aug 6, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#1802 at 70997431.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: closing this as stale. It has been waiting on a contributor update for 14+ days with no author push or comment. Reopen if you want to pick it back up.

@MinhNNguyen

Copy link
Copy Markdown

Verification (author run, before pipeline)

  • Backend lint:check: pass.
  • Unit: homematch-inventory + homematch-google-sheet specs 672/672 pass. Pre-existing date-dependent failure in inventory-ai-import.spec ("moves a past AI date to tomorrow…", hardcoded 2026-11-11) is unrelated.
  • E2E: full test:e2e run aborts (SIGABRT) with the known shared-DB cascade; suites alone: homematch-inventory-review 63/63 pass, homematch-google-sheet-sync and homematch-inventory-intake pass, homematch-public-listing 56/63 and bill 12/14 fail on unrelated public-API/date drift.
  • Handoff bullets → tests: 1n1b/1 ngủ 1 bếp, 2n1k2wc, Duplex 2N1K, studio gác xép/gác lửng, 1k1n all in inventory-room-type.spec.ts; DECISIONS.md parser bullet updated.

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.

3 participants