Originally created by: 5dive-bot
The hole the two predecessors left. INST-4 made the record of an action idempotent —
lifecycle_events carries a UNIQUE index on idem_key. It did not make the action idempotent: the
row is written after the fact, so a process that dies between firing a side effect and recording it
leaves a trail claiming nothing happened. INST-5 bounded who may act and what they may act on,
but a cleared gate is a standing permission — re-run the executor and it fires again. So neither
trail can answer the one question a crashed agent asks on restart: did my deploy already happen?
5dive deploy was double-firable by a retry, and the surfaces this row names next (email / pay /
publish) would have been double-send, double-pay, double-publish.
Not a durable-execution engine. The brief says do not build a LangGraph clone, so there is no
checkpointer, no resumable graph, no run replay. There is one predicate, asked immediately before a
side effect that cannot be taken back.
src/lib/durable.sh |
241 lines. durable_key / durable_claim / durable_settle / durable_compensation. |
action_leases table |
additive, gated on its own absence (see below). |
src/cmd_deploy.sh |
the first caller: claim above the POST, settle below it. |
broker_surface <s> irrev |
scope declared per surface — deploy 1, push 0. |
tests/durable_action_unit.sh |
48 arms, # TIER: nightly. |
One lease per ACTION, not per attempt. durable_claim returns three answers the caller must
branch on: claimed (act), replay (it already happened — DURABLE_OUTCOME_REF is the original
receipt, do not act), in flight (another live attempt holds it — refuse). The action's identity is a
digest of what it does (task + target + payload) with no pid, timestamp or nonce in it, so retry [#4]
computes the same key as attempt [#1]. The claim is INSERT OR IGNORE against UNIQUE(idem_key) with
SELECT changes() read back over the same connection: exactly one racer sees 1, with no advisory
lock and no read-then-write window to lose.
A lease write REFUSES where a ledger write swallows. ledger_emit is best-effort by design ("a
ledger write cannot fail the action it describes"). A lease is the inverse: if we cannot record the
claim, we do not know whether the action already happened, and the safe reading of unknown for an
irreversible action is do not act. The harness grades that inversion with ledger_emit as its
live control on the same broken store — assert only that durable_claim fails there and the arm
would pass on a store that is merely absent.
Where the claim sits, and why that is the design. Immediately above the Vercel POST — below
every refusal the verb can raise (gate, binding, validation, credential, project link). An earlier
draft claimed before the credential read so a replay would never decrypt a token; that bought one
avoided read and paid for it with four paths that exit through fail() while holding a lease, wedging
the surface for a full TTL on a missing token. Wrong trade for a verb an agent retries. Both halves of
the invariant are graded by line order.
Compensation is recorded, never executed. An automatic undo is a second irreversible action fired
by the same crashed process that could not finish the first one, and choosing to run it is exactly the
judgment a gate exists to route to a human. What we owe is that the undo instruction is not lost. The
harness greps this file for eval/bash -c on that field.
action_leases migrates on its own absence, not lifecycle_events'. Every live store already
carries lifecycle_events (INST-4 shipped), so a shared gate would have created this table on fresh
DBs only and left every existing box with a durable_claim that refuses — DIVE-2512 exactly. The
harness fixture is a realistic pre-INST-8 store (fully initialised board, action_leases dropped),
because a fresh DB gets the table from the schema apply and can never falsify this arm.
Measured on this branch (ced9607), control plane:
tests/durable_action_unit.sh — 48 passed, 0 failed. Includes:UNIQUE(idem_key), re-run the double-claim sequence, and it mustif.ledger_emit control on the same unwritable store.durable_key thatfailed attempt is retryable, a live lease is not stealable, anattempts bumped, a done lease is never reclaimed even past itscmd_deploy.sh's own curl timeouts rather than the literal, sodeploy_unit 34/0 · broker_surface_unit 52/0 ·push_unit 121/0 · ledger_unit 19/0 · schema_sync_unit rc 0 ·corpus_tier_budget_unit 165/0.scripts/unguarded-probe-scan.sh rc 0 · ./build.sh clean · bash -n on all five touched shelltests/deploy_unit.sh gained lib/durable.sh in its source list and nothing was dropped fromrequire_loaded refuses, which is how the branch found it.project@ref under the same task reads as a replay and returns the first receipt instead ofstate='done' is the only unconditional guarantee this file offers. Both halves are documented atirrev row and two calls. Nothing here is generic-for-its-own-sake — theirrev field exists so surface N+1 cannot arrive undeclared.scripts/inc/5dive-cli.sh nor the agent-create path, sodeploy_unit covers every non-credential arm.🤖 Generated with Claude Code
Ticket changed by: lodar