Skip to content

Admin consistency contract source notes

Each operation is described with one of three classes, or with a hybrid that names which part falls into which class.

  • Strict sync. The response is sent only after the state change is committed to storage, the audit row (when the route writes one) is committed, and observers on the serving replica see the change. A 2xx means all three already happened.
  • Async best-effort. The response means the work was handed to an in-process queue or task. Nothing durable backs it. A crash, a full channel, or a failed write can lose it, and the client is not told.
  • Async guaranteed. The response means a durable row exists (for example a scheduler job row) that a worker on any replica will pick up, with retries and crash recovery. Delivery is eventual, not immediate.

“Serving replica” means the cc-lb process that handled the admin request. “Peer replica” means any other process that shares the same database.

Subsystem Operation(s) Class Durable at response Converges later via
Admin mutations 38 mutating admin routes Strict sync for state and audit, written in two transactions (see below) Domain state, then audit row Not applicable
Dynamic routing view Mutations that touch upstreams, principals, keys, or plugins Strict sync on the serving replica, with rebuilds serialized per process; async on peers The state behind the view Postgres LISTEN/NOTIFY with a 250 ms debounce, then a later successful reconcile pass (60-70 s interval plus jitter, not a deadline)
Configuration editor Draft put, validate, save Strict sync for storage and file Draft row, validation report, or the written config file Never at runtime: a saved file applies on process restart
Scheduler Admin actions that enqueue jobs; cron ticks Async guaranteed Job row in the scheduler queue Worker poll; durable Pending retries within class limits; stale-lock recovery
Subscription quotas Usage refresh after successful reset or already_used results Awaited provider read, fenced quota transaction, and serving-replica cache publication; refresh failure reported separately Settled reset outcome; quota latest rows and checkpoints committed before successful local publication Peer hydration and regular usage polls remain async
OAuth token refresh Lazy refresh on the proxy path Strict sync for the token; best-effort audit New token ciphertext and bumped token generation Peers rebuild through NOTIFY or reconcile
Price catalog Catalog fetch and install Async guaranteed fetch; async best-effort install Snapshot in storage and the disk cache (fetch job only) Each replica’s 60 s local installer
Request events Proxy request rows Async best-effort Nothing at proxy response time Lifecycle assembler insert with bounded retries
Dashboards Summary and usage reads Read of a materialized rollup Not applicable Usage rollup job every 30 s (3 s jitter); 2 s response cache
Subscription quotas Observations from upstream headers Async best-effort for the serving replica’s cache and for persistence Nothing at proxy response time Lifecycle subscriber updates the cache; batched writer (256 rows or 100 ms); Postgres peers hydrate on a single best-effort NOTIFY; every reconcile pass also attempts a hydrate from storage, independent of the view hash

Code: crates/cc-lb-admin/src/audit.rs, crates/cc-lb-admin/src/v1/, crates/cc-lb-admin/src/routes.rs.

The audit write is synchronous. record_admin_audit awaits append_audit on the storage pool directly. Nothing is buffered, so when a route returns success, its audit row is already committed. When no storage is configured, record_admin_audit returns success without writing anything.

State and audit are written in two separate transactions, in this order:

  1. The handler commits the domain change, for example UpstreamStore::update.
  2. The handler awaits record_admin_audit.
  3. If the route affects routing, the handler rebuilds the dynamic view before responding (see Dynamic routing view).

Once the handler sees that step 1 committed, it runs everything after it (steps 2 and 3, plus any other writes that follow the commit) as a continuation on a separate task through complete_after_commit (crates/cc-lb-admin/src/v1/post_commit.rs). The continuation runs independently of request cancellation: a client disconnect drops the request, not the task. A connected request awaits the continuation’s result, and the existing failure responses for audit, storage, and rebuild errors are unchanged, so the continuation does not guarantee that the audit row or the rebuild succeeds. Runtime shutdown can cancel the task, and the route then returns 500; a panic in the continuation propagates to the waiting request instead of being converted to 500.

For upstream writes (create, update, enable and disable, API-key and OAuth token writes, refresh completion, clearing the warmup dialect plugin) and the plugin registry label update, both storage backends read the returned record inside the write transaction and commit last. A failure while reloading or decoding that record rolls the write back, so the route returns an error without a committed change, and the continuation starts right after the storage commit.

If step 2 fails, the handler returns 500 with {"error": "audit_write_failed"}, but the step 1 change is already committed and is not rolled back. The client gets an error even though the change took effect, and no audit row records it. Check current state with a GET before retrying. On “Rebuilt” routes (see the table below), the handler first attempts to rebuild the serving replica’s view from committed storage, so routing on that replica follows the committed change when the rebuild succeeds. The 500 body is the same and carries no generation or rebind header; if that rebuild fails, it is logged and the view waits for a later notification or reconcile rebuild. The exceptions:

  • POST /admin/v1/principals/{id}/keys attempts to compensate. If the audit write fails, record_issue_audit_or_revoke tries to revoke the newly issued key; the handler then attempts a view rebuild and returns 500 (crates/cc-lb-admin/src/v1/keys.rs). If the revocation also fails, both errors are logged, the key stays active, and the response is the same 500. Check the key’s state before retrying.
  • POST /admin/v1/config/save does the reverse. If the success audit fails, it logs the error and still returns 200, because the file is already written.
  • POST /admin/v1/upstreams/from-oauth-draft attempts to hard-delete the new upstream if scheduler seeding or metadata storage fails. After attempting the rollback and the PKCE cleanup, the handler attempts a serving-view rebuild for either rollback outcome, then returns 500 oauth_draft_create_failed. If the hard delete fails, the upstream stays persisted and the response detail contains rollback delete failed. That compensation runs before the audit write. An audit failure after it does not roll anything back.

A few other failures after the commit also attempt a serving-view rebuild before returning their original error, because the committed change stays in storage. A failed rebuild is logged and does not change the response:

  • PUT/PATCH /admin/v1/upstreams/{id}, when seeding a warmup bootstrap job fails.
  • POST /admin/v1/upstreams/{id}/oauth/complete, when seeding the refresh or warmup jobs fails.
  • POST /admin/v1/upstreams/from-oauth-draft, when deleting the PKCE flow row fails after the upstream and its metadata are stored.
  • DELETE /admin/v1/plugins/registry/{id}, DELETE /admin/v1/plugin-chain-entries/{id}, and POST /admin/v1/principals/{principal_id}/plugin-chain/reorder, when a storage read that follows the commit fails.

Most handlers audit only the success path. Validation and storage errors return early without an audit row. Three routes audit both the success and the failure of their main operation:

  • POST /admin/v1/upstreams/{id}/limit-resets/claim, because a failed or timed-out claim may still have used the grant on the provider side.
  • POST /admin/v1/plugins/wasm, which records failures as plugin_registry_upload_attempt.
  • POST /admin/v1/config/save, which records failures as config_save_failed.

These routes still return some errors before the audited operation starts, and those write no operation row: a rejected request body, the upstream lookup failure or 404 for a claim, and the upload rate limit (429) or a failed rate-limit audit query for an upload. The save handler’s own authorization check writes no config_save_failed row, but through the shipped router a caller without write permission is stopped earlier by require_admin_auth, which awaits an authz_denied audit row before returning 403 (a failed write there is logged and the 403 still returns).

Limit-reset claim audit rows retain the stable upstream UUID, verified provider and selected coupon metadata when available, normalized provider result, and post-settlement usage-refresh outcome before the HTTP body is serialized. A local settlement failure preserves any known provider result; an uncertain claim remains unknown. Audit-write failure still returns audit_write_failed and can leave no recorded attempt after a provider side effect. The sensitive-read history endpoint filters this existing audit table by exact action and UUID claim route before limiting results (default 100, maximum 1000, with has_more). Its timestamp is the local audit-write time in milliseconds, not provider redemption time, and it cannot establish activity outside cc-lb or beyond retained audit rows.

The plugin registry label update and WASM garbage collection write audit rows like the other mutating routes:

  • PATCH /admin/v1/plugins/registry/{id} updates the registry label, records plugin_registry_label_update(id=<registry id>), and rebuilds the view.
  • POST /admin/v1/plugins/wasm/gc deletes unreferenced WASM blobs from storage one at a time and attempts to delete their cache files from disk. Candidates are processed on the request future until one blob is actually deleted. After that first successful deletion, the remaining deletions, cache-file cleanup and summary audit run in the post-commit continuation. If no blob is deleted, all candidates are checked on the request and the final audit runs in the continuation. After the loop it writes one summary row, plugin_wasm_gc(removed=<count>), also when nothing was removed. If a deletion fails partway, the route returns the storage error and writes no audit row for the blobs already removed. It does not rebuild the view.

Rejected authentication is audited synchronously. require_admin_auth awaits record_auth_rejected before it returns 401. If that write fails, it logs a warning and still returns 401, after a fixed 100 ms delay (crates/cc-lb-admin/src/auth/mod.rs). Some read routes also write synchronous audit rows (audit_query, config_editor_read, config_history_read). A row written by GET /admin/v1/audit does not appear in that same response.

Optimistic concurrency: principal, upstream, plugin registry, and plugin chain resources return ETag: W/"<revision>". Most of their update and delete routes require If-Match, and return 428 if_match_required when it is missing. A stale revision returns 409 stale_revision with current_revision for principals, upstreams, and OAuth completion, and 412 stale_revision with current for plugin registry and chain entries. For principals, a revision mismatch on a live principal returns the same stale_revision body with current_revision on SQLite and Postgres. Conflicts on a soft-deleted principal still depend on the operation and backend: repeating a soft delete returns 409 storage_conflict without a revision on both, while enabling or disabling a deleted principal with an older revision returns storage_conflict on SQLite and stale_revision on Postgres. Some routes take the revision another way:

  • PUT /admin/v1/principals/{id}/allowed_models reads expected_revision from the JSON body, not If-Match.
  • POST /admin/v1/principals/{principal_id}/plugin-chain/reorder takes an expected_revision for each entry in the body.
  • POST /admin/v1/plugins/wasm never reads If-Match. An upload that replaces an existing registry entry of the same name with different bytes is handled in one of two ways. An explicitly confirmed replacement sends the multipart part confirm_replacement=true and must also send replace_registry_id and expected_revision. An automatic replacement, allowed without confirmation when the incoming version is a higher semver than the current one, may omit both parts. When expected_revision is omitted, the server uses the revision it just read from storage, so no client-supplied revision is checked and a concurrent change between the client’s read and the upload is not detected.
  • POST /admin/v1/upstreams/{id}/oauth/complete checks the upstream revision captured when the flow was started with /oauth/start, stored in the PKCE flow row.
  • Configuration draft routes carry expected_revision in the request body.
Routes State Audit Dynamic view on serving replica
POST /admin/v1/principals; PATCH, DELETE /admin/v1/principals/{id}; POST /admin/v1/principals/{id}/enable, /disable; PUT /admin/v1/principals/{id}/allowed_models, /router-terminal Committed After state Rebuilt
POST /admin/v1/principals/{id}/keys Committed After state; on failure, revocation of the key is attempted but can fail Rebuilt
POST /admin/v1/principals/{id}/keys/{key_id}/revoke Committed After state Rebuilt
POST /admin/v1/upstreams; PUT, PATCH, DELETE /admin/v1/upstreams/{id}; DELETE /admin/v1/upstreams/{id}/warmup-dialect-plugin Committed (an update that turns warmup on for an OAuth upstream also enqueues one warmup job per lane the credential supports) After state Rebuilt
POST /admin/v1/upstreams/from-oauth-draft; POST /admin/v1/upstreams/{id}/oauth/complete Committed, and refresh/warmup jobs enqueued as applicable; for from-oauth-draft, a failed onboarding step triggers a hard delete that can itself fail After state Rebuilt
POST /admin/v1/principals/{principal_id}/plugin-chain, /reorder; DELETE /admin/v1/plugin-chain-entries/{id} Committed After state Rebuilt
DELETE /admin/v1/plugins/registry/{id}; POST /admin/v1/plugins/wasm Committed After state (upload audits failures of the upload itself, not its prechecks) Rebuilt
PATCH /admin/v1/plugins/registry/{id} Committed After state Rebuilt
POST /admin/v1/plugins/wasm/gc Reported blobs deleted from storage; cache-file deletion is best-effort One summary row after the deletion loop, also when nothing was removed; a deletion error returns before that audit write Not rebuilt
POST /admin/v1/oauth/draft/start, /admin/v1/oauth/draft/complete; POST /admin/v1/upstreams/{id}/oauth/start PKCE flow row committed After state Not rebuilt
PUT /admin/v1/config/draft; POST /admin/v1/config/draft/validate Draft or validation report committed After state Not rebuilt
POST /admin/v1/config/draft/download None (returns bytes) Before the bytes are sent; on audit failure no bytes are sent Not rebuilt
POST /admin/v1/config/save File replaced, draft cleared After state; on audit failure it still returns 200 Not rebuilt
POST /admin/v1/upstreams/{id}/subscription-metadata/refresh Metadata (and refreshed token, if needed) committed inline After state Not rebuilt
POST /admin/v1/upstreams/{id}/warmup/fire-now Provider call done inline; the warmup attempt row is written best-effort After state Not rebuilt
POST /admin/v1/upstreams/{id}/limit-resets/claim Provider claim done inline; epoch advanced after any outcome; successful reset or already_used followed by awaited single-upstream usage refresh Success and failure of the claim, after the upstream lookup Quota cache published before usage_refresh: "refreshed"; reset outcome retained if refresh fails

Code: crates/cc-lb-admin/src/v1/mod.rs, crates/cc-lb-control/src/dynamic_view.rs, crates/cc-lb-server/src/notify_listener.rs, crates/cc-lb-server/src/reconcile.rs.

Serving replica: strict sync, with a deferred escape hatch. Each “Rebuilt” route in the table above calls add_dynamic_rebind_headers after its audit write. That rebuilds the DynamicView from storage and installs it with try_store_if_newer, which installs a view only when its generation is strictly greater than the resident one. Every rebuild, whether from an admin route, the NotifyListener, or the Reconciler, reads the resident generation g and produces a view with generation g + 1.

Rebuilds in one process are serialized. Each of those three paths holds the DynamicViewHolder rebuild lock (lock_rebuild) from the resident-generation read through the build and the install, so two rebuilds never start from the same generation and an older build cannot replace a newer one. The admin rebuild starts after the mutation and its audit row have committed, so the view it installs was built from storage that includes the mutation. A rebuild waits for any rebuild already in progress, so a queued rebuild can add latency to the admin response. The compare-and-swap in try_store_if_newer remains as a defensive check; under the lock it rejects a view only after generation saturation or a publication made outside the lock.

The response then carries one of two headers:

  • x-cc-lb-generation: <n>: under the normal rebuild protocol (generation not saturated, every publisher holding the lock), n is the generation this route’s rebuild installed, built after the mutation committed, and n or a newer generation is resident. A later conflicting mutation may already have superseded that state. If the defensive compare-and-swap rejected the view (saturation or a publication outside the lock), n is the generation resident at that moment and does not prove that this route’s view was installed.
  • x-cc-lb-rebind-status: deferred: the rebuild failed and was logged. The status code is still 2xx because the storage change is committed, but this replica keeps serving the previous view until a later notification or reconcile pass rebuilds it.

build_dynamic_view collects the storage revision hash before it reads upstream and principal contents. If a mutation commits while a build is reading contents, for example a write on another replica during a local Reconciler or NotifyListener build, the installed view can hold pre-mutation contents, but it then also holds the pre-mutation hash, so the hash no longer masks the drift. A later reconcile pass whose storage reads succeed detects the changed hash and rebuilds, even when no notification arrives; a pass whose hash read or build fails leaves the view as it is. On Postgres, the mutation’s NOTIFY usually triggers an earlier NotifyListener rebuild after its 250 ms debounce; that debounce is not a completion bound.

Generation numbers are counted per process, so they cannot be compared across replicas.

Peer replicas: async. Neither path is backed by a persistent queue.

  • Postgres: upstream, principal, key, plugin registry, and plugin chain writes call pg_notify inside the same transaction, so the notification is sent on commit, and a failed pg_notify rolls the write back. Each replica’s NotifyListener waits 250 ms to batch pending events, then rebuilds and installs the result under the same rebuild lock and compare-and-swap. If the database listener connection drops, the notifier reconnects with exponential backoff that starts at 50 ms, doubles, and is capped at 5 s. The delay is not reset after a successful reconnect, so repeated drops in one process keep using the larger delay. Notifications sent while it was disconnected are lost, but after every successful LISTEN the notifier publishes a synthetic principal change event, which makes the NotifyListener rebuild the view from storage. If that rebuild is installed, it includes upstream, principal, key, and plugin changes committed during the gap. If the in-process broadcast lags, the listener also rebuilds from storage. The only fixed 1 s delay is a single retry when the NotifyListener first subscribes to the notifier’s in-process channel; if that retry also fails, the listener stops and only the reconcile loop remains.
  • Both backends: every replica runs a Reconciler. Its interval is 60 s plus a random 0-10 s offset, and each tick waits another random 0-10 s before running. On each pass it hashes storage revisions. When the hash differs from the hash stored in the resident view, it takes the rebuild lock, rereads the resident view and the hash, and rebuilds if they still differ. This is the fallback for missed notifications. The hash covers only upstream revisions, API-key ciphertexts, OAuth token generations, whether an OAuth upstream’s stored apply error requires an operator reconnect, principal revisions, plugin registry entries, and plugin chain revisions. A runtime refresh failure that requires a reconnect is a status write that bumps no revision and sends no NOTIFY, so a view picks it up on its next rebuild, which the changed hash makes the next successful reconcile pass perform when nothing else rebuilds first. An OAuth reconnect or refresh also bumps no spec revision, but it always advances the token generation, so a reconnect that clears the marker cannot return the hash to a value sampled before the failure. Because every view’s hash is collected before its contents, a view built from older versions of those inputs never carries a newer hash, so a later successful pass detects that drift. A failed pass is logged and leaves the view unchanged, and the interval is a schedule, not a repair deadline. It is the only cross-process path for SQLite, whose change notifier never publishes across processes.

Code: crates/cc-lb-admin/src/settings.rs, crates/cc-lb-admin/src/routes.rs, crates/cc-lb-server/src/signal.rs.

  • PUT /admin/v1/config/draft checks expected_revision, stores the draft in the database, and returns the new revision. A stale revision returns 409. The running configuration does not change.
  • POST /admin/v1/config/draft/validate stores the validation report for that revision. An invalid draft still returns 200, with the report marked invalid.
  • POST /admin/v1/config/save requires the revision to be validated and the on-disk fingerprint to match, then rewrites the file with atomic_replace. It then clears the draft and appends a history entry. If clearing the draft or writing history fails, it logs the error and still reports success, because the file is the source of truth.

No runtime convergence. cc-lb reads its configuration file only at startup. A saved file applies only after the process restarts. SIGHUP reloads only the TLS certificate and key, and only when listener.tls.reload_on_sighup is enabled. Upstreams, principals, keys, and plugin chains live in the database and follow Dynamic routing view instead.

Code: crates/cc-lb-scheduler/src/worker/backend_api.rs, crates/cc-lb-scheduler/src/worker/dispatch.rs, crates/cc-lb-scheduler/src/jobs/apalis_housekeeping.rs, docs/scheduler.md.

Async guaranteed. push_adaptive_task and push_cron_task insert a Pending job row directly and await the insert. Admin handlers that enqueue jobs await this insert before responding:

  • PUT/PATCH /admin/v1/upstreams/{id} when the update turns warmup on for an OAuth upstream with credentials. It enqueues one bootstrap job per lane the credential supports; a Gemini OAuth credential on the Antigravity profile gets both the primary and third-party lanes.
  • POST /admin/v1/upstreams/{id}/oauth/complete, which enqueues the refresh job and the warmup bootstrap jobs.
  • POST /admin/v1/upstreams/from-oauth-draft, which enqueues the refresh bootstrap job (skipped for never_refresh credentials) and, when warmup is on, the warmup bootstrap jobs.

A duplicate idempotency key returns Conflict, which handlers treat as already queued. Any other enqueue error returns an error response, but the domain write is already committed. from-oauth-draft is the exception: it attempts to delete the new upstream. After a 2xx, the job row exists (or an earlier row with the same idempotency key does). The row is not guaranteed to still be Pending when the client sees the response. Bootstrap jobs are enqueued with a run time of now, and the workers run concurrently with the request, so a worker can claim or even finish the job first.

Execution happens later on whichever replica’s worker claims the row:

  • Each job has a 60 s execution timeout (ENTITY_TIMEOUT, SINGLETON_TIMEOUT).
  • Retries follow the retry classes in docs/scheduler.md. JobOutcome::Retry durably reschedules the same row as Pending at now + delay; exhausting its retry class produces DeadLetter and a terminal Killed row.
  • ApalisHousekeepingJob (hourly by default) reaps Running locks older than APALIS_STALE_LOCK_THRESHOLD_SECS (120 s). It reaps Queued locks older than 120 s only when the owning worker has no fresh heartbeat within that threshold, preserving prefetched batches buffered on a live worker. It moves eligible non-keepalive rows back to Pending and increments attempts by one, so a job lost to a worker crash runs again after the next housekeeping pass. It marks eligible cache keepalive rows Killed.

Cron ticks are produced by every replica from an epoch-aligned IntervalSchedule (k * interval_secs + phase_secs), so replicas starting at different times emit identical tick_secs and duplicate rows for the same tick collide on the unique (job_type, idempotency_key) index, running only one job per tick.

Post-reset usage: awaited, not queued. After successful terminal reset or already_used results, the handler directly reads usage for that upstream and awaits durable quota publication followed by publication to the serving replica’s routing cache. For Anthropic OAuth upstreams, when /api/oauth/usage responds with HTTP 429, refresh_upstream_usage records 429 in oauth_usage_poll_cursors and falls back to a lightweight /v1/messages probe, persisting real anthropic-ratelimit-unified-* headers under the same generation and reset-epoch fence (with pg_notify to Postgres peers) only when at least one main quota window (5h, 7d, 7d_fable) is observed. The response keeps the reset result separate from nullable windows_reset and usage_refresh: refreshed means an affected main routing quota was published; failed means freshness was not established, including when the refresh integration is unavailable or the fallback probe receives no main quota observations; not_applicable means the upstream is no longer eligible for usage polling. An unknown window count remains null, not zero. Failure never repeats redemption or substitutes zero usage. Once committed, the continuation runs through complete_after_commit and survives request cancellation as described above.

Anthropic and OpenAI usage polls (as well as the Anthropic post-reset fenced header probe via record_subscription_quota_fenced_headers) check their captured OAuth generation and reset epoch in the same transaction that writes quota latest rows and checkpoints. SQLite uses BEGIN IMMEDIATE; PostgreSQL serializes the transaction with claim-fence writes through a per-key advisory lock, including when the epoch key is absent. A changed generation or epoch rejects the batch without writing quota. Fenced samples bypass the asynchronous sample queue. After a successful transaction, cache publication uses request order so an older poll cannot overwrite a newer poll’s published batch. Provider calls run outside that cache synchronization. These changes add no schema or migration.

Claim settlement advances the epoch after any outcome, including an unknown outcome, invalidating older snapshots. The durable fence remains pending only while the claim is in flight or settlement fails; the browser’s local pending marker separately suppresses uncertain-claim resubmission. A successful refresh guarantees publication on the serving replica, not immediate visibility on every peer. PostgreSQL peer caches converge through notifications and hydration; regular usage polls also remain asynchronous.

OpenAI coupon inventory is independent of routing-window support. A valid monthly main allowance can establish manual-redemption eligibility and keep inventory available even though monthly routing quota is not represented. Inventory, ordinary usage credits, or additional model allowances alone do not establish a refreshed affected main quota; the reset result is retained with usage_refresh: "failed" when no supported main routing quota was published.

A valid provider observation without a supported main routing quota is still a successful scheduled poll: it records the normal 200 attempt cursor and success classification. The observation separately records whether an affected main quota was published; the post-reset refresh requires that flag before reporting refreshed.

Inline, not queued. Fire-now warmup, subscription metadata refresh, and limit-reset claims call the provider during the request. Metadata refresh and limit-reset results are committed before the response. Fire-now is a hybrid: the provider call and the audit row are inline, but the warmup attempt row is written best-effort. execute_warmup_attempt logs a failed insert_warmup_attempt and returns the computed outcome anyway (crates/cc-lb-engine/src/warmup_attempts.rs), so a 2xx fire-now response does not prove the attempt row exists. Fire-now warms one lane per request (?lane=, default primary).

GET /admin/v1/upstreams/{id}/warmup reads committed job rows directly. Apalis stores Pending retries (with a future run_at), Failed rows (which Apalis may reclaim while attempts < max_attempts), and terminal Killed rows in the scheduler jobs table.

Code: crates/cc-lb-signer-anthropic-oauth/src/lib.rs, crates/cc-lb-server/src/refresh.rs, crates/cc-lb-storage-postgres/src/adapter/upstreams.rs.

Lazy refresh on the proxy path: strict sync for the token. When signing fails with ExpiredToken, LazyRefreshSigner takes a per-upstream in-process lock, so one refresh runs per upstream on each replica. It then calls refresh_one:

  • Credentials marked never_refresh (long-lived tokens) fail immediately and are never sent to the token endpoint.
  • Otherwise ApalisLazyRefreshClaimGuard enqueues an OAuthRefresh job keyed by upstream and token expiry. The idempotency key makes concurrent replicas share one job. The caller then polls read_oauth_token_generation once a second for up to 60 s, until the generation advances or the job reaches a terminal state. When it sees a terminal state, it re-reads the generation before reporting failure.
  • If the wait times out or fails, the caller falls back to an in-process refresh.

The refresh flow commits the new encrypted token in one transaction through complete_refresh or complete_split_refresh. That transaction increments oauth_token_generation, clears last_apply_error, and (on Postgres) sends NOTIFY. Only then does the signer rebuild from storage and sign the request.

Audit is best-effort. The refresh flow’s audit append (emit_audit) only logs a warning if it fails. Neither the token nor the proxied request is affected.

The admin routes that may refresh a token inline (subscription metadata refresh, limit-reset claim) keep the ordering described in Admin mutations and audit records. An audit failure after a committed refresh returns 500. GET /admin/v1/upstreams/{id}/oauth/status reads storage directly.

Code: crates/cc-lb-server/src/app.rs, crates/cc-lb-pricing/src/loader.rs, crates/cc-lb-scheduler/src/jobs/price_catalog.rs.

  • Fetch: async guaranteed. PriceCatalogRefreshJob runs on the scheduler every hour by default. It fetches the catalog with a 10 s timeout, skips the write when the fingerprint is unchanged, and otherwise writes the snapshot to storage and the disk cache before upserting the fingerprint. A failed step requests Retry with a 30 s delay. The Maintenance retry class reschedules it once at that delay and marks the row Killed if the retry also fails. The fetch job does not update the in-memory catalog on any replica.
  • Install: async best-effort, per replica. At startup, install_default_fallback_if_uninitialized installs the built-in snapshot if nothing is loaded yet. A background task then runs install_latest_local immediately and every 60 s (PRICE_CATALOG_LOCAL_INSTALL_INTERVAL). It installs the stored snapshot when its hash changed, falling back to the disk cache. Failures are logged, and the current catalog stays in place. Within one replica, a new catalog takes effect within about 60 s of the fetch job committing it.
  • Effect on requests. If a principal has a USD cost limit and the model is not in the catalog, the request is rejected with 503 (cost limits unavailable for model). Positive cached usage without an applicable cached-read rate also leaves completed actual costs empty; a published zero rate remains known. When actual cost is unavailable at completion, managed-key CostUsd accounting finalizes the original admission estimate as liability while measured requests and tokens settle and concurrency releases. Those usage-bucket amounts are limit-accounting liabilities, not a claim that an unknown request has a known actual cost. If neither an actual price nor an admission estimate exists, monetary usage is unchanged while measured request/token usage is retained. Rows are not re-priced later.

There is no admin route that triggers a catalog refresh.

Code: crates/cc-lb-control/src/event_bus.rs, crates/cc-lb-engine/src/lifecycle_event_assembler.rs, crates/cc-lb-engine/src/request_diagnostics_sink.rs, crates/cc-lb-admin/src/events_routes.rs, crates/cc-lb-admin/src/dashboard_routes.rs, crates/cc-lb-admin/src/response_cache.rs.

Request rows: async best-effort. The proxy response does not wait for the request event row:

  • Lifecycle events go to the assembler over a bounded channel (capacity 4096). When the channel is full, events that carry row data are moved to detached overflow tasks that wait for space, up to 1024 such tasks. Beyond that limit, and for other non-activity events, the event is dropped and counted as lifecycle_assembler_full; advisory RequestActivity heartbeats are dropped without spawning overflow tasks and counted as lifecycle_assembler_activity_dropped.
  • In-flight partials use a 300 s sliding idle TTL (refreshed at most once every 60 s by RequestActivity across active frames, pings, and silent-wait timers, while also touching the LimitEngine reservation directly and renewing live Postgres concurrency holds every 30 s within the 90 s crash-leftover bound) capped by a hard max TTL (default 3600 s, or max(3600 s, upstream_total_secs, limit_reservation_ttl.ttl_secs)).
  • After RequestTerminated, the assembler holds the row for up to 200 ms (FINALIZATION_GRACE) for late pricing and cache events, then inserts it.
  • A failed insert is retried twice, after 50 ms and 200 ms. After three consecutive failures a circuit breaker opens and later rows get one attempt each. Rows still failing are dropped, logged, and counted as lifecycle_assembler_storage_error.
  • On shutdown, the assembler drains the channel and any overflow tasks for up to 2 s, then flushes held rows. The serve process waits for this and every other shutdown hook (including the diagnostics drain) to finish before it exits, up to 15 s after the proxy listener stops (SHUTDOWN_HOOKS_TIMEOUT); past that bound it logs a warning and exits, and anything still unwritten is lost.

Once the insert commits, the assembler publishes RequestEventUpdate::Final on the bus.

Diagnostics line: async, after the insert. With observability.request_diagnostics_log on, the assembler queues one cc_lb.request_diagnostics.v1 stdout line after the insert commits and before it publishes RequestEventUpdate::Final. A dedicated thread writes queued lines; the queue holds 1024 lines. A failed insert produces no line. The line shares the stdout pipe and lock with tracing logs, so a stalled log collector can also delay request-path tracing writes.

  • request_events_v1 is the source of truth for all 99 operational, latency-breakdown, and abnormal-stream-error scalar fields. They are stored in typed relational columns; payload is dropped, so request-event reads have zero TOAST overhead.
  • The line carries the five deep diagnostic fields cache_breakpoints, cache_control_message_indices, routing_trace, iterations, and internal_errors, plus an optional native_cache object when native cache analysis is available; the object is omitted when there is no analysis. Serving-bundle cache_breakpoints retain at most 32 prefix candidates in total, including bounded lookback_prefixes and their breakpoint/content-block positions. These candidates stay in the off-path diagnostics line, not the request-event row. When the native values are invalid, the object is present with its evidence marked invalid.
  • The line also carries the eight self-contained outcome and session-correlation fields thread_id, observed_session_id, input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens, duration_ms, and upstream_ttfb_ms, plus the optional integer fields cache_write_input_tokens, cache_write_input_tokens_30m, and cache_write_input_tokens_12h. An absent native write counter means it was not reported or its write component is invalid or unusable; a valid reported 0 is present as 0. Malformed or contradictory TTL values project all three counters as absent.
  • Graceful shutdown drains the queue for up to 2 s. If stdout is still stalled at the deadline, shutdown proceeds without joining the writer thread and without logging (logs share the stalled stdout). Every line the writer has not finished is counted as a diagnostics shutdown timeout. If a timed-out in-flight write returns before exit, its bytes may still land on stdout once, but its outcome stays counted as dropped — accounting is conservative and no line is counted twice.
  • The first line per event_id matches the stored row. A late terminal event for an already persisted orphan row can produce a second line that the database ignored; consumers keep the first.
  • Cache-keepalive renewal rows are inserted by the renewal finalizer, and the assembler emits their line when their lifecycle events arrive. A renewal row whose lifecycle events were dropped (lifecycle_assembler_full) or finalized after the assembler has stopped has a stored row but no line. Its diagnostic fields are always empty.

Event reads. GET /admin/v1/events/recent and GET /admin/v1/events/delta read committed rows only. They never include rows still held by the assembler. GET /admin/v1/events/stream first backfills committed rows after the client’s Last-Event-ID. Storage applies the event filters before the 500-row limit, so each page contains up to 500 matching rows; a shorter page means that cursor range is exhausted. For a delta page that is exhausted, next_cursor advances to max(since_cursor, cursor_hi); a full page keeps the cursor of its last matching row. If the stream backfill returns exactly 500 matching rows, it preserves the existing reset behavior and ends. The client can resume safely without losing rows in a filtered cursor gap. Committed-row visibility is unchanged, including PostgreSQL’s xmin safety boundary. After the backfill it streams live bus updates and, on Postgres, updates from StorageTailPoller, which polls storage every event_bus.storage_tail_poll_interval_ms. A lagging subscriber receives reset and the stream closes.

Dashboards: materialized. GET /admin/v1/dashboard/summary reads only usage rollups. These are updated by the usage_rollup job, which runs every 30 s with 3 s jitter by default. On Postgres the rollup only takes events whose transactions are below the current snapshot xmin, so a long-open transaction elsewhere delays it.

GET /admin/v1/dashboard/usage reads the same rollups. Per-principal category costs come directly from usage_rollups_v2; principal totals use a 2 s in-process coalescing cache (PRINCIPAL_TOTALS_CACHE_TTL).

Local rollups retain three additive event counters: priced_event_count, unpriced_event_count, and unmetered_event_count. The dashboard wire names are priced_request_count, unpriced_request_count, and unmetered_request_count. Request counts, tokens and known costs retain their existing totals; an unavailable price never becomes a measured zero.

pricing_completeness distinguishes priced, known_zero, partial, unpriced, unmetered, and unknown. With complete classification, priced requests have priced or known_zero, requests without billable usage are unmetered, and a mix of priced and unpriced requests is partial.

The unclassified remainder is request_count - (priced_event_count + unpriced_event_count + unmetered_event_count), saturating at zero. Any positive remainder makes the result partial only when at least one request has a recorded price or the recorded known cost is positive; otherwise it is unknown. This rule also applies to legacy windows with zero tokens and zero cost, and to gaps mixed only with unpriced or unmetered requests. Neither case proves free or unmetered usage. A recorded positive subtotal remains visible; a priced zero mixed with a gap remains qualified as partial. Classification never re-prices events against the current catalog.

Nonempty rollup-backed summaries and buckets return the state and all three counters, including explicit zeros. Empty totals and zero-filled buckets omit all four fields. Estimated API-key months use the same classification; provider-reported organization buckets and months omit these local counters.

SQLite and Postgres add classification counters with zero defaults to existing rollups. Only ordinary rollup ingestion adds classification evidence, in the same transaction as its request, token, cost and checkpoint delta. Existing rollup totals are never retrofitted, even when their original raw events remain available. Idle ticks, retention gaps and raw-event pruning cannot repair historical classification.

Old rollup workers can still add totals without the new counters, leaving an unclassified remainder. Updating every worker prevents new gaps; it does not repair existing ones. Old readers do not understand the new completeness contract and may still display missing prices as zero. Upgrade readers as well as workers before relying on this presentation.

The independent historical category-cost backfill remains in place. Dashboard validators include a semantics version and the rollup revision, covering the ingestion checkpoint and category-cost backfill cursor. A semantics upgrade invalidates older validators even without traffic; there is no pricing classification backfill cursor.

Native cache-write counters retain reported-zero versus absent evidence. Effective cache-write totals preserve available per-event evidence and raw native-write lower bounds during mixed-version writes. Historical rollups without that evidence do not promise an exact reconstructed effective total.

The UI shows unavailable prices as a neutral dash and a reason. Partial amounts are known subtotals with a plus sign. Unknown prices never appear as free usage in charts, cost shares or request details.

Code: crates/cc-lb-control/src/event_bus.rs, crates/cc-lb-engine/src/lifecycle_subscription_quota_subscriber.rs, crates/cc-lb-engine/src/subscription_quota_events.rs, crates/cc-lb-storage-postgres/src/adapter/upstream_subscription_quota.rs, crates/cc-lb-server/src/notify_listener.rs, crates/cc-lb-admin/src/subscription_quotas.rs.

Async best-effort, in three stages. The proxy path does not update the quota cache itself. The event bus hands lifecycle events to a separate subscriber task over a bounded channel (capacity 4096) with a non-blocking send. When that channel is full, the event is dropped and counted as lifecycle_subscription_quota_full, and its observation never reaches the cache or storage. The proxy response can finish before the subscriber has processed the events. When the subscriber handles an UpstreamResponseStarted event for a 2xx or 429 response, it does three things:

  1. Serving replica cache. It upserts the observation into the in-process subscription_quota_cache. This happens on the subscriber task, independently of the proxy response, so it may land before or after the client receives the response. It is not guaranteed at response time.
  2. Storage, async best-effort. It enqueues the observation on the writer’s bounded channel (subscription_quota.writer_channel_capacity, 4096 by default). When that channel is full, the observation is dropped from storage and counted as subscription_quota_full. The writer flushes batches of up to 256 records, or every 100 ms. A failed write is logged and the cache keeps the observation.
  3. Peer replicas. On Postgres, after a batch commits, the writer sends one NOTIFY per affected upstream, once, outside the transaction. Peers debounce for 250 ms and then reload those upstreams’ latest quota rows from storage. A failed NOTIFY is logged and not retried; the committed rows survive, and peers pick them up on their next successful hydrate. Every dynamic view build hydrates the cache for all upstreams: at startup, on a rebind notification for upstreams, principals, keys, or plugins, on the synthetic event after a LISTEN reconnect, when the in-process broadcast lags, or on a reconcile pass that finds a changed revision hash. These hydrates replace a cached observation with a stored one whose timestamp is the same or newer. Independently of any build, every Reconciler pass also attempts to hydrate the cache from storage for the upstreams in the resident view before it compares revision hashes (crates/cc-lb-server/src/reconcile.rs). That periodic hydrate captures a per-slot version for each cached (upstream, window, source) observation before the storage read; every replacement of a slot, from any path, bumps its version. A stored observation then replaces the cached one when its timestamp is strictly newer, or when it is equal and the slot’s version is unchanged since the capture. An equal-timestamp observation that another replica persisted while its NOTIFY was lost is therefore recovered, while a read that raced a local or notified observation cannot restore older content. Empty slots always hydrate. It does not depend on the revision hash, which does not cover quota samples, so committed observations missed by a lost NOTIFY reach a peer on its next successful periodic read. The reconcile schedule (60 s plus 0-10 s, then another 0-10 s per pass) is not a recovery deadline, because storage availability and read duration also apply. On SQLite there is no cross-process quota notification; another process’s committed rows reach the cache through that periodic read or a dynamic view build. A failed hydrate is logged, the cache keeps its previous values, and the rest of the reconcile pass still runs.
Read Source Shows a new observation
GET /admin/v1/subscription-quotas/latest In-process cache for canonical windows; meta_v1 for Gemini period-unknown meters and raw quota responses Canonical windows after cache publication; bound raw observations across replicas after the usage poll’s compare-and-put commits
GET /admin/v1/subscription-quotas/series Storage After the batch flush
GET /admin/v1/subscription-quotas/aggregate Newest whole observation per upstream and window across cache, durable latest, and raw checkpoints Cache observations after publication; durable observations after commit; history after the flush

Gemini usage polls persist period-unknown meters and successful raw quota response bodies under gemini_period_unknown_quota:<upstream_id> in meta_v1. /latest reads both the durable latest rows (to suppress a raw group when a newer canonical observation exists) and this meta record. It validates the current account/project binding before exposing optional period_unknown_meters; email-bound records retain continuity across routine OAuth token refreshes, while project-only records require a matching credential generation. Raw bodies additionally require an owner-bound record and a matching OAuth profile.

Each entry in /latest’s upstreams array may include raw_summary and raw_fallback, each shaped as {observed_at_unix_millis, body}. Each body retains unknown provider fields and its own successful observation timestamp; a failed side preserves its previous body and timestamp within the same binding and profile. Poll publication validates the captured credential fence before persistence. These bodies are provider evidence and do not imply a price or quota period. Raw snapshots follow the same source/window filters as period_unknown_meters; header-only views omit them. Peers read committed records without cache hydration. A group’s authoritative canonical or empty bucket response clears that group’s period-unknown meters, independently of the retained raw bodies.

/aggregate, Anthropic pool snapshots, Anthropic /pool-history, and /api/oauth/usage compare observation timestamps across the cache, durable latest, and raw checkpoints for each (upstream_id, window). They select one newest whole observation. An explicitly Absent winner tombstones older numeric checkpoints for current reads without deleting historical checkpoint rows. All providers exclude absent windows from eligible and missing-observation counts; Unobserved windows remain eligible with a missing observation.

/aggregate, /api/oauth/usage, and Anthropic /pool-history omit a window when every member is explicitly absent. This includes Anthropic secondary windows exposed by /api/oauth/usage as seven_day_sonnet, seven_day_opus, and limits. Equal-weighted OpenAI and Gemini /pool-history retains all-absent windows with eligible_upstreams = 0.

Codex credit observations use these same delivery boundaries. Usage polls store the full credit state on overage; response headers store partial state on unified; Responses WebSocket codex.rate_limits frames enter the same off-path subscriber without changing their forwarded bytes. Cache and storage retain field-specific observation time and source for has_credits, unlimited, limit_reached, and balance. Missing fields do not refresh an older field. Routing compares explicit flags by their own newest applicable evidence: balance never implies availability, and stale positive flags never admit traffic. Credit checkpoint identity compares effective credit values merged across both physical streams, excluding provenance metadata. Unchanged polls update latest per-field provenance without adding checkpoints. History records state known at commit; older delayed credit observations do not create backdated checkpoints or rewrite past states. Non-credit quota fields keep per-source change detection.

Request events may carry nullable funding evidence. included_estimated and credits_estimated require a complete main-limit response matched to the request or turn. Connection-only WebSocket frames, incomplete meters, extra limit families, balance-only changes, and ambiguous turn ordering remain null. The field is an estimate of the response’s quota state, not a billing receipt.

Subscription display metadata. OpenAI usage polls merge the plan and email from the usage response only after its account ID matches the current credential. Gemini polls collect the selected tier and userinfo when metadata is missing or the eight-hour metadata cadence is due. loadCodeAssist uses an explicitly configured upstream base_url, including a Cloud Code override for the Antigravity profile. Without an upstream override, it keeps the profile’s configured metadata base and existing default host. Userinfo always uses the profile’s configured endpoint.

An explicit root base resolves to /v1internal:loadCodeAssist; version and custom prefixes are preserved, and a known terminal action is replaced. An explicit upstream /metadata becomes /metadata:loadCodeAssist, while a profile metadata base /metadata keeps /metadata/v1internal:loadCodeAssist. Operation-specific default hosts are unchanged.

This work runs after successful quota observation, outside the proxy path. Metadata errors leave the quota outcome and previous valid fields intact. Admin metadata reads see the committed record; a proxy response does not guarantee that enrichment has run. The metadata write compares both the captured credential generation and the metadata record read before collection within one storage transaction. A delayed observation for a replaced credential, a newer metadata publication, or a deleted upstream is discarded without changing the successful quota outcome. Gemini imports without an account email bind the collected display identity to the project and credential generation; email-bound accounts retain their case-insensitive account/project binding across ordinary token refreshes. Tests may call SchedulerDispatch::poll_usage directly and await its return before checking persisted display metadata, as the test-scoped scheduler_dispatch::oauth::tests::provider_metadata cases do.

GET /admin/v1/subscription-quotas/pool-history keeps the existing quota snapshot contract and, for OpenAI, may include a credits object. Credit history uses persisted balance state for the enabled OpenAI OAuth accounts in the same membership set as pool_quota_upstreams. Historical points step-hold recorded state through the requested range; checkpoint age is not historical polling freshness.

Only the current tail may extend to now, and only while each balance sidecar is fresh. A stale sidecar ends the tail at its last successful balance observation. Coverage changes create a null gap instead of a fabricated zero or continuous drop. The pool sum excludes unlimited, invalid, stale, and missing balances, keeps partial contributor counts, and sums decimal strings exactly before the display truncates once.

The existing quota history still records provider snapshots and applies its documented freshness and retention rules. Clients can request server-relative history with relative_range_secs and optional window_quantum_secs; the server resolves those bounds from the same clock used for now_unix_secs.

Assert right after a 2xx admin response:

  • Domain state through the storage API or a follow-up GET, and the audit row through query_recent_audit. Both are committed before the response. For example, crates/cc-lb-admin/tests/v1_principals.rs checks the audit row right after the response.
  • The new ETag revision, which can go straight into the next If-Match, or into the body expected_revision for the routes listed under optimistic concurrency.
  • For “Rebuilt” routes, under the normal rebuild protocol, x-cc-lb-generation names the generation this route’s rebuild installed on the serving replica, built after the mutation committed (see Dynamic routing view). The view or proxy traffic can then be asserted right after the response, also in a full server where the NotifyListener and Reconciler run, provided no later conflicting mutation can run in the test. A later rebuild may already have installed a newer generation, so compare the resident generation with >= unless the admin route is the only source of rebuilds. crates/cc-lb-admin/tests/v1_synchronous_rebind.rs builds AdminState with a test SnapshotRebinder and no NotifyListener or Reconciler, sends a single mutation, then checks that the resident generation equals the header and that the view contains the new upstream. crates/cc-lb-server/tests/dynamic_view_rebuild_serialization.rs holds another rebuild in progress while the admin request runs and checks the view when the response returns. When the response carries x-cc-lb-rebind-status: deferred, do not assert the view.
  • Job rows enqueued by the handler: assert that a row with the expected idempotency key exists, not its status. For example, after warmup is turned on, the warmup bootstrap row exists, but a worker may already have claimed or finished it. Assert Pending only when the test controls the scheduler worker, for example when no worker is running.
  • After successful reset or already_used results with usage_refresh: "refreshed", assert the observed usage in the serving replica’s quota cache immediately. Test refresh failure separately: the reset result is unchanged, no second redemption occurs, and usage is not replaced with zero. Assert unknown windows_reset as null; assert not_applicable when the upstream is no longer eligible for usage polling. An unavailable refresh integration reports failed. Unknown claim outcomes advance the epoch on successful settlement and invalidate old snapshots; the browser’s pending marker, not a permanently pending server fence, suppresses automatic resubmission.

Do not assert right after a response. Wait on the named seam instead:

  • View convergence on peer replicas. Install a test-scoped tracing layer like RebindCompletionLayer in crates/cc-lb-server/tests/managed_key_multi_instance.rs, which fires when a NotifyListener rebuild finishes, and after each signal probe with proxy traffic until the expected status appears (wait_for_proxy_status in the same file). This seam needs the Postgres notifier, because SQLite publishes no change events. Bound the wait with a deadline. To test the reconcile path without a notifier, call Reconciler::reconcile_once directly and assert after it returns, as crates/cc-lb-server/tests/dynamic_view_rebuild_serialization.rs does.
  • Subscription quota cache. At the engine level, drive the subscriber directly as the unit tests in crates/cc-lb-engine/src/lifecycle_subscription_quota_subscriber.rs do: feed events into spawn_lifecycle_subscription_quota_subscriber through a test channel with a recording SubscriptionQuotaCacheLike and a SubscriptionQuotaSink, close the sender, await shutdown() on the handle so queued events drain, then assert the recorded cache entries and the sink receiver. For a peer’s view of committed quota rows, write the rows to storage, call Reconciler::reconcile_once, and assert the cache after it returns, as crates/cc-lb-server/tests/reconcile_subscription_quota_hydration.rs does. A server-level test that asserts GET /admin/v1/subscription-quotas/latest on the serving replica after a proxied request still needs a new test-scoped observer that signals when the subscriber has applied the observation.
  • Scheduler job execution. Inject a dispatch closure that reports each job over a channel, like dispatching_scheduler_ctx in crates/cc-lb-scheduler/tests/worker.rs, and wait on that channel with a deadline. The worker’s persistence layer writes durable row transitions (Running, rescheduled Pending, Done, Killed, Failed) around handler execution. After a dispatch signal, bounded-poll SQL for the expected row status and attempt count before asserting persisted state. To measure claim latency, use first_job_timing in crates/cc-lb-server/tests/cache_keepalive_wall_clock.rs, which reads the exact job’s persisted lock_at and run_at. A live worker may finish or reschedule before its session’s generation and enqueue state are observed. Post-reset usage refresh runs inline.
  • Lazy OAuth refresh. Use read_oauth_token_generation and the controllable fixtures in the test module of crates/cc-lb-server/src/refresh.rs (TestOAuthRefreshClaims::wait_for_contention, LazyRefreshFixture::hold_refresh_response, wait_for_refresh_start).
  • Price catalog. Seed it with the test helper and wait with wait_for_price_catalog in tests/integration/managed_api_key_full_flow.rs.
  • Request event rows. Subscribe to the bus and wait for RequestEventUpdate::Final for the specific request (crates/cc-lb-engine/tests/lifecycle_request_events.rs), or install a test-scoped observer. In server-level tests where the exact number of expected rows is known, wait_for_row_count in crates/cc-lb-server/tests/rfc_0002_fix_live_qa.rs polls storage until the count equals that number and panics after a 10 s deadline. Do not use settled_row_count from the same file as a completion signal: it returns once the count stops changing for a few 300 ms reads, or after 15 s, which is a timing heuristic, not proof that a row was written.
  • Postgres request-event cursor visibility. A committed row or RequestEventUpdate::Final does not guarantee that the row is below the cluster-wide snapshot xmin horizon. After known writes, call request_event_stable_seq_ceiling(max_wait) and use its returned ceiling for cursor/delta assertions. This existing storage barrier waits for the relevant in-flight transactions; get_request_event point reads can verify committed identities independently. Do not treat an immediate current_request_event_cursor() as a commit-completion barrier.
  • Dashboards. Call rollup_usage_once() on the storage directly after seeding events (crates/cc-lb-admin/tests/dashboard_summary.rs, crates/cc-lb-admin/tests/dashboard_usage.rs). On Postgres, call wait_for_events_visible_for_rollup first (crates/cc-lb-storage-conformance/tests/storage_roundtrips_postgres.rs).
  • Stream tailing on Postgres. Wait on the StorageTailPoller broadcast receiver, as in crates/cc-lb-engine/tests/storage_tail_poller.rs.

The AGENTS.md CI flake rules apply. Never add sleep or retry loops to hide timing, and never add a public flush, completion, or notification method to a production type just so a test can wait. If none of the seams above fits, write a test-scoped observer or wrapper.