Skip to content

chore(batch): run two prod batch workers - #22376

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

Git-on-my-level merged 3 commits into
mainfrom
lane/opus-worker-replicas

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What

Raises the prod batch-pipeline-worker Deployment from 1 to a fixed 2 replicas. Autoscaling stays off: no HPA is rendered and autoscaling.enabled: false is unchanged. Dev stays at 1. This PR is independent of the draft HPA lane (lane/luna-worker-hpa) and touches only replicaCount in the prod values.

Cost: one more L4 node, a g2-standard-8 on 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:

 spec:
   # L4 scale-from-zero, image pull and joint model startup exceeded 600s in dev.
   progressDeadlineSeconds: 1800
-  replicas: 1
+  replicas: 2
   # Never allocate surge GPUs or co-locate a second chain on one device.
   strategy:
     type: Recreate

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-prod agent tier:

  • batch-pipeline-pool: g2-standard-8 with 1 nvidia-l4, autoscaling on, totalMaxNodeCount: 4, locationPolicy: ANY, zones us-central1-a/b/c. One node is allocated today, with allocatable nvidia.com/gpu: 1. The pool has no GPU sharing or time-slicing config.
  • Placement: labels env=prod, service=batch-pipeline match the chart nodeSelector, and the taints nvidia.com/gpu=present and omi.ai/batch-pipeline=true (NoSchedule) match its tolerations.
  • One pod per node: each pod requests and limits nvidia.com/gpu: 1 and each node exposes exactly one, so two pods cannot share an L4. Pod anti-affinity would add nothing, so none was added. With locationPolicy: ANY the second node can come up in any zone that has L4 stock.
  • Nothing else in the way: there is no PDB or worker HPA in 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:

  • Leases: _pull_shard leases inside a Firestore transaction with a fresh token. heartbeat, complete, fail and defer all check owns_lease, meaning state leased, a matching token and an unexpired lease_until. Spend admission seals compute_admission_token to the same token. A replica whose lease expired cannot publish, because complete returns False and registering the artifact raises result_lease_lost.
  • Scheduler.pull shards: the 64 DRR control shards are documents, and control_candidate is only a hint. The transaction re-reads the shard, so two workers that pick the same shard serialize through transaction retry.
  • Ordered merge (drain_owner/commit_next): one transaction per commit reads the owner doc and first_pending. Concurrent drains serialize and give one gap-free log_sequence / previous_segment_id chain. Concurrent merging is not new: serving (backend-integration, at least 3 instances) already runs recover and drain_owner against the worker today.
  • Recovery: 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-once prepare/start intents. Adding replicas does not change who issues paid calls.
  • Privacy fences: every job or result write passes assert_batch_write_allowed in its transaction. A fenced lease is moved to privacy_blocked.
  • No single-worker assumptions: no module-level singleton, unfenced cursor or "only one worker" check exists. _GPU_CHAIN_LOCK is per process, and each pod has its own GPU.

Evidence

All runs used bin/omi-heavy with nice -n 19.

Layer Test Result
Unit, serializable store tests/unit/test_batch_pipeline_two_workers.py: two real Pumps, each in its own thread and loop, 8 independent owners × 2 units 2.01× / 1.96× faster than one pump (4.15s → 2.07s). Every unit computed, accepted and committed exactly once, with gap-free per-owner chains
Firestore emulator tests/integration/test_batch_pipeline_two_workers_firestore.py: two pumps, each with its own client, prod flags (head priority on) Split 8-unit burst plus 5 owners: no duplicate compute, accept or commit, and the chain follows capture order. Stolen lease: the expired holder's result never reaches the log. Fence mid-flight: nothing published and fenced units end privacy_blocked. Empty ASR: exactly one quarantine, held for recovery. Passed 3 of 3 runs after the timing fix below
Gauntlet New batch-two-workers scenario: two real batch_pipeline_runtime processes with real admission, serving, OIDC spend admission and paid-recovery leaf Both replicas drained work. Each unit was computed and completed once, the burst committed in capture order, and the empty-ASR unit made exactly one paid call. The full --only batch suite passed 4 of 4 runs after the timing fix below
Chart test_batch_pipeline_chart.py and test_cross_service_deploy_contract.py pass

Emulator 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.

  • Queue gauges: they are sampled per pod at the top of run_once. Two pods produce two identical series, so dashboards and alerts should use max, not sum. Moving sampling to its own task matters only for the HPA lane. It is deferred, and not needed without an HPA.
  • Duplicated reads: recover, due('result_ready') and the metrics refresh now run once per replica.
  • Fresh-lane fair-use overshoot: the fair-use check is check-then-act, so overshoot is bounded by replicas × batch size (8). Backfill reservation is atomic per content key.
  • Shard herd: both workers pick the lowest-service control shard, so their pull transactions collide and retry. This is negligible at 2 replicas with batches of several minutes. Revisit before scaling well beyond 2 by randomizing among the lowest k shards.

Deploy (not done here)

Deploy Diarizer to GKE (.github/workflows/gcp_diarizer.yml, workflow_dispatch) with environment=prod, service=batch-pipeline-worker, branch=main (or a full merged SHA). The run rebuilds the worker image from that source and runs helm upgrade with the new digest. Strategy is Recreate, so both pods restart. Expect a cold start of more than 10 minutes while the second L4 node provisions.

After the deploy, watch:

  • 2/2 Ready;
  • omi_batch_pipeline_events_total{event="lease_expired"} and the rate of event=batch_pump outcome=retry;
  • per-pod completed rate.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

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]>
@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 ⚠️ Failed 2026-10-19T06:43:36.690696Z 2f1fa25 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

Copy link
Copy Markdown
Member Author

CI note: the Sync Cloud Tasks gauntlet failure is in the existing batch-empty-asr-recovery scenario (quarantined job reported 'processing' while recovery was pending). That scenario runs before the new batch-two-workers one, so the new scenario never ran. main fails the same way (runs 39198865655 and 39198374815). Locally, the full --only batch suite including batch-two-workers passed 4 of 4 runs. Re-run CI once main is fixed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +972 to +974
from google.cloud import firestore

from database.batch_pipeline_privacy import BatchPrivacyBlocked, assert_batch_write_allowed

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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'})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +123 to +125
if start_after is not None:
while not start_after():
await asyncio.sleep(0.05)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 70f9bac into main Oct 19, 2026
56 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/opus-worker-replicas branch October 19, 2026 07:12
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