Repository navigation
feat(batch-pipeline): bounded merge head wait for out-of-order catch-up (Fix C) - #22820
Conversation
…up (Fix C) Catch-up uploads arrive newest-first, so the capture-ordered merge held every newer result behind the owner's oldest unready head. Once any ready result has waited BATCH_PIPELINE_MERGE_HEAD_WAIT_SECONDS (default 60; off/<=0 restores strict order) behind an unready head, the merge releases the owner's ready rows in capture order; the head later appends as late_capture. The commit body, log chain, watermark, owner revision fence and projection order are unchanged. complete() and every recovery re-entry stamp ready_at; rows without it never start a bypass. Two owner-scoped job indexes back the queries; a missing index logs head_wait_unavailable and keeps strict order. Bypass commits carry head_wait_bypass and log closed labels only. David ruled 2026-10-20. 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: ed0de61d1a
ℹ️ 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".
| raw = os.getenv('BATCH_PIPELINE_MERGE_HEAD_WAIT_SECONDS', '').strip().lower() | ||
| if not raw: | ||
| return MERGE_HEAD_WAIT_DEFAULT |
There was a problem hiding this comment.
Wire the merge-wait kill switch into deployment manifests
When this default-on ordering change needs to be disabled, the documented off value cannot be deployed consistently: the commit adds no BATCH_PIPELINE_MERGE_HEAD_WAIT_SECONDS entry to backend/deploy/runtime_env.yaml, either backend-listen values file, or the batch-pipeline-worker chart values/template, so all inspected serving and GPU-worker deployments silently use 60 seconds with no managed rollback control. Add the setting to the Cloud Run/GKE runtime contract and expose it through the worker chart before shipping this as an ops kill switch.
AGENTS.md reference: backend/AGENTS.md:L153-L153
Useful? React with 👍 / 👎.
… refuse fenced successors The strict commit transaction no longer issues head-wait queries. A blocked owner is probed non-transactionally for its longest waiter; only an expired wait opens a second transaction that re-reads the waiter, selects the earliest-captured ready row and runs the unchanged commit body. The emulator takes a collection-wide lock per transactional query, so the in-transaction probe stalled heartbeats and lost leases in the two-worker gauntlet. An owner-wide privacy fence that refuses the released successor now returns None like strict order instead of raising out of maintenance (Grok review). The missing-index fallback records the shared firestore_read fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A transient read error from the non-transactional head-wait probe now returns None, the strict-order result, instead of escaping commit_next and cutting a serving maintenance tick short (Grok r2 nit). The fallback helper is imported at module level so the missing-index handler cannot raise. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts were Fix C's own lines (identical on both sides) plus main's flag registry and deployment classification, which take main's version with this branch's three flag rows re-added; the rendered registry and index manifest are regenerated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… beside catch-up (#22842) * feat(batch-pipeline): bounded merge head wait for out-of-order catch-up (Fix C) Catch-up uploads arrive newest-first, so the capture-ordered merge held every newer result behind the owner's oldest unready head. Once any ready result has waited BATCH_PIPELINE_MERGE_HEAD_WAIT_SECONDS (default 60; off/<=0 restores strict order) behind an unready head, the merge releases the owner's ready rows in capture order; the head later appends as late_capture. The commit body, log chain, watermark, owner revision fence and projection order are unchanged. complete() and every recovery re-entry stamp ready_at; rows without it never start a bypass. Two owner-scoped job indexes back the queries; a missing index logs head_wait_unavailable and keeps strict order. Bypass commits carry head_wait_bypass and log closed labels only. David ruled 2026-10-20. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(batch-pipeline): probe head wait outside the commit transaction; refuse fenced successors The strict commit transaction no longer issues head-wait queries. A blocked owner is probed non-transactionally for its longest waiter; only an expired wait opens a second transaction that re-reads the waiter, selects the earliest-captured ready row and runs the unchanged commit body. The emulator takes a collection-wide lock per transactional query, so the in-transaction probe stalled heartbeats and lost leases in the two-worker gauntlet. An owner-wide privacy fence that refuses the released successor now returns None like strict order instead of raising out of maintenance (Grok review). The missing-index fallback records the shared firestore_read fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(batch-pipeline): head-wait probe read errors keep the strict result A transient read error from the non-transactional head-wait probe now returns None, the strict-order result, instead of escaping commit_next and cutting a serving maintenance tick short (Grok r2 nit). The fallback helper is imported at module level so the missing-index handler cannot raise. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(batch-pipeline): fresh uploads reach a conversation within 2 min beside catch-up David's bar (2026-10-20): fresh uploads (capture lag <= 10 min) reach "conversation exists" at p95 <= 2 min and are never held by the owner's catch-up backlog. Ramp runs 14-16 measured fresh p95 546 s: GPU queue and compute were seconds; the time went to the capture-ordered merge head (mostly leaked-lease retries, fixed by #22805), the owner-serial projection chain behind the backlog, and quarantine recovery pickup. - Fresh-first merge (BATCH_PIPELINE_MERGE_CATCH_UP_DEPTH, default 32, off restores the plain merge): admission stamps fresh_capture from capture end. Catch-up commits wait while the owner already has 32 committed rows awaiting projection; when a catch-up row heads the owner, a non-transactional probe finds the earliest pending fresh row and, if ready, a second re-verifying transaction commits it ahead of the backlog. Commit body, log chain, late marking and log-ordered projection are unchanged. Owners held this way are re-offered by owner on every pump maintenance tick and after each serving projection sweep, so one held backlog filling the 100-row result_ready page cannot hide another. New merge_fresh job index; without it the merge logs fresh_first_unavailable and keeps the plain order. - GPU priority (BATCH_PIPELINE_FRESH_GPU_PRIORITY_ENABLED, default on): fresh lane uploads older than 10 min lease at RECENT, after fresh uploads, instead of sharing the owner's FRESH FIFO. - Recovery dispatch: the candidate scan restarts after a short page (it used to skip every earlier candidate for a whole pass), and serving dispatches on its own 5 s loop on the maintenance leader (BATCH_PIPELINE_RECOVERY_DISPATCH_INTERVAL_SECONDS, off = pass only). pipeline_sim (testing/fresh_latency_scenario.py, a live owner-chain walk model): with a 300-row newest-first catch-up owner, that owner's own fresh uploads go from p95 829 s (today) to under 2 min. Stacked on #22820. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(batch-pipeline): fresh-first review fixes (fair-use lane, erased watermark, stuck fresh head) Grok review of the fresh-first merge: - GPU spend admission picked fresh-lane fair-use checks by priority 0, so fresh-lane catch-up admitted at RECENT skipped the hard restriction and daily audio ceiling and drew on the backfill budget. Admission now reads the upload's recorded sync lane (priority only when no lane is recorded); the sim admission model matches. - Privacy erase dropped log_sequence from the erased result, so an erased projection watermark turned the catch-up hold off. The erased row keeps its log position (an ordering field, like previous_segment_id). - With catch-up held and the earliest fresh row stuck (retry), a later ready fresh row lost the bounded head wait. The fresh probe now reads up to 8 pending fresh rows and, once a ready one has waited the head-wait bound, commits the earliest ready fresh row (head_wait_bypass too). - Record-lane units are classified like uploads; docs and flag notes say so. - The fresh-latency sim walker honours the 30 s owner-chain walk budget. With it, depth 32 left too little margin at production's per-row cost; the default is now 16 (fresh p95 42 s beside a 300-row catch-up owner, same catch-up drain as 32). Fix C's replay pins the hold off to keep isolating the head wait. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(batch-pipeline): fresh-first round-2 review fixes (fence fall-through, durable holds) Grok round 2: - A privacy fence on the probed fresh row returned early, so Fix C's head wait never ran for the owner's other ready rows. It now falls through. - Held owners lived only in memory; after a restart a held backlog could fill the global result_ready page and hide another owner's ready rows. A hold now sets a durable merge_holds/{owner_key} marker (no user ID; owner purge deletes it) that leader maintenance in the pump and serving re-offers and clears once a drain no longer holds. - The fresh probe reads up to 32 pending fresh rows (the query cap), not 8. - A head-wait pick among fresh rows re-verifies inside the transaction that the skipped earlier fresh row is still unready. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(batch-pipeline): fresh-first round-3 review fixes (hold state, marker paging, fenced head) Grok round 3: - The hold marker and in-memory set were cleared whenever the strict attempt found an unready head, although the owner was still over the depth cap. Held now means "at the cap with rows pending, whatever the head's state"; a marker clears only once the owner is below the cap or has nothing pending. - Marker recovery read the same first 50 markers every tick. Leader maintenance now pages with a rotating cursor (ordered by owner key). - A privacy fence on the strict commit of a catch-up head escaped before the fresh probe. The owner's ready fresh row now still commits; the fence is re-raised only when nothing else commits. - A head-wait pick among fresh rows re-verifies every skipped earlier fresh row, not just the first. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(batch-pipeline): isolate held-owner re-offer from fenced heads (round-4 review) Grok round 4: - A fenced result_ready head (BatchPrivacyBlocked re-raised by commit_next) aborted leader maintenance before the durable-marker re-offer, and a failure inside the marker page skipped the rest of that page while the cursor moved past it. The global ready-page drain, each marker owner and each in-memory held owner now run in their own try (pump and serving), logging event=batch_merge action=held_reoffer|ready_drain outcome=retry. - A fence re-raised for a non-catch-up head skipped hold bookkeeping, leaving a fenced owner first in the pump's in-memory set. Bookkeeping now runs before any re-raise. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…puted (#22866) ## Summary The `batch-two-workers` scenario 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: - 3 of 54 runs before #22805 (Fix B) - 2 of 14 runs between Fix B and #22820 (Fix C) - 1 of 7 runs after Fix C 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_started` and `worker_item_result`, are recorded when a segment is computed, not when it is completed. Batch compute is at-least-once by design: 1. A renewal that times out (`HEARTBEAT_TIMEOUT_SECONDS=8`; the emulator takes a collection-wide lock for every transactional query) marks the lease lost. 2. If the re-heartbeat at publication is also ambiguous, the pump drops its result and lets the lease expire. 3. `recover()` re-queues the segment and the other replica leases it again. Publication still happens exactly once. `complete()`, `fail()`, `defer()` and `release()` are all fenced by `owns_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_workers` now asserts the real cross-replica invariants: - **Every compute held its own lease.** For each segment, computes and worker results are at most `job.attempt`. A recompute is only allowed after a lease transition. Two replicas computing under one lease still fails. - **Each segment is committed once.** The job state is `committed`, the segment has one result-log entry, and the burst's `log_sequence` values are unique. - **The log chain is intact**, in log order. - **Capture order holds.** If no entry is marked `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 #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-workers` passed 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._publish` refuses to publish when the pre-publication heartbeat is ambiguous, even though `complete()` 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 with `omi_batch_pipeline_events_total{event="lease_expired"}` before changing it. 🤖 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/22866?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/22866?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F22866&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. -->
…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 BasedHardware#22373, before BasedHardware#22805 and BasedHardware#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 BasedHardware#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]>
…ait (#22878) ## What The post-recovery owner wake (`/recover-quarantine` → `reconcile(owner_id, recovered)`) now releases the recovered unit at once. It passes a release set to the merge drain: the recovered unit, then up to 32 of its content's other units. When strict order, fresh-first and the head wait commit nothing, the first row in that set that is still the owner's pending, ready job commits. It skips the 60 s head wait and the catch-up depth hold, and the commit transaction re-verifies it. The same wake's owner-chain walk then projects it. - **Unchanged:** the commit body, late marking, log chain, watermark and projection order. Rows outside the release set keep their own head wait. An unready or fenced row is dropped from the set. - **Telemetry:** release commits carry `recovered_release: true` and log `event=batch_merge outcome=recovered_release source= head_state=` (closed labels, no IDs). - **Kill switch:** `BATCH_PIPELINE_RECOVERED_MERGE_RELEASE_ENABLED`, default on; `false` restores the head wait and depth hold for recovered units. The registry row has a `ramp` block. ## Why (5% run 18, T0 2026-10-20 13:51Z, ro-prod aggregates) - **The wake did nothing:** 46 of 54 post-recovery owner wakes (`action=owner_chain outcome=summary`) advanced 0 rows. - **Why:** a recovered unit re-enters the merge with `ready_at` set to its settle time. Behind an unready, earlier-captured head, which in run 18 was always `head_state=leased` (80 of 80 `head_wait_bypass` lines), it waited out W=60 plus a maintenance tick. Settled → commit was 65–86 s for every held unit. Projection then waited for the next 20 s sweep. ## Honest scope This removes the recovered unit's own merge wait. It does **not** by itself bring run 18's gate p95 (322 s) under 300 s. - That tail is content-sibling completion: about 200 s from persist to ledger completion. The siblings sat behind the same leaked-lease heads. - The GPU worker image was still 4981b47, without #22805 (Fix B) or the GPU half of #22820 (`ready_at` on `complete`). So the siblings could never start their own bypass. - Deploying the current worker is the main lever (sim below). ## Sim (`python -m testing.recovered_release_scenario`, run 18 shape) The shape is three catch-up owners with 6–9-unit contents, 10% leaked first-attempt leases, 15% empty-ASR recovery, and the production wake. Values are quarantine→projection p95 in seconds (the gate metric), with recovered settle→commit p95 in brackets, for seeds 1/2/3. | world | release off | release on | |---|---|---| | run 18 (leaks, worker without `ready_at`) | 409 / 439 / 602 [65–73] | 409 / 439 / 602 [0] | | leaks, worker stamps `ready_at` | 191 / 185 / 205 [50–68] | 191 / 185 / 205 [0] | | no leaks (Fix B live) | 22 / 24 / 51 | 22 / 24 / **25** | ## Verification - `BACKEND_UNIT_TEST_FILE_LIST=<list> nice -n 19 bash backend/test.sh` over the following, all passing: - `test_batch_pipeline_recovered_release.py` (10) - `test_recovered_release_sim.py` (3) - `test_batch_pipeline_owner_chain_projection.py` - `test_batch_pipeline_merge_head_wait.py`, `test_batch_pipeline_merge_head_wait_sim.py` - `test_batch_pipeline_merge_fresh_first.py` - `test_batch_pipeline_serving.py` - `test_fresh_latency_sim.py` - `test_pipeline_sim_scenarios.py` - `scripts/check_feature_flag_registry.py`: OK. - Layer: unit tests and the hermetic sim only. The live path has not been exercised. ## Rollout On by default, with a kill switch. Ramp: 5% run 19 → 25% → 50% → 100% by 2026-10-24, expanded by the two-lane lead session. Clean metric: hash-cohort quarantine→projection p95 ≤ 300 s, `recovered_release` lines present, no new chain or privacy errors. Failure-Class: FC-batch-fault-domain-head-of-line-poison 🤖 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/22878?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/22878?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F22878&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. -->
Summary
Fix C from the two-lane ramp-5 work. Catch-up uploads reach the batch merge newest-first: the app's
nextSyncUploadBatchsorts pending WALs bytimerStartdescending, and admission is synchronous with upload. The capture-ordered merge then holds every newer result behind the owner's oldest, still-unready head. In runs 14 and 16 that merge wait (c1) was the dominant segment: p95 281 s and 341 s.David ruled 2026-10-20: yes. Catch-up uploads may publish newer parts first and fold older parts in late, with at most a 60 s wait.
late_capture, the same path recovered quarantines already take.batch-two-workersgauntlet: the emulator takes a collection-wide lock per transactional query, which stalled heartbeats and lost leases. In production it would also add query locks to every blocked drain.commit_nextthen returnsNone, exactly as strict order would, instead of raising out of serving maintenance. Grok found this in review.previous_segment_id,log_sequence), watermark and late marking, owner revision fence, owner-serial projection in log order, and sibling, billing and privacy fences are all untouched.ready_at.Scheduler.completeand all four recovery re-entry writers (quarantine settle ×2, speech redrive, terminal-empty) stamp it. A row withoutready_at(written by a pre-change worker) never starts a bypass, so a mixed-version rollout stays strict.BATCH_PIPELINE_MERGE_HEAD_WAIT_SECONDSdefaults to60;offor<= 0restores strict order. It is registered asops_kill/ terminalkeepinconfig/feature-flags.yamland classified as config. With W=0 the merge issues no new queries and writes a byte-identical result log (tested).batch_pipeline_{prod,dev}_jobs:merge_ready(owner_key, merge_pending, state, capture_at, segment_id) andmerge_ready_age(owner_key, merge_pending, state, ready_at). Both are declared insync_pipeline_indexes.pywith the manifest regenerated, and both queries have registered drivers. If an index is not READY the query raisesFailedPrecondition. The merge records the sharedfirestore_readfallback, logsevent=batch_merge outcome=head_wait_unavailable, keeps strict order (commits nothing that strict order would not) and backs off for 5 min. Index READY before deploy is still the intended order.head_wait_bypass: trueon its result row and logsevent=batch_merge outcome=head_wait_bypass source=<gpu_pump|ordered_merge> head_state=<leased|ready|retry|...> wait_bucket=<lt120|...> count=1, with no IDs.backend/docs/batch-pipeline-serving.mdnow records the ruling, W, the mechanism and the transient visible effects, replacing "no change to transcript visibility order is assumed".Deviation from the design note (option b)
The design gates the bypass on the earliest-captured ready row having waited W. Under a reverse-arrival stream, each newly ready older row resets that clock, so the bypass would never fire until arrivals stop. This change gates on the longest-waiting ready row, a second small indexed query, and still commits ready rows in capture order. The rule becomes: no ready result waits more than about W behind an unready head.
Notification risk (design §5.4)
I checked whether a first-summary notification fires on a partial conversation that is later prepended. It does not; there is no visible push on this path.
SYNC_UPDATE(reprocess=True). That mode skips created-side effects: the created webhook, folder assignment and audio files (process_conversation.py_emit_derived_effects)._send_important_conversation_notification_if_neededandsend_new_memories_notificationhave no callers.plan_replacement).min, so a prepend inside that window lands before the first summary. Later prepends regenerate the summary through the outbox.Evidence
Unit tests (
backend/test.shwithBACKEND_UNIT_TEST_FILE_LIST; 57 batch, sim, Firestore-guard and flag files): green.test_batch_pipeline_merge_head_wait.py:ready_atstays strict; a recovered re-entry row bypasses; a quarantined head needs no bypass;off/0/-5issues no new queries;Nonewhile another owner still commits;test_batch_pipeline_merge_head_wait_sim.py: the run 14 replay (below).stale_no_purgenow pins strict order, since it demonstrates what the purge alone prevents. A new sibling variant shows the head wait no longer lets a fenced head block the owner.Sync Cloud Tasks stack gauntlet (
--only batch, local): all 10 batch scenarios pass, includingbatch-two-workers, after the probe change. Load average was about 89 when it passed. One earlier local run under load failedbatch-burst's worker start-order check; that check is scheduler pull order, which this change does not touch.Emulator (
firebase emulators:exec --only firestore):test_head_wait_commit_order_converges_to_one_conversation: all 6 orders of 3 separately uploaded contiguous units, where units 0 and 2 join only through unit 1, pass through real batch projection and assignment.test_global_recovery_sweep_advances_past_held_pages_without_extra_query,test_batch_flag_recovers_real_sdk_read_abort_with_fresh_transaction[×2],test_projection_discovery_drains_beyond_101_ready_rows_without_reprojection).test_two_workers_commit_each_segment_once_in_capture_orderflakes with409 Transaction lock timeoutwhen run after those failures. It also failed on the base commit in that combination (1 of 2 runs), and passes alone (3/3 on this branch).Sim replay (
python -m testing.merge_head_wait_scenario, seeds 1–3, consistent):make preflight: 38 checks passed.Rollout
gcp_firestore_indexes.yml(dev auto, prod approval) and confirm READY before the backend train. Until then the merge stays strict and logshead_wait_unavailable.head_wait_bypassis non-zero only for catch-up or leaked-lease owners;late_captureshare among non-catch-up owners is unchanged against run 12.BATCH_PIPELINE_MERGE_HEAD_WAIT_SECONDS=offon GPU workers and serving hosts. A mismatch between hosts is safe, because both choices pass the same owner fence.Product invariants affected
none
🤖 Generated with Claude Code