Skip to content

feat(durable): Postgres storage on the grouped commit contract - #5

Open
rgarcia wants to merge 2 commits into
mainfrom
hypeship/postgres-grouped-commit
Open

rgarcia wants to merge 2 commits into
mainfrom
hypeship/postgres-grouped-commit

Conversation

@rgarcia

@rgarcia rgarcia commented Oct 30, 2026

Copy link
Copy Markdown

Summary

Rebases the Postgres storage adapter onto upstream main (which now carries pi-durable's group commit, e5c6182) and ports it to the batched Storage.commit(batches, receive, context) contract.

  • A group of batches is one round trip: a new commit_batches plpgsql function locks the session row and checks the owner once, then runs the existing commit_batch per batch inside a subtransaction. A refusal by one of the adapter's checks (SQLSTATE DU003 to DU009) keeps the batches before it and returns the refusal; any other error, ownership included, raises and rolls the call back.
  • A batch containing a document.copy starts a new call once the batches before it are durable, because the copy's source is materialized while preparing. Everything else is one call.
  • A failed database read while preparing a copy is an unknown outcome (rejects the call), never a refusal.
  • Schema version 3 also widens the task status check to admit sleeping, added upstream in 1.4.0.
  • kernel/pi main was fast-forwarded to upstream main (50af8c1); the base branch hypeship/durable-postgres-storage starts there.

Tests

PI_DURABLE_POSTGRES_URL=... vitest --run test/postgres-storage.test.ts: 72 tests pass against Postgres 17, including upstream's new conformance cases (prefix kept before a refusal, a malformed later batch, a batched copy against the earlier batches' state, receipts before resolution) on both the plain and the reopen-per-commit storages, plus a new round-trip test: one query for three plain batches, three for a group whose last batch copies a document the first two wrote.

Root tsc --noEmit and biome are clean.

Port the adapter to Storage.commit(batches, receive, context). A group of
batches goes to a new commit_batches function in one round trip: it locks
the session row and checks the owner once, then runs commit_batch per batch
in a subtransaction, so a refusal by one of the adapter's checks keeps the
batches before it and ends the call with the refusal, while any other error
rolls the call back and rejects it. A batch with a document.copy starts a
new call once the batches before it are durable, since the copy's source is
read while preparing; every other group is one round trip.

Schema version 3 also admits the sleeping task status added in 1.4.0.

A round-trip test pins one query for a group of plain batches and three for
a group whose last batch copies a document the earlier ones wrote.
@rgarcia
rgarcia changed the base branch from hypeship/durable-postgres-storage to main November 3, 2026 15:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant