Skip to the page

How it works

The quest state machine

Every state a quest can be in, what moves it, and the effects each transition asks for.

Ask Claude Ask ChatGPT Markdown

When a quest does something you did not expect, the answer is in this machine. It is a pure function in packages/core/src/lifecycle.ts: given a quest and an event, it returns the next quest and the effects to carry out.

The main line

Text
sensed → triaged → researching → hypothesised [A] → reproducing
       → planned [B] → patching → proving → ready [C] → landing
       → watching → closed

[A], [B] and [C] are the checkpoints. At each one the machine emits a checkpoint request carrying the policy's blocking flag.

The branches

FromWhenTo
provingProof failed, attempts remainpatching
provingAttempts exhaustedparked
reproducingCannot reproduceparked
landingThe base branch movedpatching, to rebase
watchingRegressionrolled_back
rolled_backRollback confirmed completeresearching, at revision + 1
any active statePausedparked
parkedResumedthe state it was in
hypothesised, planned, readyA person claims the reviewhanded_off
handed_offThe owner releases itthe state it was in
any active stateKilled, or a checkpoint rejectedabandoned

closed and abandoned are terminal. Events that arrive afterwards are absorbed without changing the quest, with one exception: usage receipts can still be recorded, so late costs are not lost.

All sixteen states

StateMeaning
sensedA signal arrived.
triagedA route was chosen.
researchingEvidence is being gathered.
hypothesisedA hypothesis is written. Checkpoint A.
reproducingA failing check is being written.
plannedThe failure is reproduced and a plan exists. Checkpoint B.
patchingA fix is being written.
provingThe proof bundle is being assembled.
readyProof is complete. Checkpoint C.
landingThe reviewed commit is being written.
watchingDeployed and under observation.
closedWatched clean. Terminal.
rolled_backA regression was seen; waiting for the rollback receipt.
parkedStopped, with a reason. Resumable.
handed_offA person holds the review.
abandonedKilled or rejected. Terminal.

How a quest starts

Triage picks a route when a quest is created:

RouteResult
auto_fix, research_onlyStarts research.
humanGoes to the inbox.
ignoreAbandoned, and the fingerprint is muted for 24 hours.
duplicateMerged into the existing quest; no new one.
conflictA parked child that waits for its parent to land.

A regression reopens the matching closed quest. It keeps its identity and its severity floor, attaches the new signal, increments the revision and starts research again.

Checkpoints in detail

  • A blocking checkpoint waits for a person.
  • An advisory checkpoint advances only if an automatic decision is supplied for it. Those come from a durable model evaluation with its own evidence checks.
  • In shadow mode a decision is recorded and the quest does not advance, whatever the verdict.
  • Revise at A, B or C returns to research, planning or patching.
  • A research-only quest that is approved at A parks and notifies you. It was never going to patch.

What invalidates an approval at C

An earlier C approval stops counting when any of these happen: new proof, a new signal during proof, a change to the base, or a human revision. A human revision that changes the head increments the revision and requests proof again.

Claimed reviews

A claim is exclusive and only possible at a checkpoint. While it is held, workflow actions and decisions are refused; comments still work. If proof succeeds during a claim, the review stays held at C. If it fails, ownership is cleared before the quest returns to patching or parks.

Proof completion

For proof to complete, the machine requires a recorded patch head, and a bundle whose quest ID, revision, risk, base and head match, along with the canonical SHA-256 digest of that exact bundle. This binds a submitted bundle. It does not independently attest that its commands ran.

Effects

A transition can ask for any of these:

EffectAsks for
run_triageA routing decision.
start_agent, stop_agentAn agent step to begin or be aborted.
run_proof, run_probesThe proof bundle or specific probes.
request_checkpointA checkpoint request, with its blocking flag.
request_spend, start_respondent_runA spend approval, then the study it paid for.
land, rebase, rollbackForge writes.
start_watch, register_regression_probePost-landing observation, and keeping the reproduction.
notify_inbox, reply_commentMessages to people.
merge_signal, mute_fingerprintSignal bookkeeping.
resume_dependents, deliver_child_evidenceCoordination between related quests.

Each effect has a key of the form trail:rev:type:event:occurrence. The event identifies the operation; the occurrence separates repeated commands of the same type in one transition. Payload text is not part of the key. The orchestrator persists event IDs and uses the keys to deliver each effect once.

Replay

fold runs a list of events through the machine in order with a given policy and returns the first invalid transition, if any. Replaying the same events with the same policy reproduces the same decisions and the same effect keys. That is what makes recovery from the journal possible.

What this does not verify

The machine's tests cover the transition table, creation, checkpoints, rollback, handoff and randomized replay. They verify decisions and schemas only. Whether an agent actually ran, a forge write happened or a watch observed anything is established elsewhere, by the adapters and the ledger.

Next