Contracts and event lifecycle
A browser reconnects after missing part of an answer. Its last event number means something only if the server knows which run and attempt it belongs to.

DRAFT · ILLUSTRATIVE CONTRACTS
Imagine reloading a page halfway through a streamed answer. The server needs enough information to return the right conversation, distinguish a retry from a new request, and identify the last event the reader saw. These proposed contracts describe that exchange. No live endpoints are supplied here.
Translate HTTP request and response shapes into domain commands at the boundary. The rules governing a run should survive a change of transport, broker, or model provider.
Browser commands
| Proposed endpoint | Behavior |
|---|---|
POST /v1/conversations/{id}/runs | Authorize, deduplicate an idempotency key, persist an accepted run, return run identity and cursor |
GET /v1/runs/{id}/events?after={cursor} | Authorize subscription, replay retained events when available, then deliver live events |
POST /v1/runs/{id}/cancel | Idempotently record cancellation intent and notify the current run owner |
GET /v1/conversations/{id} | Return a bounded authorized snapshot with per-run checkpoints |
The endpoint table leaves a real design choice open. Select cookie or token authentication, then demonstrate reconnection with the actual browser transport. Native EventSource and fetch-based SSE differ in how they send headers and reconnect. A browser subscribes through an authorized gateway. Internal broker subjects stay behind it.
Event envelope
{
"schema_version": 1,
"event_id": "evt_example",
"conversation_id": "conv_example",
"run_id": "run_example",
"attempt": 1,
"sequence": 42,
"type": "answer.delta",
"payload": { "text": "A supported answer fragment" }
}A cursor identifies a position in one retained run attempt's history. Its encoding remains open. A conversation snapshot includes a checkpoint {run_id, attempt, cursor} for each resumable run; a cursor must never be reused for a different run or attempt. A start command supplies the checkpoint for the newly accepted run. Deliver deltas, source records, retrieval status, terminal state, and errors as distinct typed events. Source records include document revision, source anchors, and evidence IDs.
Run authority
Cancellation intent is separate from transport disconnect. The run owner serializes competing terminal transitions. Attempts carry fencing information so a stale owner cannot append or complete a newer attempt. The exact lease and fencing mechanism is open until durable storage and deployment topology are selected.
Ordering and recovery invariants
Suppose the client has rendered event 42 for run_example, attempt 1. Keep the visible answer and the last contiguous sequence together when you test recovery.
| Next delivery | Expected client action |
|---|---|
| Sequence 42 again | Ignore the duplicate. Keep one copy of the text and leave the checkpoint at 42. |
| Sequence 44 arrives before 43 | Hold 44 and request replay after 42 for the same attempt. Apply 43 and 44 once, in order, when the missing event arrives. |
| The server no longer retains event 43 | The proposed recovery response would indicate that the cursor expired and supply or identify an authorized snapshot. Replace the partial answer with that snapshot, then subscribe after its checkpoint. The HTTP status, response fields and cursor encoding remain undecided. |
- Accepted commands are durable before success is acknowledged.
- Each append is authorized for the current run attempt and ordered by sequence.
- Clients deduplicate replay overlap, detect gaps, and reject stale attempts.
- Each run snapshot and its live subscription share a run-scoped checkpoint boundary. Catch-up handles the interval between them.
- Retention expiry returns an explicit resynchronization result and a new snapshot.
- Terminal status is authoritative. A completed record cannot be silently changed by a late delta.
- No reconnect silently starts a second model generation.
Replay of persisted deltas restores output. It does not reconstruct a provider's hidden inference state. A worker failure produces interruption or a defined continuation attempt.
Durability policy to decide
Direct delivery with asynchronous batched persistence minimizes synchronous storage work, but text displayed since the last persistence checkpoint may be absent after a crash. Persist-and-ack before delivery provides a stronger displayed-output guarantee at additional cost. Measure both before choosing. Record transcript durability separately from short-lived status events.
Evidence and publication contracts
Retrieval returns eligible, versioned evidence with original text, source anchors, retrieval provenance, and claim qualifiers. The adapter reports approximation, filtering, cancellation, and snapshot capabilities. Generated enrichment remains labeled and linked to its dependencies.
Publication checks the current source revision and artifact fingerprint in the same authority that activates an index version. The transaction also records a boundary event for outbox publication. Consumers reconcile versioned state rather than relying on receiving every notification.