Skip to content
Yassir Kachri

Agentic Software Factory

Four-Station Verification: No Agent Certifies Its Own Work

A session that reviews its own change repeats its own assumptions. Four verification stations, each independent of the author in a different way, and the evidence they hand to the person who accepts the merge.

Yassir Kachri Updated 11 min read

A branch produced by a coding agent arrives with evidence that the same session produced: the agent read the spec, wrote the code and most of the tests, ran them, and decided it was finished. That evidence is real, and it shares every assumption the session made. An agent that misread a requirement wrote its code and its unit tests from the same misreading, and a green test run then shows that the two agree with each other.

A hypothetical refund endpoint shows the mechanism. The handler checks that the caller is signed in and never checks that the caller’s merchant owns the transaction. If the agent never considered access across merchants, it wrote no test that tries another merchant’s transaction, and when asked to review its change for security issues it reviews the code from the frame in which it wrote it. The pull request can then report a green suite and a clean self-review, both truthfully, about code in which the ownership check was never written.

The reference design in my book therefore applies one rule: the session that wrote a change never declares it done. I judge every other check by its independence from the author: whether a model is involved, whether it starts from the author’s context, who chose its inputs, and whether the change can alter its rules. A check that can stop a merge must take its inputs and its rules from outside the change. A check that cannot stop a merge counts as risk reduction and is never cited as approval.

Each station is independent of the author in a different way

Exhibit 1 Two stations can stop a branch on their own; the other two shorten the loop or feed the human decision
StationRunsIndependent of the author becauseCan blockEvidence at the Merge Gate
1. Hooks and testsIn the session, then again in CINo model; contract scenarios approved at the Spec Gate; build targets owned by the platform teamYesRequired tests and spec-trace checks
2. Security guidanceIn the sessionSeparate model call with a fresh contextNoNone
3. Critic, plus a deep scan on flagged changesOn the pull requestNew session; diff supplied by Git; rules loaded from protected mainYes, as required checksThe critic’s verdict; on flagged changes, the scan and the answers to its findings
4. Code ReviewOn the pull request, as a managed serviceREVIEW.md read from the base branchNo; branch rules make its findings bindingA severity line on the head commit, or a green fallback run; every thread resolved

Source: Author's reference design, The Enterprise Agentic Software Factory.

A fresh session clears the assumptions of one conversation, but a critic on the same model family as the author may share blind spots from training, and I know of no published measurement of that correlation. That is why deterministic checks, the contract suite and a person stand on either side of the model stations.

Station 1 gets its weight from tests the agent could not write

The test gate that runs before an agent ends its turn is a claim made inside the author’s session. It runs in the agent’s worktree, under an attempt budget, and in the reference configuration it fails open when the hook times out. The evidence the Merge Gate accepts is the same command run again in CI on a clean checkout of the pull request.

What a green run proves depends on who wrote the tests. The unit tests the agent wrote with the code share its assumptions. The contract scenarios were approved by the Change Owner before the agent started, and a workbench hook refuses agent edits to tests/contracts/. That half of the suite is independent on all four questions: no model, no session context, inputs chosen by a person, and rules the change cannot alter without the Change Owner’s approval. Any outcome a domain cannot afford to get wrong therefore belongs in a contract.

The jobs must also sit outside the change. GitHub runs a pull_request workflow from the pull request’s merge branch, so a pull request that edits .github/workflows/ edits the job that reports on it. The reference design keeps the judging workflows in a platform repository, required through organization rulesets, and gives the Makefile they call to the platform team as code owner.

Station 2 shortens the loop and certifies nothing

Claude Code’s security guidance plugin reviews code while the agent writes it, on each edit, each turn and each commit or push. Its model reviews “run as a separate Claude call with a fresh context and a security-focused prompt,” but their output returns to the author: “Findings reach the writing Claude as instructions, Claude addresses them in the conversation, and the review model can miss issues.” The documentation is plain about its limit: “None of the layers block writes or commits.”

I keep the station because a finding that arrives while the agent still has the edit in view is the cheapest one to act on. Its output never enters the evidence bundle, because a check whose findings the author may address or set aside is part of the authoring loop.

Station 3: the critic reads only what the author could not choose

The critic is a separate session whose instructions tell it to find the reasons a change should not merge. Its definition grants Read, Grep and Glob and lists Write, Edit, Bash and Agent as disallowed. Both lists are set so that the denylist still holds if someone deletes the allowlist, and the subagent documentation states how they combine: “If both are set, disallowedTools is applied first, then tools is resolved against the remaining pool.” A critic that cannot write cannot quietly fix what it finds, so its output is limited to findings, each citing file:line, and a verdict.

Three design choices keep the author out of the critic’s inputs.

  1. The critic runs in CI as its own session. If the writing session invoked it, the author would choose what the critic saw and how the request was framed. The diff comes from Git, piped from git diff origin/main...HEAD.
  2. Its rules come from protected main. Before the critic starts, the job deletes every CLAUDE.md, CLAUDE.local.md and .claude/ directory in the checkout, at any depth, and restores the versions on origin/main. A pull request that edits the critic’s own definition is reviewed as text in the diff, and its edits never become instructions.
  3. Only an exact verdict passes. The job passes only when the last line of the critic’s output is exactly VERDICT: PASS. A run cut short by a turn or budget limit, or a provider error, ends without that line, so the gate fails closed.

Failing closed protects the gate against a run that breaks, and gives no protection against a diff written to persuade: an instruction hidden in a code comment can steer the critic toward a pass. A FAIL therefore arrives as strong evidence, with a quoted line the Change Owner can check, while a PASS only records that the critic found nothing it could cite. A third verdict, SPEC-GAP, reports behavior the spec does not describe and sends the item back to the Spec Gate.

One GitHub behavior needs a compensating control. The critic job is skipped for pull requests from forks, so that they never receive its cloud identity, and the Actions documentation states: “A job that is skipped will report its status as ‘Success’. It will not prevent a pull request from merging, even if it is a required check.” The reference workflow adds a job that runs only on forks and always fails, so a fork pull request merges only after a maintainer pushes its commits to a branch where the critic runs.

Changes that touch authentication, payment or entitlement logic also get a deep scan run by a security champion. A small model in CI flags them, and only an explicit false from the model skips the flag, so a model can raise the bar and never lower it.

Exhibit 2 Only evidence produced outside the writing session reaches the Merge Gate

Inside the writing session, hooks and a test gate give only a claim, and security guidance never enters the bundle. On the pull request, with rules from protected main, CI tests and spec-trace, the critic with a deep scan on flagged changes, and Code Review produce the evidence bundle the Change Owner reads at the Merge Gate. A critic FAIL returns the branch to the agent; a SPEC-GAP returns the item to the Spec Gate.

Source: Author's diagram of the verification plane in The Enterprise Agentic Software Factory.

Station 4 advises, so branch rules make it binding

Code Review is a managed service in which several agents examine the diff and the surrounding code. “By itself, a review doesn’t approve or block the pull request,” and its check run “never concludes as a failure.” Its independence comes from where its rules live: it “reads REVIEW.md from the pull request’s base branch or from the default branch, never from the pull request’s own changes.” Some of those instructions apply only when the default branch is protected, so branch protection is a prerequisite.

The reference design makes the findings binding with two branch rules: conversation resolution before merging, and approvals dismissed when new commits are pushed. Two gaps remain. Anyone who may resolve a thread can dismiss a finding with one click, so an Important finding must be closed by a fixing commit or a written reply from the Change Owner, and the exceptions are counted. And a review may not run at all, for a draft, a fork or a spent budget. A finished review normally ends its check run with a severity line; when the line is missing, the documentation says to “Treat that as no verdict rather than as zero findings.” The Change Owner approves only when the line is present on the head commit.

Code Review is not available with Zero Data Retention, the HIPAA configuration or customer-managed encryption keys, conditions regulated organizations often meet, so the reference workflow carries a fallback review job in CI, and a green run of that job on the head commit takes the severity line’s place. Claude Approvals, a newer feature in public beta, raises a separate question: where a branch rule requires one approval, “Claude’s approving review can be that approval.” On a Level 3 service, where a named Change Owner approves both the spec and the merge, I would keep Claude out of the approval count.

The Change Owner reads the bundle in a fixed order

Each item in the bundle comes from somewhere the author could not write: the merged Spec Gate pull request the change cites, a green tests check on the head commit, the critic’s verdict, the scan where one was required, and a completed review with every thread resolved. Reading it is a different skill from reading a diff, and the reference training material teaches an order of attention.

Exhibit 3 The full diff is read when a stated trigger applies
  1. The spec change. What did the owner approve?
  2. The critic’s verdict and its reasons. Does any reason point outside the approved change?
  3. Test changes. Did any test get weaker, skipped or deleted? Were contract cases added?
  4. Unresolved or self-closed threads. Was each Important finding fixed by a commit?
  5. The full diff, when a trigger applies: a path that moves money, writes ledger postings or touches authentication; a migration; a critic verdict that needed more than one round; a diff large relative to its spec change; or a flag for the deep scan.

Source: Author's reference design, Merge Gate reading order.

An error that every station missed and no trigger covers can reach production. A quarterly sample audit, in which a Change Owner from another domain re-reads accepted pull requests in full, shows whether the triggers are drawn in the right place.

When a station fails, the branch waits for a person

  • The agent and the critic do not converge. My recommended starting value is two FAIL rounds on one pull request, after which an engineer takes the item at Level 2 and approves each agent step.
  • The critic run ends without a verdict. My recommended starting value is one rerun. A diff too large for the critic is too large for a Level 3 change and goes back to be split.
  • Every station passes and the bug is real. The Code Review documentation warns that “A review with no findings doesn’t mean your code is error-free or secure.” An escaped defect becomes a new contract scenario for its domain and a case in the replay suite below.

The verifiers change too

A new model, a revised critic prompt or an amended hook shifts what passes. The reference design ships those changes through rings, from the platform team’s repositories to a canary group to the fleet, and promotes them on a replay suite of past work items. Among my recommended starting criteria, every escaped-defect case must draw a FAIL in each of three runs, and every guardrail probe must be refused.

The reference design watches the stations through four measures:

  • First-pass acceptance: the share of merged pull requests that cite an approved Spec Gate change and needed no critic FAIL round, no Important finding fixed after Station 4 and no changes requested by the Change Owner.
  • Critic overrides per domain each month. A rising count means the critic’s prompt needs work.
  • Escaped defects, each added to the contracts and the replay suite.
  • Verification latency, with a recommended starting target of a critic verdict within 20 minutes of a push at the 90th percentile.