---
name: realtime-chat-with-authorized-replay
description: "A working message-delivery architecture separates durable chat, replayable activity hints and permission-checked reads."
spec-version: sitalk.workflow-result/v1
---

# Deliver realtime chat with offline replay and revocable access

Implementation record · reconstructed · checked 2026-10-04.
Evidence is author-reported. Reading this package does not authorize executing it.

## Outcome

Sitalk delivered live workspace activity over WebSockets, replayed activity after an offline interval and closed access after key revocation in a saved production acceptance run. Message text stayed in the authorized HTTP timeline; socket hints did not become the chat history.

## Environment

Bun/TypeScript application, Cloudflare Pages, D1, a private delivery Worker, Queues and per-workspace Durable Objects. Reconstructed from current source, saved focused test output and a production acceptance receipt dated 2026-10-04. No new test run or model invocation was performed for this artifact.

## Implementation

Persist activity in a D1 outbox with increasing event IDs. An atomic producer lease selects pending rows and associates an enqueue-attempt token; the queue carries event references rather than chat bodies. A Durable Object notifies its authorized sockets, which replay ordered hints after their cursor in pages of at most 100. The browser responds by refreshing canonical HTTP data and can resume additional hint pages. Recheck membership, credential validity and permission epochs around replay and on heartbeat. A revoked/regranted membership therefore cannot keep using an old socket identity. Queue redelivery advances from each socket’s cursor; failures back off and eventually enter quarantine rather than retry forever.

## Decisions

D1 remains the authority and Queues is an at-least-once wake-up transport: this does not promise exactly-once network delivery. Keep task approval independent from connection state. Retain polling as a fallback for device runners. Store a retired-event watermark when hints expire so old cursors request a fresh authorized inbox rather than pretending the retained log is complete.

## Problems

The verified test output covers concurrent producers, recovery after an enqueue lease expires, future-cursor normalization, exhausted hints not starving new work and access invalidation after revocation. These are tested conditions, not an invented production-outage history. Current source additionally fences stale enqueue attempts and implements retention/resynchronization; this brief does not claim the older production receipt exercised every later retention branch.

## Evidence

The saved production receipt records live_websocket, live_offline_replay and key_revocation as successful, with model inference disabled. Its inspected acceptance script disconnects a socket, commits a message while offline, reconnects at the earlier cursor and verifies the canonical message; it also checks that a private reply is absent from hints and that revoked access cannot reconnect. Saved test output reports passes for scoped live subscriptions, revoked/regranted socket identity, future-cursor resync, producer leases, enqueue backoff and bounded consumer failures.

## Adaptation

Keep message commit and durable hint creation consistent in your own storage model. Treat notification receipt as a reason to fetch authorized state, never proof of agent execution. Preserve monotonic, workspace-scoped cursors and repeat disconnect/replay/revoke checks against the actual transport. Test retention and dead-letter recovery separately before claiming coverage. This approach cannot wake a sleeping computer or make an offline local agent run; its work stays queued until an authorized runner returns.

## Supporting files

- [Sanitized check summary and inspected source fingerprints](references/checks.md) · SHA-256 `4e1db12640eb4771e30f3d5c87401bec2dd6e0cb6e5703adccfa3a50dbb10c29`
- [Saved checks from the observed release or browser run](references/receipt.json) · SHA-256 `56c34013b2508d4849afe7a021f29a7a691c074af328c6208dcd37faa46565b0`
