createBarrierHandler
createBarrierHandler(
options): (request) =>Promise<Response>
Defined in: packages/server/src/circuits/subscribe.ts:799
The convergence-barrier route (ADR-0056 decision 4).
Proxied rather than exposed: the engine’s control plane is unauthenticated by design and is not client-reachable, so surfacing the barrier on our own authenticated endpoint costs nothing and keeps the trust boundary intact.
maxAgeSeconds may cache the answer briefly, but only a HEALTHY one. For the pendingFlips term
staleness is safe in exactly one direction — it moves the barrier backwards, so a stale reading can
only DELAY an alignment, never satisfy one falsely. flipFailures inverts that: a cached
pre-degradation zero would let a group align against an engine that has already
lost membership effects, which is precisely the alignment the term exists to refuse. So a degraded
reading is never cached and never served from cache, and the cache window is exactly the bound on
how long a client may align against a freshly-degraded engine — which is why the default is 0.
Parameters
Section titled “Parameters”options
Section titled “options”engine
Section titled “engine”{ createShape(request): Promise<CircuitsShapeHandle>; releaseShape(shapeId, subscription): Promise<void>; replicationState(): Promise<CircuitsReplicationState>; }
engine.createShape
Section titled “engine.createShape”(request) => Promise<CircuitsShapeHandle>
Register a shape and get the stream to follow — and renew that registration.
There is deliberately no renewShape: a renewal IS this call, repeated with the same
request.subscription on the same definition (fork ADR-0008). The engine answers the same
handle, counts nothing extra, and moves the lease forward. That is also why a create whose
response was lost can simply be sent again, and why the control plane’s token re-mint can renew
every live claim without a second route.
Two outcomes a caller must distinguish:
- 409 (CircuitsEngineError.status) — the id names a DIFFERENT shape already. One name, one shape; nothing was taken, and a retry will not change it.
- a different handle — the claim had lapsed or the shape was evicted, so this call re-subscribed rather than renewed. The stream the old grant named is not this one (ADR-0007).
The engine shares by definition: two identical bodies collapse onto one maintained stream and return the same handle. Nothing here has to check for that or cache against it — which is exactly why the shared tier’s predicate must be GENERATED. Two subscribers in one scope produce identical bodies only because neither’s identity reached the predicate; they are still two distinct subscriptions, because each names its own claim.
The answer is VALIDATED, not cast, for the same reason replicationState validates the barrier: an engine that acknowledges a create without saying which subscription it recorded or how long that subscription lives cannot be renewed or released by id at all, and defaulting either field would invent a lease this control plane was never promised.
engine.releaseShape
Section titled “engine.releaseShape”(shapeId, subscription) => Promise<void>
Release ONE named subscription’s claim on a shape (DELETE /shapes/{id}?subscription=…).
Idempotent, and that is the whole point of naming the claim: releasing one that is already
gone is a no-op 200 rather than a decrement that steals another subscriber’s. A caller whose
response was lost may simply send it again.
There is no anonymous form here. The engine still accepts a bare DELETE /shapes/{id} as a
legacy refcount decrement, but it carries no claim identity and is not retry-safe, so this
client never issues one.
The shape itself survives its other subscribers and then follows the engine’s retention lifecycle (idle → dormant → evicted); this is a release, not a delete.
engine.replicationState
Section titled “engine.replicationState”() => Promise<CircuitsReplicationState>
The engine’s convergence barrier (ADR-0056): where replication is, how many computed-but-undelivered subquery flips remain, and how many flip batches the engine gave up on.
The engine answers a sync field beside these and it is deliberately NOT read: it is the
__el_sync sentinel watermark — an i64 the engine’s conformance harness bumps and waits on as
a global quiescence fence — which no pgxsinkit database ever writes, so it is 0 everywhere and
says nothing about convergence.
pendingFlips > 0 means a revocation has been computed and not yet written to any stream,
which no wire-format watermark can see. That is the term the Electric wire could not express
at all, and the reason the barrier is read out of band rather than inferred from a position.
flipFailures > 0 means a batch was abandoned after exhausting its propagation retries:
those membership effects are gone rather than late. The engine keeps the abandoned batch’s
pendingFlips count held — so the waiting terms never falsely read converged — and latches
itself degraded: /ready answers 503, so do its membership-bearing routes, and a reaper
deletes every subquery shape stream. Recovery is an operator restart.
The answer is VALIDATED, not cast. An engine that does not report both counters cannot answer the question this barrier asks, and defaulting a missing term to zero would manufacture a converged reading out of an engine that never claimed one.
maxAgeSeconds?
Section titled “maxAgeSeconds?”number
resolveAuthClaims?
Section titled “resolveAuthClaims?”(request) => {[key: string]: unknown; app_metadata?: {[key: string]: unknown; roles?: string[]; }; sub?: string; } | Promise<{[key: string]: unknown; app_metadata?: {[key: string]: unknown; roles?: …[]; }; sub?: string; } | null> | null
Returns
Section titled “Returns”(request) => Promise<Response>