Gates Catch Defects. The Behavioral Layer Prevents Them.

We’ve been running QAPAF, the Qaori Autonomous Software Factory, with a 12-gate quality system for months. Every artifact that exits the factory passes through structured gates: spec review, architecture validation, code quality, security, test coverage, documentation. The gates work. They catch what agents get wrong.

But catching defects is not the same as preventing them.

Every defect that reaches a gate was produced by an agent operating with incomplete context, inadequate constraints, or poor defaults. The gate found it after the fact. The revision cycle paid for the gap. Over time, at scale, that cost accumulates.

We shipped Epic 22 to fix the upstream.

What the Behavioral Layer Is

The behavioral layer is a set of disciplines injected before any task begins. Not documentation. Not suggestions. Behavioral constraints that shape how agents operate at every session.

Five components:

1. QAPAF Skills Layer. Five markdown skill files, session initialization, spec-first discipline, plan formatting, TDD enforcement, debug protocol, injected at the start of every factory session. An agent that opens a session in QAPAF receives these constraints as part of its operating context. There is no opt-out. The Iron Laws are stated once, early, and apply throughout.

2. Spec-First Enforcement. No task dispatches without an approved spec. The orchestrator blocks at dispatch time if the spec gate has not been passed. This is not a review step, it is a hard stop. Agents cannot begin implementation by deciding the spec is obvious.

3. Fresh-Context-Per-Task Dispatch. Every implementation task receives a fresh, isolated context packet. The packet contains exactly what the implementer needs: the task spec, the relevant files, the active gates, the agent role, the escalation path. It contains nothing else. Context contamination, one task’s assumptions polluting the next. Is structurally prevented.

4. Two-Stage Independent Review. After every task, two independent reviewers run in sequence. Stage 1 checks spec compliance. Stage 2 checks code quality. Neither sees the other’s output. Both must pass before gate 7 opens. If either fails, the task returns for revision with a documented finding. After three cycles, Qappa escalates.

5. Model Triage Protocol. A config-driven lookup table maps task type to model tier at dispatch time. Mechanical tasks run on cost-efficient models. Integration work runs on mid-tier. Architecture and security decisions run on the best available. The selection is deterministic, not discretionary, and produces no surprises.

What It Changes

The gates do not change. They continue to operate exactly as before, downstream of the behavioral layer. Every artifact still passes gates 1–12 before it exits the factory.

What changes is the defect rate that reaches those gates.

An agent that starts every session with explicit behavioral constraints, cannot dispatch a task without an approved spec, operates in an isolated context, and submits work to two independent reviewers before any gate opens, that agent produces fewer defects per task. The gates run the same process on a cleaner input.

The Compound Effect

Quality systems that only catch defects are expensive at scale. Every defect found at gate 7 represents work that was planned, built, reviewed by the implementer, and submitted, before anyone with independence looked at it. That is a large investment in something that will be revised.

Prevention is cheaper than detection. The behavioral layer is the prevention investment.

The two compound. Prevention reduces the defect rate. Detection catches what prevention misses. Neither is sufficient alone. Both together produce a factory that gets progressively more reliable as the behavioral layer matures and the gate data informs future skill iterations.

That is the design. Epic 22 is the first production version of it.


The full architecture of QAPAF remains internal. What I can share publicly is the principle: governed agentic factories are not built by adding more gates. They are built by shaping behavior before the gates ever run.

Gates catch defects. The behavioral layer prevents them.

More posts: