| name | deep-qa |
| description | Use when reviewing, auditing, QAing, critiquing, verifying, or assessing any artifact — a spec, code change, diff, PR, research report, skill, prompt, or document. Also use for pre-completion verification ("verify this works", "prove this is done", "evidence before claiming complete"). Trigger phrases include "review this", "audit this", "QA this", "find issues", "find defects", "critique this", "check this for problems", "what's wrong with this", "evaluate this", "run QA", "review the diff", "review the PR", "review my code", "deep QA", "defect audit", "code review", "assess this", "verify this works", "verify before completing", "prove this is done", "is this actually working". The single skill for all quality assurance — adversarial review, pre-completion verification, and evidence gathering. Cross-model critic lanes (GPT/Gemini via OpenAI-compatible endpoint) are enabled by default for blind-spot diversity; disable with --no-cross-model. |
| user_invocable | true |
| argument | Path to artifact file (or inline content), with optional flags:
--type doc|code|research|skill override artifact type detection
--auto skip all interactive gates
--diff [ref|range] QA a git diff instead of a full artifact;
ref defaults to HEAD~1 (last commit);
use HEAD~3, a SHA, or a branch name;
use A..B for a commit range within a branch
(e.g., --diff b0228a0c6..HEAD for only
the last N commits, not the whole PR)
--verify Pre-completion verification mode: run
tests, typecheck, build, gather evidence
that the change actually works. Reports
what passed, what failed, what's unverified.
--no-cross-model Disable cross-model critic lanes (GPT + Gemini);
cross-model is ON by default
|
| category | qa |
| capabilities | ["adversarial-critique","parallel-agents","defect-detection","severity-classification","ensemble-judges","cross-model-diversity"] |
| best_for | ["Reviewing existing artifacts for defects","Auditing specs, code diffs, PRs, research reports","Finding problems you haven't thought of"] |
| not_for | ["Fixing defects (use autopilot)","Designing from scratch (use deep-design)","Exploring a topic (use deep-research)"] |
| input_types | ["artifact-file","git-diff"] |
| output_types | ["defect-registry"] |
| output_signals | ["termination_label","critical_count","major_count","minor_count"] |
| complexity | moderate |
| model_tier | sonnet |
| cost_profile | medium |
| execution | {"sagaflow":"required","temporal_skill":"deep-qa-temporal","estimated_duration":"10-30min"} |
| related_skills | [{"name":"autopilot","relation":"follow-up","note":"Fix defects that deep-qa finds"},{"name":"deep-design","relation":"alternative","note":"When you need to design, not just review"},{"name":"deep-qa --mode proposal","relation":"alternative","note":"When reviewing a proposal rather than a technical artifact"}] |
| maturity | stable |
Deep QA Skill
Systematically audit an existing artifact for defects using parallel critic agents across QA dimensions tailored to the artifact type. Unlike deep-design (which designs and iterates) or deep-research (which explores the web), deep-qa takes an artifact as-is and finds what's wrong with it.
No spec drafting. No redesign. Find and report.
Execution Model
Pressure awareness: this skill applies the pressure circuit breakers from _shared/pressure-awareness.md. After each critic round, check for diminishing returns (round N < 20% of round N-1 findings → eligible for early termination). After 3 rounds with < 20% new findings, stop rather than grinding.
Shares deep-design's core execution contracts:
- All data passed to agents via files, never inline. Artifact, known-defects list, angle definitions — all written to disk before spawning.
- State written before agent spawn, not after.
spawn_time_iso written before Agent tool call. Spawn failure records spawn_failed status.
- Structured output is the contract; free-text is ignored. Severity judges produce machine-parseable structured lines. Unparseable output → fail-safe critical.
- No coordinator self-review of anything load-bearing. Severity classification delegated to independent judge agents.
- Termination labels are honest. Seven defined labels map to all reachable termination paths — never "no defects remain." See Phase 5 for the complete vocabulary.
- Hard stop is unconditional.
hard_stop = max_rounds * 2 is set at initialization and checked at the start of every round before any user prompt. No extension can exceed it.
Shared contracts: this skill inherits the four execution-model contracts (files-not-inline, state-before-agent-spawn, structured-output, independence-invariant) from _shared/execution-model-contracts.md. The items listed above are the skill-specific elaborations; the shared file is authoritative for the base contracts.
Cross-finding coherence: this skill applies the coherence-integrator pattern from _shared/cross-finding-coherence.md at Phase 5.5.a-coherence — after draining pass-1 judges and BEFORE pass-2 informed judges. The integrator reads all deduped critic output files simultaneously and annotates each finding with cross-finding relationships (contradictions, emergent patterns, coverage gaps). These annotations are included in pass-2 judge input files so judges see the cross-finding context when confirming/upgrading/downgrading severity.
Subagent watchdog: every run_in_background=true spawn in this skill (severity judges, coordinator summaries, batched pass-2 judges) MUST be armed with a staleness monitor per _shared/subagent-watchdog.md. Use Flavor A (Monitor tail per spawn) with thresholds STALE=3 min, HUNG=10 min for Haiku judges and summaries — these are short-running tasks and a 30-min quiet period is always pathological. TaskOutput status field is not evidence of progress; output-file mtime is. This contract adds timed_out_heartbeat to this skill's termination vocabulary (per-lane watchdog kill) and stalled_watchdog / hung_killed to per-lane state — see shared doc §"State schema additions" + §"Termination-label addition".
Adversarial judging (3 of 4 mechanisms adopted)
See _shared/adversarial-judging.md for the full pattern: blind severity protocol, mandatory author counter-response, rationalization auditor, falsifiability drop.
Current deep-qa adoption status:
| Mechanism | Adopted? | Location |
|---|
| Independent judges (baseline) | ✅ yes | Severity classification is delegated to independent Haiku batches in Phase 3 step 10. |
| Blind severity protocol (two-pass) | ✅ yes | Phase 3 step 10 strips critic-proposed severity before pass-1 judge spawn; Phase 5.5.b runs pass-2 informed judges that may confirm/upgrade/downgrade; calibration signal logged if confirm rate is 0% or 100%. |
| Mandatory author counter-response | ✅ yes | Critic template requires an Author counter-response field — if the critic cannot write a plausible defense, the defect is filed as a minor observation instead of a defect. |
| Rationalization auditor | ✅ yes | Phase 5.6 spawns an independent auditor before final synthesis; REPORT_FIDELITY|compromised triggers re-assembly from judge verdicts only; two failures → "Audit compromised — report re-assembled from verdicts only" label. |
| Falsifiability drop (not downgrade) | ❌ no | deep-qa's nitpick filter downgrades unfalsifiable concerns to minor notes rather than dropping them. Intentional divergence — user chose to keep this behavior when adopting the other three mechanisms. See _shared/adversarial-judging.md §4 for the pattern this skill deliberately departs from. |
Cross-Model Critic Lanes
When --cross-model is passed (or always in --auto mode for diff-mode QA), deep-qa spawns additional critic lanes through an OpenAI-compatible endpoint using non-Claude model families. This provides cross-model diversity — findings confirmed independently by different model families have the highest confidence.
Architecture: Cross-model critics run alongside normal Sonnet subagents. They receive the same angle files and artifact content. Their findings merge into the same dedup pipeline.
Model selection:
- GPT lane:
gpt-5.4-pro via OpenAI-compatible endpoint
- Gemini lane:
gemini-3.1-pro-preview via OpenAI-compatible endpoint
- Set
CRITIC_BASE_URL and CRITIC_API_KEY env vars (falls back to OPENAI_BASE_URL / OPENAI_API_KEY)
When cross-model critics run:
- Default: always (all modes) — cross-model diversity is on by default
--no-cross-model flag: skip cross-model lanes entirely
Cross-model critic allocation per round:
- Of the 8 critic slots per round, allocate up to 2 for cross-model lanes (1 GPT, 1 Gemini)
- Cross-model critics get the highest-priority angles from the frontier
- Remaining 6 slots run normal Sonnet subagents on the remaining angles
Implementation: Each cross-model critic is spawned as a Bash tool call running a Python script:
python3 ~/.claude/skills/deep-qa/scripts/cross-model-critic.py \
--angle-file deep-qa-{run_id}/angles/{angle.id}.md \
--artifact-file deep-qa-{run_id}/artifact.md \
--output-file deep-qa-{run_id}/critiques/{angle.id}-{model}.md \
--model gpt-5.4-pro \
--angle-id {angle.id} \
--dimension {angle.dimension} \
--mode {artifact_type} \
--known-defects-file deep-qa-{run_id}/known-defects.md
The script accepts --mode (code/doc/research/skill/security) and tailors both the system prompt and output format to the artifact type. Output is FORMAT.md-compliant — same **QA Dimension:** headers and ### Defect: structure as Sonnet critics — so Phase 3 dedup and synthesis consume it without transformation.
Script location: ~/.claude/skills/deep-qa/scripts/cross-model-critic.py
Cross-model weighting in dedup (Phase 3 step 7):
When deduplicating findings, apply this weighting:
| Signal | Confidence | Action |
|---|
| Same finding from 2+ different model families (e.g., Sonnet + GPT-5.4-pro) | Highest | Preserve at highest proposed severity; tag cross_model_confirmed |
| Same finding from 2+ Sonnet critics (same family) | High | Normal dedup — merge at highest severity |
| Single cross-model finding not confirmed by any Sonnet critic | Standard | Verify normally; flag as cross_model_unique for extra attention in synthesis |
| Single Sonnet finding | Standard | Normal processing |
Add cross_model_confirmed and cross_model_unique tags to defect entries in state.json. In Phase 6 synthesis, highlight cross-model-confirmed findings prominently.
Cost: Cross-model adds ~$0.10-0.30 per critic round (2 additional model calls), ~$0.05 for forcing-function blind-spot discovery, ~$0.10 for pass-2 severity judge, ~$0.05 for rationalization auditor. Total run cost increase: ~30-50% (enabled by default).
Failure handling: If a cross-model API call fails (timeout, model unavailable, auth error), log the failure and continue with Sonnet-only critics for that round. Cross-model lanes are supplementary — never block the run.
Artifact Types
| Type | Applies to | Required QA Categories |
|---|
doc | specs, design docs, RFCs, API docs, architecture docs | completeness, internal_consistency, feasibility, edge_cases |
code | source code, system architecture descriptions | correctness, error_handling, security, testability, temporal_coupling |
research | research reports, literature reviews, deep-research outputs | accuracy, citation_validity, logical_consistency, coverage_gaps |
skill | Claude skills, system prompts, agent specs, tool instructions | behavioral_correctness, instruction_conflicts, injection_resistance, cost_runaway_risk |
See DIMENSIONS.md for full dimension tables and angle examples.
Workflow
Phase 0: Input Validation Gate
--verify mode (pre-completion evidence gathering)
When --verify is present, deep-qa runs in verification mode instead of adversarial review. This is the lightweight "prove it works" check before claiming completion.
Step 0a-verify — Discover execution environment:
Before running any tests, probe the project for its actual Python/test environment. Do NOT use bare python/python3 — projects with tox, venvs, or multi-environment setups may have the correct interpreter in a non-obvious location. Discovery order:
- Check for
tox.ini / setup.cfg [tox] — if present, look for .tox/*/bin/python interpreters
- Check for
.venv/, venv/, or project-specific venvs (e.g., test/*/.tox/py/bin/python)
- Check
pyproject.toml for build system / test runner config
- If multiple venvs exist, use the one that matches the changed code's test suite
- Record the chosen interpreter path in the verification report
Step 0b-verify — Gather evidence:
- Identify what must be proven: what behavior changed? What should work now?
- Run verification in priority order, using the discovered interpreter:
- Existing tests (
{interpreter} -m pytest, tox, test suite) — prefer narrowest relevant subset
- Type check / build (
mypy, tsc, cargo check, etc.)
- Narrow direct commands (import check, smoke test, curl endpoint)
- Manual validation steps if automation insufficient
- Collect results: what passed, what failed, what's unverified.
Step 0b-verify-mutation — Mutation testing (conditional):
After step 0b-verify confirms tests pass (green baseline), run mutation testing to verify tests actually catch meaningful failures:
- Gate: Only run if ALL of: (a) tests passed in step 0b, (b) test files exist for the changed code, (c) artifact type is
code, (d) --depth=quick is NOT set.
- Invoke: Spawn the
mutation-test skill as a background agent targeting changed files. Pass a 3-minute total budget. The skill measures baseline test duration, generates mutations prioritized by severity (business_logic + concurrency first), and runs each within an adaptive timeout (3× baseline).
- Consume structured records: Read the structured result records from mutation-test (not the markdown report). Only
survived status records become verification gaps. Other statuses map to caveats:
survived with scope: changed → Unverified ⚠️ as "Tests pass but don't catch: {description}"
survived with scope: adjacent_unchanged → Unverified ⚠️ as "Pre-existing test gap (not introduced by this change): {description}"
killed / timeout → Verified ✅ (tests caught the mutation)
skipped_budget / baseline_failed / no_tests → Verification Caveats (not defects)
- All mutations killed → Verified ✅ as "Mutation testing: {N}/{N} mutations killed"
- Verdict impact: Surviving mutations with
scope: changed in business_logic or concurrency categories downgrade verdict from verified to partially_verified. Surviving mutations with scope: adjacent_unchanged are noted but don't downgrade the verdict — they are pre-existing gaps.
Step 0c-verify — Report:
Output a verification report:
## Verification Report
### Verified ✅
- {what passed and how}
- Mutation testing: {K}/{N} mutations killed
### Failed ❌
- {what failed and the error}
### Unverified ⚠️
- {what couldn't be checked and why}
- {surviving mutations from mutation-test, if any}
### Verdict
{verified | partially_verified | failed}
Do NOT claim completion if any critical path is unverified. If no realistic verification path exists, say so explicitly. Then stop — --verify mode does not run adversarial critics.
--diff mode (fast post-commit QA)
When --diff [ref|range] is present, the artifact is built from the git diff rather than a full file. This costs ~10% as much as a full-repo QA and catches regressions in the changed code and its immediate callers.
Ref parsing: If the argument contains .. (e.g., b0228a0c6..HEAD, master..feature), treat it as a commit range — use git diff {A} {B} and git log --oneline {A}..{B}. This enables reviewing a SUBSET of a branch (e.g., "only the last 4 bug-fix commits, not the whole PR"). If no .., treat as a single ref and diff against HEAD as before.
Step 0a-diff — Build diff artifact:
- Run
git diff {ref} (or git diff {A} {B} for ranges) — include ALL tracked files, not just *.py. Frontend code (.svelte, .tsx, .ts, .js, .vue), templates, SQL, proto files, YAML manifests, and JSON fixtures are routinely consumers of data contracts that Python code changes, and must be in scope. (Previously this step filtered to *.py, which caused UI/frontend defects in multi-language projects to be invisible to diff-mode QA.)
- If diff is empty: error "No changes found between HEAD and {ref}" (or "between {A} and {B}").
- Extract changed files from the diff header lines (
--- a/..., +++ b/...).
- For each changed file, find callers of any added/modified function or method:
- Use
grep -rn "def <name>" <changed_file> to extract function names from + lines
- Use
grep -rn "<name>(" --include="*.py" to find call sites in the repo
- Include the call-site file + ±10 lines of context for each hit (cap at 5 callers per function, 20 functions total)
- Build
artifact.md with three sections:
# Diff QA Artifact
## Ref: {ref} → HEAD
## Changed files: {list}
## Section 1: The Diff
{full git diff output, unified format}
## Section 2: Caller Context
{per-function: function name, callers found, relevant snippets}
## Section 3: Pre-existing behavior (for context only)
{unchanged surrounding code ±20 lines for each changed hunk}
- Size check: same as normal mode (~80k token warning).
Automatic angle seeding in diff mode — in addition to normal dimension angles, always add these high-priority angles before round 1:
- "Legacy-symbol sweep (MANDATORY, CRITICAL priority). Enumerate every pre-change name, string literal, dict key, constant, attribute, env var, or magic value that this PR is replacing (e.g. old function names, hardcoded strings like
\"start\"/\"end\", old config keys, old sentinels). Then grep -rn the entire repository — NOT just changed files — for each one. For every remaining occurrence, classify as: (a) correctly updated in this PR, (b) legitimate legacy-compat path with a documented fallback, (c) stale docstring/comment referencing the old contract, or (d) a MISSED UPDATE. Report every (c) and (d). This angle must spawn its own critic; do not fold it into another dimension. Missed updates in unchanged files are the highest-impact latent defects and they are invisible to diff-scope review."
- "Contract fanout audit (MANDATORY, CRITICAL priority whenever the PR changes ANY named or shared contract). A contract here is anything that connects code that changes to code that doesn't: an API signature, a data-shape (dict keys, schema fields, enum values, wire format), a calling convention (how a command is invoked, how a process re-enters itself, how a handler is registered), a named symbol used as an identifier, a protocol, or a configuration key. For every changed contract: (1) enumerate every producer of the contract — every place that emits, constructs, serializes, or writes the contract value; (2) enumerate every consumer — every place that parses, reads, introspects, or renders it; (3) scope the search across the ENTIRE artifact surface — every file, every language, every format the repo contains — not just the files the diff touches and not just the language the diff is written in; (4) for each location classify as: correctly updated / legitimate legacy-compat with documented fallback / stale docstring-comment-message / MISSED UPDATE, and report every stale and missed as separate defects. This principle specializes to many concrete patterns depending on the contract — for illustration only: if the contract is how subprocesses re-enter an entrypoint, producers are every command-builder across orchestrators/runtimes/sidecars/CLI-wrappers; if the contract is the shape of a persisted artifact, consumers include every reader across languages (frontend UIs, generated types, schemas, views, fixtures, dashboards); if the contract is a named identifier used as a dict key, both producers and consumers span the repo. The failure mode being defended against is that refactors reliably update the two or three closest-to-hand producers and consumers and miss the rest — that set of 'the rest' is where the highest-leverage latent defects live. Adapt the concrete search to the actual contract under review; the invariant is the breadth, not any specific command. Reasonable starting points are grep-based symbol searches, git-log-based caller traces, and type/schema-tool searches; if the artifact has non-text components (binaries, generated files), note the gap explicitly rather than skipping."
- "Docstring / comment contract consistency. Grep for docstrings, inline comments, and user-facing error messages that reference the OLD contract by name. For a PR making a backward-compat claim, docstrings that still say
run['end'] when end steps can now be renamed ARE user-facing defects — they mislead readers who trust documented contracts. File as minor but DO file."
- "For every new conditional expression in the diff (
if, elif, while): what are the False/empty/None/zero branches? Are they all safe?"
- "For every changed function signature or return type: do all callers handle the new contract?"
- "For every attribute, return value, or method that the PR newly makes
Optional[X] (previously always non-None): grep every consumer in the repo and verify each handles None without crash, KeyError, or silent wrong-behavior. Do not assume lint or validation catches it earlier — audit the consumer's code."
- "For every new subprocess, file handle, network connection, or lock opened in the diff: is it always closed/drained/released on all exit paths?"
- "For every security-sensitive path touched (auth, subprocess args, file paths, serialization): what are the injection/bypass edge cases introduced by the change?"
- "Fix-regression analysis (MANDATORY when the diff description or commit message contains 'fix', 'revert', 'narrow', 'restrict', or 'drop'). For every fix in the diff: (1) identify the ORIGINAL motivation — what use case or behavior was the pre-fix code serving? (2) Verify the fix doesn't re-break that original use case. A common pattern: code was widened to support case X, the widening caused a regression in case Y, the fix narrows the scope back — but now case X is broken again. Trace both the forward path (does Y work now?) and the backward path (does X still work?). If the fix strips, removes, or conditionally gates something, ask: what OTHER code paths relied on the stripped/removed/gated thing?"
- "Papers-over-vs-root-cause check (MANDATORY when the diff is a bug fix). For each fix: does it address the stated root cause, or does it suppress the symptom? Signs of papering over: adding a filter/skip/guard at the consumer instead of fixing the producer, catching an exception instead of preventing the condition, stripping a value instead of not setting it in the first place, adding a conditional that avoids the crash path without fixing why the crash path is reachable. If the fix papers over, file as major — the underlying bug still exists and will resurface in a different form."
- "Structural-twin sweep. After identifying a bug the diff fixes,
grep -rn the entire repo for structurally identical patterns — same missing guard, same hardcoded value, same env-var leak, same unhandled Optional. The fix addresses ONE instance; the question is whether other instances of the same bug pattern exist in untouched files. File each twin as a separate defect. This is distinct from contract-fanout (which traces consumers of a changed contract) — structural-twin traces the BUG PATTERN, not the contract."
- "Checkpoint/ordering analysis for env vars and subprocess state. For every environment variable, config value, or mutable process state that the diff adds, removes, strips, or conditionally sets: trace its lifecycle across ALL subprocess spawns in the file and its callers. Verify: (1) the value is present BEFORE every subprocess that needs it, (2) the value is absent AFTER every subprocess that should NOT inherit it, (3) the ordering is correct — stripping happens after the last legitimate consumer and before the first illegitimate inheritor. Common defect: env var is stripped in one code path but still inherited via a different subprocess spawn mechanism (e.g.,
Popen vs run, local vs remote executor, direct spawn vs decorator-mediated spawn)."
- "Resource exhaustion / liveness audit (MANDATORY when the diff adds subprocess.run, Popen, HTTP calls, or retry loops). For every
subprocess.run/Popen/requests.get/urlopen/grpc call: verify a timeout= parameter is set. For every retry/polling loop: verify a max-retry cap exists. For every open()/connect() without a context manager: verify cleanup on all exit paths. A missing timeout means the error-handling path is unreachable for the hang failure mode — the process blocks forever and the caller's except clause never fires. File missing timeouts as major when the call targets an external service (S3, HTTP, gRPC) and minor for local operations."
- "Cross-method consistency audit (MANDATORY when the diff modifies a value that is independently computed in multiple methods). For every semantic value computed in a changed method (rootdir, env dict, path prefix, config key, normalization result):
grep -rn the same variable name across ALL methods in the file and its callers. If two methods independently derive the same value (e.g., one captures repo_root before a chdir, another uses os.getcwd() after), verify they produce identical results in all execution contexts. Locally-correct methods that silently disagree are invisible to single-function review and are the root cause of mode-dependent bugs (works in PR mode, fails in baseline-gen mode)."
- "Cross-file orchestration sequencing audit (MANDATORY when the diff changes 2+ files that are composed by a caller/orchestrator). Identify every function, script, or pipeline that SEQUENCES the changed files — bootstrap command builders, pipeline definitions, Makefile targets, shell scripts that source/call the changed files in order. Open each orchestrator even if it is NOT in the diff. For each pair of changed files (A, B) where A produces state (env vars, files, config) that B consumes: verify A runs BEFORE B in the orchestrator's sequence. The failure mode: each file's change is correct in isolation, but the orchestrator runs the consumer before the producer, so the consumer inherits stale/dirty state. Concrete pattern: file A cleans up an env var, file B shells out to a subprocess that needs a clean environment — but the orchestrator runs B first, then A. This is the 'file-local review without call-site composition' class of bug (missed in PR #1800 --env-file argv ordering, PR #1850 PYTHONHOME bootstrap sequencing). To find orchestrators: grep for import/call sites of changed functions, trace callers that invoke MULTIPLE changed files, check for command-list builders that return ordered sequences of operations."
- "Environment isolation audit (MANDATORY when the diff constructs an env dict for subprocess execution).
grep -rn 'os\\.environ' in every file the diff touches. For each hit: verify the code reads from the *prepared* env dict (the one passed to subprocess.run(env=...)) rather than from os.environdirectly.os.environ.get()in a method that receives or constructs a customenvdict is almost always a bug — it re-injects the ambient environment, defeating the isolation the dict was built to provide. Also check: does the prepared dict inherit fromos.environ.copy()` or from a clean builder function? If the former, verify that unwanted vars are explicitly popped."
artifact_type in diff mode: Default to code. Override with --type as normal.
--diff + --auto: Fully unattended — runs with defaults, no gates.
Print: Starting deep QA on: diff {ref}..HEAD ({N} files changed) [type: code] [run: {run_id}]
After building the diff artifact, proceed to Phase 1 as normal. The artifact IS the diff + context; the workflow is identical.
Step 0a — Read artifact (normal mode, when --diff is NOT present):
- If argument is a file path: read file, write contents to
deep-qa-{run_id}/artifact.md
- If argument is inline content: write to
deep-qa-{run_id}/artifact.md ⚠️ inline content is silently truncated at context limit — warn user if content appears large
- If empty or inaccessible: error
- Size check: After writing, check approximate token count. If artifact.md exceeds
80k tokens: warn "Artifact is large ({N} tokens). Haiku critics (depth 2+) may only see part of it." If --auto: proceed with warning. If interactive: ask "Continue? [y/N]"
Step 0b — Artifact type detection:
- If
--type is provided: use it as authoritative, skip content inference, skip ambiguity prompt. Store artifact_type = --type in state.json.
- If
--type not provided: infer from content (file headers, structure, terminology — see DIMENSIONS.md). If ambiguous: "I'm interpreting this as type=[X] because [2-3 evidence signals]. Correct? [y/N/type:doc|code|research|skill]" (skip prompt if --auto).
- Store
artifact_type in state.json.
Multi-file discovery (after type is determined):
- If
artifact_type == "skill" AND argument was a file path: check the parent directory for companion files matching DIMENSIONS.md, FORMAT.md, STATE.md, SYNTHESIS.md.
- If companion files exist: concatenate all into
artifact.md (SKILL.md first, then companions alphabetically). Show Files in scope: [list] in the pre-run scope declaration.
- If
--auto and companions found: include them automatically.
Step 0c — Safety check:
- If artifact contains credentials, tokens, or PII: warn user before passing to subagents
- If artifact requests harmful functionality: decline
Print: Starting deep QA on: {artifact_name} [type: {artifact_type}] [run: {run_id}]
Phase 1: Dimension Discovery (see DIMENSIONS.md)
- Select QA dimensions from DIMENSIONS.md based on
artifact_type
- Generate 2-4 critique angles per dimension + 2-3 cross-dimensional angles
- Required categories per type must each get at least one angle (CRITICAL priority if uncovered after round 1)
- Cap frontier at 30 angles total
Pre-run scope declaration (show before proceeding; skip entirely if --auto):
Deep QA: "{artifact_name}"
Artifact type: {artifact_type}
Files in scope: {list of files included in artifact.md}
QA dimensions ({N}): {list}
Initial angles: {count}
Suggested max_rounds: {recommendation}
Hard stop: {recommendation * 2} rounds (non-overridable)
Wall-clock estimate: {time range}
Invocation: {interactive | automated (--auto)}
Set max_rounds [default {recommendation}]: _
Continue? [y/N]
If --auto: use recommended max_rounds automatically, do not show this prompt.
max_rounds recommendation formula:
initial_angles = count of angles in Phase 1
min_rounds = ceil(initial_angles / 8) # 8 agents/round
recommended = ceil(min_rounds * 1.3) # 30% expansion from agent-discovered sub-angles
recommended = max(recommended, 3) # never suggest < 3 rounds
recommended = min(recommended, 6) # cap at 6 for typical artifacts
if auto_mode:
recommended = min(recommended, 2) # --auto caps at 2 to reserve budget for synthesis
Why cap --auto at 2 rounds: Round 3+ rarely discovers critical new defects but adds ~33% more context, often causing truncation on complex artifacts before the skill reaches Phase 6 synthesis. Two rounds with 8 critics each (16 total critic passes) is sufficient for most artifacts. Interactive mode retains the higher cap since the user can manage the budget.
Phase 2: Initialize State
- Generate run_id:
$(date +%Y%m%d-%H%M%S)
- Create directory structure:
deep-qa-{run_id}/state.json — run state (see STATE.md)
deep-qa-{run_id}/critiques/ — one file per critique angle
deep-qa-{run_id}/angles/ — per-angle input files for critics
deep-qa-{run_id}/judge-inputs/ — per-defect input files for severity judges
deep-qa-{run_id}/artifact.md — copy of artifact content
deep-qa-{run_id}/forcing-function-angles.md — from Phase 1.5
deep-qa-{run_id}/qa-report.md — written at Phase 6
- Write lock file:
deep-qa-{run_id}.lock — verify write succeeded before proceeding
- Store
hard_stop = max_rounds * 2 in state.json — immutable after initialization
Phase 2.5: Forcing-Function Blind-Spot Discovery
Runs AFTER state initialization (Phase 2) and BEFORE round 1 (Phase 3). Extends the pre-mortem blind-spot seeding pattern (_shared/premortem-blind-spot-seeding.md) with three structural forcing functions adapted from deep-idea's generation mechanisms.
Purpose: The dimension table is static — it knows about correctness, security, etc. But each artifact has domain-specific defect categories that the table doesn't cover. A billing service needs "business rule conformance"; a distributed system needs "partition tolerance"; a migration needs "rollback safety." The forcing functions structurally generate these domain-specific angles rather than relying on the dimension discovery agent to invent them from free association.
Agents: 1 Haiku agent + 1 cross-model agent (GPT-5.4-pro via cross-model endpoint), both run_in_background=false (block; outputs feed into round-1 frontier). Timeout: 60s each. On timeout: log FORCING_FUNCTION_TIMEOUT (per-agent), proceed with whichever completed. The skill runs fine without them — they are supplementary coverage, not load-bearing. Skip cross-model agent if --no-cross-model.
The cross-model agent receives the same prompt but produces genuinely different blind-spot angles due to different training data. Write its output to deep-qa-{run_id}/forcing-function-angles-cross-model.md. Merge both outputs into the round-1 frontier (dedup by angle similarity before inserting).
Cost: $0.10 total ($0.05 Haiku + ~$0.05 cross-model). Runs once per QA run. Skipped on resume if {run_id}/forcing-function-angles.md already exists.
Prompt template:
You are a blind-spot detector for a QA review. The artifact being reviewed is:
"{artifact_name}" [type: {artifact_type}]
The QA dimensions already selected for this artifact are:
{list of dimensions from Phase 1}
Your job is to find defect categories that those dimensions CANNOT catch, using three structural forcing functions. For each, generate 1-2 concrete QA angles.
**FORCING FUNCTION 1 — INVERSION**
For each selected dimension, ask: "What is the OPPOSITE failure mode that this dimension would never catch?"
- correctness checks for wrong outputs → what about correct outputs that violate business/domain rules?
- security checks for insufficient protection → what about excessive protection that locks out legitimate users?
- error_handling checks whether errors are caught → what about errors that are caught but provide no diagnostic context?
- performance checks for slowness → what about premature optimization that makes code unmaintainable?
Generate 1-2 inverted angles not covered by any existing dimension.
**FORCING FUNCTION 2 — CROSS-DOMAIN TRANSPLANT**
Ask: "What would a reviewer from a DIFFERENT discipline check that these dimensions miss?"
- What would an SRE check? (degraded-mode behavior, blast radius, observability)
- What would a DBA check? (rollback safety, lock duration, migration ordering)
- What would a UX researcher check? (API misuse likelihood, cognitive hazard in naming)
- What would a compliance auditor check? (license contamination, data retention, PII handling)
Generate 1-2 cross-domain angles specific to THIS artifact's domain.
**FORCING FUNCTION 3 — ASSUMPTION NEGATION**
List 3 assumptions this artifact makes, then negate each:
- "The artifact is self-contained" → what bugs exist in its interaction with adjacent systems?
- "The consumer is a competent senior engineer" → what would a junior developer get wrong?
- "The artifact's stated purpose is its actual use" → how is it actually consumed, and does it work for that?
Generate 1-2 assumption-negation angles specific to THIS artifact.
Output format — one angle per line, numbered:
1. [INVERSION] {concrete QA question} — Dimension: {new_dim_name or existing_dim} — Why: {1 sentence}
2. [CROSS-DOMAIN] {concrete QA question} — Dimension: {dim} — Why: {1 sentence}
...
Requirements:
- Each angle must be specific to THIS artifact, not generic. "Check for security issues" is useless. "Does the billing rounding logic match the business rule in the accounting spec?" is useful.
- Do NOT repeat angles already covered by the selected dimensions.
- 4-6 total angles. Quality over quantity.
- Write to: {forcing_function_path}
Coordinator action after agent completes:
- Read
deep-qa-{run_id}/forcing-function-angles.md
- Convert each listed angle to a round-1 direction with
priority=critical and source="forcing_function"
- These compete with dimension-derived angles in the frontier but get priority scheduling (same treatment as premortem angles)
- Tag each in state.json:
"source": "forcing_function", "forcing_type": "inversion|cross_domain|assumption_negation"
Combining with premortem: If the skill also runs the premortem pattern (Phase 0e), both sets of angles merge into the round-1 frontier. Premortem angles target "how this run could go wrong" (meta-level); forcing-function angles target "what defect categories the dimension table misses" (content-level). They are complementary.
--auto behavior: Forcing-function discovery runs in --auto mode (it's cheap and improves coverage). Skip only if --fast or explicit --skip-forcing-functions flag.
Phase 3: QA Rounds
Hard stop check (fires BEFORE prospective gate, every round, unconditionally):
if current_round >= state.hard_stop:
→ terminate immediately; no prompt; no extension offered
→ label: "Hard stop at round {hard_stop}"
→ proceed directly to Phase 4/Phase 5.5/Phase 6
This check cannot be bypassed. Extensions update max_rounds but never hard_stop.
Prospective gate (fires after hard stop check; skipped if --auto):
About to run QA Round {N}: {frontier_size} angles queued
Critics this round: up to 8 | Potential judge agents: up to {frontier_pop × 5}
Estimated cost: ~${critics_cost + judges_cost + summary_cost} ({running_total} spent so far)
Continue? [y/N/redirect:<focus>]
- If N: stop → label:
"User-stopped at round N"
- If redirect: add high-priority angle targeting the specified focus, then proceed
- Skip if
--auto
Per round:
- Pop up to
max_agents_per_round (8) highest-priority angles from frontier; enforce frontier cap (see STATE.md)
- Write all required data to files BEFORE spawning, then verify each write (file exists + non-empty):
- Known defects file:
deep-qa-{run_id}/known-defects.md
- Angle files:
deep-qa-{run_id}/angles/{angle.id}.md
- If any verification fails: halt with error, do not spawn
- Batch state update: Write
status: "in_progress" and spawn_time_iso for ALL angles in a single state.json write. Re-read state.json and verify generation == N+1. If mismatch: log conflict, retry once with fresh read, then halt.
- Spawn ALL critics in a SINGLE message — emit all tool calls in one response so they run concurrently (120s timeout). Unless
--no-cross-model is passed, the message contains a mix: up to 6 Agent tool calls (Sonnet critics) + up to 2 Bash tool calls (cross-model critic scripts). Each agent reads its own angle file; you do NOT need to read angle files before spawning. Do NOT read files, check state, or do any work between tool calls — the entire set must be in one turn. Sequential one-at-a-time spawning is a workflow violation.
- On timeout: mark
timed_out, write "generation": += 1, do NOT re-queue, do NOT increment dedup counter
- Collect new angles from ALL completed agents BEFORE running dedup
- Apply dedup against stable pre-round snapshot. Assign
depth = parent.depth + 1 to each critic-reported angle. Reject angles where depth > max_depth. Enforce frontier cap with required-category protection (see STATE.md).
- For each new defect: Dimension cross-check (synchronous): verify the critique file's declared
**QA Dimension:** header matches the angle's assigned dimension in state.json. If mismatch: flag as potential injection, do NOT set required_categories_covered.{category} true. Create defect in state.json with critic-proposed severity and judge_status: "pending".
- Run coverage evaluation: read
required_categories_covered from state.json (not coordinator-summary.md). For any uncovered required category: generate CRITICAL-priority angle. Write "generation": += 1 after updating coverage_gaps and rounds_without_new_dimensions.
- Background severity judges (pass-1 blind): Batch new defects into groups of up to 5. For each batch: write combined defect data to
deep-qa-{run_id}/judge-inputs/batch_{round}_{batch_num}.md with the critic-proposed severity STRIPPED from each defect entry (blind-severity protocol; see _shared/adversarial-judging.md §1). Then spawn a single Haiku severity judge agent with run_in_background=true (see SYNTHESIS.md for batched judge prompt). Record batch in background_tasks.judges in state.json with pass: 1. Each defect gets a judge_pass_1_verdict field once the batch completes.
- Background coordinator summary: Spawn Haiku subagent with
run_in_background=true to write a cumulative coordinator summary (see SYNTHESIS.md). Record in background_tasks.summaries in state.json.
- Increment round → immediately proceed to next round's step 1 (do not wait for background tasks)
MANDATORY CONTINUATION: After collecting all critic results for any round, you MUST continue — either to the next round's step 1 (if rounds remain) or to Phase 5 termination check (if this was the last round). Producing an empty response or ending the turn after critic collection is a workflow violation. The skill is not complete until Phase 6 writes qa-report.md.
Pipelining rationale: Severity judges and coordinator summaries are reporting artifacts consumed only in Phase 6. They do not affect angle selection, dedup, or coverage evaluation. Running them in the background while the next round's critics execute hides their latency entirely.
Mutation testing lane (empirical TESTABILITY — Round 1 only):
When ALL of: (a) artifact_type == "code", (b) test files exist for the artifact's target files, (c) --no-cross-model is NOT set, (d) --depth=quick is NOT set — spawn a mutation-test background agent in Round 1 alongside the first critic batch:
- Spawn: In the same single-message critic spawn (step 4), include an additional Agent call that invokes the
mutation-test skill targeting the artifact's source files. Pass total budget of 3 minutes. The agent runs independently and writes structured result records to deep-qa-{run_id}/mutation-results.json.
- Collect: Drain the mutation-test agent at Phase 5.5 (alongside pass-1 judges). Do NOT wait for it during rounds.
- Ingest structured records into state.json: Only records with
status: "survived" become defect entries. All other statuses are verification metadata, not defects.
survived + scope: changed → defect in state.json with dimension: "TESTABILITY", source: "mutation-test", judge_status: "pre-judged". Severity: critical only when category is business_logic or concurrency; otherwise major.
survived + scope: adjacent_unchanged → defect with severity: "minor", excluded from autopilot's fix loop. Pre-existing gap not introduced by this change.
survived + scope: unrelated → do NOT create a defect. Report in a low-noise appendix only.
killed, timeout → not defects. timeout means the mutation was detected (tests couldn't finish = breakage caught).
skipped_budget, baseline_failed, no_tests → verification caveats logged in state.json metadata, not defects.
- Report: Include mutation-test results as a subsection in the Phase 6 final report under TESTABILITY findings. Separate
changed-scope findings (actionable) from adjacent_unchanged (informational).
- Skip gracefully: If mutation-test agent times out, fails, or finds no test files, log and continue — the lane is supplementary.
No redesign phase. Defects are catalogued with severity; status remains open unless disputed by validation.
Phase 4: Fact Verification (research artifacts only)
For artifact_type == "research", run before final synthesis. Skip entirely for other types.
- Spawn Haiku verification agent
- Extract top-N factual claims (N = min(20, total claims found))
- Risk-stratified sampling: single-source primary → numerical/statistical → contested → corroboration candidates
- Spot-check citation URLs: accessible? attributed claim present in source text?
- For numerical claims: compare EXACT numbers — flag mismatch even if semantically similar
- Output:
deep-qa-{run_id}/verification.md
- See SYNTHESIS.md for full protocol
Phase 5: Termination Check
Note: The hard stop check at the start of Phase 3 fires unconditionally before this check is evaluated. All labels below apply to paths that reach Phase 5.
Any-of-4 — evaluate in order, stop when FIRST is true:
- User-stopped: User chose N at a prospective gate → label:
"User-stopped at round N"
- Coverage plateau:
rounds_without_new_dimensions >= 2 AND all explored angles in state.json have exhaustion_score >= 4 → label: "Coverage plateau — frontier saturated"
- Budget soft gate:
current_round >= max_rounds with non-empty frontier. Show gate (skip if --auto):
Budget limit reached (max_rounds={N}). Frontier still has {M} unexplored angles.
Hard stop at round {hard_stop} — remaining headroom: {hard_stop - current_round} rounds.
Options: [y] Extend by {min(recommended, hard_stop - current_round)} more rounds [+N] Custom [n] Stop
- Extension validation: cap any extension at
hard_stop - current_round; reject extensions that would reach or exceed hard_stop
- User chooses n → label:
"Max Rounds Reached — user stopped"
- User extends → update
max_rounds, continue; hard_stop is NOT updated
--auto: stop immediately → label: "Max Rounds Reached"
- Frontier empty: evaluate "Conditions Met" check below
"Conditions Met" check (only when condition 4 fires):
- Read
required_categories_covered from state.json
- ALL three must be true: (1) frontier empty, (2) all required categories covered, (3)
rounds_without_new_dimensions >= 2
- All true → label:
"Conditions Met"
- Any false → label:
"Convergence — frontier exhausted before full coverage" (list uncovered required categories in report)
Complete label vocabulary — all reachable paths:
| Label | When |
|---|
"Conditions Met" | Condition 4 fires + all-3 satisfied |
"Coverage plateau — frontier saturated" | Condition 2 |
"Max Rounds Reached — user stopped" | Condition 3 + user n |
"Max Rounds Reached" | Condition 3 + --auto |
"User-stopped at round N" | Condition 1 |
"Convergence — frontier exhausted before full coverage" | Condition 4 + not all-3 |
"Hard stop at round N" | Phase 3 pre-check fires |
"Audit compromised — report re-assembled from verdicts only" | Phase 5.6 rationalization auditor reports REPORT_FIDELITY|compromised on two consecutive assemblies |
Never use a label not in this table. Never write "no defects remain."
Phase 5.4: Budget Gate (fast-finish check)
Before entering the expensive post-processing pipeline (drain → coherence → pass-2 → audit → synthesis), check whether enough budget remains to complete it. A truncated session with no final report is strictly worse than a complete report with degraded severity calibration.
Budget pressure signals — if ANY are true, enter fast-finish mode:
- Round count ≥ 3 in
--auto mode (should not happen with the cap, but defensive)
- Total defects found > 15 AND current round ≥ 2 (many findings = large context from critic outputs)
- Context compaction has occurred (the coordinator observes a
context_management event or notices prior conversation history is missing/summarized)
Fast-finish mode — when triggered, set state.json.fast_finish = true and:
- DO drain pass-1 blind judges (Phase 5.5.a) — they're already running, just collect results
- SKIP Phase 5.5.a-coherence (cross-finding coherence integrator)
- SKIP Phase 5.5.b (pass-2 informed judges) — use pass-1 verdicts as final
- SKIP Phase 5.6 (rationalization audit)
- Proceed directly to Phase 6 with pass-1 judge verdicts and critic-proposed severities as fallback for any unjudged defects
- Add caveat to final report: "Budget-constrained run: pass-2 severity calibration and rationalization audit were skipped. Severity ratings are pass-1 blind verdicts only."
Termination label addition: "Budget-constrained completion" joins the label vocabulary when fast-finish fires. This label is appended to the normal termination label (e.g., "Max Rounds Reached — budget-constrained completion").
If none of the budget pressure signals fire, proceed normally to Phase 5.5.
Phase 5.5: Drain Background Tasks + Pass-2 Informed Severity
Before proceeding to Phase 5.6 (rationalization audit) and Phase 6 (final report), all background tasks from the pipelined rounds must complete, AND the blind-severity protocol must finish pass 2.
5.5.a — Drain pass-1 blind judges:
- Wait for ALL background severity judge batches (from
background_tasks.judges in state.json where status == "running" and pass == 1). Use TaskOutput with block=true for each.
- Wait for ALL background coordinator summaries (from
background_tasks.summaries). Use TaskOutput with block=true for each.
- Apply pass-1 judge results to state.json: For each completed judge batch, read the output file. For each defect classification:
- Parse the structured
DEFECT_ID / SEVERITY / CONFIDENCE / REASONING lines
- Store as
defects.{id}.judge_pass_1_verdict (do NOT yet overwrite defects.{id}.severity — pass 2 is authoritative)
- Set
defects.{id}.judge_status: "pass_1_completed"
- Write
"generation": += 1
- Handle pass-1 timeouts: If any pass-1 batch timed out, retain critic-proposed severity for those defects. Set
judge_status: "pass_1_timed_out". Log JUDGE_TIMEOUT_BACKGROUND_PASS_1: {defect_ids}.
5.5.a-coherence — Cross-finding coherence integrator (fires after pass-1 drain, before pass-2):
Per _shared/cross-finding-coherence.md:
- Collect all parseable critic output files from all rounds (post-dedup).
- Write integrator input manifest to
deep-qa-{run_id}/coherence/input-manifest.md containing: list of all critic output file paths, artifact path, known-defects path, dimension taxonomy.
- Spawn Sonnet coherence-integrator agent with the manifest. Output:
deep-qa-{run_id}/coherence/round-all-coherence.md. Timeout: 120s.
- Parse
STRUCTURED_OUTPUT block for FINDING|, GAP|, and PATTERN| lines.
- For each
FINDING|{id}|{annotation} line: attach annotation to defects.{id}.coherence_annotation in state.json. Write generation += 1.
- For each
GAP|{dim_a}|{dim_b}|{description}|{angle} line: create a CRITICAL-priority angle in the frontier for the next round (if rounds remain) or flag in the final report (if this is the last round).
- For each
PATTERN|{pattern_id}|{finding_ids}|{root_cause}|{severity_suggestion} line: store in state.json.emergent_patterns[] for Phase 6 final report.
- If integrator output is unparseable or timed out: log
COHERENCE_PARSE_FAILED or COHERENCE_TIMED_OUT. Proceed without annotations — pass-2 judges run normally (degraded mode). Flag in Phase 6 report.
- If
STANDALONE rate is 100% across 6+ findings: log COHERENCE_SHALLOW warning — include in Phase 6 caveats.
Why between pass-1 and pass-2: Pass-1 judges classify severity blind (without critic or cross-finding context). The integrator runs on critic output, not judge output — it identifies relationships between findings, not between severities. Pass-2 judges then receive BOTH the pass-1 verdict AND the coherence annotation, allowing them to upgrade severity for pattern-members or scrutinize contradicted findings.
5.5.b — Spawn pass-2 informed judges:
For each defect where judge_pass_1_verdict exists:
5. Write deep-qa-{run_id}/judge-inputs/batch_pass2_{batch_num}.md containing: the full defect (INCLUDING critic-proposed severity this time), the pass-1 verdict, any coherence annotation from Phase 5.5.a-coherence (contradiction/pattern/standalone status), and the pass-2 prompt asking the judge to confirm, upgrade, or downgrade with rationale. Coherence annotations give the judge cross-finding context: a PATTERN_MEMBER annotation suggests the judge should consider aggregate severity; a CONTRADICTS annotation suggests the judge should scrutinize the finding's evidence base.
6. Spawn Haiku judge (pass-2) with run_in_background=true. Record in background_tasks.judges with pass: 2.
6b. Cross-model severity judge (unless --no-cross-model): Additionally spawn 1 cross-model judge batch via cross-model endpoint (GPT-5.4-pro) covering the same defects. Write input to deep-qa-{run_id}/judge-inputs/batch_pass2_cross_model.md. Run via cross-model-critic.py with --mode set to the artifact type. The cross-model judge uses the same pass-2 prompt (confirm/upgrade/downgrade). Record in background_tasks.judges with pass: 2, source: "cross_model". When both Haiku and cross-model pass-2 verdicts exist for the same defect, apply majority rule: if they agree → use that severity; if they disagree → use the higher severity and tag cross_model_severity_split in state.json for transparency in the final report. Cost: ~$0.10 per run.
7. Wait for ALL pass-2 batches (Haiku + cross-model) with TaskOutput block=true.
8. Apply pass-2 verdict as authoritative: For each defect:
- Parse pass-2
SEVERITY / CONFIDENCE / RATIONALE / CALIBRATION (confirm|upgrade|downgrade)
- Set
defects.{id}.severity = pass-2 SEVERITY (authoritative — may differ from pass-1)
- Set
defects.{id}.judge_status: "completed"
- Record pass-2 verdict in
defects.{id}.judge_pass_2_verdict
- Write
"generation": += 1
- Calibration check: compute rate of
CALIBRATION == "confirm" across all pass-2 verdicts. If rate == 100% OR rate == 0%, log CALIBRATION_SUSPICIOUS: rate={rate} — the judge may be anchoring despite the blind protocol. Surface this in Phase 6 final-report caveats.
5.5.b2 — Aggregate severity assessment (after pass-2 completes):
After all pass-2 verdicts are applied, check for defect-density escalation:
- Group all defects by dimension.
- For any dimension with 5 or more minor defects, auto-generate an aggregate finding:
- Title: "Systemic quality issue in {dimension}: {count} minor defects indicate a pattern"
- Severity: major (density-escalated)
- Scenario: "While no individual defect in {dimension} is major, the accumulation of {count} minor issues means a consumer faces {count} independent judgment calls. The probability of getting all correct is low."
- Root cause: "Systemic underspecification / inconsistency in {dimension}"
- Mark as
source: "aggregate_escalation" in state.json (not a critic-filed defect)
- For compound defect interactions (from coherence integrator
COMPOUNDS_WITH annotations):
- If two findings are annotated
COMPOUNDS_WITH and their compound severity exceeds both individual severities, create a compound finding:
- Title: "Compound: {finding_a_title} + {finding_b_title}"
- Severity: the
emergent_severity from the annotation
- Scenario: the
interaction_mechanism from the annotation
- Mark as
source: "compound_escalation" in state.json
- The original findings remain — the compound finding is additional, not a replacement
5.5.c — Final state checks:
- Verify coordinator summary: Check that the final
coordinator-summary.md exists and is non-empty. If missing or empty: log SUMMARY_WRITE_FAILED: final, use the most recent non-empty summary.
- State invariant check: Verify no defect has
judge_status of "pending" or "pass_1_completed" (all should be completed or a timeout variant). If any remain, log error and retain critic-proposed severity for those defects.
Drain timeout: Wait up to 120s total for all background tasks in Phase 5.5. After 120s, proceed with whatever has completed — timeouts are handled gracefully per steps 4-6 and the step-11 invariant check.
Phase 5.6: Rationalization Audit
Before final report assembly, spawn an independent auditor to detect coordinator drift. The auditor reads judge verdicts and the draft summary; it does NOT evaluate defects themselves — it evaluates whether the coordinator's assembly reflects the verdicts honestly. See _shared/adversarial-judging.md §3 for the pattern.
5.6.a — Spawn auditor:
- Write auditor input file
deep-qa-{run_id}/judges/rationalization-audit-input.md containing:
- Path to
state.json (authoritative defect registry, with pass-2 verdicts)
- Paths to all pass-2 judge verdict files
- Path to the latest
coordinator-summary.md
- Expected report structure (severity-sorted registry; coverage table; caveats)
- Spawn TWO auditor agents in parallel (both fresh context — must NOT be any agent that participated in critique or judging):
- Haiku auditor (standard)
- Cross-model auditor (GPT-5.4-pro via cross-model endpoint, unless
--no-cross-model) — write input to deep-qa-{run_id}/judges/rationalization-audit-input-cross-model.md and run via cross-model-critic.py with --mode matching artifact type. The cross-model auditor provides genuine independence from the Claude model family that ran the coordinator, critics, and Haiku judges — catching coordinator drift that same-family auditors might share.
Both use the same prompt asking for structured output:
STRUCTURED_OUTPUT_START
ACCEPTANCE_RATE_{DIMENSION}|{rate} (one line per QA dimension; rate = pass-2 confirm % per dimension)
DEFECTS_TOTAL|{count from state.json}
DEFECTS_CARRIED|{count in draft summary}
DEFECTS_DROPPED|{count dropped before report}
SUSPICIOUS_PATTERNS|{list or "none"}
REPORT_FIDELITY|clean|compromised
RATIONALE|{one line}
STRUCTURED_OUTPUT_END
- Write outputs to
deep-qa-{run_id}/judges/rationalization-audit.md (Haiku) and deep-qa-{run_id}/judges/rationalization-audit-cross-model.md (cross-model).
5.6.b — Handle verdict:
- Merge auditor verdicts: If both auditors ran, apply conservative merge: if EITHER reports
compromised, treat as compromised. If both report clean, treat as clean. Tag cross_model_audit_agreement: true|false in state.json. Include both audit results in the final-report caveats.
- If
REPORT_FIDELITY|clean: proceed to Phase 6. Include audit result in the final-report caveats (for transparency).
- If
REPORT_FIDELITY|compromised (first failure):
- Halt current assembly. Log
AUDIT_COMPROMISED_1: {rationale}.
- Re-assemble: coordinator writes a new draft report strictly from pass-2 judge verdicts, with no summarization, combination, or softening. Every defect verdict becomes a report entry as-is.
- Re-run the auditor(s) with the re-assembled draft.
- If
REPORT_FIDELITY|compromised (second failure):
- Halt. Log
AUDIT_COMPROMISED_2: {rationale}.
- Terminate with label
"Audit compromised — report re-assembled from verdicts only" (see Phase 5 label table).
- Write the pass-2-only report to
qa-report.md with a prominent caveat at the top: "⚠️ Coordinator drift detected by rationalization auditor on two consecutive assemblies. This report is the mechanical assembly of judge verdicts without coordinator synthesis."
Auditor timeout: 120s. On timeout: treat as REPORT_FIDELITY|compromised (fail-safe to worst legal verdict).
Phase 6: Final QA Report
- Do NOT read raw critique files — use coordinator summary + mini-syntheses + state.json + Phase 5.6 audit result
- Spawn Sonnet subagent to write
deep-qa-{run_id}/qa-report.md (see FORMAT.md)
- After subagent completes: verify
qa-report.md exists and is non-empty.
- If missing or empty: re-spawn once.
- If still missing: write a minimal emergency report directly from state.json (defect list + coverage table + termination label). Log
SYNTHESIS_FALLBACK: emergency report generated from state.json.
- For
research type: include verification results from Phase 4
- Report includes: severity-sorted defect registry, disputed defects, cross-dimensional patterns (from Phase 5.5.a-coherence emergent patterns), coverage assessment, honest caveats, open issues,
files_examined list, invocation mode
- If coherence integrator ran: include a "Cross-Dimensional Patterns" section listing each emergent pattern with its member findings, shared root cause, and aggregate severity implication
- If coherence integrator was degraded (unparseable/timed-out): include caveat: "Cross-finding coherence analysis unavailable — findings were judged independently without cross-finding context"
Model Tier Strategy
| Tier | Model | Used for |
|---|
| Coordinator | (main session) | Orchestration, gap detection, state management |
| Researcher | sonnet | Depth-0 and depth-1 high-priority critic angles |
| Scout | haiku | Depth-1 medium, depth-2+, coordinator summaries, severity judges, verification |
| Synthesis | sonnet | Final QA report |
Tier selection (same logic as deep-design):
if depth == 0: → Researcher (sonnet)
elif depth == 1 and priority == "high": → Researcher (sonnet)
else: → Scout (haiku)
Numeric-precision override (MANDATORY — deterministic-tool protocol): Any critic task whose success depends on exact counting, tallying, recount-against-claim, or aggregating numerical results from an API response, JSON array, or structured list MUST use a deterministic tool (jq, wc -l, grep -c, SQL COUNT(*)) applied to a file on disk — NOT eyeball-counting, NOT prose-estimation, NOT "let me list them out" loops. Model tier does not save you here: empirical failures observed on Haiku, Sonnet, AND Opus 4.7 when asked to count 100-item JSON arrays inline. They all confabulate plausible totals after scrolling; off-by-5-to-50 errors occur silently and propagate into the report as "verified" numbers.
Required protocol for any numeric verification step:
- Fetch the data via tool (JQL,
gh api, etc.) — full response into agent context.
Write the entire response verbatim to a path (e.g., /tmp/count-<subject>-p<N>.<ext>). Do NOT summarize before writing — the file contents are the ground truth.
- If paginated (
isLast: false, next_page_token, Link: next, etc.), fetch the next page, write to p2, p3, ... until the API reports the last page.
Bash with the counting tool that matches the file shape (see Counting-substrate hierarchy below). Sum across pages via awk '{s+=$1} END {print s}'.
- Report only the integer from step 4. No prose, no narrative count, no re-derivation from memory.
Agent prompts for counting tasks MUST include the literal instruction: "DO NOT count by reading. Use a deterministic tool." File-size variance (full 30KB response vs. summarized 3KB) does not affect correctness — the tool counts the anchor pattern regardless of whether inner objects are intact.
Counting-substrate hierarchy (pick the first that matches the artifact shape):
| Shape | Tool | Example |
|---|
| JSON array | jq '.<path> | length' | jq '.issues | length' resp.json |
| JSONL (one object per line) | wc -l | wc -l < resp.jsonl |
| Markdown table rows | awk '/^|/{c++} END{print c-2}' (subtract header + separator) | awk '/^|/{c++} END{print c-2}' report.md |
| Bulleted / numbered list | grep -cE '^[[:space:]]*([-*•]|[0-9]+\.)' file.md | — |
| HTML table rows | pup 'tr' -p | grep -c '<tr>' or xmllint --xpath 'count(//tr)' file.html | — |
| CSV/TSV | wc -l (minus header) or awk -F, 'END{print NR-1}' | — |
| Delimited blob (commas, pipes) | tr ',' '\n' | wc -l | — |
| Line-per-item text | grep -c <anchor> where anchor uniquely marks each item | grep -cE 'PR #[0-9]+' notes.txt |
| Structured prose with identifiable anchor | grep -cE '<regex>' on the anchor token | ticket IDs, URLs, timestamps, usernames |
| Truly unstructured prose (narrative with no regular item-marker) | NOT deterministically countable — see fallback below | — |
Fallback for unstructured blobs (no regular anchor exists):
Option A — extract-then-count (preferred). Spawn an extraction subagent whose only job is to transform the blob into a structured list (one item per line) and write to a file. Then count the extracted file with wc -l. The extraction step is verifiable (human or second-pass agent can spot-check sample lines against the blob); the counting step is deterministic.
Option B — flag as unverifiable. If the artifact claims "N items" against a blob with no extractable anchor pattern, the claim itself is a defect (unverifiable_count). File it as a medium-severity finding: the author must either restructure the source into countable form, or downgrade the claim from "N" to "approximately N" with explicit uncertainty.
Never eyeball-count a blob and accept the result as verified. The confabulation rate on 30+ items is ~100% across all model tiers — and prose blobs are worse than JSON arrays because there's no syntactic anchor to latch onto.
This applies at critic-spawn time AND during final-report numeric verification. Any integer in the output that was not produced by a deterministic tool is suspect.
Model tier: prefer Opus for orchestration (pagination logic, error recovery) but the count itself comes from jq, not the model. Haiku + jq beats Opus + eyeball every time.
Review Mode Presets (ported from review skill)
When invoked with a --mode flag, deep-qa selects mode-specific focus dimensions:
| Mode | Dimensions | Use case |
|---|
--mode code (default) | correctness, security, performance, edge_cases | Code review |
--mode security | owasp_top10, secrets_exposure, injection, auth_bypass, supply_chain | Security audit |
--mode proposal | feasibility, completeness, risk, alternatives, market_fit | Proposal critique (see below) |
--mode claims | accuracy, evidence_quality, counter_evidence, recency, methodology | Claim validation |
--mode design | architecture, scalability, failure_modes, operability | Design review |
--mode migration | rollback_safety, lock_duration, deploy_window_compatibility, data_integrity | Database migration review |
--mode iac | state_lifecycle_safety, blast_radius, state_backend_security, drift_risk | Infrastructure-as-code (Terraform, Helm, CloudFormation) |
--mode pipeline | secret_scope, step_ordering, artifact_integrity, cache_poisoning | CI/CD pipeline definitions |
--mode data-pipeline | schema_contract, idempotency, freshness_sla, data_quality | Data pipeline / ETL (dbt, Spark, Airflow) |
--mode test | assertion_validity, test_isolation, environment_parity, coverage_intent | Test code review |
--mode api-contract | backward_compatibility, wire_format_safety, codegen_safety, versioning | API contracts (OpenAPI, protobuf, GraphQL) |
These map to the existing --type parameter. When --mode is specified, it overrides the dimension discovery phase with the preset dimensions.
Domain-specific mode details
--mode migration — for Alembic, Flyway, raw SQL DDL, or any schema-change artifact:
- rollback_safety: "If this migration runs and then the deploy is rolled back, does the old code still work with the new schema? Is there a
down() migration?"
- lock_duration: "Does this DDL acquire a table lock that blocks reads/writes? For large tables: is
CONCURRENTLY or online-schema-change tooling used?"
- deploy_window_compatibility: "During the deploy window when old code and new schema coexist, do all queries succeed? Are new NOT NULL columns populated with defaults before old-code queries run?"
- data_integrity: "Does this migration preserve existing data? Could a partial migration (crash mid-execution) leave data in an inconsistent state?"
--mode iac — for Terraform, CloudFormation, Helm, Pulumi:
- state_lifecycle_safety: "What does
terraform plan do with this change? Does any resource get destroyed-and-recreated? Is prevent_destroy set on stateful resources?"
- blast_radius: "If this resource is modified, what other resources are implicitly affected via dependency graph? Could a rename trigger a cascading destroy?"
- state_backend_security: "Does this resource definition cause secrets (passwords, API keys) to appear in the state file? Is the state backend encrypted and access-controlled?"
- drift_risk: "Could manual changes to the infrastructure cause drift from this declared state? Are there resources managed outside of IaC that this configuration depends on?"
--mode pipeline — for GitHub Actions, Jenkinsfiles, CircleCI, GitLab CI:
- secret_scope: "Does each step have access only to the secrets it needs? Can a PR from a fork exfiltrate secrets via
pull_request_target or similar triggers?"
- step_ordering: "Are step dependencies (
needs:, dependsOn) correct? Could a deploy step run before tests complete?"
- artifact_integrity: "Are build artifacts verified (checksums, signatures) before use in later steps? Could a cache be poisoned by a prior run?"
- cache_poisoning: "Is the cache key specific enough? Could a malicious PR modify cached dependencies (node_modules, pip cache) to inject code into subsequent default-branch builds?"
--mode data-pipeline — for dbt models, Spark jobs, Airflow DAGs:
- schema_contract: "Does this pipeline change any output schema (column names, types, partitioning)? Are downstream consumers updated? For dbt: do all
ref() models still resolve?"
- idempotency: "Is this pipeline safe to re-run? Does it use
INSERT OVERWRITE/MERGE instead of INSERT INTO? Will a retry duplicate data?"
- freshness_sla: "Does this pipeline's schedule align with its source tables' update times? Does it read stale data if a source table hasn't been populated yet?"
- data_quality: "Are there data quality checks (not-null, unique, accepted_values) on the output? Could a silent upstream schema change propagate bad data?"
--mode test — when the artifact being reviewed IS test code:
- assertion_validity: "Do assertions actually test meaningful behavior, or are they tautological? Does
assert response.status_code != None actually verify correctness? Is the function-under-test mocked away?"
- test_isolation: "Do tests share mutable state, depend on execution order, or modify global fixtures? Can each test run independently and in parallel?"
- environment_parity: "Does the test environment match production closely enough? SQLite-in-tests vs PostgreSQL-in-prod? Mocked S3 vs real S3? Do the differences hide real bugs?"
- coverage_intent: "Do the tests cover the behavior the code is supposed to have, or just the behavior it happens to have? Would a buggy implementation still pass these tests?"
--mode api-contract — for OpenAPI, protobuf, GraphQL schemas:
- backward_compatibility: "Does this change break existing clients? Removed fields, type changes, renamed endpoints, changed response shapes?"
- wire_format_safety: "For protobuf: are deleted field numbers never reused? For JSON: are new required fields backward-compatible (have defaults)?"
- codegen_safety: "Will code generators produce valid code from this schema? Are field names reserved keywords in target languages (class, type, import)?"
- versioning: "Is this a breaking change that requires a version bump? Is the deprecation path documented for removed fields?"
Proposal mode enhancements (--mode proposal)
When --mode proposal is active, three additional phases run before standard critic dispatch:
-
Claim extraction — an independent agent reads the proposal and extracts every verifiable factual claim (statistics, funding amounts, market sizes, citations, competitive claims, negative-existence claims like "no one has built X"). Each claim is written to a structured registry. The coordinator does NOT filter or reclassify claims.
-
Per-claim fact-checking — one fact-check agent per claim (or per 3-5 claim cluster) runs web searches to verify. For named vulnerabilities: CVE databases. For research citations: arXiv/Scholar. For competitor claims: Crunchbase/GitHub/product pages. For "no one has built X": 5+ distinct searches before VERIFIED. Each agent proposes a verdict (VERIFIED / PARTIALLY_TRUE / UNVERIFIABLE / FALSE) with evidence URLs. The credibility judge (standard blind-severity protocol) issues the authoritative verdict.
-
Landscape research — the alternatives dimension critic runs competitive research via web search, producing per-competitor findings. A landscape judge issues: MARKET_WINDOW|open|closing|closed, PLATFORM_RISK|low|medium|high, MOST_LIKELY_PLATFORM_THREAT|{vendor}|{timeline}.
Proposal termination labels (replace standard labels when --mode proposal):
high_conviction_review — ≥80% claims VERIFIED/PARTIALLY_TRUE, zero FALSE, zero unresolved fatal weaknesses, rationalization audit clean.
mixed_evidence — 50-80% verified, OR any FALSE claim, OR any fatal+inherent_risk weakness.
insufficient_evidence_to_review — critic quorum failed OR >40% claims UNVERIFIABLE OR rationalization audit compromised twice.
declined_unfalsifiable — every weakness rejected by judges as unfalsifiable.
Finding Format Requirements
Every finding MUST include:
- Line reference: exact
file:line or line range, not "in the function"
- Severity: critical / major / minor with justification
- Concrete fix: specific code change or approach, not "consider fixing"
- Category: correctness / security / performance / style / other
Auto-Fix Mode (--fix)
When --fix is passed, deep-qa adds a fix-review loop after the QA rounds:
- Collect all critical + major findings
- Spawn a builder agent to fix them (one at a time, test after each)
- Re-run QA on the fixed artifact
- Loop until no critical/major findings or
--max-rounds exhausted
This changes deep-qa from "surface defects" to "surface and resolve defects."
Additional Flags (ported from review skill)
--fix — auto-fix critical/major issues and re-review (loop)
--no-cross-model — disable non-Claude critics via cross-model endpoint (on by default; see Cross-Model Critic Lanes above)
--mode — select preset dimension focus (code/security/proposal/claims/design)
--max-rounds=N — cap critique-fix loop (default: 3)
Golden Rules
- QA is adversarial but grounded. A critic that says "looks good" has failed. But a critic that reports 15 defects and 12 are theoretical non-issues has also failed — it wastes the owner's time and erodes trust in the report. Find REAL problems that would actually cause failures in production.
- Every defect needs a concrete scenario. "This might be unclear" is not a defect. "A reader with context X but not Y will interpret section Z as [wrong meaning], causing [consequence]" is a defect.
- Classify honestly. Don't inflate minor defects to critical. Don't downgrade critical defects to minor. A "theoretical race condition that requires adversarial scheduling" is minor at most, not critical.
- No fixing — only reporting. Suggested remediations are optional guidance. The artifact owner decides how to fix.
- Validate defects before accepting. Apply falsifiability, contradiction, and premise checks. A defect is only real if it survives validation.
- Critique what's missing. The most dangerous defects are omissions — components referenced but not specified, error paths not defined, assumptions not stated.
- Independence invariant. Coordinator orchestrates; it does not evaluate. Severity classification is always delegated to independent judge agents.
- Termination means coverage is saturated, not zero defects. The report is honest about what wasn't covered.
- Artifact type shapes dimensions. Don't apply code security analysis to a research report. Dimensions must match the artifact.
- Never suppress disputed defects. Disputed defects are documented, not silently dropped.
- QA verdicts only apply to the artifact version they ran on. Any post-QA modification (enrichment, integration, reorganization, data join, re-export) invalidates prior QA and requires a fresh pass on the current version. A clean QA on draft v1 says nothing about v2. Verify the artifact hash or modification time matches the QA run when citing prior verdicts.
- For subject-attribution claims, trust the source of truth, not the chain of evidence. "X did Y" must be verified by querying Y's system of record for X — not by reading the report, not by matching content patterns, not by inferring from adjacent citations. Every intermediate data stage between source and report is a place the attribution can silently corrupt.
- Source-of-truth queries must be semantically equivalent to the claim — not weaker. A query that returns results does not validate a claim unless the predicate matches. "X owns Y" →
assignee = X, NOT assignee = X OR reporter = X. "Merged on date D" → mergedAt = D, NOT createdAt = D. "In window W" → resolved IN W for completion claims, NOT created IN W. "Currently open" → re-query at QA time, NOT trust the snapshot. A weaker predicate produces a query that succeeds and looks like it confirmed the claim — silently passing the bug. The QA's job is to construct the strict predicate and use it.
- Independent re-counting beats trusting reported totals — AND the recount itself must be tool-derived, not eyeball-derived. If the report claims N items and shows a table, count the table rows via deterministic mechanism:
grep -c '^|' file.md for markdown rows, jq '.issues | length' for JSON arrays, wc -l for line-per-item lists. Never "let me count them: 1, 2, 3..." — all models confabulate on arrays >30 items. Counts in narrative summaries drift from underlying data after edits — and the drift is invisible because the narrative looks consistent with itself. After every QA round that fixes defects (deletions, additions, reassignments), recount via tool. See Numeric-precision override above for the full Write→jq protocol.
- Hallucinated proper nouns are silent defects. Sample unusual proper nouns (project names, person names, tool names, codenames) and verify each has at least one backing citation. A confidently-named tool or teammate that has zero supporting URL/ticket/Slack/doc citation is a likely hallucination — verify by querying source systems for the noun. Pleasing-sounding plausibility is not evidence.
Anti-Rationalization Counter-Table
These are excuses critics and judges use to suppress, downgrade, or ignore real defects. Each row is a defensive entry — when you catch yourself thinking the excuse, look at the reality.
| Excuse | Reality |
|---|
| "This defect is theoretical — it COULD happen under unusual circumstances" | Apply the practical-manifestation requirement. "COULD happen if..." is minor at most. "WILL happen under realistic load" is the bar for critical. |
| "The framework prevents this (gevent / scoped sessions / expire_on_commit)" | Verify the framework guarantee in code, not in your head. Cite the specific line or documented contract. If unverified, the defense does not exist. |
| "We already discussed this defect in an earlier round" | New round = new evaluation. Check the known-defects file; if the ID is not listed, it's a new defect and must be filed. |
| "Coverage looks good enough to terminate" | Read required_categories_covered from state.json (not from coordinator-summary.md, not from vibes). "Looks good" is not a label. |
| "100% of judge verdicts agree with critics on severity" | Then the judge is broken or the critics are inflating. Independence invariant failed. Investigate the calibration. |
| "This is just a documentation gap, not a real defect" | If a real consumer (implementer, maintainer, incident responder) would interpret it wrong, it's a defect. Construct the concrete misinterpretation scenario. |
| "Defensive code is missing but the condition can't occur" | Verify the defended-against condition cannot be triggered given the surrounding code's invariants. If it CAN be triggered, missing defense is a defect. |
| "The author intended X; that's what they meant" | Intent doesn't matter. The artifact as written is what consumers see. Critique what IS, not what was meant. |
| "Inflate this to critical to be safe — better to over-report" | Inflation wastes the owner's time and erodes trust in the report. Critical requires: WILL fail in production, data loss, or real security attack vector. Apply honest calibration. |
| "Terminate because no critical defects remain" | Forbidden label. Use the Phase 5 vocabulary table only. Termination means coverage is saturated, not zero defects. |