Skip to content

test(backend): batch-lane scenarios in the emulator gauntlet - #22208

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/opus-emulator-stack
Oct 19, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/opus-emulator-stack

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Why

The emulator gauntlet in testing/sync_cloud_tasks_stack proved the legacy Sync v2 path across real process boundaries. The batch lane, which carries the two-lane rollout, had no such coverage. Revision replacement, duplicate task delivery and the privacy fence were only exercised in production.

What

run.sh (and the existing npm run test:sync-cloud-tasks-stack:emulator) now also runs batch-lane scenarios across three separate processes on the Firestore emulator and a private Redis. --only {all,sync,batch} picks the family.

process real fake
admission ASGI /v2/sync-capture-manifest, /v2/sync-local-files → accept_upload, decode, AES-GCM staging, intake/job/ledger rows, status route filesystem bucket
serving ASGI main lifespan Serving loop, authorize-compute, reconcile, recover-quarantine behind the production OIDC dependency, projection, enqueue_named_task, lease recovery paid STT leaf (counted), Google token verifier (one exact local token per audience/identity pair)
batch worker batch_pipeline_runtime.run_process: signals, Pump/Scheduler/FirestoreStore, heartbeats, spend admission over loopback, merge, PipelineWorker, artifact encryption words, diarizer and VAD leaves (per-owner latency, empty and fail rates, capacity); CUDA probe no-op; lease/heartbeat shortened to 8 s/2 s in the worker process only

Every child process installs the shared no-egress guard (isolation.py). The strict task recorder now also validates recovery and sync_reprocess tasks.

Scenarios (assertions read emulator/Redis state and HTTP codes)

  • Happy path: projection on the capture conversation, ledger completed, one words call, zero paid calls. Fair use is metered once and never re-metered by reconciles.
  • Empty ASR: quarantine, a recovery task, exactly one paid call, then projected. Duplicate and late deliveries return held with no further paid call.
  • Revision replacement (real signals):
    • Worker SIGTERM: it drains and publishes once.
    • Worker SIGKILL: the lease survives, and the replacement recovers it after expiry and completes once, with no doubled words call.
    • Serving SIGTERM during the paid call: the request finishes and the redelivery doesn't re-pay.
    • Serving SIGKILL during the paid call: no re-pay. The unit stays running until the 900 s abandoned rule (see below).
  • Privacy fence (advance_privacy_generation):
    • Mid-compute: persist fails closed, no projection.
    • After recovery prepare: cancelled, zero paid calls.
  • One-owner burst: drained in upload order.

Behavior found (real code, not changed here)

  1. Quarantined-but-recoverable jobs poll as status: failed with poll_after_ms: 0. See utils/batch_pipeline/intake.py durable_status, where any quarantined job means failed, whatever its recovery_state. A polling client stops before recovery completes.
  2. GET /v2/sync-local-files/{job_id} returns 500 after the privacy fence. BatchPrivacyBlocked from tx.check_privacy escapes get_durable_job_status and the route. The fenced job also stays leased until its lease expires.
  3. Serving SIGKILL during the paid call strands the unit. It stays recovery_state: running, and redelivery is correctly held. The 900 s abandoned_running rule then settles it as a failure rather than retrying. This is the shape of the 2026-10-18 Modulate incident.
  4. PR CI scope. The hermetic-e2e job's run_sync path filter doesn't match backend/utils/batch_pipeline/** or backend/diarizer/**. A batch-only PR therefore doesn't run this gauntlet until push or merge group. Fixing that is a workflow change and isn't made here.

Verification

Local, m5, nice -n 19, on origin/main ecd1f40:

  • Full gauntlet passed in 2:04; batch only ≈ 70 s. CI time rises by about 1 minute.
  • tests/unit/test_sync_cloud_tasks_stack_ci_wiring.py: 2 passed.
  • pre-commit is clean.

Test harness only. No production behavior change, no workflow change.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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-19T02:23:18.165781Z faaf981 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.

@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: 5a93505e0d

ℹ️ 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".

@Git-on-my-level

Copy link
Copy Markdown
Member Author

PR CI skipped the Sync Cloud Tasks Stack Gauntlet, because the run_sync path filter doesn't match backend/testing/sync_cloud_tasks_stack/. So I dispatched the workflow on this branch: run 39154335813. Sync Cloud Tasks Stack Gauntlet, Listen Pusher Stack Gauntlet and Hermetic Backend E2E all passed, including every batch scenario.

Git-on-my-level and others added 2 commits October 19, 2026 08:42
Extend testing/sync_cloud_tasks_stack so the real batch pipeline runs
end to end across separate processes on the Firestore emulator and a
private Redis: admission (real accept_upload, staging, intake/job/ledger
rows), a serving process (real main lifespan Serving loop, authorize,
reconcile and recover-quarantine routes behind the production OIDC
dependency), and a batch worker process (real run_process: signals,
Pump/Scheduler/FirestoreStore, heartbeats, spend admission over loopback,
PipelineWorker, artifact encryption) with configurable fake words,
diarizer and VAD leaves and a counted fake paid STT leaf.

Scenarios assert durable emulator state and HTTP codes: happy path,
empty ASR -> quarantine -> one paid recovery (duplicate deliveries held),
revision replacement via real SIGTERM/SIGKILL of the worker and of the
serving process, a privacy fence mid-compute and after recovery prepare,
and a small one-owner burst. The no-egress guard now covers every child
process; the strict task recorder also validates recovery and enrichment
tasks. `run.sh --only batch` runs just these (~70 s locally).

Test harness only; no production behavior change.

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

Address Codex review on the batch-lane gauntlet (all harness-only):

- Assert the projected conversation is the capture named in the manifest
  instead of recording the comparison as evidence only.
- Fail the one-owner burst when the worker starts segments out of
  admission order or more than once; the scheduler's per-owner FIFO makes
  that a real guarantee worth guarding.
- Fail the serving-sigterm scenario when the old revision does not
  actually exit, so the replacement can never silently shadow it.
- Require the killed-revision redelivery to return HTTP 200 `held`,
  the safe acknowledgement Cloud Tasks depends on.
- Bind the audience into the local OIDC token representation
  (local-sync-oidc:{audience}:{identity}) so two routes sharing a
  service account can no longer replay one token cross-audience; mint
  sites and the verifier share one helper.
- Validate sync_reprocess payload key/token formats (64/32 hex, matching
  the production handler's 400 path) and bind the task name to
  sr-{key}-{token} plus the sanctioned -repair-{generation} suffix.
@Git-on-my-level
Git-on-my-level force-pushed the lane/opus-emulator-stack branch from 5a93505 to faaf981 Compare October 19, 2026 02:14

@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: faaf9814e7

ℹ️ 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 +190 to +197
location = os.getenv('SYNC_TASKS_LOCATION', '')
queue = os.getenv('SYNC_TASKS_QUEUE', '')
audience = os.getenv('BATCH_PIPELINE_RECOVERY_TASK_AUDIENCE', '').strip()
invoker_sa = os.getenv('SYNC_TASKS_INVOKER_SA', '').strip()
if not all((project, location, queue, audience, invoker_sa)):
raise RuntimeError('batch recovery task configuration is incomplete')
if parent != self.queue_path(project, location, queue):
raise RuntimeError('batch recovery task used an unexpected queue parent')

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 Validate the configured recovery queue

Production config sets BATCH_PIPELINE_RECOVERY_TASKS_QUEUE to the dedicated batch-quarantine-recovery queue, but the harness omits that setting and validates only SYNC_TASKS_QUEUE. Consequently, these scenarios exercise the fallback sync-jobs binding rather than the deployed route, so a producer regression that ignores or misroutes the dedicated recovery queue remains green; configure and validate the recovery-specific queue here.

Useful? React with 👍 / 👎.

Comment on lines +213 to +216
task_id = str(task.name).rsplit('/', 1)[-1]
if str(task.name) != self.task_path(project, location, queue, task_id) or not _RECOVERY_TASK_ID.fullmatch(
task_id
):

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 Bind recovery task names to their payload

When the producer emits a syntactically valid task name containing the wrong stage or an unrelated 64-hex segment hash, this check still accepts it because _RECOVERY_TASK_ID validates only the shape. Production constructs the name from current_stage() and sha256(segment_id), so the gauntlet can pass while deterministic deduplication is no longer scoped to the recovery payload; extract and compare those name components with body['stage'] and segment_id.

Useful? React with 👍 / 👎.

Comment on lines +534 to +536
meter = stack.fair_use_meter_ms(upload.uid)
if meter <= 0:
raise StackFailure('batch projection did not meter fair-use speech')

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 Assert the initial fair-use amount

If the first projection double-charges or undercharges this single four-second upload, the scenario still passes because it checks only that the meter is positive and then remains unchanged. That does not establish the advertised exactly-once accounting behavior; compare the initial meter with the expected milliseconds from the upload's full-speech fake VAD result before testing subsequent reconciles.

Useful? React with 👍 / 👎.

Comment on lines +538 to +539
for _ in range(2):
stack.reconcile()

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 Require duplicate reconcile calls to succeed

When both explicit /reconcile requests return an error or cannot reach the serving process, their status values are ignored, and _drive_to_status immediately succeeds from the already-completed status without issuing another reconcile. The duplicate-projection assertions therefore pass without exercising a repeated sweep at all; require successful reconcile responses before checking that transcript and metering remain unchanged.

Useful? React with 👍 / 👎.

Comment on lines +128 to +132
if role == 'batch-serving':
return {
'BATCH_PIPELINE_SERVING_ENABLED': 'true',
'BATCH_PIPELINE_RECOVERY_MODE': 'on',
'BATCH_PIPELINE_RECOVERY_ALL_ADMITTED': 'true',

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 Exercise the deployed async projection mode

The checked backend/deploy/runtime_env.yaml and production overlay enable BATCH_PIPELINE_ASYNC_PROJECTION_ENABLED, but this allowlisted serving environment omits it, so the flag defaults to false and every scenario uses the synchronous projection branch without start_followups(). Regressions in the currently deployed async follow-up path can therefore pass this new gauntlet; enable the production-on projection mode in the serving role.

Useful? React with 👍 / 👎.

Comment on lines +12 to +14
Java 21+ for the Firestore emulator. Run one scenario family with
`backend/testing/sync_cloud_tasks_stack/run.sh --only sync` or
`--only batch` (the default, `--only all`, runs both; CI runs both). The runner gives Firebase a fresh

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 Trigger the batch gauntlet for batch-pipeline changes

On pull requests that change only backend/utils/batch_pipeline/**, backend/database/batch_pipeline_*, or backend/diarizer/batch_pipeline*, the run_sync predicate in .github/workflows/backend-hermetic-e2e.yml does not match those paths, so the job containing this new batch suite is skipped despite this documentation saying CI runs it. Extend that predicate to the batch implementation paths so regressions are caught on the PR rather than only on a later merge-group or push run.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 818ca00 into main Oct 19, 2026
57 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/opus-emulator-stack branch October 19, 2026 02:49
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor follow-up on this PR (both review rounds):

Round 1 (threads from 10-18, resolved ✅): all six Codex findings were addressed in faaf9814e7 — capture-conversation assertion, burst drain-order assertion, serving-SIGTERM exit check, killed-revision held acknowledgement, audience-bound local OIDC tokens, and reprocess payload binding (64/32-hex + name binding). Verified with the full emulator gauntlet locally before push. Threads resolved just now.

Round 2 (threads from 10-19 02:23Z): five of six are legitimate and were fixed + verified locally (dedicated batch-quarantine-recovery queue routing, async projection mode, recovery task-name↔payload binding, exact fair-use amount, reconcile must return 200) — but this PR merged at faaf9814e7 mid-flight, so that commit (39f5073b7b, full gauntlet green) could not be pushed. It's parked in the monitor worktree with a follow-up ticket (pr-22208-post-merge-codex-followups.md) and will come back as a fresh PR against main. The sixth (hermetic-e2e run_sync path filter) was scoped out in the PR body's "Behavior found #4" and is not implemented.

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