TechFabricTechFabricPlatform
Platform referenceHost

Durable outbox egress

Atomic canonical-event delivery records, lease-based relay, retries, replay, and truthful at-least-once semantics.

Outbox egress is an optional OutboxPlatformHostStore capability in @fabricorg/platform-host. appendEventWithOutbox writes the canonical AssetEvent and delivery record together. PostgreSQL uses one statement inside the application-provided transaction; the memory adapter mirrors ordering and leases for deterministic tests. A memory store may enable governed Host outbox egress only when constructed with an explicit MemoryPlatformHostTransactionProvider whose snapshot and restore functions cover its domain database; otherwise transactionalOutbox is false and Host configuration fails closed. When outbox egress is enabled, a transaction-scoped event requires transactionWithEvents and its appendEventWithOutbox operation before handler execution.

runOutboxRelayCycle leases pending records, publishes, checkpoints, retries with backoff, and dead-letters poisoned messages. Delivery is at least once. A publisher crash after send but before checkpoint may republish the same immutable event ID, which consumers use as the deduplication key. The bus envelope separately carries event type and schema version, tenant/space, ledger sequence, correlation/causation, timestamps, producer module version, trace context, payload classification, and consistency. The canonical event remains audit truth; outbox rows are delivery state only.

The envelope leaves out the actor unless the application opts in through outbox.includeActor(event, classification), which must return true to add actorId and actorType. The default is exclusion for every classification, so existing publishers receive an unchanged envelope. An included actor reaches every sink of every relay reading that outbox. Each outbox record stores the decision as actorDisclosure, and the relay passes it to the publisher as context.actorDisclosure: included, suppressed (the hook left the actor out), or legacy (a record written before Host stored the decision, which never carries an actor).

A dead-lettered record stays put until an operator requeues it with host.requeueOutboxDeadLetter. The host authorizes the operator through authorizeOutboxRequeue, and without that hook every requeue is refused. The store then moves the record from dead_letter to pending by compare-and-set within its tenant and space, and only if its lease token is still the one the host read and authorized. It resets the attempt budget, and appends who requeued it, when, why, and the attempt count and last error it replaced. The relay republishes it under the same event ID. A pending or published record, a record in another scope, the losing side of two concurrent requeues, and a record dead-lettered again after it was authorized all get a typed refusal, and nothing is written for them.

Event payloads must already obey Platform redaction requirements. Payload classification labels handling expectations but doesn't redact secrets. Adapter and compliance lifecycle events are excluded from bus egress by default because their audit payloads may contain request, response, policy, or vendor data. shouldPublish can opt an event in only after the application has made that payload safe for the external bus; canonical storage is unaffected.

To deliver outbox events to customer-registered webhook endpoints, use @fabricorg/webhook-delivery, which supplies a fan-out publisher for this relay.