Skip to main content
This chapter continues the workflow manual.

Persistence with SQLite

Create a local durable store:
The store maintains these logical records: The database is initialized additively. Opening an older workflow database creates newly introduced tables without deleting existing execution data. Resumption still requires compatible pinned definitions; see the version-2 migration guidance in execution contracts.

Opening and submitting work

coordinator.open(item_id):
  1. verifies that the item is ready or in progress;
  2. loads participant traits;
  3. reads authorized shared state;
  4. assembles prior visible answers and submissions;
  5. evaluates available derived values;
  6. renders every survey question;
  7. saves the exact render and state versions; and
  8. marks the item in progress.
The returned OpenedWorkItem contains the rendered survey and execution context. Reopening reuses the first saved render and observations, preserving survey rules, memory, instructions, and groups. It does not refresh shared state. Submit an answer with a stable idempotency key:
Submitting the same key for the same item twice produces one durable submission and one completion event. Reusing it with different content or for a different item raises an error. Leased workers must pass their current attempt_id; stale workers cannot accept new responses.

The durable outbox

When an item becomes ready, the coordinator creates an outbox record in the same workflow store. Delivery reads only pending records:
Each DeliveryRequest contains:
An adapter must use the idempotency key when its external system supports one. The outbox protects the ready decision from a process failure between graph evaluation and delivery. Dispatchers atomically claim each record before calling the adapter and mark delivery using the claim token after the adapter returns. Concurrent dispatchers cannot deliver the same claimed record. Claims persist in workflow_outbox_claims across failures and restarts, and do not expire automatically: a slow request or a crash after external delivery must not cause another invitation. After stopping the original dispatcher, reconcile an abandoned claim with the external provider. If delivery succeeded, call store.mark_delivered(outbox_id, claim_token=token). If retry is safe, call store.release_outbox_claim(outbox_id, claim_token=token) before dispatching again. The table records the outbox ID, ownership token, and claim time. Humanize does not provide end-to-end exactly-once delivery here; a failure between its remote calls and the local task record requires this reconciliation.

Humanize and real respondents

HumanizeDeliveryAdapter is intentionally thin. For each ready item it:
  1. opens and renders the participant-specific survey;
  2. creates a private Humanize survey;
  3. creates a delivery;
  4. records the external survey and delivery identifiers; and
  5. returns a delivery receipt.
Later, polling imports completed responses:
For each response, the adapter calls coordinator.submit(). That submission may make new items ready, after which the outbox dispatcher delivers the next wave. Humanize owns survey presentation, invitations, and response collection. It does not need to understand the dependency graph.

Simulated respondents

The simulation uses the same coordinator and store with an in-memory inbox:
EDSLAgentAnswerer runs each rendered survey through the ordinary EDSL agent/model pipeline. A scripted object implementing answer(agent, opened) is often better for deterministic tests. response_delay and the virtual clock can model elapsed time without sleeping: