Repository navigation
chore(batch): run two prod batch workers - #22376
Conversation
Raise the prod batch-pipeline-worker Deployment from one to a fixed two replicas (autoscaling stays off). Each replica requests the single L4 on its own g2-standard-8 node; the pool's autoscaler cap is 4. Prove two pumps are safe together: - unit: two Pumps over one serializable store drain independent owners ~2x faster with once-only compute/accept/commit and gap-free chains; - emulator: two Pumps with separate Firestore clients commit each segment once in capture order across a split burst, a stolen lease never publishes, a mid-flight privacy fence publishes nothing, and an empty-ASR unit is quarantined once and held for recovery; - gauntlet: batch-two-workers runs two real worker processes against admission/serving, with one paid recovery call. 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. |
|
CI note: the Sync Cloud Tasks gauntlet failure is in the existing |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c233e0aafc
ℹ️ 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".
| from google.cloud import firestore | ||
|
|
||
| from database.batch_pipeline_privacy import BatchPrivacyBlocked, assert_batch_write_allowed |
There was a problem hiding this comment.
Move diagnostic imports to module scope
These imports are nested inside _fence_reason, so the new gauntlet code violates the backend requirement that all imports remain at module scope. Move both imports alongside the existing top-level imports so dependency failures and import relationships remain visible to repository tooling.
AGENTS.md reference: backend/AGENTS.md:L161-L169
Useful? React with 👍 / 👎.
| namespace = f'batch_pipeline_test_{uuid.uuid4().hex}' | ||
| admin = _client() | ||
| for uid in owners: | ||
| admin.collection('users').document(uid).set({'data_protection_level': 'enhanced'}) |
There was a problem hiding this comment.
Isolate or clean up seeded user documents
When this suite shares an emulator with another run, the fixture writes fixed IDs such as owner, fenced, and open into the global users collection, but teardown deletes only the UUID-namespaced pipeline collections. A concurrent run can therefore have its user privacy state overwritten or fenced by this suite, and every run leaves user documents behind; generate run-specific owner IDs or track and delete the seeded user documents.
Useful? React with 👍 / 👎.
| if start_after is not None: | ||
| while not start_after(): | ||
| await asyncio.sleep(0.05) |
There was a problem hiding this comment.
Let pre-start waits observe harness shutdown
When a start_after predicate never becomes true—for example, if worker A fails to acquire both leases in the stolen-lease test—this loop never checks finished. The outer timeout therefore waits an extra 30 seconds for the join and then leaves a daemon thread polling the Firestore store while fixture teardown or later tests run; exit the pre-start loop when finished is set before starting the pump.
Useful? React with 👍 / 👎.
What
Raises the prod
batch-pipeline-workerDeployment from 1 to a fixed 2 replicas. Autoscaling stays off: no HPA is rendered andautoscaling.enabled: falseis unchanged. Dev stays at 1. This PR is independent of the draft HPA lane (lane/luna-worker-hpa) and touches onlyreplicaCountin the prod values.Cost: one more L4 node, a
g2-standard-8on demand. That is about $633/month ($623 compute plus about $10 for the 100 GiB pd-balanced boot disk). David approved up to 4 batch GPU nodes on 2026-10-19.Render diff
helm template prod-omi-batch-pipeline-worker backend/charts/batch-pipeline-worker -n prod-omi-backend -f prod_omi_batch-pipeline-worker_values.yaml --set-string image.digest=<live digest>, before vs after:The rendered output has no other changes: no HPA and no PDB. The ServiceAccount and PodMonitoring are identical.
Does the chart or pool block 2 replicas? No.
Live read-only checks used the
ro-prodagent tier:batch-pipeline-pool:g2-standard-8with 1nvidia-l4, autoscaling on,totalMaxNodeCount: 4,locationPolicy: ANY, zones us-central1-a/b/c. One node is allocated today, with allocatablenvidia.com/gpu: 1. The pool has no GPU sharing or time-slicing config.env=prod, service=batch-pipelinematch the chartnodeSelector, and the taintsnvidia.com/gpu=presentandomi.ai/batch-pipeline=true(NoSchedule) match its tolerations.nvidia.com/gpu: 1and each node exposes exactly one, so two pods cannot share an L4. Pod anti-affinity would add nothing, so none was added. WithlocationPolicy: ANYthe second node can come up in any zone that has L4 stock.prod-omi-backend. The cluster autoscaler will not drain a node with a running worker, because its pod has nowhere else to fit.Why two pumps are safe together
Every cross-worker handoff is durable and fenced. Nothing relies on process-local state:
_pull_shardleases inside a Firestore transaction with a fresh token.heartbeat,complete,failanddeferall checkowns_lease, meaning stateleased, a matching token and an unexpiredlease_until. Spend admission sealscompute_admission_tokento the same token. A replica whose lease expired cannot publish, becausecompletereturns False and registering the artifact raisesresult_lease_lost.Scheduler.pullshards: the 64 DRR control shards are documents, andcontrol_candidateis only a hint. The transaction re-reads the shard, so two workers that pick the same shard serialize through transaction retry.drain_owner/commit_next): one transaction per commit reads the owner doc andfirst_pending. Concurrent drains serialize and give one gap-freelog_sequence/previous_segment_idchain. Concurrent merging is not new: serving (backend-integration, at least 3 instances) already runsrecoveranddrain_owneragainst the worker today.recover()re-checks state inside each transition's transaction, so double recovery is a no-op. Paid recovery runs only on the serving host and uses at-most-onceprepare/startintents. Adding replicas does not change who issues paid calls.assert_batch_write_allowedin its transaction. A fenced lease is moved toprivacy_blocked._GPU_CHAIN_LOCKis per process, and each pod has its own GPU.Evidence
All runs used
bin/omi-heavywithnice -n 19.tests/unit/test_batch_pipeline_two_workers.py: two realPumps, each in its own thread and loop, 8 independent owners × 2 unitstests/integration/test_batch_pipeline_two_workers_firestore.py: two pumps, each with its own client, prod flags (head priority on)privacy_blocked. Empty ASR: exactly one quarantine, held for recovery. Passed 3 of 3 runs after the timing fix belowbatch-two-workersscenario: two realbatch_pipeline_runtimeprocesses with real admission, serving, OIDC spend admission and paid-recovery leaf--only batchsuite passed 4 of 4 runs after the timing fix belowtest_batch_pipeline_chart.pyandtest_cross_service_deploy_contract.pyEmulator caveat, measured. The Firestore emulator holds a lock on the whole collection for a transactional query. A probe showed a write to another owner's document waiting about 1.2s behind an unrelated query transaction. Under two pumps, heartbeat p95 rose from 0.01s to 1.5s (max 4.0s), and wall time on the emulator is worse than with one pump. That is why throughput is measured on the serializable in-memory store, not on the emulator. It is also why the gauntlet scenario runs the replicas at prod's 6:1 lease-to-heartbeat ratio (60s/10s) instead of the kill scenario's compressed 8s/2s. At 8s/2s, emulator lock stalls expired healthy leases (
result_lease_lost) in 2 of 6 runs. Prod uses a 120s lease with a 20s heartbeat.Known limits
None of these block a fixed 2 replicas.
run_once. Two pods produce two identical series, so dashboards and alerts should usemax, notsum. Moving sampling to its own task matters only for the HPA lane. It is deferred, and not needed without an HPA.recover,due('result_ready')and the metrics refresh now run once per replica.Deploy (not done here)
Deploy Diarizer to GKE(.github/workflows/gcp_diarizer.yml,workflow_dispatch) withenvironment=prod,service=batch-pipeline-worker,branch=main(or a full merged SHA). The run rebuilds the worker image from that source and runshelm upgradewith the new digest. Strategy isRecreate, so both pods restart. Expect a cold start of more than 10 minutes while the second L4 node provisions.After the deploy, watch:
omi_batch_pipeline_events_total{event="lease_expired"}and the rate ofevent=batch_pump outcome=retry;completedrate.🤖 Generated with Claude Code