Skip to content

perf(batch): batch cross-owner publication and per-flight merge drains - #22362

Merged
Git-on-my-level merged 7 commits into
mainfrom
lane/opus-worker-publish
Oct 19, 2026
Merged

Git-on-my-level merged 7 commits into
mainfrom
lane/opus-worker-publish

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

What changed and why

After every GPU flight the dedicated batch pump published results one fenced transition at a time, and ran drain_owner (up to 100 ordered commits plus an empty probe) after each accepted transition. Every 5 s the maintenance sweep also re-read each result_ready job, one transaction at a time, only to learn its owner, including jobs blocked behind an ordered predecessor that it had already read on the previous sweep. All of this sits in the pump's serial chain between GPU flights (see the worker profile's "Cheapest fix": bounded cross-owner publication with one drain per owner per flight).

This PR changes three things in backend/utils/batch_pipeline/pump.py:

  • Bounded cross-owner publication. A flight's complete/fail/defer transitions now run concurrently, at most BATCH_PIPELINE_PUBLISH_CONCURRENCY in flight. Each transition is still its own lease-fenced transaction.
  • One drain per owner per flight. All of an owner's transitions land first, then that owner gets one ordered drain. Drains for different owners run concurrently under the same bound.
  • Maintenance. It drains each result_ready owner once, under the same bound. A bounded (4096-entry) segment→owner memo means a blocked result_ready job is read once rather than on every sweep. A segment's owner cannot change after admission, so a stale entry can only cause a harmless fenced probe.

Kept intact:

  • Same-owner merge stays strictly serial and capture-ordered. OrderedMerge.commit_next still commits only the owner's first pending entry, and a per-owner lock in the pump stops two drains from racing on an owner's log tail.
  • Lease fencing (owns_lease, lost-lease heartbeat re-check) is unchanged.
  • Privacy and deletion fences raise inside the transaction exactly as before. They are isolated per lease or per owner, so siblings still publish.
  • complete() remains idempotent for a duplicate delivery. Quarantine still produces exactly one recovery_state='held'. The paid-recovery intent is created downstream from that state and is untouched here.

Config (ship-on, with a kill switch): BATCH_PIPELINE_PUBLISH_CONCURRENCY defaults to 4. Values run from 1 to 16. Setting it to 1 restores the exact legacy serial path: lease order, a drain after every accepted transition, and a re-read on every sweep. A malformed value also falls back to 1. The simulation produced byte-identical numbers for the kill switch and the unmodified main pump.

Scope: this PR covers post-flight publication and the ordered merge only. Flight overlap, process_batch I/O and model batching are owned by other lanes.

Product invariants affected

none

How it was verified

Measurement setup. I used the virtual-clock simulation from #22201 (now on main) with one GPU pump (one replica) and batch size 8. Arrivals ran for 30 minutes: the 5% cohort at about 20 jobs/min (10 owners), and the upper end of the 25% cohort at about 100 jobs/min (50 owners).

The stock simulation charges zero virtual time for pump database calls, so on its own it cannot see publication or merge cost. A measurement-only harness (not in this PR) adds a Firestore round-trip model: each pump transaction or query costs db_ms of virtual time, bounded to 24 concurrent calls like db_executor. GPU work is modelled as gpu_s/item.

The before/after columns compare kill switch 1 with the default 4. I checked the "before" numbers against the unmodified main pump and they are byte-identical. Values are means over seeds 1–3 at db_ms=50.

Scenario gpu s/item Leases/min per replica, before → after Publication s per flight, before → after (max) Merge commit_next calls per job Backlog drained at (s)
5% (20/min) 1.0 19.4 → 19.3 (arrival-bound) 0.59 → 0.34 (1.48 → 0.72) 2.13 → 1.61 1825 → 1821
5% (20/min) 2.0 17.4 → 18.7 (+7%) 1.08 → 0.52 (2.45 → 1.55) 3.24 → 2.52 2021 → 1892
25% (100/min) 1.0 20.3 → 27.7 (+37%) 1.20 → 0.64 (4.7 → 3.0) 9.17 → 8.06 8840 → 6535
25% (100/min) 2.0 15.0 → 18.9 (+26%) 1.12 → 0.64 (6.4 → 3.2) 14.1 → 9.6 horizon → 9591

Sensitivity to database latency (seed 1, 25% rate, gpu 2.0 s/item, leases/min):

db_ms Leases/min, before → after
25 17.3 → 19.5 (+13%)
50 15.0 → 18.9 (+26%)
100 11.8 → 17.3 (+46%)

Concurrency 8 measured the same as 4 (18.9 leases/min), so 4 is the conservative default.

What the numbers do and don't show:

  • They are relative simulation numbers, not production throughput. Real Firestore latency, GPU flight time and the work mix decide the actual gain. The stage timers from Profile batch worker stages and connect queue-age scaling input #22324 are what should confirm it after deploy.
  • At 25%, committed jobs/min stays well below leases/min under both settings (for example 5.2 → 8.5 at gpu 1.0). That gap is capture-order head-of-line blocking, which this PR does not claim to fix.

Tests: targeted runs only, under bin/omi-heavy run -- nice -n 19 bash test.sh with BACKEND_UNIT_TEST_FILE_LIST. Files: test_batch_pipeline_{publication,pump,worker,serving,quarantine,validation_disposition,runtime,scheduler,cohort_config}.py and test_pipeline_sim*.py. All passed.

test_cancel_waits_for_nonpreemptible_compute_before_heartbeat_stops failed once under load and then passed in three isolated reruns. It is timing-sensitive (a 0.02 s sleep against a 0.04 s worker) and exercises the cancel path before publication, which this PR does not change.

Tests

New file backend/tests/unit/test_batch_pipeline_publication.py:

  • Per-owner capture order and the previous_segment_id / log_sequence chain hold at concurrency 1, 4 and 16, with results returned out of capture order.
  • Exactly one drain per owner per flight; the kill switch restores per-transition drains.
  • Transitions are bounded and overlap across owners.
  • Same-owner drains never overlap, including maintenance drains racing post-flight drains, and the lock table empties afterwards.
  • A lost or stolen lease publishes nothing, and its successor waits behind it.
  • A privacy fence on one owner's merge, or on one transition, does not suppress the other owners.
  • Duplicate publication of a flight (same tokens and results) leaves jobs/results/owners unchanged, and quarantine is held once.
  • Maintenance drains each ready owner once and does not re-read blocked result_ready jobs on every sweep.
  • Config parsing and bounds for the kill switch.

UI evidence

UI-Evidence: none -- backend worker only

Failure class (fixes)

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 3 commits October 19, 2026 10:16
After a GPU flight the pump published one fenced transition at a time and
ran an ordered drain after every accepted transition. Owners now publish
concurrently under a bounded knob (BATCH_PIPELINE_PUBLISH_CONCURRENCY,
default 4; 1 restores the serial path), and each owner gets one drain per
flight after all of its transitions land. Every transition remains its own
lease-fenced transaction; same-owner drains are serialized by a per-owner
lock and the merge still commits the capture-order head. Maintenance drains
each result_ready owner once, bounded the same way.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Jobs blocked behind an ordered predecessor were re-read every 5s sweep just
to find their (immutable) owner. A bounded segment->owner memo, fed by
leases and first reads, removes those repeated reads when publication
concurrency is on; the kill switch keeps the legacy read-per-sweep path.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T07:26:57.353108Z e9fc8d4 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.

Git-on-my-level and others added 3 commits October 19, 2026 11:55
# Conflicts:
#	backend/config/batch_pipeline.py
… registry

Registry and deployment-setting classification only, matching how
BATCH_PIPELINE_WORKER_IO_CONCURRENCY is registered. No logic change.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	backend/utils/batch_pipeline/pump.py
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
…22425)

* feat(rollout): runtime _ramp percents and the ramp controller (lane 6 M1)

Contract (f): rollout_cohorts/_ramp holds per-env percents and legacy_sync.
utils/rollout/runtime_percent.py reads it with a 30s process cache on the
rollout executor, serves last-known-good on error, and falls back to the env
value on a cold start or a missing document, so with no document behaviour is
unchanged. config/ reaches it through a resolver seam in
config/rollout_cohorts.py, bound by configure_rollout_runtime(). Unbound
processes keep env values. summary_guarantee and batch_live_preview now read
their percent through the seam. valid_uid rejects _ramp* ids. CAS writes
create a history row in the same transaction and refuse range or nesting
violations.

Contract (g): scripts/rollout/ramp_controller.py has a pure decide() and a
thin runner. The runner writes only the batch-pipeline/first-summary percents
and acts only while legacy_sync=on. It moves one step at a time, at most once
per 10 minutes, and never past 100. It uses the fleet gate's data-loss tokens
for ROLLBACK_ZERO and stops after two rollbacks in 24h until a human
lock_cleared write. Every decision goes to STATE and every action to anx.
After a sleep or restart gap, the first tick only holds (S9).
scripts/rollout/ramp_set.py is the operator CLI. inject_gate.py is the
staging-only rehearsal wrapper.

config/batch_pipeline.py is untouched (frozen until #22362/#22373 reach
integration).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(rollout): align runtime_percent with the lane 1 stub; no package __init__ files

Snapshot source 'firestore' and revision int (0 = no document) match
lr/01-stubs. RAMP_DOC_ID re-exported. utils/rollout and scripts/rollout
are namespace packages, because the dead-code ratchet blocks __init__.py
there. LIFECYCLE headers are now on line 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(rollout): run _ramp reads in a fresh context, never the request's

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(rollout): C1 gate-unavailable escalation; BYOK not re-held at dispatch

C1 (lead ruling): a gate that cannot run (ro_prod_unavailable,
timeout_incomplete, parity_not_run, ...) holds. After 3 consecutive such
ticks (~30 min) the controller pages the lead, then pages again every 3
ticks. The streak lives in the heartbeat file, so it survives a restart;
a pause gap resets it.

admission.authorize: admission decides funding once (contract (c)). A unit
whose admission policy snapshot records provider_reason=byok skips the
dispatch-time funded re-check, which runs without the user's keys or BYOK
consent and would re-hold a BYOK owner on every lease (David: BYOK routes
like everyone). A missing or other policy keeps today's re-check, so this
stays behaviour-neutral until E1 writes binding.policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 984bf72 into main Oct 19, 2026
58 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/opus-worker-publish branch October 19, 2026 10:33
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
, #22362, #22461, #22471 sync)

- config/feature-flags.yaml: kept both new rows (LISTEN_LOOP_METRICS_ENABLED from main,
  ENRICHMENT_ROUTE from integration); rendered doc regenerated.
- #21932 moved the legacy sync runner's 500/503 into _run_sync_job_attempt: known gaps and the
  task-target KNOWN set gain the four _run_sync_job_attempt keys (legacy, leave with C11), drop
  the _run_sync_job_body/503 keys and recover_quarantine/503 (fixed by #22476).
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