Skip to content

app/: live updates over server-sent events for the pages and the CLI's --wait (sc-8897, sc-8900); CLI 0.2.23 - #149

Merged
ndbroadbent merged 1 commit into
mainfrom
laravel-sse-v2
Dec 3, 2026
Merged

ndbroadbent merged 1 commit into
mainfrom
laravel-sse-v2

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Live updates over server-sent events for app/: the build and project pages, and the CLI's --wait. Replaces #94, rebuilt on current main (the frontend in frontend/, app/ in the root workspace, settings in config.rs) and fixed against the review findings.

What it does

  • GET /api/ui/live/orgs/{org}/projects/{project} and .../builds/{number} (app host, the session): the pages follow these and read their data again on each event.
  • GET /api/v1/live/builds/{id} (API host, a token): the CLI's --wait. Each event carries the build exactly as GET /api/v1/builds/{id} answers it.
  • Notifications: a BuildChanged listener (listeners::tell_the_live_streams), plus a new build, a build starting to process, and each processing run that makes progress while waiting for renders. They go through Postgres LISTEN/NOTIFY (app/src/live.rs, already on main).

The review findings

  1. Every stream starts with the current state. The first event is snapshot: the build's JSON for the CLI, and "read now" for the pages. The stream subscribes before it reads, so nothing falls between the two. A browser that reconnects, or a CLI that starts after the build finished, has the state at once. Tests: a_stream_opened_after_the_build_finished_has_its_final_state_at_once, a_reconnection_starts_with_the_current_state, and the frontend's live.test.tsx.
  2. Limits and connection hygiene. Each web process has three limits: VISUALCI_LIVE_MAX_STREAMS_PER_PRINCIPAL (30, counting a person, a project token, or a visitor's IP), VISUALCI_LIVE_MAX_STREAMS_PER_BUILD (100) and VISUALCI_LIVE_MAX_STREAMS (2000). A stream over a limit is refused before it starts, with a 429 and Retry-After: 30 in each endpoint's error format.
    • Each stream's slot is released when its response body is dropped, which happens when the client goes away, the stream's lifetime ends (VISUALCI_LIVE_STREAM_SECONDS, 30 minutes) or the server shuts down.
    • A comment goes out every 15 s.
    • An idle stream holds no database connection. Reads happen only when a CLI event is sent, at most 4 at once per process (READS), so a burst that reaches every stream can't take web's 20-connection pool.
    • Tests: a_stream_past_a_limit_is_refused (its own test binary, live_limits.rs), each_limit_refuses_the_next_stream_and_a_closed_stream_frees_its_place, a_closed_stream_gives_its_place_back.
  3. The same Principal. Streams take the existing Principal extractor. On the API stream, a token it doesn't recognise falls back to mcp::oauth_principal, so a vca_ token is checked against its own resource (<mcp url>/mcp, scope mcp).
    • A project token follows only its own project's builds, never a public project's.
    • A person can follow their organizations' builds, plus public projects' builds, as MCP's get_build allows.
    • The page streams are open to anyone for a public project, matching the pages themselves.
    • Anything else gets a 404.
    • Tests: a_project_token_follows_only_its_own_projects_builds, people_follow_their_organizations_builds_and_public_ones, an_mcp_clients_oauth_token_follows_on_its_own_resource (an admin-resource token and a revoked token both get a 401). The OAuth connect helper moved from mcp_admin.rs to tests/oauth_client/.

CLI (0.2.23)

wait follows the stream and keeps its exit codes, because it still returns the Build that test_exit_code reads (0, 1, 3, 4). It falls back to polling in these cases:

  • the server doesn't offer the stream (an older server's 404, a 429, any response that isn't text/event-stream);
  • nothing arrives within 10 s (a buffering proxy);
  • three streams in a row end without sending anything.

A stream that goes silent for 45 s is reconnected. While it follows a stream, wait also reads the build once a minute, in case the stream only sends keep-alives. At the timeout it reads the build one last time.

Tests (fake server): wait_follows_the_live_stream_until_the_build_is_decided, a_wait_that_starts_after_the_build_finished_returns_at_once, wait_polls_when_the_server_has_no_live_stream, wait_polls_when_a_proxy_holds_the_stream_back, wait_reads_the_build_when_the_stream_only_keeps_alive, wait_answers_the_undecided_build_at_its_timeout.

The docs' VISUALCI_VERSION pins stay on 0.2.22 until 0.2.23 is released.

Frontend

  • useLive reads again on snapshot and changed. Pages poll only while no stream is open.
  • If the server refuses the stream, the page reopens it 30 s later.
  • While a stream is open, a build that's still in progress is read once a minute as a backstop.
  • There's no live indicator in the UI, so the VisualCI build should show no visual changes.

Proxies, health and docs

  • The responses send Cache-Control: no-cache, no-transform (which stops Cloudflare and Envoy compressing them) and X-Accel-Buffering: no.
  • /status gains live_streams_open and live_listener (idle, starting, ok or stale).
  • Docs: the env-vars page and .env.example are regenerated, reference/api.md has a new "Follow a build" section, and design.md has a "Live updates" entry.

Infra (talira-ai/infra), needed before streams last past a minute in production

visualci-subdomain-routes sets timeoutPolicy.response: 60s, so Envoy cuts every stream at 60 s. The fix is a route for the prefixes /api/ui/live and /api/v1/live with timeoutPolicy.response: infinity, keeping idle: 300s (comments arrive every 15 s). Until then, clients reconnect each minute and get a fresh snapshot, which works but is wasteful.

Supersedes #94.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@visualci-com

visualci-com Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #232 · 341 unchanged · no changes

This PR vs base: 8 changed, 2 added since #211, across 2 builds

docspring/visualci · journeys · build #230 · 14 unchanged · no changes

This PR vs base: 2 added since #207, across 2 builds

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

…s --wait (sc-8897, sc-8900); CLI 0.2.23

Every stream starts with a snapshot of the current state; streams authorize with the same Principal as the API and
MCP (vca_ tokens on their own resource); open streams are capped per principal, per build and per process (429 with
Retry-After); idle streams hold no database connection. The CLI's --wait follows /api/v1/live/builds/{id} and falls
back to polling when there's no stream. Supersedes #94.

Co-Authored-By: Claude <noreply@anthropic.com>
@ndbroadbent
ndbroadbent merged commit 653cf57 into main Dec 3, 2026
14 checks passed
@ndbroadbent
ndbroadbent deleted the laravel-sse-v2 branch December 3, 2026 22:03
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