Skip to main content

Leases, fences, and the result outbox

Status: Ready

Article ID: 004

Truth label: Current

Audience: System designer

Reader outcome: Explain how AGENTASIAN protects task state across crashes, late results, and repeated delivery.

Related articles: 008, 051, 052

Target week: 02

Last verified: 2026-09-13

Technical reviewer: Codex source audit

Editorial reviewer: Codex editorial audit

Three failures to design for​

A distributed worker can fail at awkward times:

  1. It can disappear after claiming work.
  2. It can return after a newer attempt has started.
  3. It can finish while Central is unavailable.

A lease, a fence, and an outbox address those failures separately.

The lease answers: is this attempt still alive?​

When a worker claims a task, Central assigns an expiry time. The worker renews that lease while the coding process runs. If renewals stop, Central eventually treats the attempt as abandoned.

The lease prevents a task from remaining in progress forever after a worker crash. It does not prove that the process is healthy or that the output is correct. It only provides a time-bounded claim on the task.

At a checkpoint, the lease is cleared. Human review can take minutes or days without making an execution lease appear active.

The fence answers: which attempt is current?​

Every claim increments the task fence. A worker must include that fence when it renews the lease, writes logs, or reports a result.

Imagine attempt 1 loses its network connection. Central expires it and starts attempt 2. Attempt 1 later reconnects with a successful result. Without a fence, that late result could overwrite attempt 2. With a fence, Central records attempt 1 as superseded and leaves current state unchanged.

The fence converts “last response wins” into “current attempt wins.”

The outbox answers: what if Central is down at completion?​

The worker writes its terminal payload to durable local storage before it depends on delivery. The payload includes the task, fence, result, and run token needed by Central.

If delivery fails, the entry stays in the outbox. The worker can redeliver it after Central returns. Central responds with one of the meaningful outcomes:

  • accepted, so the entry can be removed
  • duplicate, so the already-applied entry can be removed
  • superseded, so the stale evidence can be recorded and removed
  • a retryable transport or server failure, so the entry stays
  • a rejected authentication or validation failure, so evidence is preserved without retrying forever

The transaction connects them​

Central claims a task inside an immediate SQLite transaction. It rechecks eligibility before assigning the run id, fence, lease, worker, and run token. Result handling authenticates first, validates the fence, deduplicates the task-and-fence pair, writes trace evidence, and then applies the supervision mode.

Together, the controls provide this sequence:

claim transaction -> renewable lease -> fenced writes -> durable result
-> authenticated delivery -> deduplicated state change

What this does not solve​

These controls protect Central task state. They do not stop two different tasks from editing the same checkout at the same time. They also do not make a network filesystem safe for SQLite. Central must use one native local data root, and operators must avoid colliding tasks on one working directory.

Next lesson​

Continue with Trace every run.

Derivative map​

  • Weekly package: WEEK-02
  • Long video: VIDEO-W02-LONG
  • Shorts: SHORT-W02-PROBLEM, SHORT-W02-MECHANISM, SHORT-W02-WARNING
  • Email: EMAIL-W02
  • LinkedIn: LI-W02-A, LI-W02-B
  • X: X-W02-A, X-W02-B
  • Visual: VISUAL-W02

Review record​

  • Technical claims checked against the current canonical sources.
  • Truth label and nearby limitations reviewed.
  • Examples checked for secrets, client material, and private paths.
  • Editorial structure, internal links, and repository voice reviewed.

Review completed: 2026-08-27

Re-audited against the running product: 2026-09-13