Skip to content

feat!: share live GraphQL refreshes across identical subscriptions - #342

Merged
patrickleet merged 3 commits into
v5from
refactor/v5-review-26b-live-sharing
Nov 25, 2026
Merged

patrickleet merged 3 commits into
v5from
refactor/v5-review-26b-live-sharing

Conversation

@patrickleet

@patrickleet patrickleet commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Task 26 stage B ([[tasks/v5-review-26]]): live delivery. Review findings 05 #7, #13, #19 and #11.

What changed

  • One producer loop (src/graphql/subscribe.rs) for catalog live roots and external read roots. external_roots.rs had a second, already-drifted copy, which is now gone. Both kinds stop on a closed hub.
  • Shared execution: each distinct read gets one shared entry. Each change is debounced, executed once, and published to every subscriber. Each subscriber keeps its own hash gate and protocol envelope. A subscriber that joined between frames, or skipped one while slow, catches up with one read from its own cursor, so replay stays exact.
  • Sharing key:
    • Catalog: role, compiled SQL, every bind, tables, byte paths, and, with the protocol on, the cache scope and schema hash. Binds carry every row-policy and claim value. The cache scope is a MAC over privilege, roles, principal partition and every claim a policy reads.
    • External: role, section, source, root, arguments and the full session.
    • BindValue has hand-written Eq/Hash: floats compare by bits, JSON by the text sent to the driver.
    • Shared executions issue tokens through a fresh accumulator copy and never touch a subscriber's accumulator.
  • Bound and backpressure:
    • live_concurrency(n) (default 8, 0 rejected) caps first reads, refreshes and catch-ups together.
    • The lock is always taken before the permit.
    • Entries keep only the latest frame, so a slow subscriber skips frames instead of stalling others.
  • Lifecycle: the entry is torn down with its last subscriber. A failed shared execution reaches every sharer and removes the entry in the same step.

Executions

Measured with hundred_origin_subscribers_share_one_execution_per_change, written first and run against the old code:

Producers Executions to open Executions per change
Before 100 100 100
After 1 100 1

Findings

  • feat: boundaries #7, Make mixed commits transactional #13: fixed.
  • fix: return microsvc transport join errors #19 (frame metadata in a side FIFO): not fixed. async-graphql has no per-response slot to carry the envelope with its value. Metadata is now recorded at the moment its value is yielded, so an error frame can no longer pick up a later frame's metadata.
  • feat: sourced macro #11 (per-table version-row trigger serializes writers): confirmed by reading the SQL, not fixed. A sequence isn't transactional, so readers could cache old data under a new version. A fix needs a monotonic source that commits with the data, such as the projection change cursor.

Breaking changes

  • New live_producer_count() counts producers (distinct reads); live_subscriber_count() still counts subscription streams. Both are available in every graphql build. (b40553c fixed the first CI run: the gateway load test read origin producers as subscriptions.)
  • New: live_concurrency, DEFAULT_LIVE_CONCURRENCY. LiveQueryStream is backed by a boxed stream.
  • An external root's failed first read ends the stream instead of failing the subscription future.

Tests

New unit tests (src/graphql/subscribe/tests.rs) use a counting fake read under paused tokio time. They cover:

  • one execution per change;
  • different keys never sharing;
  • the concurrency bound;
  • teardown;
  • a slow subscriber;
  • resumable catch-up;
  • terminal shared failure;
  • a closed hub.

sessions_share_a_live_producer_only_when_their_binds_match shows two tenants get 2 producers, and a second session for the same tenant joins the existing one.

Run locally:

  • make test-local (real Postgres and compose services): 2,910 passed, 0 failed.
  • distributed_leaderboard --features redis,graphql with Redis: 30 passed.
  • Gateway workflow commands and tests/gateway-{portable,native}: OK.
  • CLI with --include-ignored: 342 passed. e2e-celld: 31 passed. e2e-ui offline: OK.
  • wasm32 workers, game cells and the domain check: OK. Game server: 68 passed.
  • SvelteKit browser test (fleet required, Redis): 1/1.
  • 30× loops of the new tests, the graphql_query_protocol live and hundred-subscriber tests, and graphql_subscriptions_sqlite: 0 failures.

Not done

  • The 30× loops ran on SQLite only; Postgres ran once, in the full suite.
  • Not run: tests/gateway-postgres/run.py and JS (wire output unchanged). The ignored workerd load test separate_origin_and_client_savings now passes locally in all 8 host/mode rows.
  • Change wake-ups are still per table: a write to another tenant's rows still wakes every read on that table, though it now executes once per read.
  • First reads still cost one execution per subscriber.

One producer loop (src/graphql/subscribe.rs) drives catalog live roots
and external read roots. Subscribers whose read compiles to the same
(role, SQL, binds, cache scope) share one execution per change; each
keeps its own hash gate, envelope and resume-exact catch-up. Live
executions are capped per engine (live_concurrency, default 8); slow
subscribers skip to the latest frame instead of stalling others; the
entry is torn down with its last subscriber. 100 subscribers: 100 -> 1
execution per change.

BREAKING CHANGE: live_subscriber_count counts producers (distinct
reads), not subscribers; an external root's failed first read ends the
stream instead of failing the subscription future.

Implements [[tasks/v5-review-26]]
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cdf44dd4-369d-40f6-8891-aea8d4b3ae77

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Origin sharing made live_subscriber_count count producers, so the
gateway load test (CI-only, ignored) saw 1 origin subscription instead
of 100 in the non-sharing modes. live_producer_count now counts shared
reads and live_subscriber_count counts streams; the load test asserts
the gateway's savings on subscriptions and one origin producer in
every mode.

Implements [[tasks/v5-review-26]]
@patrickleet
patrickleet merged commit 1edb52e into v5 Nov 25, 2026
27 checks passed
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