Skip to content

fix(batch): read the admission service frontier outside the transaction (sync 503 storm) - #24855

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/pipeline-frontier-hint
Nov 7, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/pipeline-frontier-hint

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

What

Since at least 11-06 22Z, /v2/sync-local-files on backend-sync has been returning 503 sync_batch_unavailable to 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.

  • 15 min of logs: 3,805 retries, 54 recovered, 713 exhausted.
  • The hot spot is FirestoreTransaction.service_frontier. It runs order_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).
  • Firestore locks the documents a transactional query reads. The top-service control document is the one workers advance constantly, so admissions conflict with worker control writes.

Fix: read the frontier as a non-transactional hint.

  • It only seeds a rejoining owner's credit through 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.
  • No custody, privacy or ordering invariant reads it.
  • Query shape is unchanged; only the transaction binding is dropped. The digest-pinned query-shape entry is re-pinned with an updated reason.

Kill switch

New FIRESTORE_READ_LEVERS lever admission_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, like batch_timeliness_leader.

Tests

  • tests/unit/test_batch_admission_frontier_hint.py:
    • the default reads with transaction=None;
    • lever 0, invalid or out-of-range restores the transactional read;
    • activate() still takes the max, so a stale frontier never lowers credit.
  • Guards: 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)

  • The ERROR event=batch_intake outcome=retry exception_type=FirestoreContentionExhausted phase=admit rate collapses.
  • The run.googleapis.com/request_count 503 rate on backend-sync falls and the 202 rate rises.
  • Trip: set admission_frontier_hint to 0.

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T12:05:20.381615Z f9e3b06 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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].

View guided diff | Turn on auto-fix | Re-trigger cubic

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +24 to +26
monkeypatch.setattr(store_module, 'service_frontier', frontier)
tx = SimpleNamespace(name='admission-transaction')
return store_module.FirestoreTransaction(object(), 'batch_pipeline_dev', tx), tx, calls

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Git-on-my-level and others added 2 commits November 7, 2026 18:49
…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]>
@Git-on-my-level
Git-on-my-level merged commit 4139845 into main Nov 7, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/pipeline-frontier-hint branch November 7, 2026 15:01
Git-on-my-level added a commit that referenced this pull request Nov 7, 2026
…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. -->
kriegcloud pushed a commit to kriegcloud/omi that referenced this pull request Nov 7, 2026
…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]>
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