Repository navigation
fix(batch): read the admission service frontier outside the transaction (sync 503 storm) - #24855
Conversation
The owner-activation frontier query (order_by service desc, limit 1) ran inside the admission transaction, locking the top control doc that workers advance constantly. Admissions exhausted their contention retries and sync uploads got 503 sync_batch_unavailable for ~94% of requests. The frontier only seeds a rejoining owner's credit via max(own, frontier), so a non-transactional hint suffices. Lever admission_frontier_hint (FIRESTORE_READ_LEVERS, default 100; 0 restores). Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
No issues found across 5 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
You’re at about 90% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d4adee070a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| monkeypatch.setattr(store_module, 'service_frontier', frontier) | ||
| tx = SimpleNamespace(name='admission-transaction') | ||
| return store_module.FirestoreTransaction(object(), 'batch_pipeline_dev', tx), tx, calls |
There was a problem hiding this comment.
Cover the admission contention incident with an emulator test
For the admission/worker contention scenario this change fixes, the new tests replace the entire frontier query with a function returning a constant, so they verify argument forwarding but never exercise query locking or concurrent worker writes. The existing frontier emulator test in backend/tests/integration/test_batch_pipeline_firestore.py exercises sequential activation, not this contention scenario. backend/AGENTS.md explicitly requires emulator coverage first for incidents involving queries, retries, or contention. Add an emulator regression that advances another shard's frontier while admitting an inactive owner and verifies that admission completes with the hint enabled; retain these unit tests as supplementary guards.
AGENTS.md reference: backend/AGENTS.md:L232-L232
Useful? React with 👍 / 👎.
…airness bound Contention logs recorded control_query for the frontier read even when the admission_frontier_hint lever moved it outside the transaction; drop it on that path so post-fix attribution names only contended transactional reads. Document the bound in the scheduler CONTRACT: a joiner can be served ahead by about one pull batch committed during its admission transaction; earned credit is never lowered. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s transactional Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on commits (#24864) ## What Follow-up to #24855 (lead2 c54915 / 45d52f). #24855 reads the owner-activation service frontier outside the admission transaction, to stop the sync 503 storm. Luna correctness found the cost: a pull committing meanwhile can leave a rejoining shard below the true frontier, so it gets served ahead of others by about one pull batch. This PR restores the bound without bringing back a transactional lock on a hot control doc: - `activate()` stamps `p{prio}_frontier_hint` with the activation time and notes `(shard, priority)` on the Firestore transaction view. - After the admission commits, `FirestoreStore.run` calls `reseed_hinted_activation`. It re-reads the frontier with no transaction, then lifts `service = max(own, frontier)` in a one-attempt transaction on the shard's OWN control doc, only while the marker is set. RPC deadlines are 1.5 s with no retries, because the upload ack waits on it. Failures are only logged. - A pull within 30 s of activation that beats the re-seed lifts the shard itself from a fresh frontier read. A later pull only consumes the marker, so waiting its turn is never charged to the joiner. Same lever as #24855: `admission_frontier_hint` set to 0 stamps nothing. Postgres, sim and memory stores have no note hook, so their behavior is unchanged. ## Rejected alternative A pure pull-time clamp (design b) lifted the joiner at its first pull. That charges it for service other shards earned while it waited: `test_shards_weight_service_by_active_owner_count_and_preserve_global_priority` drifted from 6/6/6 to 5/6/7. This PR keeps that test green. ## Review One Luna round (correctness + prod safety) found two blockers, both fixed in the second commit: 1. A pull consuming the marker before the re-seed kept the stale credit. Fixed with the 30 s pull-lift window. 2. The re-seed was unbounded before the upload ack. Fixed: one attempt, 1.5 s deadlines, no retries. ## Tests - `tests/unit/test_batch_admission_frontier_hint.py`: 16 tests covering the re-seed lift, no-ops once the marker is consumed or gone, never lowering credit, the activation note behind the lever, a pull beating the re-seed, a late pull consuming only, the post-commit ordering, and isolation from exceptions. - Query-shape registry: `reseed_hinted_activation` and `FirestoreStore.run` are registered as covered by the existing `service_frontier` driver, with `timeout` classified shape-neutral. - 745 passed across the scheduler, query shapes, contention and live suites. Failure-Class: none 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/24864?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/24864?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F24864&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
…on commits BasedHardware#24855 reads the owner-activation service frontier outside the admission transaction; a pull committing meanwhile could leave a rejoiner below the frontier (served ahead by up to a pull batch). Activation now stamps p{prio}_frontier_hint and notes the shard; after the admission commits the store re-reads the frontier (no transaction) and lifts the shard in a small transaction on its own control doc only while the marker is set. A pull that reaches the shard first just consumes the marker, so waiting is never charged to the joiner (a pull-time lift did, drifting the fairness test 6/6/6 to 5/6/7). Same lever: admission_frontier_hint 0 stamps nothing. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
Since at least 11-06 22Z,
/v2/sync-local-fileson backend-sync has been returning503 sync_batch_unavailableto about 94% of uploads (Monitoring: 503 at about 3.5/s vs 202 at about 1.8/s). Phones retried and their ring buffers overwrote audio before it synced; one reported log shows 254,484 packets lost (coordinator a56650).Cause: batch intake's admit transaction exhausts its contention retries.
FirestoreTransaction.service_frontier. It runsorder_by(p{prio}_service DESC).limit(1)on the control collection INSIDE the admission transaction, whenever an owner (re)activates (utils/batch_pipeline/control.py:30).Fix: read the frontier as a non-transactional hint.
max(own_service, frontier). A frontier stale by milliseconds can at most give that owner a sliver of extra fairness credit; it never lowers earned credit.Kill switch
New
FIRESTORE_READ_LEVERSleveradmission_frontier_hint, default 100 (ships on).{"admission_frontier_hint": 0}restores the transactional query exactly. This adds no new env key: one entry in the existing levers JSON, likebatch_timeliness_leader.Tests
tests/unit/test_batch_admission_frontier_hint.py:transaction=None;activate()still takes the max, so a stale frontier never lowers credit.test_firestore_query_shapes,test_render_backend_runtime_env,test_flag_budget,test_batch_stage_env_ratchet,test_batch_pipeline_live,test_firestore_read_levers: 812 passed.Verify after deploy (backend-sync)
event=batch_intake outcome=retry exception_type=FirestoreContentionExhausted phase=admitrate collapses.run.googleapis.com/request_count503 rate on backend-sync falls and the 202 rate rises.admission_frontier_hintto 0.Failure-Class: none
🤖 Generated with Claude Code