Skip to content

app/: live updates' transport, LISTEN/NOTIFY (sc-8897, sc-8900) - #76

Closed
ndbroadbent wants to merge 3 commits into
laravel-webhooksfrom
laravel-live
Closed

ndbroadbent wants to merge 3 commits into
laravel-webhooksfrom
laravel-live

Conversation

@ndbroadbent

Copy link
Copy Markdown
Member

Part of sc-8900, for sc-8897 (live updates). Stacked on #74.

This is the transport the SSE endpoints will use. It's built as sc-8900 seam 4 describes: Postgres LISTEN/NOTIFY between replicas, with no WebSockets and no broadcaster service.

  • live::notify(topic) sends pg_notify('visualci_live', topic), with topics such as build:42. Inside a transaction it's delivered on commit, so nobody hears about a change they can't read yet.
  • live::subscribe(url) returns every topic sent from now on, from any replica. One PgListener per process starts with the first subscriber, and after a lost connection it reconnects with backoff (0.5 s, doubling up to 30 s).
  • Topics only say "look again". The stream's handler reads the current state, so a missed notification costs a moment rather than giving a wrong answer, and payloads never carry data a subscriber mightn't be allowed to see.
  • Health: CheckLive runs every minute. It notifies a random probe topic, waits up to 10 s for this process's listener to hear it, and pushes VISUALCI_LIVE_HEARTBEAT with the result, so a listener that's connected but deaf fails the heartbeat.

Next, once features' BuildChanged (#73) is on main: a listener that notifies build:<id> and project:<id>, and the EventStream endpoints for the build page and the CLI's --wait.

Tests: app/tests/live.rs runs against the real Postgres server, because test transactions roll back and NOTIFY never arrives inside them. It checks that a notification from another connection reaches a subscriber, and only after the commit. The whole app suite passes on docspring-dev, and clippy is clean.

@visualci-com

visualci-com Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #335 · 331 unchanged · no changes

This PR vs base: nothing since #272, across 3 builds

Updated as builds change. Agents can review with VisualCI's MCP tools.

…IFY on one channel, one listener per process (started by the first subscriber, reconnecting with backoff) fanning topics out to subscribers; notify() is delivered on commit; topics only say 'look again', so a missed one costs a moment and payloads carry no data; CheckLive notifies itself every minute and pushes VISUALCI_LIVE_HEARTBEAT only when it arrives
…h fresh LISTEN and each silent reconnect tells subscribers to re-read everything (*), as they must on Lagged too; every process probes its own listener each minute over a separate connection and restarts it when the probe doesn't come back in ten seconds (a half-open connection), with live::healthy() for its health check; the queue worker's heartbeat waits for the listener to be ready before probing; topics are capped well under Postgres's 8000 bytes; documented: LISTEN needs a direct or session-mode connection, not a transaction-mode PgBouncer
@ndbroadbent

Copy link
Copy Markdown
Member Author

Included in #87.

@ndbroadbent ndbroadbent closed this Dec 3, 2026
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