Repository navigation
lr/06: cap-hold units handed to batch are charged without a stale window (ladder debit) - #22513
Conversation
…tale window Subscription ruling 10-19 on #22467 (cap-hold rehome). This closes the cap_hold_ladder_debit draining precondition (#22479). A: legacy recovery debits the ladder budget synchronously, but a hold handed to batch is debited only when projection commits. The backlog worker therefore checked the next candidate against stale capacity, and with remaining=None a whole page overshot (60-unit allowance, three 40-unit holds: 3 admitted, now 1). - recover_selected reserves the hold's units (the worker's own candidate units) before the hand-off is durable. - work() subtracts open reservations for the current period from capacity(). - A reservation settles when the batch outcome is known. Projected means the usage is committed atomically with the ledger; briefly both count, never neither. Failed or abandoned releases it. A 6h TTL releases it with an error log and a counter. - Previous-period reservations never shrink the new month. - The real job lease serializes two workers for one owner; a test proves it. B: cap-hold admission carries usage_period (the funded choice's month). Projection backdates the hourly stamp to that period's last second only across a rollover, never forward. Transcription has no day rollup, and the month query reads the doc id/year/month from the stamp. Usage sessions re-read a closed month in full. C: a test asserts the cap-hold path (accept_upload) never builds a native_record binding, which would skip the usage write. Lane 8 signed off on the edits in its files (recover_selected, intake.accept_upload usage_period, its hook test expectations). Worker test harnesses stub the reservation read; the new behaviour is covered in test_cap_hold_batch_debit.py. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lr/06-cap-hold-debit
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lr/06-cap-hold-debit # Conflicts: # backend/utils/batch_pipeline/intake.py
Codex Review SummaryThis 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. |
|
Subscription-session review of #22513 at 0f507dd: one change requested, then LGTM. Good:
Requested change: TTL expiry must not release a reservation whose batch job is still alive.
Nit, optional: if |
Subscription session review of #22513 (PR comment 6270782314). A batch job that is still pending past the threshold is slow, not lost; a lost job already reads as abandoned. Releasing it would let the backlog worker over-admit while batch still owes the debit, which reopens gap A. Such a reservation is now kept and still counted. It is marked stale once, with an error log and omi_cap_hold_reservations_released_total{outcome= "stale"}. Release happens only on projected, failed or abandoned. Other-period entries stop counting at once and are pruned after 7 days. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lr/06-cap-hold-debit
|
Subscription session: LGTM at 3121458. A pending reservation keeps counting past STALE_SECONDS and is flagged once with outcome=stale and an error log. Only projected, failed or abandoned releases one. Other-period entries stop counting and are pruned after 7 days. This closes my requested change; good to merge per lane 1. |
…BasedHardware#22513 x BasedHardware#22422) BasedHardware#22513 added CAP_HOLD_RESERVATIONS_RELEASED.labels(outcome=outcome) and BasedHardware#22422's contract (e) label ratchet landed after it, so test_reason_label_enums fails on the integration tip and in every lane PR. Route the value through a _bounded_outcome() helper that folds non-members of OUTCOMES to 'unknown'. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
This closes the
cap_hold_ladder_debitdraining precondition (#22479), following the Subscription session's ruling of 10-19 on #22467.A: stale capacity. Legacy recovery debits the ladder budget synchronously. A cap-held hold handed to batch is debited only when projection commits, so the backlog worker checked the next candidate against stale capacity. With
remaining=None, a whole page overshot: a 60-unit allowance with three 40-unit holds admitted 3, and now admits 1.recover_selectedreserves the hold's units (the worker's own candidate units) before the hand-off is durable.processing_backlog_worker.work()subtracts open reservations for the current period fromcapacity().omi_cap_hold_reservations_released_total{outcome="stale"}. This follows the Subscription review, PR comment 6270782314.B: period attribution. Cap-hold admission carries
usage_period(the month of the funded choice). Projection backdates the hourly stamp to that period's last second only across a rollover, and never moves it forward. The month query reads the doc's id, year and month from the stamp. Transcription has no day rollup, and usage sessions re-read a closed month in full.C: a test asserts the cap-hold path (
accept_upload) never builds anative_recordbinding, which would skip the usage write.Lane / contract
Lane 06 (funding gate for contract (h) draining). Owner sign-offs for edits to other lanes' files:
cap_hold_recovery.recover_selected, theintake.accept_uploadusage_periodpass-through, and the expected events intest_cap_hold_batch_admission;utils/processing_backlog_worker.py(+ its test harnesses): no §3 lane owner; it is Subscription session code. The lead assigned this fix to lane 6, so lane 6 owns this edit, and the Subscription session's LGTM is requested alongsidecap_hold_recovery.py.cap_hold_recovery.py, newcap_hold_reservations.py): LGTM requested on the bus at 15:3xZ.database/batch_pipeline_projection.py,prepare_accountingonly): ack requested on the bus at 15:3xZ.Product invariants affected
INV-DATA-1: path match only. This diff does not alter the Firebase/Firestore project or any serving endpoint.
users/{uid}/stt_cap_hold_reservations/current, lives on the existing data-plane client and is written underexternal_write_fence.Verification
All unit layer, m5, serial:
test_cap_hold_batch_debit.py(22, new);test_cap_hold_batch_admission(24);test_processing_backlog_worker_review(44);test_processing_backlog(47);test_batch_pipeline_quarantine(19);test_batch_pipeline_projection(40);test_cap_hold_durability(23);test_batch_pipeline_intake(22);test_batch_provider_stt(66);test_held_audio_summary(18);test_sync_cap_hold_recovery(29);test_sync_cloud_tasks(186).The import side-effect scan and the flag registry are OK. The full suite and preflight run on m1 (
m1-check). Not run: staging (draining is not used there yet).Rollback
Revert the PR. Draining stays blocked by #22479's
cap_hold_ladder_debitprecondition until it is re-landed. Nothing user-visible changes while legacy sync ison, because the batch hand-off only runs in draining or dark.Failure-Class: none
Line-Count-Exception: backend/routers/sync.py | 3820 -> 3857 | integration content (lane 10 legacy-dark, already on integration/legacy-retire); this PR does not touch routers/sync.py, and the pre-push gate diffs against main
🤖 Generated with Claude Code