Skip to content

fix(sync): isolate backfill UID sequencer from dev - #19647

Merged
Git-on-my-level merged 11 commits into
mainfrom
lane/sequencer-env-scope
Sep 28, 2026
Merged

Git-on-my-level merged 11 commits into
mainfrom
lane/sequencer-env-scope

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Make the legacy UID sequencer production-only. Every Firestore registry operation rejects non-prod before I/O; dev sweep/wake and sequenced-task delivery are inert. Prod keeps its existing owner and pending collections without a backfill gap.
  • Prefix non-prod sync Redis job, run-lock, epoch, backfill slot, and cutover keys; put non-prod sync content ledgers and dead letters in stage-suffixed collections. Existing prod paths and keys stay unchanged.
  • Remove the global mode-key cutover trigger. Existing prod quiet deadlines are honored until expiry; new waits follow only a direct job registered for the same UID.
  • Add a dry-run-first recovery operator script and a runbook. New failure records carry failure_stage for attribution.

Incident cause and limits

Dev and prod used the same Firestore sequencer collections and Redis host. The dev sweep could claim prod pending work, and dev workers then failed staged-audio downloads against the dev bucket. The shared global cutover guard wrote a 30-minute deadline whenever its mode key was not on, including when missing. That branch explains the observed synchronized 30-minute stalls. The available aggregates do not prove whether an unobserved direct admission, Redis eviction, or a reset made the key non-on; legacy_migration log events do not write the mode key.

Historical dev-side sync_staged_audio_expired events do not prove prod objects remain. The supplied aggregate count has no job IDs, UIDs, or task payloads. Recovery requires a reviewed manifest correlating dev failure events with retained task metadata. The script checks only Redis job and GCS object-existence metadata; it downloads no audio. No production data or service was accessed or changed for this PR.

Rollout and recovery

After merge, deploy the new code to both dev sync services at 100% traffic; verify no old dev revision serves traffic or has an in-flight request; only then resume the dev sync-jobs and sync-backfill queues. Keep the dev sequencer Scheduler job paused. Old prod revisions retain their current keys and documents during the prod mixed-revision window. No scheduler or GCP configuration is changed here.

Dry-run command from backend/ after separately authorized production credentials and a reviewed JSONL manifest are prepared:

OMI_ENV_STAGE=prod .venv/bin/python scripts/recover_dev_failed_sync_backfill.py --manifest /secure/path/dev-failed-sync.jsonl

A later authorized recovery adds --apply. See backend/docs/runbooks/sync-backfill-sequencer-env-isolation.md for selection, input, and idempotency details. The script was not run against prod. Apply now resumes an existing deterministic recovery job after interruption at creation, ledger claim, registration, or kick; tests cover each boundary. Dev sequenced and legacy backfill deliveries ACK before any Redis or registry access.

Verification

  • backend/.venv/bin/python -m pytest -q tests/unit/test_sync_stage_isolation.py tests/unit/test_sync_backfill_uid_sequencer.py tests/unit/test_recover_dev_failed_sync_backfill.py tests/unit/test_sync_cloud_tasks.py tests/unit/test_sync_backfill_inflight_limit.py tests/unit/test_sync_dead_letters.py from backend/: 185 passed.
  • backend/.venv/bin/python -m pytest -q tests/unit/test_sync_status_read_ownership.py from backend/: 12 passed.
  • backend/.venv/bin/python -m pytest -q tests/unit/test_sync_capture_pipeline.py from backend/: 20 passed.
  • npm run test:sync-cloud-tasks-stack:emulator: passed with isolated Firestore and Redis.
  • bash backend/testing/e2e/run.sh -q --tb=short: 120 passed, 3 skipped, 2 xfailed with an explicit offline stage.
  • backend/.venv/bin/python -m pytest -q tests/unit/test_sync_job_stale_self_heal.py tests/unit/test_sync_jobs_corrupt_blob.py tests/unit/test_sync_two_lane.py tests/unit/test_sync_v2.py from backend/: 224 passed with explicit prod stage fixtures.
  • test_sync_ledger_fence_cutover.py stalled during collection in an attempted wider run; it was stopped without running tests.
  • OMI_PR_BODY_FILE=/tmp/omi-sequencer-env-scope-pr-body.md make preflight: 33 checks passed. scripts/failure-class validate --pr-body-file /tmp/omi-sequencer-env-scope-pr-body.md: passed.

Missing or unknown OMI_ENV_STAGE now logs an invalid sync-stage error and returns HTTP 503 from every sync route. Strict stage selection also rejects all sync Redis key and Firestore collection access before choosing a name. Only explicit prod, dev, local, and offline stages are accepted.

Failure-Class: new

🤖 Generated with Claude Code

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