Repository navigation
fix(backlog): explicit retry state for batch backlogs (core: class 1 retry cap, class 3 held re-drive budget, class 6 counter) - #24936
Git-on-my-level wants to merge 25 commits into
Conversation
Class 1 (the retry cap only observed outside the CAPTURE_COVERAGE_MODE serve cohort, so lease-expiring units retried forever). CAPTURE_RETRY_CAP_ENFORCED, default off (lead2 ruling 64b2fa: enforcing quarantines rows, a custody change). When on, a batch lease expiry at BATCH_PIPELINE_MAX_ATTEMPTS quarantines for every uid (retained held, the transition explicit worker failures already take). The sync dispatching cap keeps the cohort decision (enforce=False): a passed dispatch retry deadline is queue delay, not failure. Backlog switches are parsed literally and never re-read through the capture-coverage serve-mode parser, which would turn an unset default-off switch on. Alert omi-backlog-retry-cap-quarantine-rate. Tests run the switch true, unset and false; legacy cohort tests pin the off state. Failure-Class: FC-state-deadline-without-reader-exit
…base (default ON) Class 2 (a running sync lease expiry reset dispatch_attempt to 0, so the attempt budget never bounded crashes). SYNC_DISPATCH_ATTEMPT_CARRY_ENABLED, default on (lead2 ruling 64b2fa: it only stops the reset, cuts retries). The carry is unsafe without dispatch_attempt_base, so both ship together: dispatch_attempt stays the carried task identity, and dispatch_attempt_base restarts the legacy dispatching-deadline budget at each new epoch, exactly as main's reset did. Without the base a crash plus a delayed replacement fails the job in a capture serve cohort while class 1 is off. Crashes are counted in running_expiries (an expiry while a budget deferral's deferred_until marker is live is not a crash; reset at claim). The reconciler finalizes a running owner at SYNC_TASKS_MAX_ATTEMPTS only with class 1 on; the CAPTURE_COVERAGE_MODE cohort never turns that on, and with class 1 off the count is observed only. redrive_job never refuses a running owner. Alert omi-backlog-sync-running-cap-rate. Tests run the switch true, unset and false, class 1 on and off, serve mode and serve cohort, budget-deferral chains, terminal jobs and the delayed dispatch budget. Failure-Class: FC-state-deadline-without-reader-exit
…fault ON) Class 6, counter only (amendment 12:49Z: the counter goes in core because it is independent of the projection re-arm and the terminal stop, which stay in the follow-up). BATCH_HELD_REDRIVE_COUNTER_ENABLED, default on (lead2 ruling 64b2fa: counter and alert on). - Every held re-drive (nightly, operator, status poll of a held_expired dead letter) increments held_redrives through one shared helper. - The nightly scan and committed poll re-drives record held_redrive_budget_spent at or over MAX_HELD_REDRIVES (3), alerted by omi-backlog-held-redrive-budget-spent. Counting and an alert only: no requeue refusal, no state change, and the projection release path is untouched. Tests run the counter true, unset and false for requeue counting, the nightly observation and repeated poll re-drives. Failure-Class: FC-state-deadline-without-reader-exit
Class 3 (a requeue from held or dead-letter kept attempt at or above the cap, so a re-drive re-quarantined on its first failure). BATCH_HELD_REDRIVE_BUDGET_ENABLED, default off (lead2 ruling 64b2fa: a re-drive with a fresh budget moves held rows back into processing, a custody change). When on, every held re-drive (nightly, operator, status poll) resets attempt to 0 and keeps the prior value in held_redrive_last_attempt, through the same helper as the class 6 counter. Tests run the switch true, unset and false, and the counter x budget combinations through the real status-poll path. Failure-Class: FC-state-deadline-without-reader-exit
Switch table, defaults and rollback for classes 1, 2, 3 and the class 6 counter, plus the known pre-existing projection re-arm gap on main (batch_pipeline_projection_release.py:290), which this branch does not change.
One conflict: config/feature-flags.yaml, additive, both sides kept (the four core switches and main's new rows); the registry doc and monitoring exports were regenerated. No code conflicts. BATCH_HELD_DEAD_LETTER_ENABLED and ghost settle unchanged.
The pre-existing gap is now addressed on main behind BATCH_PIPELINE_PROJECTION_RESTORABLE_CAP_EXPIRY_ENABLED (default off). This branch still does not touch batch_pipeline_projection_release.py.
config/feature-flags.yaml conflicted again (additive). Resolved to main's file with the four backlog rows moved to the end of the flags list, so new rows main adds under 'flags:' no longer collide with them. Registry doc and monitoring exports regenerated. No code conflicts.
test_requeue_idempotent_and_usable_with_flag_off_retains_attempt_and_audio_history asserts a requeue keeps attempt at the cap, which is main's behavior and the class 3 off path. Running the suite with BATCH_HELD_REDRIVE_BUDGET_ENABLED=true in the environment made it fail by design. The class 3 on path (attempt reset, held_redrive_last_attempt) is covered in test_backlog_state_machine.py. Failure-Class: test-contract 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.
4 issues found across 21 files
Confidence score: 3/5
alert-rules.jsonuses a series the Cloud Run sync services do not export, so this alert may not fire. Point it at an exported series or make sure the services export this one.held_dead_letter.pyincrements the re-drive budget counter before the decision, so skipped, failed, and replayed rows can inflate it. Record it once per committed transaction, as the runbook specifies.backlog_state_machine.pylogs an INFO line on every per-unit check, which can flood logs during a large nightly scan. Passlog=False.intake.pyuses a function-local import that violates backend policy. Moverecord_transitionto the module import block.
You’re at about 98% 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].
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/config/backlog_state_machine.py">
<violation number="1" location="backend/config/backlog_state_machine.py:49">
P3: `held_redrive_counter_enabled()` logs an INFO line on every call because it doesn't pass `log=False`. It runs once per held unit in the nightly scan, so a large backlog floods logs. Pass `log=False` on this per-unit accessor, following the `metrics.py` convention.</violation>
</file>
<file name="backend/charts/monitoring/alert-rules.json">
<violation number="1" location="backend/charts/monitoring/alert-rules.json:32459">
P2: This rule reads `omi_backlog_state_transitions_total{transition="sync_running_cap_reached"}`, but that series is not exported from the Cloud Run sync services. Neither `backend/deploy/cloud_run_gmp_sync.yaml` nor the prod sync exporter imports an `omi_backlog_` family. With `noDataState: OK`, the alert will stay silent forever. Add the family to the sidecar regex and the sync exporter import list together with this alert, or drop the rule until it is ingested.</violation>
</file>
<file name="backend/utils/batch_pipeline/held_dead_letter.py">
<violation number="1" location="backend/utils/batch_pipeline/held_dead_letter.py:76">
P2: The nightly `held_redrive_budget_spent` counter fires before the re-drive decision, so skipped, failed, and replayed rows inflate it. The runbook says this counter is counted once per committed transaction. Record it only in the `if changed:` branch, using the spent state captured before the requeue, so it counts committed re-drives only.</violation>
</file>
<file name="backend/utils/batch_pipeline/intake.py">
<violation number="1" location="backend/utils/batch_pipeline/intake.py:378">
P3: Move the new `record_transition` import to the module import block; backend policy forbids function-local imports and the dependency has no cycle requiring lazy loading.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a80f4fc13b
ℹ️ 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".
… sync running cap Custody review on a80f4fc, two blockers. 1. /redrive-dead on a held_expired dead letter bypassed the class 3 attempt reset and the class 6 count: only the status poll passed automatic=True. Every held_expired re-drive now goes through account_held_redrive, and Scheduler.redrive_dead records held_redrive_budget_spent after commit, like the nightly scan and the poll. Plain dead rows are unchanged. 2. With class 1 unset and CAPTURE_COVERAGE_MODE off, running_cap returned None, so a running lease that kept expiring past the cap was redriven forever with no signal. running_cap now always returns an observe-only decision while class 1 is off (would_quarantine), and a committed running-lease redrive at or over the cap records sync_running_cap_observed, alerted by omi-backlog-sync-running-cap-unenforced. The cap still terminalizes only with class 1 on. Tests drive the /redrive-dead route with counter x budget on and off, below and at the budget, and the sweep with class 1 unset, false and true. Main's two retain-attempt held tests pin class 3 off. No default changes. Failure-Class: FC-state-deadline-without-reader-exit Co-Authored-By: Claude Opus 5.5 <[email protected]>
…amilies Custody review on abd11f1. 1. The held re-drive alert needed more than 64 spent-budget observations an hour, so one recording looping through held, expiry and re-drive (about once per 8 days, no terminal stop in core) never alerted. New rule omi-backlog-held-redrive-unit-looping fires on any spent-budget observation in the last 8 days, so a single unit is enough and a looping unit keeps it firing. The 64/h volume rule stays. 2. The Cloud Run metrics exporters did not import omi_backlog_state_transitions_total or omi_capture_retry_cap_total, so every backlog alert read vector(0). Both families are added to the prod and dev main and sync exporter allowlists, with a contract test that every family the backlog alerts query is imported by both releases. 3. /requeue-quarantined counted the re-drive but never reported a spent budget. The operator requeue now records held_redrive_budget_spent after commit; the nightly pass, which already observes in its scan, does not signal twice. 4. retry_cap's docstring, a retry_hygiene comment and the quarantine-rate alert title said the cap enforces by default; class 1 is off by default. Tests evaluate the alert rule definitions through scripts/alert_backtest.py over a simulated nightly loop of one recording. No default changes. Failure-Class: FC-state-deadline-without-reader-exit Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t rules The unit-looping alert test evaluates both held re-drive rules; the volume rule uses a 1h window, which the day-only parser rejected. Failure-Class: test-contract Co-Authored-By: Claude Opus 5.5 <[email protected]>
…chine-core # Conflicts: # backend/charts/monitoring/alert-rules.json # backend/charts/monitoring/gmp-query-migration-inventory.json
…itch parsing Custody review on 53a692d. A. An expired deferred_until marker was read as proof the budget-deferred replacement ran, so the running cap could fail the job and release its owner while the delivery was only late. The replacement retires the marker when it starts, so any marker still on the job now keeps the delivery obligation: the expiry is not a crash and the cap does not finalize. B. The class 3 attempt reset could run without the class 6 counter, and the terminal stop is not in core, so nightly re-drives could grant fresh budgets forever with no alert. The reset now takes effect only with the counter on and only while the unit has fewer than MAX_HELD_REDRIVES re-drives; a spent or uncounted unit keeps main's retained loop and the spent-budget signal. C. The backlog switches lowercased and trimmed their value, so TRUE enabled them. They now enable only on the exact raw value true; main's other switches keep their parsing. D. Terminal and vanished-job cleanup counted a running crash; only a lease expiry with no pending replacement does now. E. The sync running cap recorded quarantine before the fenced handoff; it is recorded only after finish_expired_job succeeds. Each fix has a test that fails on 53a692d and passes here. No default changes. Failure-Class: FC-state-deadline-without-reader-exit Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t of core Coordinator ruling (b): core keeps class 1, class 3 and the class 6 counter; class 2 (SYNC_DISPATCH_ATTEMPT_CARRY_ENABLED) and the sync budget-deferral chain move to the follow-up branch with their open items. - utils/sync/retry_hygiene.py, utils/sync/uid_sequencer.py and database/sync_backfill_sequencer.py return to main's text: no attempt carry, running_expiries, dispatch_attempt_base, deferral_pending, running cap, running-cap observation or deferred-finalizer recording. - retry_cap now enforces only for callers that opt in (enforce=True); the batch lease-expiry cap opts in, so class 1 is batch-only and main's sync dispatch cap keeps its CAPTURE_COVERAGE_MODE cohort decision. - The switch, its flag row and registry entry, the sync_running_cap_reached and sync_running_cap_observed transitions, and the two sync running-cap alerts are removed; the runbook drops class 2. - Class 2 tests move with it; a new test pins main's sync dispatch cap under class 1 on and off. Defaults of the kept switches are unchanged. Failure-Class: FC-state-deadline-without-reader-exit Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rt tests The class 2 removal restored this file to main's text, dropping the class 1 pin with it. Its batch cohort tests assert the legacy shadow decision, which is the CAPTURE_RETRY_CAP_ENFORCED off path; running the suite with the switch forced true failed them. The enforcing batch path stays covered in test_backlog_state_machine.py. Failure-Class: test-contract Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es for the owner Custody review on da4132e (luna-core-5-1). With class 3 and the class 6 counter on but class 1 off, an owner outside the served CAPTURE_COVERAGE_MODE cohort got a fresh attempt budget although its lease expiries only defer: the unit stayed runnable without bound, the spent-budget alert never saw it, and the retry-cap alert counts only quarantines. The reset now takes effect only where the batch retry cap enforces for the owner (class 1 on, or the owner in the served cohort); elsewhere it is a no-op and main's behavior is kept. The class 6 counter is unchanged. test_class_3_reset_only_where_the_retry_cap_enforces_for_the_owner fails on da4132e and passes here; class 3 reset tests now enable class 1. No default changes. Failure-Class: FC-state-deadline-without-reader-exit Co-Authored-By: Claude Opus 5.5 <[email protected]>
Switching class 3 OFF stops new budget resets. Existing grants persist until their unit runs or finishes. Each grant is capped at MAX_ATTEMPTS. Documentation and a regression test only; no behavior or default change. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
omi-backlog-held-redrive-unit-looping was agent tier, so omi-tier-silent muted it, and its UID was outside live-alert-gate.json. One looping unit stays under the volume alert's threshold, so nobody was notified. Route it as a page on the same Telegram receiver with no mute interval, add the UID to live-alert-gate.json so the monitoring workflow imports and reads it back, and regenerate alert-rules.json. A test pins the route. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preserve both backlog re-drive and main orphan-repair flag declarations by regenerating the flag registry from the merged sources. Failure-Class: FC-state-deadline-without-reader-exit
Emit nightly and operator spent-budget metrics from the shared recovery commit boundary, retain replay and privacy fences, suppress per-unit flag logs, and admit transition metrics through the sync sidecar. Move new imports to module scope and document the core pipeline transitions. Pin committed, skipped, failed and replayed candidates in regression tests. Failure-Class: FC-state-deadline-without-reader-exit
Replace the retired scan-owned emission assertion with the shared recovery commit contract. Failure-Class: FC-state-deadline-without-reader-exit
|
Completion checkpoint — 2026-11-09 20:02 UTC (quiet-host validation/push needed)
Next on a quiet host: rerun |
|
Published completion checkpoint — m1-mac-studio, 2026-11-09 Pushed Local unit verification at that head: 2,051 passed across 33 files, through All seven replied review threads were resolved after verifying publication. Exact-head CI is running; final CI status will be recorded separately. No live behavior is claimed. Unit file selection |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 71c6774e72
ℹ️ 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".
|
|
||
|
|
||
| def transitions(name): | ||
| from utils import backlog_metrics |
There was a problem hiding this comment.
Move the new test imports to module scope
The new test module introduces function-local imports here and throughout its helpers and test cases, including backlog_metrics, KILL_SWITCHES, json, and Path. These still violate the backend guide's explicit requirement that all imports be at module scope; the rule has no test-file exception. Move the newly added test imports to the module import section.
AGENTS.md reference: backend/AGENTS.md:L168-L168
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed on published head 71c6774: this new test module still contains function-local imports, so the guide-compliance finding remains open. The seven original handoff threads are resolved; this new finding is not addressed by those published fixes. The file passed all 83 tests locally and exact-head CI is green, which verifies behavior but does not resolve the import-policy issue. Leaving this thread open in the publication handoff rather than claiming it fixed.
|
Publication complete — 2026-11-09 20:43 UTC
No GCP tier or production data was used. All local test processes and CI waiters have exited. The clean m1 worktree has been removed with managed Git. |
…+ corrected rollback docs (supersedes #24936 head) (#25012) <!-- claude-projects-attribution: {"github_login":"Git-on-my-level"} --> _Requested by **David**_ --- **Merge head: `14752f01a0ba0e75cfb89642dd4187eddf0eea87` (14752f0).** Luna delta review SHIP and CI green (63 passed, 0 failed) at this exact head. Merge with `--match-head-commit 14752f0`. Switches ship default OFF. ## Supersedes #24936's head This supersedes the head of #24936 (`lane/backlog-state-machine-core`, now `71c6774e720` on the remote). That branch was moved by another lane and carries 11 commits that were not reviewed here. This PR carries only the reviewed rollback docs and pin test on top of `9f7d51691fe9`, the last reviewed head of #24936. #24936 stays open for now. What this PR contains, against main: - #24936's reviewed core at `9f7d51691fe9` (class 1 retry cap, class 3 held re-drive budget, class 6 counter, the single-unit looping page). Its description, switches, defaults, ramp plans and verification are in #24936's body; nothing in it changed here. - One new commit on top: the corrected rollback docs and the class 1 pin test (below). - A merge of origin/main `a8f3ad08ebf`. Its only conflict was the generated `backend/docs/feature-flag-registry.md`, re-rendered from the merged `config/feature-flags.yaml`: main's rows plus this branch's three switches. ## Product invariants affected Those of #24936's reviewed core, unchanged (see #24936). The commit added on top is documentation, code comments and one unit test: no behavior, default or switch change. ## Failure class (fixes) Failure-Class: FC-state-deadline-without-reader-exit Retry state in the batch and sync backlog paths lost its counters or never ended work. This core PR gives three classes their own counter or budget, each behind its own switch, with tests that run each switch on and off. ## Known gaps - The rollback-contract test for the class 3 note with class 1 off (the reviewer's item). The note in `config/feature-flags.yaml` is now qualified: re-quarantine after a class 3 grant depends on class 1 (`CAPTURE_RETRY_CAP_ENFORCED`) enforcing for the owner, and with class 1 off for an owner outside the served cohort, lease expiry defers instead, as on main. The test is not in this PR. Follow-up: `lane/backlog-state-machine-followup` (local, scope in the bus post). - The class 2 sync running-lease reset (`backend/database/sync_backfill_sequencer.py:947`, `dispatch_attempt` reset to 0 on the running-lease path). Class 2 is out of this PR. Follow-up: `lane/backlog-state-machine-followup`. ## Why The rollback text for class 1 (`CAPTURE_RETRY_CAP_ENFORCED`) and class 3 (`BATCH_HELD_REDRIVE_BUDGET_ENABLED`) claimed every grant stays capped at `MAX_ATTEMPTS` after a switch goes OFF. The code does not do that: `expire_lease` reads class 1 on each lease expiry, and with it off (owner outside the served cohort) the unit defers as on main and is not quarantined at the cap. ## Change Rollback semantics, now stated the same way in `backend/utils/batch_pipeline/scheduler.py` comments, the `backend/docs/runbooks/backlog-state-machine.md` "Turning it off" cells, and here: - Class 1: switching class 1 OFF stops new cap enforcement. Existing grants persist until they finish; no clawback. Each grant is capped at `MAX_ATTEMPTS` only while the retry cap enforces for the owner (class 1 on, or the owner in the served cohort). With class 1 off, lease expiries defer, as on main. - Class 3: switching class 3 OFF stops new budget resets. Existing grants persist until their unit runs or finishes; no clawback. Each grant is capped at `MAX_ATTEMPTS` only while the retry cap enforces for the owner (class 1 on, or the owner in the served cohort). With class 1 off, lease expiries defer, as on main. ## Tests `test_class_1_on_to_off_keeps_grants_quarantines_only_while_on_then_defers` in `backend/tests/unit/test_backlog_state_machine.py`, with class 1 switched mid-run: - the cap quarantines while class 1 is ON; - a class 3 grant's attempts are kept when class 1 goes OFF (no clawback); - after OFF, lease expiries defer past the cap with no new quarantine. It passes on the current code (a regression pin). A temporary mutation that kept the cap enforcing after OFF (`enforced = enforce` in `utils/capture/retry_cap.py`) made it fail: attempts `[1, 2]` instead of `[1, 2, 3, 4]`. The mutation was reverted and is not committed. 🤖 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/25012?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/25012?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25012&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. --> Merged origin/main (no force) on m1-mac-studio per lead2 0dac49; pre-push hook ran on m1. ## Pre-review fix batch A-F (lead2 7a3c9e); pre-push hook ran on m1 - A: detect spent transitions only in the eligible, privacy/content-verified winning re-drive transaction; emit after commit. Exclude today-expired skips, CAS losers, refused rows and staging-input repairs. - B: keep durable held accounting independent of the telemetry switch. Persist a once-per-unit spent marker and page on new transitions over 1h; later nightly cycles never re-fire the same unit. The retained loop remains documented; no terminal stop added. - C: reuse RecoveryStore.checked() and held eligibility for poll and /redrive-dead budget resets. Neither operator route consumes held grants or resets attempts for input_expiring. - D: accept nonnegative integral floats, log malformed-value signals without values/content, and normalize malformed legacy counts from zero on the next verified re-drive. - E: normalize true-only switches with trimming and case folding, matching other kill switches; all other explicit values fail closed. Update parser tests, registry and runbook. - F: keep backlog_state_transitions_total in the sync GMP source scrape allowlist, retain its prod_sync exporter import, and validate every backlog alert metric through both source filters and downstream importers. The batch changes runtime behavior; the earlier documentation-only scope statement describes the original head. Audio custody is retained and content/privacy ownership is verified before re-drive grants. Validation details below reflect hermetic tests; no production endpoints were called. Validation on m1 (2026-11-10): 765 passed across ten backend/test.sh invocations with xdist and per-file sessions (121 state-machine, 62 scheduler, 42 held dead letter, 163 quarantine recovery, 85 intake, 108 input retention, 54 monitoring telemetry, 75 alert-rule contract, 27 provisioning, 28 alert backtest). Changed production files: pyright 0 errors. Registry check OK; all 19 runtime-image source contracts and all 45 local preflight checks passed. Shared checked() fence extraction preserves worker source closure. Endpoint routes are exercised hermetically with FastAPI TestClient; no live backend was started. Dated evidence: backend/docs/listen_pusher_pipeline/changes/2026-11-10-backlog-redrive-fence-accounting.md. Full pre-push hook passed on m1 at 2026-11-10T13:17:01.181572+00:00; complete push wall time 74.92s, exit 0. Hook evidence: 45 shared preflight checks, full backend pyright 0 errors, 297 hook-selected unit tests (121/62/42/18/54), OpenAPI compatibility/codegen and pinned formatting passed. Pushed earlier commit 9e593c9. No force push, no verification bypass, no merge. P2 polling-status fix (2026-11-10): refresh the status snapshot from the successful re-drive transaction so ready units return queued with a 3000 ms poll hint; refused re-drives retain held status and 300000 ms polling. Added returned-status assertions and active-token/provider-route refusal coverage; backend/test.sh passed 312 tests across state machine, intake, scheduler and held dead letter. CI fix (2026-11-10, m1-mac-studio): extract the unchanged ledger owner predicates into dependency-free `database/sync_ledger_ownership.py` and migrate all batch callers, cutting the scheduler recovery-fence import path into `utils.cloud_tasks`; regenerate the GMP inventory with `backend/scripts/monitoring_gmp_shadow.py --inventory --output backend/charts/monitoring/gmp-query-migration-inventory.json` to match the current 1h backlog alert. Contract tests remain unchanged. CI-fix validation on m1: `backend/scripts/run-unit-ci.sh --changed-files <PR changed paths> --shard 8/5` passed all 345 file-isolated sessions (8,205 passed, 37 skipped). The whole shard was rerun with `DYLD_LIBRARY_PATH=/opt/homebrew/lib` after the first local run could not discover the installed libopus. Separately, every `test_runtime_image_contracts*.py`, every `test_monitoring_gmp*.py`, and `test_backlog_state_machine.py` passed (265 tests across four separate file sessions). `make preflight` passed all 45 checks. Existing sync ownership/checkpoint and batch projection/artifact-missing regression tests also passed (139 tests across four isolated files). Full-hook push passed for `6aa568fa0bc17ae0a4129463abdfb9d7d721ef7a`: 45 PR checks, full backend Pyright (0 errors), hook-selected unit tests, OpenAPI/compatibility checks, and pinned formatting. The shared owner predicate has a public name for cross-module type checking. Final-head focused/ownership regression rerun: 404 passed in eight isolated files; final-head shard 5/8 rerun: 8,205 passed, 37 skipped in 345 isolated files. Failure-Class in the CI-fix commit: `FC-runtime-image-boundary`. No production endpoints were contacted. FIX-FIRST poll transaction-order fix (2026-11-10, m1-mac-studio): `Scheduler.redrive_in_transaction` and `requeue_quarantined_in_transaction` return the updated job plus its spent flag (`RedriveResult | None`). `durable_status` builds the refreshed response from that returned job without a post-write `tx.get`. Queue append completes its queue/frontier/control reads before staging writes. `/redrive-dead` and nightly/operator recovery keep boolean acceptance and emit the spent signal only from the successfully committed transaction result. The existing refused-redrive test is retained. A strict transaction regression raises `ReadAfterWriteError` on every get after a put or patch and covers held-expired/historical jobs, below/at budget, and telemetry on/off. Fix commit class: `FC-joined-writer-writes-before-transaction-reads`. Pipeline note: `backend/docs/listen_pusher_pipeline/changes/2026-11-10-backlog-poll-redrive-status.md`. FIX-FIRST validation on m1: `backend/test.sh` passed 483 tests across five separate file sessions: backlog state machine 131, intake 85, scheduler 62, held-dead-letter 42, quarantine recovery 163. `backend/scripts/run-unit-ci.sh --changed-files <PR changed paths> --shard 8/5` passed 8205 tests, 37 skipped across all 345 files, with `DYLD_LIBRARY_PATH=/opt/homebrew/lib`. `make preflight` passed all 45 selected checks. FIX-FIRST published earlier commit `e98f7063a69fcc54fcafafac577205af729e8876`. The full pre-push hook passed: 45 shared checks, full backend Pyright with 0 errors, hook-selected unit tests, runtime source closure, OpenAPI/client compatibility and pinned formatting. Negative control: restoring only the old poll `tx.get` made all eight strict regression cases fail with `ReadAfterWriteError: get after write: jobs/segment`; after restoring the fix all eight passed. The source was restored exactly before publication. No force push, verification bypass, PR merge or production endpoint access. Shard-2 lifecycle CI fix (2026-11-10, m1-mac-studio): restore the original local `BATCH_PARTIAL_STATUS = 'partial'` declaration and comment in `database/sync_ledger.py`, and import only `ledger_owner_matches` from the pure ownership module. The lifecycle scanner can again resolve the writer's literal alias; no contract test or lifecycle baseline changes. The ownership helper and GPU import boundary remain unchanged. This restores the unchanged value's source visibility, with no runtime state/value change; fix commit declares `Failure-Class: none` for this CI-only correction. CI audit: [run 42871725269, shard 2/8](https://github.com/BasedHardware/omi/actions/runs/42871725269/job/130024386026) has exactly one failed test: `test_no_undeclared_or_stale_lifecycle_field_builder[database/sync_ledger.py]`. The other seven shards and guardrails passed. No tests directly import `sync_ledger_ownership`; the local ownership regression manifest conservatively follows static and literal dynamic imports to 873 unit/service/router test files, plus the runtime-image contract file. Shard-2 fix validation on m1: `backend/test.sh` passed the lifecycle file alone (1,734 tests) and the complete ownership-import regression manifest plus runtime image contract (874 files; 28,323 passed, 64 skipped), using isolated pytest sessions. The unchanged authoritative runner `backend/scripts/run-unit-ci.sh --changed-files <PR changed paths> --shard 8/2` passed all 342 files (9,127 passed); `--shard 8/5` passed all 345 files (8,187 passed). Both used `DYLD_LIBRARY_PATH=/opt/homebrew/lib` for the installed native Opus library. `make preflight` passed all 45 checks. Shard-2 fix published earlier commit `9f7a6a07ea57ffd598121ec629300e0daf988c5a`. Full pre-push hook passed: 45 shared checks, backend Pyright with 0 errors, hook-selected unit tests, runtime source closure, OpenAPI/client compatibility and pinned formatting. Shard 2: 9,127 pytest tests passed, 15 skipped; shard 5: 8,187 pytest tests passed, 37 skipped. The canonical shard-5 pytest count excludes 18 environment-validation checks printed inside another test, which were included in earlier 8,205 totals. No contract test or lifecycle baseline was changed. No force push, verification bypass, PR merge or production endpoint access. ### Review follow-up: multi-unit poll transaction buffering Verified earlier commit `9f7a6a07ea57ffd598121ec629300e0daf988c5a` before creating a fresh task worktree; ran `make setup` only there. The review concern does not reproduce with the production transaction wrapper. The class is named `FirestoreTransaction` (not `BatchTransaction`): `backend/database/batch_pipeline_store.py:159-176` buffers put/patch/defer_set, `:281-282` runs the complete callback before flush, and `:220-241` completes commit-fence reads before raw set/update calls. `RecoveryFence.checked` (`backend/database/batch_pipeline_recovery_fence.py:28-82`) only reads; scheduler requeue/redrive and queue append (`backend/utils/batch_pipeline/scheduler.py:73-104,994-1042`) use buffered puts. No raw transaction set/update or external document write joins these helpers. Privacy token minting, when enabled and eligible, schedules a delayed independent transaction (`backend/database/batch_pipeline_privacy.py:426-478`), not a write to the poll transaction. Added 12 two/three-unit poll cases using the real FirestoreStore, wrapper, recovery fence, scheduler and flush against the shared StrictFirestore raw transaction double. They demonstrate actual raw reads after earlier buffered puts, all candidate writes still buffered on entry to flush, and privacy reads during flush before raw writes. All-eligible and mixed active-token/receipt refusals verify refreshed status, queue head/tail/links, unchanged refused records, per-unit spent telemetry on/off, and a negative control that raw reads after flush raise ReadAfterWriteError. Kept the existing single-unit refusal and returned-job regressions; renamed the latter to distinguish its stronger wrapper-level constraint. No runtime ordering or flag changes are required. Commit declaration: `Failure-Class: none` (evidence and regression coverage, no production read-after-write violation found). Validation: backlog state machine, intake, scheduler, held dead-letter, projection held dead-letter and quarantine recovery: **521 passed** across six isolated files. CI runner shard 2/8: **342 files, 9,127 passed, 15 skipped**; shard 5/8: **345 files, 8,187 passed, 37 skipped**. `make preflight` with the saved PR body passed all **45 checks**; Full publish hook passed (manifest checks, backend Pyright with zero errors, unit tests, runtime-image contracts, OpenAPI compatibility and formatting). Pushed head `14752f01a0ba0e75cfb89642dd4187eddf0eea87`; no main conflict or merge was needed.
|
Hey @Git-on-my-level 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
Requested by David
Product invariants affected
none
Failure class (fixes)
Failure-Class: FC-state-deadline-without-reader-exit
Retry state in the batch and sync backlog paths lost its counters or never ended work. This core PR gives three classes their own counter or budget, each behind its own switch, with tests that run each switch on and off.
Why
The 2026-11-07 backlog root-cause review (workspace
data/run-2026-11-07-backlog-hypotheses/aggregate.md) found that backlogs recur because retry loops lose their state:CAPTURE_COVERAGE_MODEserve cohort;attemptat the cap, so the first failure re-quarantined it;This is the core split of #24893. Class 4 (record_pending park), class 5 (assignment-hold escalation), and class 6's terminal stop and projection re-arm path are on
lane/backlog-state-machine-followupand get their own PR after this merges.Class 2 removed from core (coordinator ruling b). Class 2 (
SYNC_DISPATCH_ATTEMPT_CARRY_ENABLED) and the whole sync budget-deferral chain are out of this PR: the attempt carry,running_expiries,dispatch_attempt_base,deferral_pending, the sync running cap and its two alerts (omi-backlog-sync-running-cap-rate,omi-backlog-sync-running-cap-unenforced), and their tests.utils/sync/retry_hygiene.py,utils/sync/uid_sequencer.pyanddatabase/sync_backfill_sequencer.pyare byte-identical to main. Class 2 moved tolane/backlog-state-machine-followupwith its open items (late-delivery handling through the exhaustion check, stale-epoch delivery), and ships in the follow-up PR.Change
One commit per class. Switches are registered in
config/policy/kill_switches.pyandconfig/feature-flags.yaml. They are parsed literally (trueis on, anything else is off, unset is the default), read per decision, and never re-read through the capture-coverage serve-mode parser. Defaults follow lead2's rule (64b2fa): ON only where a class just cuts wasted work or retries, OFF where it changes custody, settle or expiry semantics.CAPTURE_RETRY_CAP_ENFORCEDomi-backlog-retry-cap-quarantine-rateattemptat the capBATCH_HELD_REDRIVE_BUDGET_ENABLEDBATCH_HELD_REDRIVE_COUNTER_ENABLEDomi-backlog-held-redrive-budget-spentMain's
BATCH_HELD_DEAD_LETTER_ENABLEDpath (on) and ghost settle (False) are unchanged. This PR does not touchutils/batch_pipeline/live.pyordatabase/batch_pipeline_projection_release.py.BATCH_PIPELINE_MAX_ATTEMPTSquarantines (retained held,worker_failed) for every uid. Only the batch lease-expiry cap opts in to enforcement; every otherretry_capcaller, including main's sync dispatch cap, keeps theCAPTURE_COVERAGE_MODEcohort decision, so the sync path is exactly main's.held_expired). The counter incrementsheld_redrives, and class 3 resetsattempt. The nightly scan and committed poll re-drives emitheld_redrive_budget_spentat or over 3. There is no terminal stop in this PR.Tests
backend/tests/unit/test_backlog_state_machine.pyruns each switch true, unset and false:MAX_ATTEMPTScap, and a later re-drive gets no new reset.Legacy cohort tests in
test_capture_retry_hygiene.pyandtest_batch_pipeline_scheduler.pypin class 1 off.Local verification, at the unit layer, on head
17ffdf251b6a, against maincd6f864c3329. Each file ran in its own pytest process throughbin/omi-heavy. The 13 files were:They passed with the switches unset, and with each of classes 1, 3 and the class 6 counter forced
trueand thenfalseon its own: 841 passed and 0 failed in each of the 7 settings.make preflightwithBACKEND_UNIT_FILE_BUDGET_SECONDS=900passed all 44 checks.New since the first review:
true./redrive-deadand/requeue-quarantinednow get the class 3 and class 6 accounting and the spent-budget signal.omi-backlog-held-redrive-unit-looping; its tests evaluate the rule definition over a simulated nightly loop of one recording.omi-backlog-held-redrive-unit-loopingis added tobackend/charts/monitoring/live-alert-gate.json, so the monitoring workflow imports it on--mode importand fleet verification checks it is live, unpaused and equal to the committed rule.alert-rules.jsonis regenerated withprovision_monitoring_alerts.py --regenerate.test_single_unit_looping_alert_routes_unmuted_and_is_on_the_reviewed_import_listpins the route.Not run locally: the full CI suite, the Firestore-emulator integration tests, and anything live.
Rollout and verification after deploy
Deploying this serves only the class 6 counter (default on). Watch these alerts, all in
charts/monitoring/alerts/backlog-state-machine.json:omi-backlog-held-redrive-unit-looping: a single held recording re-driven after spending its budget, in the last 8 days. This one pages:tier: page,audience: human, receiverOmi - Services Alerting (Telegram)with no mute interval (notomi-tier-silent), routed likeomi-batch-queue-safety-blind. One looping unit stays under the volume alert's threshold, so this is the only notice.omi-backlog-held-redrive-budget-spent: more than 64 in an hour.omi-backlog-retry-cap-quarantine-rate: enforcement is off by default.Their families,
omi_backlog_state_transitions_totalandomi_capture_retry_cap_total, are imported by the prod and dev Cloud Run main and sync metrics exporters; a contract test checks that wiring. Rollback for any switch: set it tofalse; it is read per decision.Ramp plans for the OFF classes (process env, so cohorts are deployments). Order: dev, then backend-integration, then one prod service, then all prod. Owner: backlog-refactor thread. Dates: to be set by lead2.
omi_capture_retry_cap_total{outcome="quarantine"}tracks the priorwould_quarantinerate, with no runnable unit quarantinedcommittedmore often than they re-quarantine, with no rise in worker failuresRollback semantics
Switching class 3 OFF stops new budget resets. Existing grants persist until their unit runs or finishes. Each grant is capped at
MAX_ATTEMPTS.test_class_3_on_to_off_keeps_existing_grants_and_stops_new_resetspins this.Known open items (not fixed here)
projection_release_attempts >= 3bypasses expiry. Seebackend/database/batch_pipeline_projection_release.py, theif attempts >= MAX_RELEASE_ATTEMPTS: return Falseafter a restorable target. Sol wave 6 cited it asbatch_pipeline_projection_release.py:361onlane/backlog-state-machine(line 290 on main). Main now carries a fix behind the dark switchBATCH_PIPELINE_PROJECTION_RESTORABLE_CAP_EXPIRY_ENABLED(default off,de0d4d34f627); until it is turned on, the gap stands. This PR does not touch that file.tests/unit/test_batch_pipeline_startup.py::test_load_pyannote_pair_missing_depsfailed onorigin/mainearlier (the test expected "requires the GPU image" while the code raised "requires the model runtime"). It passes at this PR's base2ca7a20228b, so main has since fixed it. This PR does not touch it.🤖 Generated with Claude Code
Pre-push hook ran on m1-mac-studio (m5 load 100+; lead2 04da5e/21c414 pattern).