Skip to content

fix(batch): stop replicated coalescing scan contention (SCA-1800) - #25330

Merged
Git-on-my-level merged 2 commits into
mainfrom
agent/m1-studio-codex-sol/77224b64ecfd
Nov 15, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
agent/m1-studio-codex-sol/77224b64ecfd

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

SCA-1800: 35 serving replicas were scanning the same coalescing quota document every two seconds, exhausting Firestore contention retries even with no eligible uploads. Elect one strict namespace scan owner; followers stop before quota/group discovery. Cursor, heartbeat and new group claims validate the immutable acquisition token transactionally. Lease failure skips discovery, including when the advisory maintenance bypass is false. Existing durable group leases continue already-claimed audio through takeover.

The approved design uses a 6s discovery lease with half-TTL renewal, the existing 2s loop and randomized startup phase. New leadership state exits through expiry/replacement; it owns no audio. Hold <=60s, group lease 120s, page bound 8 and the 600s stale guard are unchanged. Compatible OFF drainers still convert holds individually; committed merged intakes retain their target. No eligibility or runtime flag change.

The group_retry metric outcome has a recovery path on the next scan after the existing group lease expires; successful fenced group completion exits through done. It creates no new persisted state and cannot refresh admission health.

Validation: real loopback Firestore rehearsal covers 35 contenders, fixed-operation accounting, stale-token rejection, leader takeover, slow claimed IO, original sample/provenance conservation, privacy/erasure, cursor fairness/restart, user-open and OFF with a nonempty queue. Focused unit/worker/serving tests, Firestore query guards, runtime-image source closure and repository preflight are recorded in the SCA-1800 evidence packet. The local selector expands to the entire backend suite; local testing stays bounded and CI owns the full selection.

Release owner must retire every old unleased scanner, including zero-traffic background revisions, before the stable 15-minute readback. Require zero quota/lease contention exhaustion, >=400 healthy empty passes and <=5s maximum heartbeat gap at 35 replicas, with actual retry/operation counts and exact image/flag binding. Modeled fixed reads/day 4,536,000 -> 1,728,000 and writes/day 1,512,000 -> <=86,400 remain estimates. Production runtime flags and staging/runtime image binding remain UNKNOWN in this local packet. Empty-cohort health cannot qualify notes quality, freshness, nonempty rollback or matched-original-audio savings. $0 booked. Multica is the only review of record; this author does not merge or deploy.

Rollback: release owner sets coalescing OFF across all producers/drainers, drains held originals individually and reconciles all source/receipt custody before removing compatible support. Never drop holds or restore the unleased scanner as a repair.

Product invariants affected

none

Failure-Class: new

View guided diff Turn on auto-fix

@Git-on-my-level
Git-on-my-level merged commit ae8332d into main Nov 15, 2026
77 of 79 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/m1-studio-codex-sol/77224b64ecfd branch November 15, 2026 13:35
Git-on-my-level added a commit that referenced this pull request Nov 19, 2026
## What changes

The batch owner-state lane gets one PR with separate implementation
commits. The first adds a post-lease packing counterfactual for all nine
G/S pairs, a validated capture-gap histogram, observed due depth and
intake cohort labels through fenced completion. It supplies measurement
for the packing decision in place of estimates based only on upload
spacing. The second adds the GMP batch read-cost recording group and CI
coverage for recurring Firestore and PostgreSQL selectors. The existing
Firestore alerts keep their current definitions and thresholds.

The probe reads one metadata-only owner prefix with at most 17 rows, one
outstanding read per process, no RPC retries, and a one-second deadline.
No authority, scheduling or sweep decisions consume its results. The
background-task ratchet records why process loss can drop only an
optional sample. The shared identity helper has no runtime configuration
imports, so the GPU worker does not become a reader of the
upload-coalescing feature flag. The recorded cost ratio uses the
existing fenced completion seconds across metric labels and marks low
volume and missing telemetry explicitly. The selector guard runs the
existing builders in the query inventory and requires actionable
deadlines or owner-reviewed, bounded, expiring exceptions. A shared
selector primitive would change the compatibility queries it is meant to
audit. The check catches the state-only legacy projection discovery and
provider sweep documented by the owner-state R1/R5 inventory. This
follows the same replicated-read failure class as the coalescing scan
containment in #25330.

## Kill switches and mixed versions

`BATCH_PIPELINE_PACKING_SAMPLE_RATE` defaults to `0.001` and caps at
`0.01`. Set `0` across the intake and lease roles, including
`worker.packingSampleRate: '0'` for Helm, to stop observation reads,
intake stamps and cohort completion counters. Restore `0.001` to resume.
The metrics scope records `job:batch_packing_counterfactual` separately.
Release can withdraw the independent GMP `GlobalRules` resource.
Reverting the cost commit withdraws the CI guard without requiring any
persistent data migration.

Old images such as `ef42ee8` ignore the optional job metadata and keep
the existing worker payload and completion counter. New readers treat
missing clocks and ambiguous Stripe paid-versus-trial evidence as
unknown. Completion disposes of the stamp on its existing fenced write.
Old workers may retain it until the ordinary job retention or erasure
path. Samples describe the visible queue shortly after commit, with
explicit capped and unavailable coverage.

## Verification and expected cost

- On the original head `6c06588ec5`, the normal pre-push hook passed 54
repository preflight checks, full backend Pyright with zero errors, and
all 40 selected backend unit test files.
- The initial `BACKEND_UNIT_TEST_FILE_LIST=<focused list> bash
backend/test.sh` run passed 715 checks across packing, scheduler,
capture decode, intake, coalescing, chart, runtime env, flag budget,
census, simulator and cost alerts. Final focused reruns passed 20
packing tests, six background-task checks and two lifecycle guard cases
for the observation module. Later simulator reruns hit the local
300-second file wall. An earlier rerun printed all 12 simulator
assertions as passing before that wall ended the process.
- `pytest -q backend/tests/unit/test_batch_census_registry.py
backend/tests/unit/test_firestore_query_shapes.py -k 'selector or
no_errors or zero_serving_debt'` passed 571 focused checks.
- `backend/.venv/bin/python
backend/tests/promql/firestore_cost_budget.py --promtool <pinned
promtool 2.55.1>` passed the existing thresholds and the new missing,
low-volume, true-zero, raw counter reset and caller-group fixtures.
- The loopback Firestore, PostgreSQL and simulator pull conformance plus
upload coalescing emulator suites passed 109 tests. The separate legacy
intake rollback fixture returns a fallback before admission on this head
and on base `9c88e7f888b0`.
- `backend/.venv/bin/python backend/scripts/cross_service_contract.py`
reported zero new and zero stale violations. The background-task ratchet
passed all six tests.
- Direct savings inferred from this PR are zero. The probe adds one
bounded read per accepted sample. A PostgreSQL probe statement timeout
closes its warm pooled connection. A later store call can incur the cost
of opening and configuring a replacement. That cost is unmeasured. A
serving readout must measure its actual billed overhead and whether
compatible jobs can be combined. The recording group is a source
artifact awaiting Release-owned install and GMP comparison.

Line-Count-Exception: backend/database/firestore_index_registry.py |
2399 -> 2402 | Keep the two metadata-only field exemptions in the
existing index authority so high-volume telemetry adds no single-field
indexes.

## Product invariants affected

- INV-MEM-4. Probe metadata and metrics add no path for user content
disclosure or custody settlement.

## Scope panel

`scope-20261118t145605-e19d` returned Luna and GLM Flash. DeepSeek ended
without a terminal answer on that run. The retry
`scope-20261118t150457-45c4` returned DeepSeek and GLM Flash. The
panel's scoping dossier returns prose without F identifiers, so
`omi-panel triage` did not accept a numbered entry.

- Accepted both reviewers' bounded, post-commit, fail-open read,
source-only metrics, fixed labels, explicit missing or low telemetry,
settled metric window, per-process coverage limits and expiring reviewed
exceptions.
- Accepted separate probe attribution and cost breakout. The probe is
outside the cost total. The old alert query retains its exact caller
regex.
- Used the original coalescing compatibility key and intake clock
evidence. Rejected inferring missing session or funding proof from
`WorkItem`, guessing paid or trial on ambiguous legacy rows, and
projecting full job documents through `pending_page`.
- Used the existing intake and completion writes for the telemetry stamp
and no worker wire changes. An in-transaction query would add
contention. An in-memory handoff would lose attribution across service
boundaries.
- Used a GMP `GlobalRules` recording resource for the fleet-wide window.
The in-cluster PrometheusRule would see only its local series. This
source is outside the Grafana JSON consumer inventory and the alert
provisioning path. Release qualification remains separate from local
PromQL tests.
- Exercised executable query builders and their existing registry. A
cursor on one page cannot establish non-wrapping progress. The
default-on guard uses reviewed exception metadata and exact builder
digests.
- Kept one PR per the lane assignment. Deferred the packing algorithm
and all live, fleet-size and savings validation to the program owner.

## Round 2 review panel

`review-20261119t041052-488d` returned FIX-FIRST on `6c06588ec5`.
Recorded `F1=accept F2=accept F3=accept` with `omi-panel triage`.

- **F1 accepted.** Native read coverage now takes the fewest samples
across every observed series of each type, then applies the 58-sample
floor. A second QUERY series at 58 preserves coverage, and a second
QUERY series at 57 suppresses the ratio.
- **F2 accepted.** The cost section accounts for the warm connection
lost on a PostgreSQL statement timeout.
- **F3 accepted.** A missing or non-finite decoded duration yields
`unknown_duration`. An invalid anchor contributes zero, and an invalid
following row preserves the eligible prefix.

### Round 2 verification

- From `backend/`, `.venv/bin/python -m pytest -q
tests/unit/test_batch_packing_counterfactual.py
tests/unit/test_monitoring_cloud_monitoring_promql_shape.py` passed 29
tests.
- `backend/.venv/bin/python
backend/tests/promql/firestore_cost_budget.py --promtool <pinned
promtool 2.55.1>` passed both new multi-series fixtures and the existing
cost fixtures.
- `pytest -q tests/integration/test_partial_pull_conformance.py
tests/integration/test_pull_batch_parity.py` passed 66 simulator and
Firestore-emulator cases. A local PostgreSQL 16.2 rerun with `-k
postgres` passed the remaining 33 cases.

## Round 3 merge verification

Merge `b15cfb58a3b` incorporates `main` at `e3cfebcfb32`. Upload intake
now forwards main's allowance refusal and this PR's packing observations
to the same admission transaction. Both the observation and admission
use the timestamp taken after the allowance probe.

- `backend/test.sh` passed 342 tests across intake, admission, allowance
holds, staging, packing and future-capture parity.
- The allowance-hold integration matrix passed 75 cases across the
simulator, loopback Firestore and local PostgreSQL. Its 18 skips are
fixture-specific.
- The separate legacy Firestore rollback fixture
`test_accepted_upload_drains_after_rollback_with_encrypted_context_and_accounting`
returned `None` at the admission assertion on both the merge and its
exact main parent.

### GitHub CI on the Round 2 head

GitHub tested merge `3577371251` for the earlier head `1a2711956c5`. The
backend unit suite is red from two failures also observed on `main`
before this follow-up.

- Shard 7 failed
`test_listen_v3_rotation_custody.py::test_frames_during_a_failed_create_never_bind_to_its_successor`
because the producer missed the transient `session-2` label before the
test reached its custody assertions. The test and relevant listen code
match the CI merge's main parent `7437adc424b9`. The same assertion
failed on earlier main `2a8b05cd3e0d` and passed on `7437adc424b9`. [PR
failure](https://github.com/BasedHardware/omi/actions/runs/44465204778/job/135361476491)
· [Earlier main
failure](https://github.com/BasedHardware/omi/actions/runs/44445981915/job/135298343674)
· [Exact main parent
pass](https://github.com/BasedHardware/omi/actions/runs/44458558798/job/135339706957)
- Shard 2 failed the CPU duration guard for
`test_monitoring_adapter_hpa_contract.py::test_hpa_and_adapter_changes_select_this_contract`
at 1.03 seconds against the 1.00-second limit. All 39 assertions in the
file passed. The same test exceeded the guard at 1.06 seconds on earlier
main `ae68d3176d80`. The selector additions in this PR match census and
Firestore guard paths outside this test's HPA and adapter inputs. [PR
failure](https://github.com/BasedHardware/omi/actions/runs/44465204778/job/135361476516)
· [Earlier main
failure](https://github.com/BasedHardware/omi/actions/runs/44416485689/job/135198319558)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/25716?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/25716?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25716&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. -->

Failure-Class: FC-sync-assignment-read-abort-escapes-retry

Implemented by a delegated agent for the batch owner-state program.


### Current head
The final head is `23d7a907b5f936b59db4f9674b4ca0bedee85d36`. Its
exact-head closure is comment 7016584048, which records the merge with
main after #25724 and the outbox commit-contention fix. lead2 gave the
batch-custody delta source ACK at this head (bus 0bd65c). CI is green.
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