Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/world-postgres-listen-self-healing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@workflow/world-postgres': patch
---

Make stream delivery durable across `LISTEN`/`NOTIFY` interruptions: the dedicated `pg.Client` now reconnects with bounded exponential backoff (250 ms → 30 s), and `readFromStream` runs a periodic re-query of `streams WHERE chunk_id > lastChunkId` as a polling safety net for chunks delivered while the LISTEN socket was down. The poll interval is configurable via `PostgresWorldConfig.streamPollIntervalMs` (default 5000 ms; set to 0 to disable). Tracks vercel/workflow#1855.
13 changes: 6 additions & 7 deletions packages/world-postgres/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Pool } from 'pg';
import type { ListenAdapter } from './listen-adapter.js';

type PgConnectionConfig =
| { connectionString: string; maxPoolSize?: number; pool?: undefined }
Expand All @@ -14,11 +13,11 @@ export type PostgresWorldConfig = PgConnectionConfig & {
*/
streamFlushIntervalMs?: number;
/**
* Plug in an alternative LISTEN/NOTIFY transport for the streamer.
* Defaults to the bundled `pg`-backed adapter (with self-healing reconnect).
* See {@link ListenAdapter} for the contract; useful for swapping in
* `bun:sql`'s native listen (oven-sh/bun#29710) once it lands, or a
* different pub/sub backend entirely.
* How often (ms) `readFromStream` re-queries the `streams` table as a
* safety net for chunks delivered while the LISTEN client was reconnecting.
* Default is 5000. Set to 0 to disable polling entirely.
*
* See `CreateStreamerOptions.pollIntervalMs` for the full contract.
*/
listenAdapter?: ListenAdapter;
streamPollIntervalMs?: number;
};
10 changes: 3 additions & 7 deletions packages/world-postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export function createWorld(
const drizzle = createClient(pool);
const queue = createQueue(config, pool);
const storage = createStorage(drizzle);
const streamer = createStreamer(pool, drizzle, config.listenAdapter);
const streamer = createStreamer(pool, drizzle, {
pollIntervalMs: config.streamPollIntervalMs,
});

return {
specVersion: SPEC_VERSION_CURRENT,
Expand All @@ -80,10 +82,4 @@ export function createWorld(

// Re-export schema for users who want to extend or inspect the database schema
export type { PostgresWorldConfig } from './config.js';
export {
createBunSqlListenAdapter,
createPgListenAdapter,
type ListenAdapter,
type ListenSubscription,
} from './listen-adapter.js';
export * from './drizzle/schema.js';
203 changes: 0 additions & 203 deletions packages/world-postgres/src/listen-adapter.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/world-postgres/src/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,10 @@ export function createQueue(
`${baseUrl}/.well-known/workflow/v1/${pathname}`,
{
method: 'POST',
duplex: 'half',
headers,
body,
}
} as any
);
const text = await response.text();

Expand Down
Loading
Loading