Skip to content

fix(backlog): explicit retry state for batch backlogs (core: class 1 retry cap, class 3 held re-drive budget, class 6 counter) - #24936

Closed
Git-on-my-level wants to merge 25 commits into
mainfrom
lane/backlog-state-machine-core
Closed

Git-on-my-level wants to merge 25 commits into
mainfrom
lane/backlog-state-machine-core

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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:

  • the retry cap only observed outside the CAPTURE_COVERAGE_MODE serve cohort;
  • a held/dead-letter re-drive kept attempt at the cap, so the first failure re-quarantined it;
  • nobody counted held re-drive loops.

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-followup and 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.py and database/sync_backfill_sequencer.py are byte-identical to main. Class 2 moved to lane/backlog-state-machine-followup with 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.py and config/feature-flags.yaml. They are parsed literally (true is 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.

Class User-facing symptom Kill switch Default Risk
1. Retry cap only observed A unit that crashes its worker retries forever, and its recording never gets a transcript CAPTURE_RETRY_CAP_ENFORCED OFF When on, quarantines batch units at the lease-expiry cap: a custody change. The sync path is unchanged. Alert omi-backlog-retry-cap-quarantine-rate
3. Requeue kept attempt at the cap A re-driven held recording fails once and goes straight back to held BATCH_HELD_REDRIVE_BUDGET_ENABLED OFF When on, a fresh budget moves held rows back into processing: a custody change. It takes effect only with the class 6 counter on, within the 3-re-drive budget, and where the retry cap enforces for the owner (class 1 on or served cohort); elsewhere it is a no-op, so it can never sustain an unalerted loop
6. Held re-drive loops not counted Held recordings loop with no visible count BATCH_HELD_REDRIVE_COUNTER_ENABLED ON Low: counting and an alert only, no state change. Alert omi-backlog-held-redrive-budget-spent

Main's BATCH_HELD_DEAD_LETTER_ENABLED path (on) and ghost settle (False) are unchanged. This PR does not touch utils/batch_pipeline/live.py or database/batch_pipeline_projection_release.py.

  • Class 1. With the switch on, a batch lease expiry at BATCH_PIPELINE_MAX_ATTEMPTS quarantines (retained held, worker_failed) for every uid. Only the batch lease-expiry cap opts in to enforcement; every other retry_cap caller, including main's sync dispatch cap, keeps the CAPTURE_COVERAGE_MODE cohort decision, so the sync path is exactly main's.
  • Classes 3 and 6 counter. One helper handles every held re-drive (nightly, operator, status poll of held_expired). The counter increments held_redrives, and class 3 resets attempt. The nightly scan and committed poll re-drives emit held_redrive_budget_spent at or over 3. There is no terminal stop in this PR.

Tests

backend/tests/unit/test_backlog_state_machine.py runs each switch true, unset and false:

  • the defaults table, with serve mode unable to change any default;
  • class 1: lease-expiry quarantine and cohort-free serving;
  • class 6 counter: requeue counting, the nightly signal, and repeated poll signals;
  • class 3: requeue fields, the fresh-budget lease expiry, and counter × budget through the status poll.
  • class 3 on to off: an existing grant is kept, runs to the MAX_ATTEMPTS cap, and a later re-drive gets no new reset.

Legacy cohort tests in test_capture_retry_hygiene.py and test_batch_pipeline_scheduler.py pin class 1 off.

Local verification, at the unit layer, on head 17ffdf251b6a, against main cd6f864c3329. Each file ran in its own pytest process through bin/omi-heavy. The 13 files were:

  • the state-machine file;
  • batch held dead letter, scheduler and retry hygiene;
  • uid sequencer, which shows the sync path is main's;
  • the config, batch unit policy and flag-budget tests;
  • the five monitoring contract files.

They passed with the switches unset, and with each of classes 1, 3 and the class 6 counter forced true and then false on its own: 841 passed and 0 failed in each of the 7 settings. make preflight with BACKEND_UNIT_FILE_BUDGET_SECONDS=900 passed all 44 checks.

New since the first review:

  • Class 2 and the sync budget-deferral chain moved to the follow-up (see above).
  • Class 3's fresh budget takes effect only with the counter on, while the unit's re-drive budget is unspent, and where the retry cap enforces for the owner; the backlog switches enable only on the exact value true.
  • /redrive-dead and /requeue-quarantined now get the class 3 and class 6 accounting and the spent-budget signal.
  • New alert omi-backlog-held-redrive-unit-looping; its tests evaluate the rule definition over a simulated nightly loop of one recording.
  • Import and read-back: omi-backlog-held-redrive-unit-looping is added to backend/charts/monitoring/live-alert-gate.json, so the monitoring workflow imports it on --mode import and fleet verification checks it is live, unpaused and equal to the committed rule. alert-rules.json is regenerated with provision_monitoring_alerts.py --regenerate. test_single_unit_looping_alert_routes_unmuted_and_is_on_the_reviewed_import_list pins the route.
  • Exporter allowlists now import the backlog metric families, with a wiring contract test.

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, receiver Omi - Services Alerting (Telegram) with no mute interval (not omi-tier-silent), routed like omi-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_total and omi_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 to false; 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.

Class Clean metric before each step
1 omi_capture_retry_cap_total{outcome="quarantine"} tracks the prior would_quarantine rate, with no runnable unit quarantined
3 Re-driven held units reach committed more often than they re-quarantine, with no rise in worker failures

Rollback 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_resets pins this.

Known open items (not fixed here)

  • Projection re-arm gap (pre-existing on main): a restorable assignment hold with projection_release_attempts >= 3 bypasses expiry. See backend/database/batch_pipeline_projection_release.py, the if attempts >= MAX_RELEASE_ATTEMPTS: return False after a restorable target. Sol wave 6 cited it as batch_pipeline_projection_release.py:361 on lane/backlog-state-machine (line 290 on main). Main now carries a fix behind the dark switch BATCH_PIPELINE_PROJECTION_RESTORABLE_CAP_EXPIRY_ENABLED (default off, de0d4d34f627); until it is turned on, the gap stands. This PR does not touch that file.
  • Known test failure on origin/main: tests/unit/test_batch_pipeline_startup.py::test_load_pyannote_pair_missing_deps failed on origin/main earlier (the test expected "requires the GPU image" while the code raised "requires the model runtime"). It passes at this PR's base 2ca7a20228b, 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).

Git-on-my-level and others added 10 commits November 8, 2026 19:56
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]>
@Git-on-my-level Git-on-my-level self-assigned this Nov 8, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 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-09T20:27:32.262206Z 71c6774 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.

4 issues found across 21 files

Confidence score: 3/5

  • alert-rules.json uses 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.py increments 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.py logs an INFO line on every per-unit check, which can flood logs during a large nightly scan. Pass log=False.
  • intake.py uses a function-local import that violates backend policy. Move record_transition to 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

Comment thread backend/utils/capture/retry_cap.py Resolved
Comment thread backend/config/backlog_state_machine.py Resolved
Comment thread backend/utils/batch_pipeline/intake.py Resolved

@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: 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".

Comment thread backend/utils/sync/retry_hygiene.py Resolved
Comment thread backend/config/backlog_state_machine.py Resolved
Git-on-my-level and others added 10 commits November 9, 2026 02:17
… 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]>
@Git-on-my-level Git-on-my-level changed the title fix(backlog): explicit retry state for batch and sync backlogs (core: classes 1, 2, 3, 6 counter) fix(backlog): explicit retry state for batch backlogs (core: class 1 retry cap, class 3 held re-drive budget, class 6 counter) Nov 9, 2026
Git-on-my-level and others added 5 commits November 9, 2026 20:34
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
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Completion checkpoint — 2026-11-09 20:02 UTC (quiet-host validation/push needed)

  • Local branch cl2/24936-core is clean at 71c6774e72097684314e4001db61dae16bb0f351. These completion commits have not been pushed. The published PR head remains 9f7d51691fe9f07d230afc64a985883fadfa58e6.
  • Merged fetched main 45436a0cc6ba5cbc4455f45218e9f9b0375b04da with a merge commit (31d3c378b85). Only conflict: backend/docs/feature-flag-registry.md; regenerated from the combined registry, preserving both core re-drive and main orphan-repair flags. No rebase or force-push. All new commits declare Failure-Class: FC-state-deadline-without-reader-exit.
  • Review fixes (2ae26c0029b): shared post-commit nightly/operator spent-budget emission, no per-unit counter-flag logs, module-scope imports, missing sync-sidecar ingestion, and the required pipeline change note. The alert regression now uses the actual strict recovery transaction. Class 2 files remain identical to merged main.
  • Affected unit run: 14 of 16 files passed, including all 22 new metric regressions, scheduler (62), held dead letter (42), recovery (163), intake (45), and telemetry ingestion (56). The state-machine file had 82 passes and one stale assertion expecting the retired scan-owned emission; corrected in 71c6774e720 to assert one post-commit emission and no replay emission. Its clean rerun is still required. test_batch_unit_policy.py timed out at the unchanged 900-second budget. The queued two-file rerun never acquired a slot and was stopped when preserving the local checkpoint.
  • make preflight stopped on the known test_firestore_query_shapes.py 900-second wall (firestore-index-guard, 919 seconds overall). The exact error was: tests/unit/test_firestore_query_shapes.py exceeded 900s (TERM, then KILL) and was terminated. Host load was 87.84 at 20:00:24 UTC and 114.72 at 20:02:30 UTC. Async-blocker, runtime source/third-party closure, dead-code, route-policy, and batch-policy gates passed; the full preflight did not pass.
  • This blocker occurred in preflight before any push attempt, not inside pre-push. No hooks were skipped or budgets raised. No CI run exists for the local head, and the PR was not merged. No GCP tier was used.
  • Every initial unresolved review thread has an evidence reply. The obsolete sync-comment thread was resolved against the already-published scope split. Seven fix threads remain open because their completion commits are still local.

Next on a quiet host: rerun tests/unit/test_backlog_state_machine.py and tests/unit/test_batch_unit_policy.py through backend/test.sh at nice 10, rerun make preflight, refresh the remote branch, then use the authorized normal push with BACKEND_UNIT_FILE_BUDGET_SECONDS=900 and OMI_PR_BODY_FILE=/Volumes/Ephemeral/scratch/pr24936/body.md. Resolve the seven fixed threads only after publication and wait for exact-head CI. Do not merge.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Published completion checkpoint — m1-mac-studio, 2026-11-09

Pushed 71c6774e72097684314e4001db61dae16bb0f351 by normal fast-forward from 9f7d51691fe9f07d230afc64a985883fadfa58e6, with the full pre-push hook. No skips, force push, budget increase, merge, deployment or GCP calls. The bundle required no further code changes.

Local unit verification at that head: 2,051 passed across 33 files, through backend/test.sh under omi-heavy and nice -n 10, with BACKEND_UNIT_FILE_BUDGET_SECONDS=900. This expands the checkpoint's targeted set with monitoring contracts and the prior CI failure's sync-sidecar file. Files run in separate pytest processes. Policy completed in 31 seconds; Firestore query shapes completed in 52 seconds. State-machine: 83 passed; metric regressions: 22 passed; sync-sidecar: 117 passed. make preflight passed all 44 checks, and the full pre-push gate passed again.

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
tests/unit/test_attach_cloud_run_gmp_sidecar.py
tests/unit/test_backlog_redrive_metrics.py
tests/unit/test_backlog_state_machine.py
tests/unit/test_batch_held_dead_letter.py
tests/unit/test_batch_pipeline_intake.py
tests/unit/test_batch_pipeline_quarantine_recovery.py
tests/unit/test_batch_pipeline_scheduler.py
tests/unit/test_batch_unit_policy.py
tests/unit/test_capture_retry_hygiene.py
tests/unit/test_config_refactor_w6.py
tests/unit/test_config_train.py
tests/unit/test_firestore_query_shapes.py
tests/unit/test_flag_budget.py
tests/unit/test_monitoring_adapter_hpa_contract.py
tests/unit/test_monitoring_alert_backtest.py
tests/unit/test_monitoring_alert_rule_contract.py
tests/unit/test_monitoring_cloud_monitoring_promql_shape.py
tests/unit/test_monitoring_cost_contract.py
tests/unit/test_monitoring_dashboard_absence_contract.py
tests/unit/test_monitoring_dashboard_query_budget.py
tests/unit/test_monitoring_datasource_health.py
tests/unit/test_monitoring_gmp_frontend.py
tests/unit/test_monitoring_gmp_shadow.py
tests/unit/test_monitoring_journey_slo_contract.py
tests/unit/test_monitoring_log_plane_migration.py
tests/unit/test_monitoring_notification_contract.py
tests/unit/test_monitoring_prometheus_ha.py
tests/unit/test_monitoring_stt_metric_zero_init.py
tests/unit/test_monitoring_stt_stream_close_zero_init.py
tests/unit/test_monitoring_telemetry_contract.py
tests/unit/test_monitoring_values_chart_keys.py
tests/unit/test_provision_monitoring_alerts.py
tests/unit/test_sync_backfill_uid_sequencer.py

@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: 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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@Git-on-my-level

Git-on-my-level commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

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.

Git-on-my-level added a commit that referenced this pull request Nov 10, 2026
…+ 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.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Closing as superseded by #25012 (merge 85de198, 2026-11-10 20:15Z): fix(backlog) explicit retry state for batch backlogs, reviewed core + corrected rollback docs, which carries this change forward with the full pre-review trail. Lead2 ruling 23f47d. Branch left intact.

@github-actions

Copy link
Copy Markdown
Contributor

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:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

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!

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