Showcase site · Recorded runs from a staged demoWatch recorded runs ↗Built byPravin Gadekar ↗

DesignSurviving failures

03 of 05 · 2 min read

What happens if a worker dies mid-investigation?

Another worker picks it up. Progress is saved after every step. A short lease gives a worker temporary ownership. When it expires, a recovery process called the sweeper hands the work to another worker. Some work can run twice.

ILLUSTRATIVE SEQUENCE01 / 07
What happens if a worker dies mid-investigation?
attempt capreset: stale queued or running runs · timeouts (dashed): also pausedqueuedrunningpausedcompletedrejectedunresolvedblockedcomparedbudget_stoppedfailedcancelled1234567
123running ends as:queuedrunningpausedcompletedrejectedunresolvedblockedcomparedbudget_stoppedfailedcancelledqueued → failed at the attempt cap.Reset cancels stale queued or running runs;eval timeouts can also cancel paused ones.
EXECUTE HANDLER

queued → running

How this step works

The execute handler takes the lease. Only one executor holds a run's lease at a time.

WHO WRITES IT

The execute handler, while it holds the lease

Each write is a compare-and-set on the run row

EXECUTE HANDLER · APPROVAL GATE

running → paused

How this step works

The graph stops at the approval gate. Only the executor holding the current lease token can write this.

WHO WRITES IT

The execute handler, when the graph stops at the approval gate

Only the current lease token can write this

DECISION ENDPOINT

paused → queued

How this step works

The decision endpoint records a decision against the exact proposal digest, a fingerprint of the plan. One compare-and-set operation checks that the run is paused and the digest matches before recording it. Otherwise it returns 409 and records nothing.

ONE COMPARE-AND-SET

Accepted only while the run is paused

and only if the proposal digest matches

Otherwise 409, and nothing is recorded

EXECUTOR

running → completed / rejected / unresolved

How this step works

The workflow returns with outcome approved, rejected or unresolved. The executor maps it to a status only when the whole workflow has returned.

OUTCOME TO STATUS

approved → completed

rejected → rejected

unresolved → unresolved

EXECUTOR · APPROVAL RE-CHECK, COMPARISON

running → blocked / compared

How this step works

Before each live action the approval is re-checked; if it fails, the run ends blocked. A comparison run stops at the gate as compared and is never approved to act.

TERMINAL

blocked: an approval re-check fails before an action, e.g. it expired after 15 minutes

compared: a comparison run stops at the gate and never acts

EXECUTOR · ROUTEDMODEL · CLAIM

running → budget_stopped / failed; queued → failed

How this step works

If a model call cannot reserve budget, the run ends as budget_stopped. An error that cannot be retried, an outdated workflow version or a missing workflow outcome ends it as failed. A run at the attempt cap fails when next claimed, even from queued.

TERMINAL

budget_stopped: a model call cannot reserve budget

failed: a non-retryable error, a stale workflow version or no outcome

queued → failed: the attempt cap is reached at the next claim

ADMIN RESET · EVAL TIMEOUTS

queued / running → cancelled

How this step works

The admin environment reset cancels only stale, non-eval queued or running runs and refuses while newer runs are working. Eval and comparison timeouts can cancel their own queued, running or paused runs.

TERMINAL

The environment reset cancels queued or running runs unchanged for 15 minutes, not eval runs

Eval and comparison timeouts can also cancel paused runs

Steps appear in order. Evidence, review and outcomes remain visible.

Evidence / agent workWaiting for a personFailingRecovered

THE TRADEOFF

What we gained

An investigation outlives any one worker, deploy or closed browser tab. Nobody has to restart it by hand.

What it costs

A resumed step may repeat a model call or a read. Every step must be safe to run twice, and there is more state to store and reconcile.

The alternative: keep the investigation in one process's memory. Simpler, but a crash loses everything and the run starts over.

ONE RESULT

A worker was killed mid-run in a test; a second worker resumed the investigation and skipped the steps already finished.

limitOther deaths in the tests are injected faults (raised errors, SQL edits, an expired lease), not killed processes; the killed-process case ran on local Omni. Not cloud-tested. Not exactly-once: nodes and model calls can repeat. Every resume re-appends about 11 replayed events.

WHAT THIS DOES NOT CLAIM

  • That no work is ever repeated; some is, by design.
  • That every save is fenced against a second worker; session appends are not.
  • That a deploy with changed code is tested end to end.

All of this page's claims in the ledger →

MORE DETAIL

Run states and who writes them

RUN STATES

One run, one status.

Each run has one database row and one status. The plan allows the transitions shown here. Each write uses compare-and-set: it updates the row only if the expected state matches. Only the party named in the table writes that status.

Lease expiry is not a transition. When a lease expires the sweeper only enqueues a task, and a new executor takes a new lease.

Run statuses, whether each is terminal, and what sets it
StatusTerminalSet by
queuednoPOST /incidents; the decision endpoint (from paused only)
runningnoThe execute handler, while it holds the lease
pausednoThe execute handler, when the graph stops at the approval gate
completedyesThe executor, when the workflow returns with outcome = approved
rejectedyesThe executor, when the workflow returns with outcome = rejected
unresolvedyesThe executor, when the workflow returns with outcome = unresolved
budget_stoppedyesThe executor, when RoutedModel cannot reserve budget for a model call
failedyesThe executor, on a non-retryable error or past the attempt cap
blockedyesThe executor, when an approval re-check fails before a live action (for example, an expired approval)
comparedyesThe executor, when a comparison run reaches the approval gate; it never acts
cancelledyesThe admin environment reset, for stale non-eval queued or running runs; eval and comparison timeouts, also for paused runs

A terminal status releases the lease, and the sweeper stops checking that run. A budget stop after approval is terminal too: actions already taken stay recorded in write_operations, and the postmortem is not drafted.

Lease and sweeper, step by step

LEASE AND SWEEPER

Who is working on a run right now?

A worker crash, in order. Only one executor holds a run's lease at a time, and the lease token is what the database checks on every executor status write and event projection to runs and run_events.

  1. 01 / Cloud Tasks → execute endpoint

    Cloud Tasks calls the private execute endpoint. It accepts only Cloud Tasks' OIDC token for the executor service account (issuer, audience and account checked). Browser Firebase tokens are rejected there.

  2. 02 / executor A → runs row

    The handler takes a lease—the right to execute the run—with a fresh lease token, and increments attempts. Each run has one active executor.

    If the run is paused, terminal (finished), or leased by a live executor, the handler returns 200 immediately without starting the runner. Past the attempt cap, it sets failed instead of running.

  3. 03 / executor A → runs, run_events

    It renews the lease while the run is running. Every status write and event projection is conditional on its token, and a failed renewal stops the executor at once.

  4. 04 / executor A ×

    The executor dies. Its lease stops being renewed and then expires.

  5. 05 / sweeper → Cloud Tasks

    Cloud Scheduler calls the sweeper to find running runs with expired leases. It also finds queued runs with no live lease, at least a minute after they were queued or decided. It queues them again and stops at the attempt cap.

    It only enqueues; it never runs the graph. It never touches a paused or terminal run.

  6. 06 / executor B → runs row

    A new executor takes a new lease token and resumes the interrupted invocation by invocation_id. Only nodes with no recorded output rerun.

  7. 07 / executor A (stale) → runs, run_events

    If the stale executor wakes up, its status and event writes fail on its old token, so it cannot change runs or run_events after another executor has taken over.

    Limit: ADK session appends are not fenced by the lease token. ADK's own revision check (StaleSessionError in DatabaseSessionService.append_event) refuses the stale writer's held append, and its attempt ends with a lost lease. A local takeover test shows the run still reaching its normal outcome.

On staging, live updates reach the browser as a stream, not in delayed batches, and a reconnect resumes from the last event it received.

The two ways a run resumes

TWO RESUME PATHS

What happens when a worker dies or a person comes back later?

The two resume paths stay separate. Both queue a task and use an executor that skips completed work. They start from different events and send different information to ADK.

Human decision

Trigger: a person approves or rejects the exact proposal.

  1. triage-api

    Checks the approver role and ties the decision to the proposal digest, a content fingerprint. One compare-and-set update records the decision and moves the run paused → queued only if the expected state matches. The server adds the reviewer identity; the client never supplies it.

  2. Cloud Tasks

    Queues a task for the private execute endpoint on whichever revision is serving.

  3. executor

    Takes the lease. To check delivery, it reads the run's ADK session for the adk_request_input function response to the gate's interrupt; it does not rely on a flag. If the decision is recorded but not delivered, the executor sends it as the function response.

  4. ADK Runner

    Matches the response id to the paused invocation, so no invocation_id is passed. Completed nodes replay from events without new model calls. If the response is already delivered, the executor resumes by invocation_id and never sends it again, because an unmatched response starts a new run.

Executor crash mid-run

Trigger: the executor dies and its lease expires.

  1. Cloud Tasks or sweeper

    Cloud Tasks retries the task, or the sweeper re-enqueues it.

  2. new executor

    Takes a new lease token and resumes the interrupted invocation by invocation_id, as ADK's resume docs describe.

  3. ADK Runner

    Completed nodes of the static graph are skipped. Only nodes with no recorded output rerun (ADR 0001, S2).

Failure cases and what happens

FAILURE SCENARIOS

What can go wrong, and what happens next?

This is not exactly-once execution. Nodes and model calls can repeat. Only external writes are idempotent: repeating them does not repeat their effects. Each is keyed by run, proposal and action in write_operations. Decision records provide the evidence; each card states its scope and limits.

Executor dies mid-run

Resumes by invocation_id; only nodes with no recorded output rerun.

Evidence: Verified: ADR 0001 S2 rows (a model error, a cancelled task, and a killed process on Omni).

Limit: Nodes and model calls can repeat; only external writes are idempotent, through write_operations.

  • Provenresume without rerunning finished nodes

One specialist fails

The join, where specialist results meet, still runs. That specialist is reported failed and the others continue.

Evidence: Verified for a missed deadline (guard node, ADR 0001) and for an error raised inside a specialist (guard test, ADR 0009); on staging a specialist's model timeout was reported failed and the run went on (ADR 0010).

  • Provenmissed deadline
  • Provenerror inside a specialist

Approval after a deploy

Compatible deploy: the run resumes on the new revision. Changed graph: the run ends failed without a model call.

Evidence: Verified: a paused run resumed and completed on a new Cloud Run revision (ADR 0001); stale-version failure (tests/runs/test_executor.py).

Limit: A restart onto a new revision is proven; a deploy with changed code is untested end to end.

  • Provenrestart onto a new revision
  • Provenversion mismatch fails closed

Takeover during a save

Takeover while an ADK event is being saved. The run reaches the same outcome as without the takeover. Its session stays consistent and replays without repeating a decision. External effects are reconciled, and recovery stays within the attempt cap.

Evidence: Verified locally (ADR 0011): with a takeover while a specialist event or apply_patch was being saved, the run paused once or completed with one pull request, and the stale writer's append was refused.

Limit: Local only, on Postgres with fake GitHub and storefront services; no takeover was forced on staging.

  • Proventakeover test

Response lost after a write

An external write succeeds but its response is lost. Reconciled, not repeated.

Evidence: Verified on staging (ADR 0011): each action's first answer was dropped on purpose, and the retry found the existing pull request and pool-limit change instead of repeating them. Locally, a lost answer at three points each ended with one branch, one pull request and one mitigation.

Limit: The lost answer is a staging test setting, not a real network drop.

  • Provenlost-response write test