Audit-Loop: Multi-Round Independent Review & Fix Workflow
A high-controllability closed-loop engineering audit skill: sizes depth by consequence, binds every audit round to a SHA-256 source snapshot, dispatches independent read-only auditors, filters false positives before editing, guards against gate-weakening/zero-run-green hacks, freezes converged tracks, and reports honest coverage limits.
1. Configuration Precedence & Knobs
Resolve parameters in strict order: 1) Explicit user instructions in chat > 2) Project .agents/audit-loop.json (or .agent/audit-loop.json) > 3) Defaults below.
| Knob | Values | Default |
|---|---|---|
scope | uncommitted | branch | branch:<base> | commit:<spec> | paths (--scope paths --paths ...) | uncommitted |
depth | auto (consequence & exec-line routed) | lite | standard | deep | auto |
tracks | Auto-split by directory/stack (with auto-sharding on large tracks) | Auto-detected |
stop_policy | zero_high_medium (0H/0M, report Low) | zero_all (0H/0M/0L) | zero_high | zero_high_medium |
max_rounds | Positive integer fuse per track (lite auto-caps at 2) | 6 |
auditor_policy | fresh_per_round | verify_then_fresh | adversarial_panel | fresh_per_round |
auditor_model | inherit | flash | pro (optional final_auditor_model override) | inherit |
verify_findings | auto (FP-check High, conf <= 7, or adversarial) | always | off | auto |
gate_integrity | true (run RH-1..RH-16 diff scan + PL-2 zero-run-green check) | false | true |
fixer_policy | coordinator (parent fixes directly) | persistent_subagent (reused via send_message) | coordinator |
fix_policy | auto_fix | ask_before_fix | audit_only | auto_fix |
engine | interactive (invoke_subagent, hot-controllable) | workflow (run_workflow batch) | interactive |
funnel_after_round | Broad full-diff audit through round K, then tighten to last-round hunks + callers (0 disables) | 2 |
churn_limit / repeat_finding_limit | Pause on file edited >= 3 rounds (PAUSED_CHURN) or same finding surviving >= 2 fixes (PAUSED_REPEAT) | 3 / 2 |
on_converged | report_only | local_commit | bump_commit_build | report_only |
Read references/project-config.md for .agents/audit-loop.json details and presets.
2. Closed-Loop Execution Procedure
Step 1: Collect Scope, Risk Tier, Guidelines & Snapshot
Run the scope collector and bind a deterministic SHA-256 snapshot first:
python3 ~/.gemini/config/skills/audit-loop/scripts/collect_scope.py --scope uncommitted --json
python3 ~/.gemini/config/skills/audit-loop/scripts/gate_integrity.py snapshot --scope uncommitted --out <artifactDir>/scratch/snapshot_r1.json
- Pass
--scope branch,--scope commit:<ref>,--scope paths --paths <p1> <p2>(or--pathsas a filter on git scopes), or--config <path>to match the request. - If
total_files == 0, stop immediately and report an empty scope. - Respect
risk_summary.recommended_depth: tiny/docs-only (lite) changes need at most 1–2 lean passes without heavy ceremony;HIGH-risk changes (auth, crypto, payments, migrations, CI, deleted executable files, or>= 200non-test exec lines) usedeepwithadversarial+silent_failurelenses. - Summarize active tracks, risk tier, effective depth, discovered scoped guidelines, verification gates, and knobs in 1–2 concise sentences before dispatching Round 1.
Step 2: Initialize or Resume the Audit Ledger
Maintain a persistent ledger at <artifactDir>/audit_ledger.md (NEVER inside the git workspace). Follow references/ledger-and-resume.md:
- If resuming after compaction, 429 quota interruption, or restart, read the ledger, run
gate_integrity.py diff-snapshotsto check for external file drift, and resume from the last incomplete round instead of restarting from Round 1. - Track per-track state,
snapshot_id, round history, ground-truth file churn,Won't-Fix,Rejected False Positives, andUnverified Items.
Step 3: Dispatch Independent Read-Only Auditors
- Default (
engine: interactive):- Read references/auditor-prompts.md and compose one focused prompt per unfrozen track (if
recommended_shardingistrueon a broad round, fan out acrosstrack.shards; ifauditor_policy: adversarial_panelon Round 1, dispatch orthogonalcore+adversariallanes in parallel). - Launch all active jobs in parallel via
invoke_subagent(TypeName="research", Model=auditor_model, ...). - Inject five mandatory blocks into every auditor prompt:
- Exact
diff_meta.commands,file_list,deleted_files, and discovered scopedguidelines+extra_rules. - Objective requirements/intent (NEVER author self-justifications like "I already verified this works").
- Evidence & Confidence Gate: verbatim code quote (
evidence),confidence(1–10), concrete consequence,autofix_class(gated_auto/manual/advisory),PRE_EXISTINGisolation, andunverified_itemsbucket. - Funnel & Re-Verification Etiquette (Round 2+): isolate per-track prior fixes; instruct auditors to re-reproduce original defects AND attack the fix itself; tighten scope to prior-round hunks + callers on rounds
> funnel_after_round. - Settled
Won't-Fix+Rejected False Positivestable so decided/disproven items are never re-raised.
- Exact
- Stop calling tools and wait reactively for subagent messages (never poll).
- Read references/auditor-prompts.md and compose one focused prompt per unfrozen track (if
- Batch / Fan-out (
engine: workflow):- Use when the user asks for automated workflow orchestration, multi-perspective fan-out, or unattended
/goalruns. - Execute scripts/audit_workflow.py via
run_workflow(ScriptPath="/Users/.../.gemini/config/skills/audit-loop/scripts/audit_workflow.py", Args={...}, Description="...").
- Use when the user asks for automated workflow orchestration, multi-perspective fan-out, or unattended
Step 4: Freshness Check, Cross-Check Synthesis, FP-Check & Safety Fuses
Read references/triage-and-verification.md when triaging findings:
- Snapshot Freshness & Three Verdicts: Verify the working tree still matches
snapshot_id. Any auditor crash, timeout, 429, malformed output, source mutation, or snapshot drift (STALE_REVIEW) yieldsUNVERIFIED— NEVER treatUNVERIFIEDasZERO_ISSUESand NEVER count it toward stall fuses. - Cross-Check Synthesis: Demote unquotable or
confidence <= 5claims tounverified_items; trace consequence-chain compounding when multiple findings hit the same module; grade by concrete consequence rather than mechanism. - Independent FP-Check (
verify_findings): Underauto, verifyHigh,confidence <= 7, oradversarialblockers before editing (underalways, verify all blockers). Record confirmed false positives inRejected False Positiveswith exact source evidence. - Convergence & Six Safety Fuses: Exclude
PRE_EXISTINGandunverified_items, evaluate remaining findings againststop_policy:- Immediately mark any converged track
FROZEN. - Trip fuses in strict precedence order:
PAUSED_REPEAT(same finding survives>= 2consecutive fix rounds) >PAUSED_DECISION(autofix_class: manual/ architectural arbitration) >PAUSED_CHURN(ground-truth file modified>= churn_limitrounds) >PAUSED_FUSE(non-decreasing blockers foroscillation_limitvalid rounds or ping-pong) >PAUSED_BUDGET(round >= max_rounds).
- Immediately mark any converged track
Step 5: Skeptical Triage, Minimal Fix, Gate Integrity & Hard Gates
audit_only: Do not edit files. Update ledger and output the honest coverage report.ask_before_fix: Present numbered findings (with confidence &autofix_class) and wait for user selection before editing.auto_fix:- Fixer Continuity: Keep the fixer stateful (
coordinatoror one reusedpersistent_subagentviasend_message) so prior invariants are never lost while auditors stay fresh. - Anti-Sycophancy Skeptical Triage: Verify every
gated_autofinding against actual codebase/platform/YAGNI constraints before editing; push back with source evidence intoRejected False Positivesinstead of applying harmful compliance hacks. Never guess onmanualitems. - Sibling-Sweep + Minimal Blast Radius + Bidirectional Regression Lock: Eliminate symmetric call-site/enum bug classes in one round without unrelated refactors; add positive + negative invariant tests for every
High/Mediumfix. - Objective Diff & Gate-Integrity Scan (
gate_integrity: true):- Run
gate_integrity.py diff-snapshots --before <prev_snap> --cwd <repo>to obtain the ground-truth touched files forfile_churn,funnel_mode, and Cross-Track Thaw (thaw anyFROZENtrack whose files were touched). - Run
gate_integrity.py scan-diff --cwd <repo> --paths <touched_files>. Any unjustifiedRH-1..RH-16hit (skipped/deleted tests, suppression pragmas, placeholders, swallowed catches, relaxed assertions) tripsPAUSED_GATE_INTEGRITY. - Run all verification
gatesfor modified tracks and verify real test execution (guard againstPL-2Zero-Run Green viagate_integrity.py check-test-output).
- Run
- Hard Gate Rule: Never launch Round
N+1while any gate is red or gate-integrity is flagged. Save the new round snapshot, update<artifactDir>/audit_ledger.md, and return to Step 3.
- Fixer Continuity: Keep the fixer stateful (
Step 6: Mid-Flight Hot Controls
Honor natural-language overrides immediately at any turn and persist them in <artifactDir>/audit_ledger.md:
- Waive / dispute (
忽略 #3,理由:.../#2 是误报,因为...): Record inWon't-FixorRejected False Positives; re-evaluate convergence immediately. - Adjust knobs (
切到 zero_all/Low 不修了/关闭 fp-check/冻结 frontend/重审 backend/再加 3 轮/只审不改/立刻收尾): Apply immediately.
Step 7: Honest Closeout & Absolute Redlines
Once all tracks are FROZEN (or user closes early):
- Verify final snapshot matches the last verified audit/gates; if any post-convergence edit occurred, re-run full gates.
- Execute
on_converged(report_only|local_commit|bump_commit_build) and deliver the Honest Coverage & Final Summary from references/ledger-and-resume.md (explicitly naming checked scope, fixed totals, rejected FPs, real gate test counts, coverage gaps, and remainingunverified_items/deferred debt). - Absolute Redlines:
- NEVER run
git push, create/push tags, open/modify PRs, or deploy/restart live services without explicit user confirmation. - NEVER weaken tests, assertions, linters, or design gates to force convergence.
- NEVER commit
<artifactDir>/audit_ledger.md, snapshot JSONs, or scratch artifacts into the repository.
- NEVER run