The team approves a change to the booking service’s cancellation rules. The orchestrator picks it up from the queue, prepares an isolated checkout and starts a fresh coding session for that task. When the session ends, the orchestrator can still find the task, the saved code and the checks. That’s where a replacement session starts if the first one stops.
Decide which records are authoritative
| Question | Where to look |
|---|---|
| Who approved the work and when is it eligible? | The shared work record, with the owner, priority, dependencies and authorisation. A support report can suggest a task. It cannot make the task eligible by itself. |
| What exactly are we building? | The approved, versioned brief or specification. Give the worker and verifier the same immutable revision. |
| Who is allowed to publish a result? | The current claim in the orchestrator’s durable store. |
| What code was produced? | The branch or recorded source revision in version control. |
| What passed? | The independent verification result, with links to evidence for that source and build. |
| Who made the decision to proceed? | The owner’s decision record or the team’s protected review system. |
The work orchestrator keeps track of what’s authorised, what’s running and where a person needs to decide. It can restart because the work record is stored separately. When it starts a task session, that session gets the approved brief, repository, starting revision, acceptance checks and permitted tools for this change. In this guide, a worker is that temporary session. The next task gets a fresh one, even if it uses the same coding tool. Independent verification runs under its own policy.
Owner approves brief and checks
→ eligible work
→ orchestrator claims the task and starts a fresh coding session
→ session records a candidate revision
→ independent verification checks that revision
→ authorised reviewer accepts, returns, or asks for a decision
Pick the next item from the approved, unblocked work the queue has capacity to run. If the worker finds an unrelated failure, give it a way to file a follow-up with evidence. Let the normal triage process decide priority.
Record a claim and a usable handoff
A claim gives one run temporary ownership of a task. A handoff is the short note that lets somebody else pick it up: where the code is, what got done and what to check next. If you assign work manually, an assignee and a note on the work item may be all you need. This example is for an orchestrator that assigns work automatically.
Where the record lives
In this example the orchestrator writes the claim and handoff to a row in its own database, such as a work_items table in PostgreSQL. The branch lives in Git, somewhere a replacement session can read it. The row holds the branch name and the exact saved revision. The YAML below is how that row might look in a debug view. There’s no YAML file for an agent to edit or a verifier to load. The task and verification contracts are separate, approved inputs that the row refers to.
# Example display of the orchestrator’s saved record
task: booking-cancellation
status: in-progress
approved_spec_revision: "<approved-git-commit>"
task_contract_revision: "<task-contract-commit>"
claim:
run: run-18
session: session-18
generation: 18
lease_expires_at: "2026-11-18T10:25:00Z"
last_heartbeat_at: "2026-11-18T10:20:00Z"
handoff:
branch: work/booking-cancellation
candidate_revision: "<candidate-git-commit>"
last_completed: Added the fixed-clock boundary tests
next: Check what happens to bookings without recorded terms
What checks it
- The orchestrator and its database check ownership. Before starting a session, the orchestrator claims the task only if it is still approved and eligible and has no active claim. When the runner sends a heartbeat, checkpoint or result, the orchestrator authenticates the submission. It updates the row only if the run and generation still match, the lease is unexpired, and the task is in a state that allows that write. Put those conditions in the same database update that saves the change. An update that affects zero rows means the write was refused. PostgreSQL’s rules for competing updates
- CI checks the code. It runs the required checks against the submitted source revision and the approved verification contract. A passing build is evidence about that revision. The orchestrator still has to match the result to the current run and candidate revision before marking the work ready for review.
- The next session checks the handoff against reality. It reads the saved revision and any available build evidence before trusting “last completed”. If the note says the boundary tests were added, the successor can look at the diff and rerun those tests. The note is there to save it from starting the investigation again.
Suppose run 17 goes quiet. The orchestrator checks the saved branch and review, then starts a fresh session for run 18 with the brief and the saved revision. If run 17 wakes up and submits a late result, the database refuses the update. Run 18 can still pick up the saved patch, see what’s there and submit it for fresh verification. An incrementing generation used this way is sometimes called a fencing token. Worker recovery trial
Guard every shared write
The database check only protects writes that go through it. Decide where a session can save work and which updates require a trusted publisher. In this example a session can save a patch to a run-specific location. The publisher owns the shared Git ref, the review status and any promotion or deployment credentials.
| Boundary | Who writes it | What to verify |
|---|---|---|
| Claim, checkpoint or result in the work store | Orchestrator | In the same conditional update, check the task, current unexpired generation and permitted state. |
| Candidate source or artefact | Session through its scoped runner | Save to a location unique to the run and record the immutable identity. Durable candidate storage carries no acceptance authority. |
| Shared Git ref or pull-request update | Trusted publisher | Check the current claim, expected remote revision and proposed source. Use a conditional update where supported. |
| Verification status or acceptance | Protected verifier and authorised reviewer or acceptance service | Bind the result to the exact source, build and approvals. A session cannot set its own trusted status. |
| Artefact promotion or deployment | Protected release service | Check the accepted artefact and environment approval at the release boundary. Record the outcome so a retry can be reconciled. |
A remote write can race with claim replacement even when you check the claim just before calling the remote API. Where the receiving system can enforce a conditional write, put the condition there. Otherwise, have one trusted publisher serialise the operation for that target and resolve or reconcile in-flight writes before allowing a replacement. An uncertain response is a reason to inspect the remote state. Repeating it blindly can publish twice. Try stale publication against each shared boundary you rely on.
Give the session a specific job
For the cancellation change, this is the kind of brief the orchestrator can give the fresh session.
Read
AGENTS.mdand the approved cancellation proposal. In this checkout, apply the 24-hour cutoff to new bookings and preserve the old terms. Use the synthetic booking fixtures and a fixed clock. Run the booking tests and the repository verification command. Leave the candidate revision and results in the work record. If a legacy record has no clear policy, leave an example and stop for the owner’s decision.
The runner gives this session write access to its checkout, local test data and the repository’s test commands. It starts without production credentials. If a required check can only run in a shared test environment, the session records which check needs it and requests approval for that action. The running environment enforces access. The brief tells the session how to use what it has.
If a separate look would help, start another fresh session with the brief, diff and evidence and give it read access to review them. Automated checks still run in CI. Use another session when the task needs different tools, permissions or an independent judgement.
Separate run budgets from permission boundaries. Give a job a time limit, a spend limit where applicable and a retry limit. Adjusting the time limit doesn’t buy the worker permission to do anything new. On a failed check, leave the evidence and next decision in the work record. Retry if there is new information or a transient failure has cleared. A worker that reaches its limit should leave a usable handoff.
Stop with a question somebody can answer
Here is what I would want to get back if the worker finds a legacy record without terms.
Decision needed. Which policy applies to older bookings with no recorded terms? The brief says to preserve their terms, but some records predate the policy field.
Options. Apply the historical policy if the booking date is enough to establish it, or route ambiguous records for manual review. The first option keeps the normal journey where the history is reliable. The second avoids making up a deadline for records the service cannot resolve.
Evidence and handoff. The synthetic fixture and failing test are on the candidate revision. The new-booking tests pass. Legacy handling is open. Resume at C03 after the owner records the decision and approves any change to the brief.
Mark the work as waiting, save the handoff and end the session. When the owner records the decision and the task is ready again, issue a fresh claim and start a new session with the approved brief and saved revision. Other eligible tasks can continue.
Build and watch the smallest useful version
A first implementation can use a shared work tracker, a versioned spec, a durable store that supports atomic updates, an isolated runner and the CI system the team already uses. For work discovery, respond to notifications and run a periodic comparison of the work records with actual workers, branches and builds. Make both routes use the same eligibility and claim check. A duplicate notification should do no harm. A missed one should turn up on the next sweep.
On the operator’s screen, show current and expired claims, work waiting for a human, verification failures, and time spent waiting for review. That is a different view from the application’s own logs and traces. Allow more sessions to run in parallel when execution is the bottleneck and the tasks can make progress independently. If review is already backed up, more simultaneous runs can make that worse.