Policy Gate

When an agent reviewer replies "Approved," it is tempting to treat that word as a green light to merge code, send a customer announcement, or trigger a payout. Yet "Approved" quietly blurs two very different things: what the reviewer actually checked, and whether the team's rules permit taking an irreversible step.

Policy Gate separates inspection from permission. Each checker records a structured finding — naming the exact version it examined, the method it used, what it left out, and any problems found — while a separate policy reads those findings and decides whether a guarded step may proceed, must go back for repair, needs another kind of evidence, or requires the requester's approval. Reach for it whenever a step is hard to undo and different checks prove different things.

Group Verification and completion
Also known as Quality Gate, Approval Gate
Core rule Keep what a checker found apart from what that finding allows
Defines records Finding, Gate decision

Why "Approved" from two reviewers isn't enough

Across engineering, operations, finance, and publishing, teams routinely place a reviewer agent in front of high-stakes actions — merging a pull request, publishing pricing copy, issuing refunds, or shipping a configuration change. When two reviewers inspect the work and both reply "Approved," the lead agent naturally concludes the change is safe.

Two quiet failures hide behind that single word. First, observation and permission get tangled together: a checker meant "I read the draft and noticed no flaws," while the lead heard "you are cleared to ship." Second, duplicate checks create a false sense of rigor: two checkers who both merely read a draft or diff share the exact same blind spot — neither actually exercised the live behavior, reconciled the source numbers, or checked edge-case timing.

Policy Gate untangles the two halves with three system-enforced rules:

  1. Checkers report facts, never permission. Every check writes an immutable Finding naming the exact version examined, the method used (read, tested, or observed), what was left out, and any problems found.
  2. A stored policy decides what happens next. An ordered list of rules evaluates the active findings for that version — counting distinct methods once — and produces one of four outcomes: proceed, repair, more_evidence, or needs_approval.
  3. The Hub executes the guarded step itself. Only the hub runs the irreversible action, and only when the latest decision is proceed for the exact version currently on offer.

Why evaluate rules as data instead of editing checker prompts? When risk changes — say a team tightens rules for billing changes or external customer emails — updating one ordered policy immediately governs every job without rewriting a single checker's instructions, and every past decision remains replayable from its stored inputs.

Informal "Approved" replies Worker submits version v1 Ready for review before risky step Checker A Reads -> Approved Checker B Reads -> Approved Lead treats "Approved" as go Two reads share the same blind spot Flaw ships past review Nobody tested live behavior or asked Policy Gate Checkers record typed findings Version, method, scope & gaps Checker A method: read (v1) Checker B method: tested (v1) Policy weighs distinct methods Proceed, repair, evidence, or approval Hub runs step only on proceed Pinned to the exact verified version
Two reviewers who only read a result count as one method and miss execution bugs. Policy Gate counts evidence by method, names what is missing, and pins execution to the exact verified version.

Architecture and participants

In a Policy Gate, the Hub acts as both the policy decision point and the enforcement point. Checkers write typed Finding records, the requester maintains the ordered Policy, and the hub writes an immutable Gate decision each time a guarded step is requested or new evidence arrives. The requester is asked last — only after all automated and checker findings for that version are clean — so human attention is never wasted reviewing broken work.

Requester Writes policy & approves Lead agent Requests guarded step Checkers Record typed findings Hub — durable records & policy evaluator Policy Ordered rules per step Gate decision Rule, outcome & inputs Finding Version, method, problems Outcomes: proceed · repair · more_evidence · needs_approval Guarded step (Hub executes) Runs only on proceed for exact version Worker & follow-up routing Repairs version, tests, or asks Requester
Policy rules and version-pinned findings feed the hub's gate evaluator. Only a proceed decision for the exact version allows the hub to execute the guarded step; all other outcomes route back to workers, checkers, or the requester.
Requester
Authors the ordered Policy rules for high-stakes steps and supplies explicit approval when a rule returns needs_approval.
Hub
Stores immutable Finding and Gate decision records, evaluates policies deterministically, holds credentials for guarded steps, and blocks stale versions.
Lead agent
Requests guarded steps, reads more_evidence rulings to dispatch the missing kind of check, and routes repair findings back to the worker.
Worker
Produces each numbered version of the deliverable and repairs defects flagged by a repair decision. Never checks its own output or runs guarded steps directly.
Checkers
Independent agents or harnesses that examine one exact version and record what method they used, what they checked, what they skipped, and any must or should problems.

Execution flow

Toggle between the normal progression — where the policy evaluates three times as missing evidence and requester approval arrive for version v1 — and the stale-version path — where a late edit supersedes v1 while approval is waiting, invalidating the old approval automatically.

Requester Hub Lead agent Worker Checkers 1. Report result ready (v1) 2. Checker A records read finding (v1) 3. Request guarded step on v1 Gate decision 1: more_evidence Policy requires tested; only read exists 4. Refuse step; missing: tested 5. Assign Checker B to test v1 6. Checker B records tested finding Gate decision 2: needs_approval Findings clean; policy asks Requester 7. Ask approval with v1 findings 8. Approve version v1 Gate decision 3: proceed Hub executes guarded step on v1 9. Guarded step complete (v1)

Each evaluation writes a new immutable decision. Decision 1 catches the missing tested method, Decision 2 asks the requester only once findings are clean, and Decision 3 permits the hub to run the guarded step on v1.

Concrete examples

Policy Gate applies to any irreversible transition — publishing communications, disbursing funds, releasing infrastructure, or merging code — wherever different verification methods catch different classes of mistakes.

Example 1 — Sending a quarterly customer pricing update

No code or unit tests
Guarded step
Send the Q4 pricing announcement email to 10,000 active accounts (revision draft-4).
Policy rules
(1) Any must problem → repair; (2) Missing tested finding (numbers reconciled against live billing rates) → more_evidence; (3) External customer send without requester sign-off → needs_approval; (4) Default → proceed.
What the gate catches
Two editorial checkers both proofread draft-4 (method: "read") and find zero typos. Because both used read, Rule 2 fires more_evidence: ["tested"]. A finance checker then reconciles the draft against the live billing table, catches an outdated annual discount figure, and logs a must problem — routing the draft back to the writer before the requester is ever bothered.

Example 2 — Payment webhook retry fix

Payments & merges
Guarded step
Merge a fix stopping duplicate payment webhook notices when a customer's server times out (commit 4f2a).
Policy rules
(1) must_fix >= 1 → repair; (2) methods lacks tested → more_evidence; (3) payment_code == true and not approved → needs_approval; (4) Default → proceed.
What the gate catches
Checkers A and B both read commit 4f2a and find no issues, noting they did not run a timeout delivery. Rule 2 blocks the merge and asks for a tested finding. Once Checker B runs a simulated timeout and passes, Rule 3 opens one approval question for the requester with both findings attached. If the worker pushes a tidy-up commit 9c1e before merge, the hub rejects merging 9c1e under 4f2a's decision with stale_version.

What this pattern is NOT — Internal scratch drafts

Negative example
Action
Saving internal meeting notes to a team scratchpad or renaming a private draft file.
Why skip it
The step is cheap to undo, reaches nobody outside the team, and has no independent checkers examining it first. Placing a Policy Gate with nothing to read only inserts bureaucracy without reducing risk.

When to use and when to skip

Use Policy Gate when

  • A transition is hard to undo or externally visible — merging code, deploying to production, spending funds, or messaging customers.
  • Multiple checks (reading, live execution, production observation, or human review) prove different properties and cannot substitute for one another.
  • The requester wants to tighten or relax rules for a specific risk class without rewriting checker prompts.
  • Auditability matters: anyone inspecting a shipped action later must see which rule and which exact findings allowed it.

Skip it when

  • The action is cheap and reversible and nobody inspects the work before taking it.
  • One person inspects every artifact themselves and immediately executes the step — their inspection and decision are already unified.
  • The system cannot hold credentials at the hub, leaving agents free to bypass the gate anyway.
  • Work products have no stable version identifier to bind findings and approvals against.

Data model and hub invariants

Policy Gate defines two append-only tables — findings and gate_decisions — referencing jobs, parties, policies (whose gate_rules hold the ordered rules with effect = 'gate'), and questions.

Finding PK id FK job_id FK checker_id version method examined not_examined? problems recorded_at voided_at? Job PK id Party PK id Policy PK id Question PK id Gate decision PK id FK job_id step version FK policy_id rule outcome missing inputs decided_at FK question_id? finding_ids 1 n 1 n 1 n 1 n 1? n n finding_ids (active findings for the same job and version) n
Finding and Gate decision anchor every check and ruling to an exact version and job_id. Cardinality markers follow catalog convention (1, 1?, n).

Table: findings

Column Postgres type Nullability Notes
id uuid NOT NULL, PK Immutable finding identifier.
job_id uuid NOT NULL, FK References jobs(id); job whose deliverable was examined.
checker_id uuid NOT NULL, FK References parties(id); never the worker that produced the version.
version text NOT NULL Exact version examined (commit SHA, artifact digest, or document revision).
method text NOT NULL CHECK (method IN ('read', 'tested', 'observed')).
examined text NOT NULL One sentence naming what the checker inspected or executed.
not_examined text NULLABLE Explicit blind spots left out of this examination.
problems jsonb NOT NULL Array of {severity: "must"|"should", where, text}; [] when clean.
recorded_at timestamptz NOT NULL Defaults to now().
voided_at timestamptz NULLABLE Set once when an upstream change invalidates the finding; NULL while active.

Table: gate_decisions

Column Postgres type Nullability Notes
id uuid NOT NULL, PK Immutable decision identifier.
job_id uuid NOT NULL, FK References jobs(id).
step text NOT NULL Guarded step kind, e.g., merge, release, send.
version text NOT NULL Exact version evaluated by this decision.
policy_id uuid NOT NULL, FK References policies(id) with effect = 'gate'.
rule text NOT NULL Name of the first rule whose conditions matched (e.g., merge.untested).
outcome text NOT NULL CHECK (outcome IN ('proceed', 'repair', 'more_evidence', 'needs_approval')).
missing jsonb NOT NULL Methods still required (e.g., ["tested"]); empty unless more_evidence.
inputs jsonb NOT NULL Exact snapshot of named values read by the policy so decisions replay deterministically.
decided_at timestamptz NOT NULL Defaults to now().
question_id uuid NULLABLE, FK References questions(id); set for needs_approval and the follow-up decision reading its answer.
finding_ids jsonb NOT NULL Array of active Finding IDs read during evaluation.

Six hub invariants

  1. 01
    Finding content is immutable; voiding occurs at most once Database constraint

    Once inserted, finding fields never change and hold no permission verdict. An upstream change may transition voided_at from NULL to a timestamp once (a repeat attempt fails with finding_already_voided).

  2. 02
    Methods, outcomes, and conditional columns are closed Database constraint

    CHECK constraints restrict findings.method to read | tested | observed, gate_decisions.outcome to the four valid outcomes, and require question_id IS NOT NULL when outcome = 'needs_approval' and missing = '[]' unless outcome = 'more_evidence'.

  3. 03
    Checkers cannot examine their own produced work Hub guard

    record_finding verifies checker_id != job.assignee_id, rejecting self-reviews with checker_cannot_be_producer.

  4. 04
    Decisions read only active findings and approvals for the exact version Hub guard

    evaluate_gate filters findings strictly by job_id, version, and voided_at IS NULL (deduplicating methods), and derives approved solely from requester approvals recorded for that exact (job_id, step, version) via record_approval (which rejects non-requesters with only_requester_may_approve).

  5. 05
    Policy must be a gate policy with deterministic first-match rules Hub guard

    evaluate_gate rejects non-gate policies with invalid_gate_policy and incomplete rule sets with no_matching_rule. Storing inputs ensures the same rules and inputs always reproduce the same outcome.

  6. 06
    Guarded steps run only under the latest proceed decision for the live version Hub guard

    run_guarded_step verifies atomically that a decision exists (no_gate_decision), matches the current version (stale_version), and has outcome proceed (gate_not_proceed).

Reference implementation

The same minimal hub guards in Lean, TypeScript, Python, and Elixir. Notice that checkers only submit findings, policies remain pure first-match rules over deduplicated methods, and the hub enforces version pinning right where the guarded step runs.

-- Hub guards for Policy Gate (findings and version-bound approvals stay separate from policy)
import Std.Data.HashMap
open Std

inductive Method where
  | read | tested | observed
  deriving Repr, BEq, DecidableEq

inductive Outcome where
  | proceed | repair | moreEvidence | needsApproval
  deriving Repr, BEq, DecidableEq

inductive Severity where
  | must | should
  deriving Repr, BEq

inductive Effect where
  | gate | delegate
  deriving Repr, BEq

structure Problem where
  severity : Severity
  «where» : String  -- «» lets a keyword be a field name
  text : String
  deriving Repr

structure Job where
  id : String
  assigneeId : String
  requesterId : String
  deriving Repr

structure Finding where
  id : String
  jobId : String
  checkerId : String
  version : String
  method : Method
  problems : List Problem := []
  voidedAt : Option String := none
  deriving Repr

structure Approval where
  jobId : String
  step : String
  version : String
  approvedById : String
  deriving Repr

-- What a rule sees: the caller's facts plus what the hub derived from findings and approvals.
structure GateInputs where
  facts : HashMap String Bool
  methods : List Method
  mustFix : Nat
  approved : Bool

structure GateRule where
  id : String
  «when» : GateInputs → Bool
  «then» : Outcome
  missing : List Method := []

structure Policy where
  id : String
  effect : Effect
  rules : List GateRule

structure GateDecision where
  id : String
  jobId : String
  step : String
  version : String
  policyId : String
  rule : String
  outcome : Outcome
  missing : List Method
  findingIds : List String
  deriving Repr

inductive HubError where
  | unknownJob | checkerCannotBeProducer | onlyRequesterMayApprove | unknownFinding
  | findingAlreadyVoided | invalidGatePolicy | noMatchingRule | noGateDecision
  | staleVersion | gateNotProceed
  deriving Repr, BEq

structure PolicyGateHub where
  jobs : HashMap String Job := {}
  findings : List Finding := []
  approvals : List Approval := []
  decisions : List GateDecision := []  -- newest first

namespace PolicyGateHub

def getJob (hub : PolicyGateHub) (jobId : String) : Except HubError Job :=
  match hub.jobs[jobId]? with
  | some job => pure job
  | none => throw .unknownJob

def recordFinding (hub : PolicyGateHub) (f : Finding) :
    Except HubError (Finding × PolicyGateHub) := do
  let job ← hub.getJob f.jobId
  if f.checkerId == job.assigneeId then throw .checkerCannotBeProducer
  let stored := { f with voidedAt := none }
  pure (stored, { hub with findings := stored :: hub.findings })

def recordApproval (hub : PolicyGateHub) (jobId step version actorId : String) :
    Except HubError (Approval × PolicyGateHub) := do
  let job ← hub.getJob jobId
  unless actorId == job.requesterId do throw .onlyRequesterMayApprove
  let approval : Approval := { jobId, step, version, approvedById := actorId }
  pure (approval, { hub with approvals := approval :: hub.approvals })

-- (`at` is a Lean keyword, so the timestamp parameter is named voidedAt)
def voidFinding (hub : PolicyGateHub) (findingId voidedAt : String) :
    Except HubError PolicyGateHub := do
  let some f := hub.findings.find? (·.id == findingId) | throw .unknownFinding
  if f.voidedAt.isSome then throw .findingAlreadyVoided
  let voided := hub.findings.map fun row =>
    if row.id == findingId then { row with voidedAt := some voidedAt } else row
  pure { hub with findings := voided }

def evaluateGate (hub : PolicyGateHub) (jobId step version : String) (policy : Policy)
    (facts : HashMap String Bool) : Except HubError (GateDecision × PolicyGateHub) := do
  unless hub.jobs.contains jobId do throw .unknownJob
  unless policy.effect == .gate do throw .invalidGatePolicy

  let active := hub.findings.filter fun f =>
    f.jobId == jobId && f.version == version && f.voidedAt.isNone
  let methods := (active.map (·.method)).eraseDups
  let mustFix := active.countP fun f => f.problems.any (·.severity == .must)
  let approved := hub.approvals.any fun a =>
    a.jobId == jobId && a.step == step && a.version == version
  let inputs : GateInputs := { facts, methods, mustFix, approved }

  let some rule := policy.rules.find? (·.when inputs) | throw .noMatchingRule
  let decision : GateDecision := {
    id := s!"dec_{hub.decisions.length + 1}"
    jobId, step, version, policyId := policy.id
    rule := rule.id, outcome := rule.then, missing := rule.missing
    findingIds := active.map (·.id)
  }
  pure (decision, { hub with decisions := decision :: hub.decisions })

def runGuardedStep (hub : PolicyGateHub) (jobId step currentVersion : String) :
    Except HubError GateDecision := do
  -- decisions are newest first, so find? returns the latest one for this step
  let some latest := hub.decisions.find? (fun d => d.jobId == jobId && d.step == step)
    | throw .noGateDecision
  if latest.version != currentVersion then throw .staleVersion
  unless latest.outcome == .proceed do throw .gateNotProceed
  pure latest

end PolicyGateHub

Evaluation and stale-version trace

Walking Example 2 (payment webhook retry fix) through these guards shows how duplicate read findings trigger more_evidence and how a late commit triggers stale_version:

Execution trace: Example 2 (payment webhook retry fix)
1. hub.recordFinding(f_read_a, job_webhook_fix, checker_a, "4f2a", "read", [])
   hub.recordFinding(f_read_b, job_webhook_fix, checker_b, "4f2a", "read", [])
   -> ok (two read findings stored; distinct methods = ["read"])

2. hub.evaluateGate(job_webhook_fix, "merge", "4f2a", policy_payment_merge, { paymentCode: true })
   -> outcome: "more_evidence" (rule: "merge.untested", missing: ["tested"])
   hub.runGuardedStep(job_webhook_fix, "merge", "4f2a")
   -> error: gate_not_proceed (hub refuses merge)

3. hub.recordFinding(f_test_c, job_webhook_fix, checker_b, "4f2a", "tested", [])
   hub.evaluateGate(job_webhook_fix, "merge", "4f2a", policy_payment_merge, { paymentCode: true })
   -> outcome: "needs_approval" (rule: "merge.payment_code"; approved=false, opens question for "4f2a")

4. // Requester approves "4f2a", while Worker pushes tidy commit "9c1e"
   hub.recordApproval(job_webhook_fix, "merge", "4f2a", requester_dana)
   hub.evaluateGate(job_webhook_fix, "merge", "4f2a", policy_payment_merge, { paymentCode: true })
   -> outcome: "proceed" (bound strictly to "4f2a")
   hub.runGuardedStep(job_webhook_fix, "merge", "9c1e")
   -> error: stale_version ("4f2a" decision cannot merge current commit "9c1e")

5. hub.recordFinding(f_test_d, job_webhook_fix, checker_b, "9c1e", "tested", [])
   hub.evaluateGate(job_webhook_fix, "merge", "9c1e", policy_payment_merge, { paymentCode: true })
   -> outcome: "needs_approval" (rule: "merge.payment_code"; "4f2a" approval ignored, approved=false for "9c1e")

6. hub.recordApproval(job_webhook_fix, "merge", "9c1e", requester_dana)
   hub.evaluateGate(job_webhook_fix, "merge", "9c1e", policy_payment_merge, { paymentCode: true })
   -> outcome: "proceed" (rule: "merge.default", approved=true for "9c1e", findingIds: [f_test_d])
   hub.runGuardedStep(job_webhook_fix, "merge", "9c1e")
   -> ok (hub merges exact commit "9c1e")

Tradeoffs and practical guidance

Policy Gate trades a small amount of policy authoring and wait latency for verifiable, auditable control over irreversible transitions. Weigh three practical costs before adding a gate:

  • Policies become production logic: an overly strict rule stalls every job, while a buggy catch-all rule lets unverified work straight through. Version policies and dry-run rule changes against stored historical inputs before activating them.
  • Self-reported method honesty: the gate can require a tested finding, but if a checker labels a pure reading pass as tested, the gate is fooled. Pair method labels with concrete artifacts (execution logs, reconciliation outputs, or replay traces).
  • Wait time on strict gates: every guarded step pauses until findings arrive, and jobs that loop repeatedly on a strict rule need a clear path to escalate to the requester.

Practical implementation notes

  • Hold credentials at the hub: if a worker or lead agent can merge, send, or deploy with its own credentials, the Policy Gate is only polite advice.
  • Pass the version into the external action: when calling downstream APIs (for example, GitHub's expected head SHA on merge), pass the evaluated version so the target system also rejects races atomically.
  • Keep the rule language small and closed: an ordered first-match list ending in a mandatory default rule stays easy to audit and impossible to fall off the end of. Treat a check that never ran as missing evidence, never as clean.
  • Withdraw stale approval questions immediately: the moment a new version replaces the version under review, supersede any open approval question so the requester never wastes time approving obsolete work.

Known uses and related patterns

  • SonarQube quality gates: measures code analysis metrics against a stored set of pass/fail conditions before permitting merge; Policy Gate extends this with method-typed findings, more_evidence, and conditional human approval.
  • GitHub protected branches: combines required reviews, passing status checks, and automatic dismissal of stale approvals when a new commit pushes to the head of a pull request.
  • Azure Pipelines deployment approvals and checks: lets resource owners attach ordered checks and human approvals to production environments before a stage may run.
  • LangGraph interrupts & OpenAI Agents SDK: pause runs when a tool call needs human approval; Policy Gate determines from versioned findings whether that approval is required in the first place.
  • XACML & Open Policy Agent (PDP / PEP): classic security architecture separating the Policy Decision Point (the gate evaluator) from the Policy Enforcement Point (the hub executing the guarded step).
  • Volgenic: evaluates versioned JSON policies before routing asks to humans and binds pull-request merges to the exact reviewed commit.

Related patterns

  • Delegation Policy — stores the requester's standing rules in advance; Policy Gate is where gate rules are applied to checker findings.
  • Evidence-Backed Completion — uses a Finding to support a checked completion claim, whereas Policy Gate permits or blocks one specific step.
  • Decision Audit — reviews past autonomous decisions; proceed gate decisions made without asking the requester feed directly into audits.
  • Self-Contained Question & Tracked Answer — package the needs_approval question with the version and findings, and route the requester's reply back to re-evaluate the gate.
  • Durable Job, Orchestrator-Workers, & Change Propagation — define Job and Party, and void findings when upstream changes overtake active work.