Repository navigation
feat(bin): add fm-gate-decide.sh to send parked gate decisions as one steer - #17
Merged
Merged
Conversation
… decisions Firstmate previews and sends its per-finding decision for a task's parked no-mistakes gate through one helper instead of a hand-written steer. The helper resolves the run and gate read-only, refuses foreign, duplicate, or missing finding ids and any --yes, annotates findings carried over from earlier rounds with their earlier decision, fix evidence, and the pipeline head, composes an argument-safe respond command plus the standing etiquette, sends it through fm-send with --resolve-key, and records each decision for later rounds. It never runs respond itself.
…en inbox delivery
…e-expansion loops in the gate-decide test. Syntax, lint, all 14 gate-decide tests, and both Linux failure suites passed locally. Linux failures involved unchanged code and did not reproduce. Bash 3.2 was unavailable locally; macOS verification remains for CI
…ments inside command substitutions in tests/fm-gate-decide.test.sh. All 14 behavior tests, targeted lint, and the local shell parse sweep passed. Bash 3.2 is unavailable locally; stock-macOS verification remains for CI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Decision helper - build inside fm.
Context: item 2 of the approved Firstmate improvements. When a no-mistakes gate parks on ask-user findings, firstmate decides and hand-writes a long steer to the worker naming the decision key, step, per-finding action, instructions and the exact
no-mistakes axi respondcommand, restating the same etiquette each time (never --yes, keep processing returns). Later review rounds often re-raise findings already fixed at the pipeline head (Quarterdeck QD-8/9/10/14 over four rounds), so firstmate re-verifies the head by hand, and hand-typed commands are sometimes malformed. Firstmate still makes every decision and the worker still drives the pipeline; the helper only removes the busywork. Approach approved: build in firstmate, propose upstream once proven.Designs and cautions (item 2 of the two cross-review reports, in substance): one firstmate script that resolves the task's run and parked gate read-only through the existing no-mistakes run attribution, takes firstmate's per-finding decision (fix, no change, approve with a reason) plus optional instructions, and sends the worker one composed steer through fm-send with --resolve-key for the gate's decision key, with the standing etiquette from one fixed template, never running respond itself. It must refuse an ID that is not in the current round, any --yes, and an incomplete or mismatched decision; render an exact, argument-safe preview; and verify the gate again immediately before sending. Carried-over IDs must not be dropped automatically, because a recurring ID may be a regression, an unfixed defect, or a new head: annotate them with the earlier decision and fix evidence, always paired with the pipeline's current head (not the worker checkout), so the fixer re-verifies at head before re-raising. The no-mistakes state database is no-mistakes' private schema, so read it only where the CLI lacks the data and fail loudly on schema drift. Retain the decision durably for later rounds. If decision text is actually lost inside no-mistakes, that fix belongs upstream in no-mistakes, not here.
What Changed
bin/fm-gate-decide.sh, which finds a task's parked no-mistakes run and gate without changing any state, using the existing run-attribution rules infm-nm-run-lib.shand a read-only query of the no-mistakes state database. It takes firstmate's decision for each finding (--fix,--no-change, or--approvewith a--reason, plus optional--instructions) and builds one steer with an exact, shell-quotedno-mistakes axi respond --step <step>command and the standard etiquette from a fixed template. It never runsresponditself.--confirmonly prints a preview. With--confirm <digest>, it checks the run, step, round, findings, and pipeline head again, then sends throughfm-send.sh --resolve-keyonly if the new steer still matches the preview's digest. It refuses, without sending or recording anything, when given--yes/-y, an ID that isn't in the current round, an ID decided twice, a finding left undecided,--approvewithout--reason,--instructionswithout any--fix, or a state-database schema it doesn't recognise. Findings carried over from earlier rounds are kept: each one is annotated with its earlier rounds, fix evidence and firstmate's earlier decision, paired with the current pipeline head. Each delivered decision is appended to<data>/<task>/gate-decisions.jsonl(fm-gate-decision.v1).tests/fm-gate-decide.test.sh. Updated the validation-supervision skill so it sends gate decisions through the helper instead of a hand-written steer, and listed the script indocs/scripts.md.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The round-6 fix snapshots the names of inbox records before calling fm-send. On a nonzero exit, it counts a record as proof of delivery only when the name is new. This is sound because fm_task_inbox_next_seq scans both the inbox and handled/, so a sequence number is never reused, and a record moved to handled/ keeps its name. The new regression test fails if the snapshot check is missing, and the earlier decided fixes are intact.
Testing
I drove the helper end to end against a real, private no-mistakes daemon whose review step parked on two real ask-user findings, using a marked lab FM_HOME and a private tmux socket. All 9 scenarios passed live: - The preview was read-only. - Every guarded refusal (--yes, unknown or duplicate id, incomplete decision, approve without a reason, digest mismatch) wrote nothing. - A refused fm-send and a repeat of a successful confirm both exited 4 and left no record. - A gate-agent caller on an unmarked home exited 3 and nothing in the home changed. - A real send closed the decision key and wrote the durable record. - The composed commands, run verbatim, were accepted by the real gate. - Round 2 annotated the carried-over finding with its round-1 decision and the pipeline head (962f2fb), not the worker checkout (b2029bc). - A stale preview confirmed after the run completed was refused. I also ran the branch's own test file, and all 14 cases passed. The lab was torn down afterwards: daemon stopped, tmux server killed, temp tree removed. This is a CLI with no visual surface, so the evidence is transcripts and the persisted record. Note:no-mistakes initon the throwaway repo printed that it installed its /no-mistakes skill at user level, which is a user-level write outside the worktree.Evidence: Preview against a real parked review gate
Source: Preview against a real parked review gate
Evidence: Refusals: --yes, foreign id, incomplete, approve without reason, duplicate, digest mismatch
Source: Refusals: --yes, foreign id, incomplete, approve without reason, duplicate, digest mismatch
Evidence: fm-send refusal records nothing (exit 4)
Source: fm-send refusal records nothing (exit 4)
Evidence: Confirmed send: inbox steer, key resolved, durable record
Source: Confirmed send: inbox steer, key resolved, durable record
Evidence: Repeated confirm after success writes no duplicate record
Source: Repeated confirm after success writes no duplicate record
Evidence: Gate agent refused on an unmarked home (exit 3)
Source: Gate agent refused on an unmarked home (exit 3)
Evidence: Worker runs the composed respond command verbatim; real gate accepts it
Source: Worker runs the composed respond command verbatim; real gate accepts it
Evidence: Round-2 carried-over annotation with earlier decision and pipeline head
Source: Round-2 carried-over annotation with earlier decision and pipeline head
Evidence: Round-2 approval sent and recorded
Source: Round-2 approval sent and recorded
Evidence: Worker round-2 respond completes the run
Source: Worker round-2 respond completes the run
Evidence: Stale preview refused after the run completed
Source: Stale preview refused after the run completed
Evidence: Persisted gate-decisions.jsonl after two rounds
Source: Persisted gate-decisions.jsonl after two rounds
QD-8 re-raise trace
Traced read-only from the no-mistakes state database and review log for Quarterdeck run
01M44G82VRN6WNZX0R3SAHANYE(review step).--bindalias duplicates--host,quarterdeck.py:2455).user_findings_jsoncarries QD-8'suser_instructions("drop --bind alias, keep repeatable --host ... Verify these are actually applied"), QD-8 is inselected_finding_ids, and the fixer session (started, then resumed in later rounds) applied it (fix_summary: changes applied, headcacdb132to86e6acfe).Conclusion: no-mistakes did not drop the decision text, which was preserved per finding in every round's respond payload and reached the fixer. The repeat came from the gate re-presenting carried findings, not from the reviewer re-raising them. This helper annotates such carried IDs with their earlier decision, fix evidence, and the pipeline head instead of dropping them. Nothing was filed upstream.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (2) ✅
bin/fm-gate-decide.sh:573- The round-5 decision to fix review-5 is still not in the code. The target commit a66ea74 ends with the round-4 change, and the durable record is still appended before fm-send runs (bin/fm-gate-decide.sh:573-576, then the send at :577). fm-send can still refuse after that append, so the refused decision stays on disk:Later rounds then read that record at bin/fm-gate-decide.sh:446-460 and show it as 'round N firstmate decision' at :483. A concrete case: a supervision branch previews while it has away authority, the authority is withdrawn, and it then runs --confirm. The record is appended, fm-send exits 1, and the next round's carried-over annotation reports a decision that was never authorized or delivered.
The user's instructions for review-5 are binding:
Other places that must change with it:
The round-3 fm_refuse_if_gate_agent call at :566 and the round-4 template wording at :531 are already applied and stay as they are.
🔧 Fix applied.
2 issues (1 error, 1 warning) still open:
bin/fm-gate-decide.sh:573- The round-5 decision to fix review-5 is still not in the code. The target commit a66ea74 ends with the round-4 change, and the durable record is still appended before fm-send runs (bin/fm-gate-decide.sh:573-576, then the send at :577). fm-send can still refuse after that append, so the refused decision stays on disk:Later rounds then read that record at bin/fm-gate-decide.sh:446-460 and show it as 'round N firstmate decision' at :483. A concrete case: a supervision branch previews while it has away authority, the authority is withdrawn, and it then runs --confirm. The record is appended, fm-send exits 1, and the next round's carried-over annotation reports a decision that was never authorized or delivered.
The user's instructions for review-5 are binding:
Other places that must change with it:
The round-3 fm_refuse_if_gate_agent call at :566 and the round-4 template wording at :531 are already applied and stay as they are.
bin/fm-gate-decide.sh:581- The round-5 fix for review-5 addedsteer_in_inbox, which treats any inbox record whose body matches as proof that this attempt enqueued the steer. It does not check whether that record existed before fm-send ran. A matching record left by an earlier successful send therefore turns a refusal into a recorded delivery.Concrete sequence:
--confirm <digest>. fm-send succeeds, the steer becomesstate/t1.inbox/001.msg, and the closed key is recorded asdelivered.--confirm, for example after losing the tool output. The digest and the snapshot verification at :576-578 both still pass.steer_in_inboxmatches the old 001.msg (or handled/001.msg). The helper appends a second record markeddelivered-unconfirmed(:600) and exits 5 with 'fm-send failed after the steer reached the worker inbox'.That breaks the decided invariant that every fm-send refusal leaves no record. Later rounds then show the duplicate as an extra 'round N firstmate decision (delivered-unconfirmed)' annotation (:463-467, :490-491). Any other refusal reached while an identical earlier steer is in the inbox follows the same path: gate agent, supervision actor or away check, or task lease.
Fix: before calling fm-send at :595, capture the set of
*.msgnames in$STATE/$TASK.inboxand itshandled/. On failure, compare only records that are new since that capture. A record the worker moves into handled/ keeps its name, so it still counts as new. This corrects the existing proof and adds no new state.The nonzero-exit branch at :596-605 is the only consumer of this proof. tests/fm-gate-decide.test.sh test_refused_send_records_nothing (:285) cannot catch the defect because its inbox starts empty. Add a case that repeats a successful confirm and asserts that no second record is written.
🔧 Fix applied.
✅ Re-checked - no issues remain.
no-mistakes initon a throwaway repo under a private NM_HOME. It reported installing the /no-mistakes agent skill at user level, which is a user-level write outside the worktree. All lab state (daemon, tmux lab socket, temp repo and homes) was torn down.Private no-mistakes v1.84.0 daemon (NM_HOME=<tmp>/nmhome no-mistakes daemon run, agent: claude) on a disposable repo/remote;no-mistakes axi run --skip document,lintparked the review step on 2 real ask-user findingsMarked lab FM_HOME viabin/fm-lab-home.sh create, task t1 meta/status with the open needs-decision key, worker window on the privatetmux -L fm-labsocketfm-gate-decide.sh t1 --fix forbidden-host-aliases --approve test-noop-config --reason ... --instructions ...(preview)Refusals:--yes, unknown id QD-99, incomplete decision, --approve without --reason, duplicate id, wrong --confirm digest--confirm <digest>with the open decision key removed (fm-send refusal) -> exit 4, no inbox, no record--confirm <digest>real send -> inbox 001.msg, key resolved in status, gate-decisions.jsonl record delivery=deliveredRepeated identical--confirmafter success -> exit 4, no second recordUnmarked disposable home with NO_MISTAKES_GATE=1 -> exit 3, home unchangedWorker step: ran the steer's respond command verbatim viashagainst the real gate (fix round, then approve round)Round-2 previews: annotation of the carried-over finding plus the earlier decision, using the pipeline head rather than the worker checkout; round-2 approve sent and recordedStale round-2 fix preview confirmed after the run completed -> refusedbash tests/fm-gate-decide.test.sh(the branch's own regression file; all 14 cases ok)✅ **Document** - passed
✅ No issues found.
🔧 **Lint** - 1 issue found → auto-fixed ✅
🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.