# Host adapter, effects and outbox

Docket is the decision and audit boundary. The host is the actor.

> **Durability notice:** When Docket runs with the Postgres case store
> (`DOCKET_CASE_STORE=postgres`), cases, facts, stage state, journals and
> explicit step events, recorded outcomes, idempotency replay records and
> queued jobs are stored in Postgres, so they survive deploys and restarts.
> Published process definitions are reinstalled from code at boot, and the
> per-process mirror-deduplication markers are not durable; losing the markers
> can cause a telemetry mirror retry, not case loss. With the in-memory fallback
> store (`DOCKET_CASE_STORE=memory`), cases and records are process-local and
> are lost on every deploy or restart, and idempotent replay holds only within
> one server process lifetime. Keep your own durable record of Docket case ids
> and pending intents outside Docket, and do not treat Docket alone as the
> system of record.

| Responsibility | Host / agent | Docket |
| --- | --- | --- |
| Read inbound work and choose when to engage | Yes | No |
| Interpret policy and return a legal edge | No | Yes |
| Hold a case at a human gate | The host waits | Docket records and reports it |
| Send a message, refund money or pay someone | Yes | Never |
| Record an approved host effect | Yes, after it happens | Stores the outcome event |
| Retry work after a transient failure | Yes | Stores the idempotent result |

## Recording a host effect

Call `record_outcome` with an outcome whose `kind` is `effect` (in shorthand,
`record_outcome(kind="effect")`) only after the effect was actually performed
and approved. Include the executed flag and a small result object that
describes what the host observed. Recording an effect does not cause Docket to
send, refund or pay.

## Idempotency

Every state-changing call should carry an idempotency key. The key scopes one
logical operation for one tenant. If the same key and the same canonical request
arrive again, Docket returns the stored result with replayed set to true. If the
key is reused with a different request body, Docket refuses the call as a
conflict. Generate a fresh key for each new logical operation, not for every
retry of that operation.

## Host-side at-least-once delivery

Treat host delivery as at-least-once. The public contract does not promise an
agent-visible job queue. For work that must outlive the process, keep the host's
own durable intent log outside Docket. A worker can crash after the external
effect succeeds but before it records completion, so the same job may be
attempted again. Give each outbox job its own idempotency key and make the
external operation safe to repeat with that key. Retry transient failures with
bounded backoff. Move exhausted jobs to a dead-letter state for human review
instead of retrying forever.

The important ordering is: record the intent in the host's own durable log,
perform the host effect, then record the outcome in Docket. If the process
crashes between steps, reconcile with the external system before retrying so a
message is not sent twice or a refund is not issued twice.
