Repository navigation
fix(sync): release cap-hold reservations at projection so a full ledger recovers (SCA-2886) - #25697
Merged
Git-on-my-level merged 2 commits intoNov 18, 2026
Conversation
…er recovers A user's stt_cap_hold_reservations ledger pins at MAX_OPEN=200 because a reservation is only released as a side effect of the worker's next capacity check, and once the bound trips that check is never reached again. The two-minute cap-hold recovery sweep catches the ValueError per owner and still returns HTTP 200, so the failure is only visible in logs. Two changes: - finish_handoff releases the matching reservation after durable projection and before erasing audio. A failed release leaves the hand-off discoverable for retry. - reserve() runs the existing settlement pass once when the ledger is full, then retries. This also frees slots left by hand-offs erased under the old code. The 200-entry bound and the six-hour stale alert still apply. _settle now matches on batch_job_id before removing an entry, so a reservation re-created for a different job is not dropped, and the released counter only increments for outcomes actually applied. Refs SCA-2886, SCA-2885.
A cap that bounds concurrent state must not be able to become a permanent block. When the only path that releases an entry is a later admission attempt, and admission is refused once the cap is reached, the cap converts a bounded resource into a deadlock. Evidence: the stt_cap_hold_reservations ledger pinning at MAX_OPEN=200, fixed in the preceding commit. Refs SCA-2886.
Codex Review Summary: ❌ FailedThis 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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Git-on-my-level
added a commit
that referenced
this pull request
Nov 19, 2026
… as backpressure (SCA-2886) (#25745) ## What this fixes #25697 released a cap-hold reservation when its projection is observed and made a full ledger run the terminal-outcome settle pass before refusing. Verify found it serving (`a6824b8`, 2026-11-19T00:49Z) but the Done check unmet: `MAX_OPEN = 200` still refused owners who legitimately hold 201-205 live reservations, so `ValueError: cap-hold reservation bound exceeded` could not reach zero. The bound was sized for a backlog page (`PAGE = 10`), but one sweep admits up to 100 turns x 10 items for a single owner before any batch outcome can settle. A page-sized bound therefore sat below a legitimate burst, and the refusal was logged as a generic worker failure with a traceback, which made the deadlock class uncountable. ## The change - `MAX_OPEN` 200 -> 1000, matching the sweep ceiling. The ledger document stays ~150 KB, far under Firestore's 1 MiB limit. The settle pass keeps terminal entries out, so the bound now counts live work only. - A full ledger raises `ReservationBoundExceeded` (a `ValueError`) carrying `live` and `settled`, and logs `outcome=bound_exceeded`. The worker catches it and logs `outcome=reservation_full` without a traceback. `settled=0` is backpressure (every entry is live); `settled>0` is the deadlock signature. - `open_units()` and `reserve()` share one settle pass (`_open_ledger`), so the two cannot drift. No schema change; no change to what a committed hold means; revert by reverting the commit. ## Done check (revised) After this serves, `ValueError: cap-hold reservation bound exceeded` in `backend-sync` logs is zero over 24 h. If any refusal appears, its `outcome=bound_exceeded live= settled=` line must show `settled=0` and never `settled>0`. `batch_admitted` holds track live batch work against the 18,951 baseline (2026-11-17T22:25Z), with `READBACK:` on SCA-2789 quoting both numbers. ## Verification - `python3 -m py_compile` on the three changed files. - Backend unit shards run in CI; this host has no backend venv (SCA-2134 places heavy checks on m1/multica-worker-1). - New tests: a full ledger of live entries refuses with `live=MAX_OPEN, settled=0` and logs `outcome=bound_exceeded`; the worker logs `outcome=reservation_full` and no `outcome=deferred`; the existing full-ledger recovery test still passes. Failure-Class: FC-cap-bound-pins-owner-without-release-path <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/25745?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/25745?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25745&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. -->
This was referenced Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
A user's
stt_cap_hold_reservationsledger pins atMAX_OPEN = 200and never recovers. Once the bound trips, every furtherreserve()for that owner raisesValueError('cap-hold reservation bound exceeded'), the two-minutecap-hold-durable-redrivesweep catches it per owner and still returns HTTP 200, and the failure is visible only in logs. It has run continuously since 2026-11-03T19:32:28Z at roughly 2,500–3,200 log entries per day.The mechanism: a reservation is released only as a side effect of the worker's next capacity check (
processing_backlog_worker.py:353). A pinned owner never reaches that check again, so the ledger cannot drain itself.The change
Two edits, both small and reversible.
backend/utils/sync/cap_hold_recovery.py—finish_handoffnow releases the matching reservation after durable projection and before erasing audio. Releasing first means a failed release leaves the hand-off discoverable for retry rather than erasing the only copy.backend/utils/sync/cap_hold_reservations.py—reserve()runs the existing settlement pass once when the ledger is full, then retries. This also frees slots left by hand-offs erased under the old code. The 200-entry bound and the six-hour stale alert still apply; neither threshold changed._settlenow matches onbatch_job_idbefore removing an entry, so a reservation re-created for a different job is not dropped, and the released counter only increments for outcomes actually applied.Verification
backend/tests/unit/test_cap_hold_batch_debit.pyfailed before the change and pass after.test_cap_hold_batch_debit.pyandtest_cap_hold_batch_admission.py.Not claimed
The 24-hour production readback is pending. This change makes a pinned ledger able to recover; it does not prove the production stock of pinned ledgers drains, and it does not address the ~30k quarantined batch stock, which is a separate item.
Product invariants affected
none
Failure class (fixes)
Failure-Class: new
Family: work-bounded-resumable — "A timeout, budget or cap does not actually bound the work, discards in-flight work, or leaves an unbounded keyspace/TTL."
Proposed class: FC-cap-bound-pins-owner-without-release-path
A cap that bounds concurrent state must not be able to become a permanent block. When the only path that releases an entry is a later admission attempt, and admission is refused once the cap is reached, the cap converts a bounded resource into a deadlock: the owner can never admit again and the entries can never be released. The bound must be reachable from a path that does not itself require admission.
Instance:
stt_cap_hold_reservationspins atMAX_OPEN = 200because release is a side effect of the worker's next capacity check (processing_backlog_worker.py:353), and a pinned owner never reaches that check. The two-minute recovery sweep catches theValueErrorper owner and still returns HTTP 200, so the deadlock is visible only in logs. Running continuously since 2026-11-03T19:32:28Z at ~2,500–3,200 entries/day.No existing class in this family fits:
FC-bounded-discovery-pinned-by-blocked-pageis about a scanner re-querying the oldest page, not about a cap whose release path requires the admission the cap refuses.