CDX-301g · Module 3

Quality Gates & Validation

3 min read

Quality gates are checkpoints in the multi-agent pipeline that validate output before allowing the pipeline to proceed. Without quality gates, a single agent's bad output propagates downstream, contaminating every subsequent agent's work. The cost of catching an error grows exponentially with pipeline depth — an error caught at the first gate costs one retry; the same error caught at the final merge costs a full pipeline re-run.

Effective quality gates are automated, fast, and binary. Automated: no human in the loop for routine checks — type checking, linting, test execution, and schema validation run automatically. Fast: a gate that takes longer than the task itself negates the pipeline's time savings. Binary: the output passes or fails — no "warnings" that agents ignore. Three gate types cover most needs: syntax gates (does it compile?), semantic gates (do tests pass?), and style gates (does it conform to project conventions?).

import subprocess
from dataclasses import dataclass

@dataclass
class GateResult:
    gate: str
    passed: bool
    output: str

def run_quality_gates(workdir: str) -> list[GateResult]:
    """Run quality gates in order. Stop on first failure."""
    gates = [
        ("typecheck", ["npx", "tsc", "--noEmit"]),
        ("lint",      ["npm", "run", "lint"]),
        ("test",      ["npm", "test"]),
    ]
    results = []
    for name, cmd in gates:
        result = subprocess.run(
            cmd, capture_output=True, text=True, cwd=workdir
        )
        gate_result = GateResult(
            gate=name,
            passed=result.returncode == 0,
            output=result.stdout + result.stderr,
        )
        results.append(gate_result)
        if not gate_result.passed:
            break  # Fail fast — no point running later gates
    return results

Do This

  • Run quality gates after every agent completes, not just at the end of the pipeline
  • Fail fast — stop the pipeline at the first gate failure and fix before continuing
  • Include type-check, lint, and test as minimum gates for any code-producing agent
  • Feed gate failure output back to the agent for context-enriched retry

Avoid This

  • Run quality gates only at the final merge — by then, the error has propagated everywhere
  • Treat warnings as passes — agents will produce increasingly sloppy output over time
  • Skip gates for "simple" tasks — the simple tasks are where overconfident agents make mistakes
  • Run all gates even after the first failure — fix the first failure before checking the rest