Repository navigation
feat(bin): gate PR readiness on independent different-family review - #1470
JaredHuynhning wants to merge 4 commits into
Conversation
fe55571 to
b378dc6
Compare
b378dc6 to
3e590c8
Compare
|
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#1470 at |
|
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. |
|
Observation, not a change request - noting this for the record since the PR is currently closed as stale (closed-stale-14d), so it is informational for anyone who picks it back up. In So any local process able to write to A direction that would close it without changing the interface: a per-round secret written into the reviewer's private data dir, interpolated into the submit command when the brief is built and required on submit - the same shape as the existing Happy to be wrong if there is an authentication step I did not read; recording it as an observation rather than filing it as an issue. |
Intent
Make independent verification a permanent structural part of Firstmate's delivery lifecycle so no finished open pull request can be presented as captain-ready until a cold reviewer from a model family different from the recorded builder has cleared the exact current head. Derive model families at runtime from recorded harness and model metadata; fail closed with the exact missing fact when the builder family or a verified different-family adapter cannot be established; give the reviewer only the original task acceptance criteria and exact diff; block only confirmed correctness, security, privacy, data-loss, and acceptance failures; allow one review plus one fix/re-review, with a second rejection opening the circuit; invalidate verdicts when the head moves; and make reviewer identity and finding the first captain-facing line. Scope the gate to finished, unmerged pull requests, keep forge access read-only, add no poller or wake-frequency increase, preserve all AGENTS.md section 7 safety boundaries through a concise named exception, and eliminate stale fixed-vendor reviewer guidance from private configuration outside the tracked pull request.
What Changed
bin/fm-independent-review.sh, a standing gate that reads a finished open pull request's exact forge head read-only, resolves the builder's model family from recorded harness/model metadata, dispatches one cold reviewer from a verified different-family adapter with only the original acceptance criteria and the exact diff, and records a verdict bound to that head. It allows one review plus one fix re-review, opens the circuit on a second rejection, invalidates verdicts when the head moves, and fails closed naming the missing fact when a family or adapter cannot be established.bin/fm-pr-check.shnow runs that gate before recording anything: it refuses to recordpr=/pr_head=or arm the merge poll without a clear verdict matching the current head, takespr_headfrom the reviewed-head binding instead of a separateghread, and buffers migration andfm-guardoutput so the reviewer identity and finding are the first captain-facing line.bin/fm-teardown.shretires the round files, verdict, and bounded bundles on completed parent-task teardown, andbin/fm-test-run.shmaps the new script and suite into thepr-forgefamily.docs/architecture.md,docs/scripts.md, and the GitLab merge-watch record. Addstests/fm-independent-review.test.sh(19 behaviours) and updates the pr-check, pr-merge, secondmate-safety, teardown, and test-run suites for the new boundary.Risk Assessment
Testing
Ran the repo runner on the new gate suite and every other changed suite, then drove the real fm-pr-check.sh and fm-independent-review.sh end to end against a real git remote with only the forge CLI and agent spawner stubbed, capturing a CLI transcript of the full reject to fix to clear lifecycle plus the circuit-breaker, head-invalidation, scope, and fail-closed paths; the gate behaves as intended and the only failures seen are a teardown case that fails identically at the base commit and a scheduler-timing assertion that passes in isolation.
Evidence: End-to-end CLI transcript of the independent-verification gate
Evidence: Reproducible harness that generates the transcript
Evidence: Captain-facing readiness output before and after independent clearance
Evidence: Second rejection opens the circuit, and fail-closed refusals name the missing fact
Evidence: Reviewer coldness: only criteria and exact diff, no builder reasoning, no prior verdict
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 7 issues found → auto-fixed (2) ✅
bin/fm-independent-review.sh:184- inspect_pr reads the GitHub PR state and head withgh-axi pr view <n> --repo <path> --json state,isDraft,headRefOid --template ..., but gh-axi'spr viewsupports only --comments/--reviews/--full. Verified live against the real binary: it exits 0, silently ignores --json/--template, and prints its own compact block (pull_request:/number: ...) that contains no head SHA and no tab separators.IFS=$'\t' readtherefore sets PR_STATE="pull_request:" and PR_HEAD="",fm_pr_head_valid ""fails, and inspect_pr refuses with 'could not establish the pull request exact head commit from the forge response'. Because fm-pr-check.sh now hard-gates on this, every GitHub PR readiness call is permanently blocked and no task can ever be reported captain-ready. The repo already uses plainghfor exactly this kind of field read (bin/fm-teardown.sh:456gh pr view "$target" --json state,headRefOid -q ..., bin/fm-pr-poll.sh:65); switch this call togh pr view "$FM_PR_NUMBER" --repo "$FM_PR_PATH" --json state,isDraft,headRefOid -q '.state + "\t" + (.isDraft|tostring) + "\t" + .headRefOid'(and adjust thecommand -vprobe togh). The new test suite mocksgh-axiwith the tab-separated shape, so it cannot catch this.bin/fm-independent-review.sh:654- A round that can never produce a verdict wedges readiness permanently with no in-band recovery. If fm-spawn fails (worktree pool exhaustion, backend error, quota), start_review appendsstatus=launch-failedto the round file but leaves it on disk; start_review refuses to recreate an existing round file (line 380), so the nextreadyat the same head hits the launch-failed branch and returns 1 forever, and if the head has since moved it takes theverdict_round != roundbranch and prints a false 'independent review pending for prior head ...' and returns 3 forever. The same wedge occurs when a reviewer launches but dies before submitting:readyreports pending indefinitely with no timeout or re-dispatch. Recovery requires an operator to hand-delete state/<id>.independent-review.round-N, which is documented nowhere. Make a round withstatus=launch-failed(no reviewer_task ever started) replaceable so the nextreadyre-dispatches, and give the dead-reviewer case either an explicit re-dispatch path or a refusal that names the exact file to retire.bin/fm-independent-review.sh:294- extract_task_criteria stops at the first line matching/^# /after# Task, so any line beginning with '# ' inside the task section truncates the criteria. Real briefs (bin/fm-brief.sh:254/363) place free-form firstmate-written task text and acceptance criteria between# Taskand# Setup, and that text routinely contains fenced shell snippets whose comments start with '# '. The truncation is silent: the bundle still passes the[ -s ]and size checks, so the cold reviewer judges the diff against a partial acceptance-criteria set and can returnclearfor a PR that fails the omitted criteria. This fails open on the one input the gate exists to check. Stop only on a known brief heading (^# (Setup|Rules|Definition of done|Herdr...)) or track fenced code blocks while scanning.bin/fm-independent-review.sh:749- submit_command authenticates the verdict only by task identity: the reviewer id must appear asreviewer_task=in a round file and its meta must recordkind=scoutwith a matching harness/model/family. Nothing binds the submission to the reviewer process itself, and the round file (mode 0600, same uid as every other firstmate agent) contains the reviewer_task id and head, so the builder task or any other local agent can runfm-independent-review.sh submit <parent> <reviewer-id> <head> clear '...'and record a clear verdict the cold reviewer never produced. That is the single fact the whole gate rests on. The repo already has a pattern for this (the per-task hook registry tokens,<id>.grok-turnend-token/<id>.kimi-turnend-token): write a per-round secret into the reviewer's private data dir, interpolate it into the reviewer brief's submit command, and require it on submit. Flagging rather than fixing because it changes the reviewer contract.bin/fm-pr-check.sh:104- fm-guard.sh moved from before the migration step to after the review gate, so its watcher-liveness and worktree-tangle banner no longer fires on the pending, rejected, or unresolvable paths - which are now the common outcomes of this command, and exactly the window in which the captain is waiting on a reviewer and a dead watcher matters most. The move was presumably needed to keep the verdict as the first stdout line (fm-guard writes 24 of its 26 messages to stdout). The same buffering pattern already applied to MIGRATION_OUTPUT solves both: run fm-guard before the review dispatch, capture its stdout, and print it after the verdict line.bin/fm-independent-review.sh:631- The clear-verdict branch duplicates a five-argument printf across an if/else whose only difference is whether the reviewer model is appended to the harness name. Compose the identity once (e.g.reviewer_id=$harnessthen[ "$model" = default ] || reviewer_id=$harness/$model) and emit a single printf, so the captain-facing line - the one output the intent makes load-bearing - has one definition instead of two that can drift.docs/scripts.md:88- AGENTS.md, docs/architecture.md, and docs/gitlab-merge-watch.md were updated for the gate, but the operator-current script index was not: bin/fm-independent-review.sh has no row, and the fm-pr-check.sh row still reads 'Record validated pr= and pr_head= values, then atomically arm a static merge poll' with no mention that it now refuses until a different-family clear verdict matches the exact head. Add the new row and amend the fm-pr-check.sh row.🔧 Fix: fix(bin): repair forge read and review round recovery
1 info still open:
bin/fm-independent-review.sh:663- The new retirement path treats a round as replaceable whenever its reviewer has no state/<reviewer>.meta and no .status, which includes a round still recorded as status=launching. fm-spawn writes the reviewer meta late (after worktree creation and backend readiness), so during that window a second overlappingready/fm-pr-check for the same task would see round_never_launched=true and run retire_round, whichrm -rfs the bundle and $DATA/<reviewer> - deleting brief.md out from under the fm-spawn call that is still launching (fm-spawn.sh:847 requires that file to exist). Preconditions are narrow: firstmate holds a per-home session lock and fm-pr-check is not called by the watcher, so single-captain operation never overlaps. Raising it rather than changing it because narrowing the check tostatus=launch-failedwould trade this away for a mid-spawn crash that is no longer auto-retired (it would still get the explicit 'retire <file>' message), and that is the author's call. No change needed if single-caller operation is the accepted assumption.🔧 Fix: refactor(bin): drop automatic stale review round retirement
✅ Re-checked - no issues remain.
/Users/jared/.claude/rules/how-i-work.md:73- Intent requires eliminating stale fixed-vendor reviewer guidance from private configuration outside the tracked pull request, but /Users/jared/.claude/rules/how-i-work.md:73 still mandates "one independent adversarial cross-check from Codex, never Gemini", which contradicts the new runtime-derived different-family rule. It sits outside the worktree, so I could not verify it was handled elsewhere and did not change it. The user needs to decide whether to update that private rule file.tests/fm-teardown.test.sh:1557- tests/fm-teardown.test.sh fails on the herdr-preflight-missing-adapter case (stderr lacks the "nothing was changed" refusal explanation). The identical failure reproduces on a clean extraction of base commit 1e24757, so it is pre-existing and not a regression from this change.tests/fm-test-run.test.sh- tests/fm-test-run.test.sh's "jobs=2 must refill the first completed slot" assertion failed once while running concurrently with the heavy pr-forge suites, and passed when the suite was re-run in isolation. It is a load-sensitive timing assertion, not a product failure.bin/fm-test-run.sh tests/fm-independent-review.test.sh(19 behaviours, all pass)bin/fm-test-run.sh tests/fm-pr-check-security.test.sh tests/fm-pr-merge.test.sh tests/fm-secondmate-safety.test.sh tests/fm-teardown.test.sh tests/fm-test-run.test.shbin/fm-test-run.sh tests/fm-test-run.test.shre-run in isolation (passes, confirming the earlier failure was load-sensitive)bin/fm-test-run.sh tests/fm-teardown.test.shrun against a clean extraction of base commit 1e24757 (same failure, confirming it is pre-existing)Manual end-to-end:bash independent-review-e2e.sh <repo-root> <workdir>driving realbin/fm-pr-check.sh task-a https://github.com/example/repo/pull/1through unreviewed dispatch, rejection, fix round, clear verdict, and post-clearance head moveManual:bin/fm-independent-review.sh submit task-a <reviewer-id> <head> reject ... --block correctness ...and the matchingclearsubmission from the reviewer bundle onlyManual: reviewer-bundle leakage check (grep -rl BUILDER_REASONING_SENTINELover the round-1 bundle and brief) and round-2 coldness check for the round-1 reviewer id and findingManual fail-closed checks: no different-family adapter available,harness=piwith no recorded model,harness=pi model=openrouter/anthropic/claude-sonnet-4.6, draft PR, merged PRManual read-only forge check: tally of everyghinvocation made by the gate across all scenarios.agents/skills/bootstrap-diagnostics/SKILL.md:42-.agents/skills/bootstrap-diagnostics/SKILL.md:42tells the operator to recover a quarantined PR poll by rearming "only through bin/fm-pr-check.sh with canonical inputs". That call now also runs the standing independent-review gate, so a rearm can be refused or can dispatch a new reviewer round when the forge head has moved since the recorded verdict. The sentence is not false, so I left it alone rather than copying the gate contract into a second agent-runtime surface; the gate's own refusal names the pending round and file. Worth a one-clause pointer to AGENTS.md section 7 if maintainers want the recovery path to state its new precondition.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.