Skip to content

Dispatch integrity isolated proof of concept

Run ./tests/dispatch_integrity_poc/run.sh from the repository root. It creates and removes a disposable PostgreSQL 16 Docker container without touching the application database. Trust authentication is confined to this unexposed, disposable container. Do not deploy this schema or use it for real data.

The prototype exercises forced RLS under a non-bypass definer role, restricted app/worker privileges, a narrow creation function, a deferred unsealed-dispatch check of sealing and graph completeness, guards against mutations after sealing, shared and per-recipient grouping, mismatches, missing contributions, and an atomic handoff row. It also checks a conflicting concurrent key insert and recovery of the winning row in a fresh transaction. This is a uniqueness experiment with pre-existing dispatches, not an idempotent creation API.

Two-connection testing covers an attempted child insertion while its parent is uncommitted, followed by a fresh attempt after the parent commits sealed. The first sees no parent and the second is rejected as sealed. It also exercises rolling back creation or sealing to savepoints, including that an unsealed parent cannot then commit. Since an unsealed parent cannot be committed in this model, these tests do not represent two transactions modifying a visible unsealed graph. They do not prove all possible interleavings.

In particular the caller supplies eligibility, canonical destinations and tenant context: these are NOT trustworthy authorization or channel assessment. The prototype does not verify actual app roles or schema restoration, idempotency, concurrent complete dispatch creation, commit uncertainty, source validation, retention, all savepoint and concurrency interleavings, workloads or adapter behavior. The deferred trigger now checks completeness and grouping when a graph is sealed; child guards acquire the parent row lock and reject later changes, including direct writes as the owner. This is not a security boundary against a table owner that can disable triggers or alter schema. The handoff remains mutable; the trigger checks its existence at commit, not its later lifecycle. Empty dispatches are accepted here. No production security or completeness guarantee follows from these limited tests.

The test deliberately demonstrates that poc_app can set an arbitrary tenant GUC and submit an invented recipient and unvalidated destination. Forced RLS under a definer role preserves the supplied context; it does not prove that the context or caller-supplied assessment is authorized or true. Closing this gap requires an explicit trust model and trusted selection/assessment boundary. Test sessions use SET LOCAL SESSION AUTHORIZATION, not just SET ROLE from a superuser session, to avoid accidentally inheriting superuser role-switch powers.