W ai4rent.net
← Reference architecture Task loop

A workflow that can prove the task is done.

Ten states, eight phases plus a policy gate, and one rule: completion is evidence, not a claim. This reference keeps the original lifecycle and adds the invariants that make it safe to run unattended.

TL;DR — Keep the state machine and the Oracle. Add idempotent transitions, a real evidence contract, risk-based human gates and evaluation before a strategy is promoted.
Task lifecycle Policy, intake, planning, execution, verification, review and completion, with clarification, retry, blocked and post-mortem branches. Policy risk · spend · data Intake classify · route Plan recon · plan.md Execute sandbox · lease Verify self + Oracle Review peer · human Complete evidence-bound Clarification max 3 rounds Rejection context fix only listed issues Retry ladder 1–2 same · 3 prune · 4+ block new attempt Blocked escalate, no silent loop Post-mortem evidence → lessons Memory lessons enter quarantine → verified → trusted HAPPY PATH Verification is not a formality: self-audit and Oracle are independent checks; evidence determines completion.
Eight phases plus a policy gate. Clarification is bounded, retries are structured, and blocked is a real state.

The lifecycle at a glance

Eight phases plus a policy gate. Self-audit and the Oracle are parallel checks, not a chain; the Oracle is mandatory for promise mode and high-risk audit mode.

  1. 00

    Intake & policy

    Classify type and complexity, attach risk, spend and data-access policy. Pick a strategy with enough evidence.

  2. 01

    Recon & plan

    Inspect the workspace, images and memory. Write plan.md with steps, risks, dependencies and a verification plan.

  3. 02

    Execute

    Run with a scoped sandbox and a heartbeat. Every tool call that mutates state is idempotent.

  4. 03

    Self-audit

    Check acceptance criteria against the plan. Produce structured evidence, not prose only.

  5. 04

    Oracle

    Independent, clean-context verifier re-runs or attests the evidence. No access to the agent’s session history.

  6. 05

    Peer review

    Blind, rotated reviewer checks quality and risk. Same-pool peers are not enough for critical work.

  7. 06

    Human gate

    Approval depends on reversibility, spend, data access and blast radius — not just complexity.

  8. 07

    Orchestrate

    DAG dependencies, leases, cycle detection and workload-aware routing.

  9. 08

    Watchdog & post-mortem

    Detect stalls vs waiting, escalate by tier, preserve evidence and extract structured lessons.

State machine

Every transition needs an owner, a guard and an audit event. Terminal states never transition again.

StateEntered whenMeaning
pendingcreated + classifiedTask is valid and has an owner.
planningcomplex taskRecon and plan are in progress.
pending_clarificationgaps foundA specific question is waiting; max 3 rounds.
in_progressplan approved / simpleAgent is executing with a lease.
auditexecution completeSelf-audit is running.
promisepromise-mode completionPromise gate and Oracle are running.
peer_reviewaudit passedIndependent peer checks the result.
pending_reviewpeer approvedHuman gate is waiting.
completedall gates passedTerminal; write the score and evals.
blockedstuck / 4+ failsNeeds escalation; never silently retried.
Task state machine Ten task states from pending to completed, with clarification, promise, blocked, post-mortem and cancelled branches. pending created + classified planning recon + plan.md in_progress lease + heartbeat audit self-audit peer_review blind + rotated pending_review human gate completed terminal pending_clarification max 3 rounds promise promise gate + Oracle blocked 4+ fails or stuck post_mortem root cause + lessons cancelled terminal Invariants compare-and-set on state lease owner on every write terminal states never move each transition writes audit_log TEN STATES Happy path on the left; side paths are explicit, bounded and observable.
Ten states, guarded transitions. “Complete” is a terminal state, not an optimistic message.
transition(task, from, to):
  assert task.state == from
  assert guard(from, to)              # owner, lease, evidence
  update tasks set state = to
    where id = task.id and state = from  # compare-and-set
  append audit_log(task, from, to, actor, evidence_hash)

Rejection context and retry

A retry without structured feedback is just another attempt at the same mistake.

FailureActionContext policy
1–2Same session, continuation prompt with rejection-context.json.Fix only listed issues.
3Prune context, switch strategy, fresh session.Keep task brief, rejection context and new strategy only.
4+Block and escalate to the human owner.Dead-letter with full evidence; no silent loop.
rejection-context.json should list: failed criteria, severity, what passed, suggested approach, previous attempt summaries and the evidence hash. The next agent gets this — not the whole failed conversation.

Evidence contract

An Oracle with clean context is only as good as the evidence it is given.

FieldRequirement
CommandThe exact command or tool call, with its working directory and environment version.
OutputExit code, stdout/stderr hashes and the relevant excerpt.
ArtifactHash, path, size and timestamp of every produced file.
CheckThe acceptance criterion it satisfies and who verified it.
NonceA unique task/attempt identity so stale evidence cannot be replayed.
{
  "task_id": "TSK-042",
  "attempt": 2,
  "nonce": "9f3c…",
  "checks": [
    {"criterion": "service returns 200",
     "command": "curl -fsS https://…/health",
     "exit": 0, "output_hash": "sha256:…",
     "verified_at": "2026-10-26T08:00:00Z"}
  ],
  "artifacts": [{"path": "…", "sha256": "…"}]
}
HTTP 200 is not proof. The Oracle must bind the check to this attempt, re-run it where possible, and reject stale artifacts, unverifiable screenshots and self-reported logs.

Human gates by risk

Complexity alone is the wrong trigger for a human.

RiskExamplesGate
LowDraft, research, formattingAuto-approve after self-audit plus sample review.
MediumPublishing, customer-visible contentPeer review; human spot-check.
HighDeploy, spend, delete, credentialsHuman approval with evidence and rollback plan.
CriticalMoney movement, legal, personal dataTwo-person rule; Oracle plus human.

DAG orchestration

DAG project orchestration A project checklist with dependencies: AWS credentials, deploy, SSL, DNS, plus a parallel documentation task. A project lock and lease prevent duplicate spawning. Project checklist normalised JSON TSK-001 AWS credentials TSK-005 draft runbook · parallel TSK-002 deploy server TSK-003 configure SSL TSK-004 DNS after deploy One project lock · one lease · idempotent spawn key partial failure leaves completed items checked; failed items blocked with evidence Cycle check reject before spawning
Dependencies are data, not a mental model. The orchestrator claims a lock, checks cycles and spawns once.

Watchdog and post-mortem

Watchdog

  • Heartbeat from the acting agent; lease expiry, not just “no status change”.
  • Distinguish waiting on a human from stuck.
  • Tiered escalation with a deadline at each tier.
  • Budget guard: time and token ceilings per task.

Post-mortem

  • Evidence first: rejection context, decision trace, score history.
  • LLM proposes; the evaluation set decides.
  • Lessons are structured: trigger, action, evidence, confidence.
  • Only evaluated lessons enter the shared brain as trusted.

What to measure

MetricQuestion
Lead timeCreated → completed, p50/p95, split by task type.
First-pass rateCompleted without retry or human reject.
Oracle catch rateFailures found by the Oracle but missed by self-audit.
Retry costTokens and time spent per successful task.
Human loadApprovals per day and time-to-decision.
Post-mortem action rateLessons that changed a strategy and passed evaluation.

Failure modes

FailureCauseFix
Double completionWatchdog + agent finish at the same timeTerminal-state guard, idempotency key, compare-and-set.
Context-loop retryAgent repeats the same failed approachStructured rejection, strategy switch, fresh session at 3rd failure.
Oracle theatreAgent supplies its own “evidence”Evidence contract, nonce, independent re-run, signed tool output.
DAG raceTwo orchestrators spawn the same taskProject lock, lease, cycle check, idempotent spawn key.
Peer collusionSame-pool reviewers approve each otherBlind review, rotation, independent quality sample.
Zombie taskStatus stuck with no heartbeatHeartbeat + lease expiry; distinguish waiting from stuck.
Full reference PDF memory + workflow Back to memory →