Repository navigation
test(batch): two-worker gauntlet asserts once-committed, not once-computed - #22866
Conversation
…puted batch-two-workers failed ~6-14% of main runs with "a segment was computed or completed more than once across replicas" since 2026-10-19 14:40Z (after #22373, before #22805 and #22820). Both counters it checked (words_started, worker_item_result) are compute-side. Batch compute is at-least-once by design: a lease whose renewal stalls (the emulator takes a collection-wide lock per transactional query; HEARTBEAT_TIMEOUT_SECONDS is 8s) is left to expire, recovered and leased again, while the stale holder's complete() is fenced by owns_lease(token). Publication stays exactly once. The scenario now asserts the real cross-replica invariants: - every compute ran under its own lease (computes <= job attempt); - each segment is committed with exactly one result-log entry; - the burst log chain is intact and in capture order; a late_capture entry is accepted only for a recomputed head that outlasted the #22820 head wait. The verified event records recomputed_after_lease_loss so the rate stays visible. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af745b5201
ℹ️ 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".
| if stack.doc('results', segment).get('segment_id') != segment: | ||
| raise StackFailure('a two-replica segment has no committed result log entry') |
There was a problem hiding this comment.
Count commits instead of checking deterministic document existence
When a fencing regression lets the same segment commit twice, both commits target the same results/{segment} document, so this final-state lookup still returns one matching document. The new uniqueness check only compares the three burst documents and does not inspect either solo owner's sequence, meaning a duplicate solo commit that overwrites its result and advances the owner log twice would pass this purported exactly-once assertion. Check the owner's final sequence/chain cardinality or durable per-commit evidence so a second write is observable.
Useful? React with 👍 / 👎.
| if not set(late) <= recomputed: | ||
| raise StackFailure('two-replica burst marked an in-order capture late') |
There was a problem hiding this comment.
Allow late captures after a lease-only retry
If the emulator stalls a worker after it leases an earlier segment but before compute begins, that lease can expire, a later ready segment can exceed the 60-second head wait, and the earlier segment can then be computed once under its second lease and correctly append as late_capture. In that valid case job.attempt == 2 but computes == 1, so the segment is absent from recomputed and this assertion keeps the gauntlet flaky. The late-capture allowance should use evidence of re-leasing rather than requiring multiple provider computations.
Useful? React with 👍 / 👎.
| leases = int(job.get('attempt') or 0) | ||
| computes = stack.words_calls(segment) | ||
| computed = sum(e['segment_id'] == segment for e in results) | ||
| if computes < 1 or computed < 1 or computes > leases or computed > leases: |
There was a problem hiding this comment.
Correlate each computation with its lease token
When a regression starts two computations under one lease while another issued lease expires or is deferred before compute, the aggregate computation count can still be less than or equal to job.attempt, so this check passes despite violating the stated one-lease-per-compute invariant. Neither provider event records a lease token or attempt number, and comparing two totals cannot establish the required correspondence; include lease identity in the evidence and reject multiple compute starts for the same lease.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27259d2979
ℹ️ 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".
| if not set(late) <= recomputed: | ||
| raise StackFailure('two-replica burst marked an in-order capture late') | ||
| if [s for s in committed if s not in late] != [s for s in expected if s not in late]: |
There was a problem hiding this comment.
Verify late flags against the committed watermark
When a recomputed segment commits in normal capture order but the merge incorrectly labels it late_capture, this check passes because the segment is in recomputed and removing it produces identical committed/expected subsequences. Since this burst uses a fresh owner, the gauntlet should walk the committed chain and verify each late flag against the preceding capture high-watermark; otherwise incorrect late-capture metadata and watermark handling go undetected.
Useful? React with 👍 / 👎.
… counts (#22920) ## Summary `batch-two-workers` in the Sync Cloud Tasks Stack Gauntlet still fails now and then with "a segment was computed more often than it was leased across replicas", even after #22866. PR #22902 hit it twice at `3508c7ca`, and that diff can't reach batch compute. The check compared compute evidence with the job's `attempt` field. That field is a retry budget, not a count of lease grants: a refund before compute lowers it. The check also printed no counts, so the CI failures couldn't be diagnosed. Changes (test harness only): - **Lease evidence.** `testing/sync_cloud_tasks_stack/batch_worker.py` wraps `Scheduler.pull` and `Scheduler.defer` in the stack worker. They emit `lease_granted` and `lease_refunded` evidence with the segment id, attempt and worker name. No production code changes. - **New bound.** `batch.py` checks `computes <= grants` and `results <= grants` for each segment. - **Counts on failure.** The failure message now includes grants, refunds, attempt, computes, results, state and failure. - **Drift is visible, not fatal.** A mismatch between `attempt` and `grants - refunds` prints and is counted as `attempt_drift` in `batch_two_workers_verified`. - **Unchanged assertions.** These still apply: one paid recovery call, one committed result log entry per segment, an intact predecessor chain, and capture order. ## Why this doesn't hide a paid-twice bug - **The counter isn't paid STT.** It counts Parakeet `transcribe_batch` calls, which run on our own GPUs in prod. Paid STT is quarantine recovery only, and `paid_calls == 1` is still asserted. - **Only one path lowers `attempt`.** `pull` is the only lease grant. `defer` is the only call that lowers `attempt`, and in this lane it runs only before compute. The `HeldWork` path is fenced off because `_BATCH_LANE_READY = False`. The `FatalGpuError` path is CUDA-only. - **Publication stays fenced.** It is checked by `owns_lease` plus `compute_admission_token`. - **Local stress agrees.** About 25 local two-worker runs, including some with a 3s/1s lease/heartbeat, never had computes exceed `attempt`. Investigation notes: `data/run-2026-10-13-two-lane-nemotron/gauntlet-double-compute-2026-10-20.md` in the omi-workspace repo. ## Test plan - [x] `backend/testing/sync_cloud_tasks_stack/run.sh --only batch` passed locally (`attempt_drift=0`, `paid_calls=1`, 5 segments, 2 replicas). - [ ] CI: Sync Cloud Tasks Stack Gauntlet. 🤖 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/22920?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/22920?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F22920&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. -->
… counts
batch-two-workers still failed occasionally ("a segment was computed more
often than it was leased") after BasedHardware#22866, e.g. PR BasedHardware#22902 at 3508c7c, whose
diff cannot reach batch compute. The check compared compute evidence with
the job's attempt field, which is a retry budget (a pre-compute refund
lowers it) rather than a grant count, and printed no counts, so CI failures
were undiagnosable.
The stack worker now records lease_granted / lease_refunded evidence by
wrapping Scheduler.pull/defer (test harness only). The scenario asserts
computes <= grants and results <= grants per segment, includes grants,
refunds, attempt, computes, results, state and failure in the failure
message, and reports attempt drift (attempt != grants - refunds) as a
visible, non-fatal attempt_drift count. The paid-once and committed-once
assertions are unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The
batch-two-workersscenario in the Sync Cloud Tasks Stack Gauntlet fails intermittently with "a segment was computed or completed more than once across replicas", and that blocks the Backend Hermetic Merge Gate. This is a test-timing problem, not a production double completion.When it started. On main, the scenario passed in all 41 runs before #22373 (10-19 12:24Z). From 10-19 14:40Z it failed with this message in:
Counting all branches, 15 gauntlet jobs failed this way, and 5 of those failures came before Fix B. So neither Fix B nor Fix C caused it, although Fix C's head-wait probes may add load to the emulator.
Why it fails. Both counters the assertion checked,
words_startedandworker_item_result, are recorded when a segment is computed, not when it is completed. Batch compute is at-least-once by design:HEARTBEAT_TIMEOUT_SECONDS=8; the emulator takes a collection-wide lock for every transactional query) marks the lease lost.recover()re-queues the segment and the other replica leases it again.Publication still happens exactly once.
complete(),fail(),defer()andrelease()are all fenced byowns_lease(job, token, now)inside the transaction. Result artifacts use create-only random names (if_generation_match=0), so a stale holder cannot overwrite the result that was committed.Change (test only)
_two_workersnow asserts the real cross-replica invariants:job.attempt. A recompute is only allowed after a lease transition. Two replicas computing under one lease still fails.committed, the segment has one result-log entry, and the burst'slog_sequencevalues are unique.late_capture, the burst must be in strict capture order. If some are, every late entry must be a recomputed head (one that outlasted the feat(batch-pipeline): bounded merge head wait for out-of-order catch-up (Fix C) #22820 bounded head wait), and the remaining entries must still be in capture order.The verified event now records
recomputed_after_lease_loss, so the rate of recomputes stays visible.Verification
backend/testing/sync_cloud_tasks_stack/run.sh --only batch(local Firestore emulator,nice -n 19): all 10 batch scenarios pass;batch-two-workerspassed in 64.0s.BACKEND_UNIT_TEST_FILE_LIST=<tests/unit/test_sync_cloud_tasks_stack_ci_wiring.py> bash test.sh: 3 passed.Follow-up (not in this PR)
Pump._publishrefuses to publish when the pre-publication heartbeat is ambiguous, even thoughcomplete()re-checks lease ownership inside its own transaction. When Firestore is slow, that wastes GPU time: a finished result is thrown away and computed again. It is worth measuring withomi_batch_pipeline_events_total{event="lease_expired"}before changing it.🤖 Generated with Claude Code