Skip to content

Pipeline (Camada 7)

The pipeline is a 7-phase saga. Every capsule traverses phases 0→6, with phases 4↔5 cycling up to 3 times on CHANGES_REQUESTED (Rule 12 — max review cycles).

Phase map

Phase Module Purpose Halts on
0 RECEPTION phases.phase_0_reception Validate capsule integrity, deadline, budget positivity, lock availability deadline_in_past, budget_tokens_non_positive, lock_unavailable:*
1 REALITY_ANCHOR phases.phase_1_reality_anchor Verify referenced artifacts exist (UBT-000 truthfulness baseline) context_ref_missing, target_missing
2 PLANNING phases.phase_2_planning Verify spec is approved (Rule 35 SDD) — DoR check spec_not_approved with missing fields enumerated
3 AUTOMATED_GATES phases.phase_3_gates Run 21 absolute constitutional rules absolute_rules_violated:[N, M, …]
4 EXECUTION phases.phase_4_execution Acquire locks → run executor → emit checkpoint lock_acquisition_failed, budget_exceeded
5 REVIEW phases.phase_5_review VerificationAgent (default auditor-haiku) reviews artifact review_rejected_terminal, review_changes_requested
6 HANDOFF phases.phase_6_handoff Final checkpoint at 100%, capsule emission

Cycle counter (Rule 12)

If Phase 5 returns CHANGES_REQUESTED, Phase 4 re-runs. Maximum 3 cycles per capsule. On the 3rd cycle without APPROVED, the pipeline halts with max_cycles_exceeded:3.

If Phase 5 returns REJECTED, the pipeline halts immediately with review_rejected_terminal — no retry.

Locks (Rule 17)

phase_4_execution acquires every path in capsule.constraints.resource_locks_required before invoking the executor. On any acquisition failure, previously-acquired locks are released and the phase halts with lock_acquisition_failed:<path>. After successful execution (success OR failure), all locks held by the capsule are released.

Budgets (Rule 16)

BudgetTracker tracks per-capsule token + dollar caps. Each model call records consumption; if either cap is exceeded, BudgetExceededError is raised and Phase 4 halts with budget_exceeded:<reason>.

WaveBudget aggregates capsule usage at the wave level for WaveScheduler to enforce wave-level caps.

Verification (Rule 15)

VerificationAgent.review() refuses to approve when producer_agent_id == self.agent_id, returning a REJECTED review with a Rule 15 violation finding. This is the structural enforcement of reviewer ≠ producer.

Continuation (CONTINUATION-PROTOCOL)

ContinuationStore.emit_pause() persists a Continuation record when one of the registered triggers fires:

  • budget_warning — >75% budget consumed
  • deadline_approaching — <5min until deadline
  • blocked_external — external dep or human input needed
  • lock_contention — >60s lock wait
  • operator_manual — explicit pause command

A resumed capsule reads the Continuation + last Checkpoint and continues from where it stopped.

Example: forcing rejection

from src.pipeline import VerificationAgent, ReviewResultType

class RejectingVerifier(VerificationAgent):
    def review(self, *a, **kw):
        rv = super().review(*a, **kw)
        rv.result = ReviewResultType.REJECTED
        return rv

orch = PipelineOrchestrator(..., verifier=RejectingVerifier())
result = orch.run(capsule)
# result.halt_reason == "review_rejected_terminal"
# result.cycles_used == 1

Schemas

Checkpoint.as_schema_dict() emits a dict that matches the JSON schema (with the state block nested).