Add an independent reviewer gate (second agent over the diff) to close-report.sh #197

Closed
opened 2026-10-15 02:59:00 +00:00 by ben · 3 comments
Owner

Filed from the 2026-10-14 infrastructure review (Claude Code session on Ben's workstation; four parallel read-only review passes over the root harness). Line anchors are against main at 3e50274.

Symptom

No second agent reads any diff anywhere in the landing path (grep: the only headless claude -p is the rebase resolver in landing-lib.sh:442-447). The close-report gates check envelope self-consistency, not code quality or spec conformance; criteria is never read. Recent practice (Ars Technica study, Oct 2026; Encore/Warp/Firecrawl factory teardowns) converges on review being the bottleneck and adversarial reviewer agents + verification-as-code being where effort goes.

Proposed change

Slot: close-report.sh between cr_violations (line ~108) and the mode branch (line ~230), which already has the diff range (gate_head vs merge-base with origin/main), the envelope (criteria/tests), the issue body, and the PR.

  • New gate 6 cr_review: a headless claude on SWARM_REVIEW_MODEL (new swarm.config key, default = SWARM_HEAL_MODEL) with a fixed reviewer prompt skeleton (prompts/review-prompt.md), read-only tools, emitting JSON {verdict: approve|reject|unsure, findings:[{file,line,severity,why}]}.
  • reject → refusal with the findings as the violation list; unsure → park ready-for-human with findings attached; approve → proceed. Fail CLOSED on unparseable output (GOTCHAS 5 lesson).
  • Post the review JSON on the thread like the envelope. In pr mode the gate must run before landing_merge_if_green.
  • Record spend for the review call in swarm.db (swarmdb_spend_from_result).

Acceptance

  • tests/close-report-lib-test.sh scenarios: approve passes, reject refuses with findings verbatim, malformed output refuses, shimmed claude.
  • Reviewer prompt skeleton added to the vendor manifest and the render pipeline (#1).

out_of_scope

Replacing the human merge in pr mode.

_Filed from the 2026-10-14 infrastructure review (Claude Code session on Ben's workstation; four parallel read-only review passes over the root harness). Line anchors are against `main` at 3e50274._ ## Symptom No second agent reads any diff anywhere in the landing path (grep: the only headless `claude -p` is the rebase resolver in `landing-lib.sh:442-447`). The close-report gates check envelope self-consistency, not code quality or spec conformance; `criteria` is never read. Recent practice (Ars Technica study, Oct 2026; Encore/Warp/Firecrawl factory teardowns) converges on review being the bottleneck and adversarial reviewer agents + verification-as-code being where effort goes. ## Proposed change Slot: `close-report.sh` between `cr_violations` (line ~108) and the mode branch (line ~230), which already has the diff range (`gate_head` vs merge-base with origin/main), the envelope (criteria/tests), the issue body, and the PR. - New gate 6 `cr_review`: a headless claude on `SWARM_REVIEW_MODEL` (new `swarm.config` key, default = `SWARM_HEAL_MODEL`) with a fixed reviewer prompt skeleton (`prompts/review-prompt.md`), read-only tools, emitting JSON `{verdict: approve|reject|unsure, findings:[{file,line,severity,why}]}`. - `reject` → refusal with the findings as the violation list; `unsure` → park `ready-for-human` with findings attached; `approve` → proceed. Fail CLOSED on unparseable output (GOTCHAS 5 lesson). - Post the review JSON on the thread like the envelope. In pr mode the gate must run before `landing_merge_if_green`. - Record spend for the review call in swarm.db (`swarmdb_spend_from_result`). ## Acceptance - `tests/close-report-lib-test.sh` scenarios: approve passes, reject refuses with findings verbatim, malformed output refuses, shimmed `claude`. - Reviewer prompt skeleton added to the vendor manifest and the render pipeline (#1). ## out_of_scope Replacing the human merge in pr mode.

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

  • Ruling: ready-for-agent.
  • Why this is a two-way door: a new fail-closed gate only ever makes landing stricter; revertible by removing the gate and its config key. The reviewer prompt skeleton is high-blast-radius design work, but the issue supplies the contract (JSON verdict schema, read-only tools, slot, model key) and the acceptance fences the skeleton edit with the byte-identical cutover fixture.
  • What proves it: offline tests with a shimmed claude exercising approve / reject / unsure / malformed verdicts, plus the render staying byte-identical to the cutover fixture.

Agent Brief

Category: enhancement

Summary: Add a new fail-closed "independent reviewer" gate to the close-report flow: a second headless agent reads the run's diff and emits a structured verdict that can refuse the close, park it for a human, or let it proceed.

Current behavior: The close-report gates only check envelope self-consistency (claims vs. landed commits/checks); no agent ever reads the diff for code-quality or spec conformance, and the envelope's criteria field is never consulted. The sole headless review-capable call in the landing path is the rebase-conflict resolver.

Desired behavior: Between the deterministic violation check and the mode branch (where the diff range, envelope, issue body and PR are all already in scope), run a reviewer gate that invokes a headless agent on a dedicated review model with a fixed reviewer prompt skeleton and read-only tools. It emits JSON {verdict: approve|reject|unsure, findings:[{file,line,severity,why}]}. reject → refuse the close with the findings as the verbatim violation list; unsure → park ready-for-human with findings attached; approve → proceed. Unparseable/empty output fails CLOSED (refuse). In PR mode the gate must run before the merge step. The review JSON is posted on the thread like the envelope, and the review call's token spend is recorded.

Key interfaces:

  • A new review-model config key defaulting to the existing heal model.
  • A reviewer prompt skeleton added to the render pipeline and the vendor manifest alongside the existing five skeletons.
  • Reviewer output contract: JSON object with verdict in {approve,reject,unsure} and a findings array of {file,line,severity,why}.
  • Spend recording via the shared spend-from-result helper.

Acceptance criteria:

  • approve verdict lets the close proceed (shimmed claude).
  • reject verdict refuses the close with the findings reproduced verbatim in the violation list.
  • malformed/empty reviewer output refuses the close (fail-closed).
  • unsure verdict parks ready-for-human with findings attached.
  • In PR mode the gate runs before the merge step.
  • The review JSON is posted on the thread and the review call's spend is recorded.
  • The reviewer skeleton renders through the prompt pipeline and is in the vendor manifest; a render stays byte-identical to the cutover fixture (or the wording change is explained).

Out of scope: Replacing the human merge in PR mode; any widening of the agent's write tools during review (reviewer is read-only).

> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** - **Ruling:** `ready-for-agent`. - **Why this is a two-way door:** a new fail-closed gate only ever makes landing stricter; revertible by removing the gate and its config key. The reviewer prompt skeleton is high-blast-radius design work, but the issue supplies the contract (JSON verdict schema, read-only tools, slot, model key) and the acceptance fences the skeleton edit with the byte-identical cutover fixture. - **What proves it:** offline tests with a shimmed `claude` exercising approve / reject / unsure / malformed verdicts, plus the render staying byte-identical to the cutover fixture. ## Agent Brief **Category:** enhancement **Summary:** Add a new fail-closed "independent reviewer" gate to the close-report flow: a second headless agent reads the run's diff and emits a structured verdict that can refuse the close, park it for a human, or let it proceed. **Current behavior:** The close-report gates only check envelope self-consistency (claims vs. landed commits/checks); no agent ever reads the diff for code-quality or spec conformance, and the envelope's `criteria` field is never consulted. The sole headless review-capable call in the landing path is the rebase-conflict resolver. **Desired behavior:** Between the deterministic violation check and the mode branch (where the diff range, envelope, issue body and PR are all already in scope), run a reviewer gate that invokes a headless agent on a dedicated review model with a fixed reviewer prompt skeleton and read-only tools. It emits JSON `{verdict: approve|reject|unsure, findings:[{file,line,severity,why}]}`. `reject` → refuse the close with the findings as the verbatim violation list; `unsure` → park `ready-for-human` with findings attached; `approve` → proceed. Unparseable/empty output fails CLOSED (refuse). In PR mode the gate must run before the merge step. The review JSON is posted on the thread like the envelope, and the review call's token spend is recorded. **Key interfaces:** - A new review-model config key defaulting to the existing heal model. - A reviewer prompt skeleton added to the render pipeline and the vendor manifest alongside the existing five skeletons. - Reviewer output contract: JSON object with `verdict` in {approve,reject,unsure} and a `findings` array of {file,line,severity,why}. - Spend recording via the shared spend-from-result helper. **Acceptance criteria:** - [ ] approve verdict lets the close proceed (shimmed `claude`). - [ ] reject verdict refuses the close with the findings reproduced verbatim in the violation list. - [ ] malformed/empty reviewer output refuses the close (fail-closed). - [ ] unsure verdict parks `ready-for-human` with findings attached. - [ ] In PR mode the gate runs before the merge step. - [ ] The review JSON is posted on the thread and the review call's spend is recorded. - [ ] The reviewer skeleton renders through the prompt pipeline and is in the vendor manifest; a render stays byte-identical to the cutover fixture (or the wording change is explained). **Out of scope:** Replacing the human merge in PR mode; any widening of the agent's write tools during review (reviewer is read-only).

swarm-claim host=matou-dev-server-01 run=21817
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=21817 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #197 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 197,
  "status": "success",
  "commits": [
    "02489231b4c8e5531d03e215e02f78a7ea96fbcc"
  ],
  "changed_files": [
    "STATUS.md",
    "close-report-lib.sh",
    "close-report.sh",
    "docs/journal/2026-10-15-197.md",
    "model-lib.sh",
    "onboarding/onboard-lib.sh",
    "onboarding/tests/fixtures/idss-prompts/review-prompt.md",
    "onboarding/tests/onboard-lib-test.sh",
    "prompts/review-prompt.md",
    "rehearsal-report.sh",
    "swarm.config",
    "tests/close-report-lib-test.sh",
    "tests/close-report-test.sh",
    "tests/model-lib-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/close-report-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/close-report-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/model-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/onboard-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "approve verdict lets the close proceed (shimmed claude)": "tests/close-report-test.sh RV-A (approve→close_stuck) + tests/close-report-lib-test.sh RV1; close-report.sh cr_review case approve proceeds",
    "reject verdict refuses the close with the findings reproduced verbatim": "tests/close-report-test.sh RV-B (findings grepped verbatim in forgejo.log, outcome=refused) + close-report.sh folds cr_review_finding_lines into violations",
    "malformed/empty reviewer output refuses the close (fail-closed)": "tests/close-report-test.sh RV-C (malformed+empty exit 1) + close-report-lib.sh cr_review_parse normalises to malformed; close-report.sh malformed case sets gate_rc=1",
    "unsure verdict parks ready-for-human with findings attached": "tests/close-report-test.sh RV-D (ready-for-human label added, ready-for-agent+agent-working removed, outcome=parked, findings posted)",
    "In PR mode the gate runs before the merge step": "tests/close-report-test.sh PR-2d (reviewer reject in agent-after-green leaves the PR unmerged); gate slots before landing_merge_if_green and before #206's marker stamp",
    "The review JSON is posted on the thread and the review call's spend is recorded": "close-report.sh cr_post_review posts the verdict JSON (RV-A reviewed()); swarmdb_spend_from_result + marker asserted by RV-E",
    "The reviewer skeleton renders through the prompt pipeline and is in the vendor manifest; render stays byte-identical to the cutover fixture": "prompts/review-prompt.md (placeholder-free) rendered by onboard_render_prompts; covered by prompts/** in onboarding/vendor-manifest; onboarding/tests/onboard-lib-test.sh idss cutover at 6 skeletons byte-identical"
  },
  "summary": "Added an independent read-only reviewer gate to close-report.sh that reads the run's diff and can refuse, park ready-for-human, or approve a close.",
  "blockers": []
}
**close-report** for #197 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 197, "status": "success", "commits": [ "02489231b4c8e5531d03e215e02f78a7ea96fbcc" ], "changed_files": [ "STATUS.md", "close-report-lib.sh", "close-report.sh", "docs/journal/2026-10-15-197.md", "model-lib.sh", "onboarding/onboard-lib.sh", "onboarding/tests/fixtures/idss-prompts/review-prompt.md", "onboarding/tests/onboard-lib-test.sh", "prompts/review-prompt.md", "rehearsal-report.sh", "swarm.config", "tests/close-report-lib-test.sh", "tests/close-report-test.sh", "tests/model-lib-test.sh" ], "tests": [ { "command": "bash tests/close-report-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/close-report-test.sh", "exit_code": 0 }, { "command": "bash tests/model-lib-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/onboard-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL; done", "exit_code": 0 } ], "criteria": { "approve verdict lets the close proceed (shimmed claude)": "tests/close-report-test.sh RV-A (approve→close_stuck) + tests/close-report-lib-test.sh RV1; close-report.sh cr_review case approve proceeds", "reject verdict refuses the close with the findings reproduced verbatim": "tests/close-report-test.sh RV-B (findings grepped verbatim in forgejo.log, outcome=refused) + close-report.sh folds cr_review_finding_lines into violations", "malformed/empty reviewer output refuses the close (fail-closed)": "tests/close-report-test.sh RV-C (malformed+empty exit 1) + close-report-lib.sh cr_review_parse normalises to malformed; close-report.sh malformed case sets gate_rc=1", "unsure verdict parks ready-for-human with findings attached": "tests/close-report-test.sh RV-D (ready-for-human label added, ready-for-agent+agent-working removed, outcome=parked, findings posted)", "In PR mode the gate runs before the merge step": "tests/close-report-test.sh PR-2d (reviewer reject in agent-after-green leaves the PR unmerged); gate slots before landing_merge_if_green and before #206's marker stamp", "The review JSON is posted on the thread and the review call's spend is recorded": "close-report.sh cr_post_review posts the verdict JSON (RV-A reviewed()); swarmdb_spend_from_result + marker asserted by RV-E", "The reviewer skeleton renders through the prompt pipeline and is in the vendor manifest; render stays byte-identical to the cutover fixture": "prompts/review-prompt.md (placeholder-free) rendered by onboard_render_prompts; covered by prompts/** in onboarding/vendor-manifest; onboarding/tests/onboard-lib-test.sh idss cutover at 6 skeletons byte-identical" }, "summary": "Added an independent read-only reviewer gate to close-report.sh that reads the run's diff and can refuse, park ready-for-human, or approve a close.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#197
No description provided.