Skip to content

integration: legacy-sync retirement (M3) - #22427

Merged
Git-on-my-level merged 144 commits into
mainfrom
integration/legacy-retire
Oct 21, 2026
Merged

Git-on-my-level merged 144 commits into
mainfrom
integration/legacy-retire

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

M3: land the legacy-sync retirement integration branch (integration/legacy-retire, swarm plan omi-knowledge-base/projects/backend-target-architecture/swarm-plan.md, contracts in contracts.md) on main. Merge with --merge (never squash); the lead runs the train from the main merge SHA.

Prod behaviour after this merge: prod legacy_sync stays on. Every new legacy-retirement path is gated: the ramp document, default-off flags or kill switches, and the DRAINING_PRECONDITIONS that ramp_set enforces before leaving on. With the mode on, intake, sync and enrichment keep today's routes.

M3 gates (lead ruling 6702cc; David authorized the merge, 10-21)

  1. Prep landed:
  2. Staging tree equality: OMI_RELEASE_TREE on all four *-staging services equals integration/legacy-retire^{tree} at this head (see the evidence section below).
  3. M2 review (GLM, which replaced Grok; ruling 43bd53):
  4. Workflows: all green on this head.
  5. Luna:

Dark-step gates and follow-ups (none block M3; prod stays on)

  • provider_stt_live (DRAINING_PRECONDITIONS): before leaving on, prod needs:
    • the provider-stt queue;
    • the PROVIDER_STT_TASKS_* env;
    • the maintenance job;
    • pagination or a due-cursor for the provider-STT outbox sweep (Luna round 2 About Firebase #4).
  • legacy_final_pass_rehomed (DRAINING_PRECONDITIONS, lead ruling b209a5): conversations still owned by legacy_final_pass_v1 with no live legacy job must be re-homed to batch first, and new final-pass ownership must stop outside on (Luna round 2 Add printing BLE device address to serial monitor #3). The final-pass-rehome lane owns this.
  • GLM P2s:
    • the router's stranded-row 409 loop without batch_adopts_stranded is lane 10 debt;
    • BYOK uploads route to batch even with legacy sync on (David, 10-19). This is a release-note item.

.github changes in this PR and David's naming

Source of the naming: swarm-plan.md, lane 7: "B4 and B5 are named .github changes (fourth round, #9)" (2026-10-19); the checkout-stall bound (2026-10-20, main 1b07e5e); #22758 build-only mode; lead ruling 209335 (David named B7 and B8 items, 2026-10-21 ~06:05Z).

File Change Named item
.github/workflows/config_train.yml (new) Config-train: plan/apply of backend/deploy/ops, manual dispatch, prod-train lock; workflow-level GIT_HTTP_LOW_SPEED_* B4 (+ checkout-stall bound for the two env lines)
.github/actions/sync-backfill-lifecycle/action.yml Prod backfill queue names come from the ops file; the train no longer reconciles the prod queue (#22455, #22480) B4
.github/workflows/gcp_backend.yml break_glass_lock input; prod concurrency group prod-train B5
.github/workflows/gcp_backend_listen_helm.yml same B5
.github/workflows/gcp_backend_pusher.yml same B5
.github/workflows/gcp_parakeet.yml same B5
.github/workflows/gcp_llm_gateway.yml same (every prod deploy writer shares the lock) B5
.github/workflows/gcp_diarizer.yml B5 lock lines plus B7: OCI revision/omi.release.tree image labels and a batch-worker image_digest promotion path (verified by check_release_tree.py) B5; B7 (David, ruling 209335)
.github/scripts/check-deployment-concurrency.py Guard that evaluates the new prod-train group expressions B5
.github/ci-budget.yaml config-train entry (B4); 1 run/day on the six deploy workflows with break_glass_lock (B5); 1.1/day on three build-only jobs (sync 11, #22758 base) B4, B5, #22758
.github/checks-manifest.yaml Registers backend/scripts/check_release_tree.py (the B7 promotion gate) B7 (David, ruling 209335)
.github/scripts/check_duplicate_routes.py Counts routers mounted through app_roles.mount_routers (B8 OMI_ROLE map) as mounted B8 (David, ruling 209335)
.github/scripts/test_pre_push_ci_verified.py Test hygiene: clean_env also pops PRE_PUSH_BASE_BRANCH and OMI_PR_BODY_FILE, so lane pushes with a non-main base do not leak into the hermetic hook runs lead authority, ruling 66dba9 (edits an existing test script; no workflow added)
.github/scripts/dead_code/backend.allowlist.json The 7 swarm contract-stub entries are removed (L01-4); every file now has importers allowlist hygiene (CI script data)

| .github/workflows/sync_ledger_fence_cutover.yml | Prod takes the prod-train lock, with a break_glass_lock input that falls back to the backend stack lock (M3 Luna review) | B5, completing it on a file that must share the backend mutation domain (lead ruling 5f60b3) |
| .github/workflows/config_train.yml (break-glass fallback) | Break-glass shares deploy-backend-stack-<env> with gcp_backend.yml (M3 Luna review) | B4/B5 (lead ruling 5f60b3) |

Staging tree evidence

Verified 23:33-23:4xZ 10-21, on tier ro-dev:

  • Services: all four *-staging services (backend-staging, backend-sync-staging, backend-sync-backfill-staging, backend-integration-staging) serve 8d062ad3cfacf8b7eb26dea737a2969423548e64 at 100%.
  • Tree: OMI_RELEASE_TREE=5c398832bc4487066abbf2d49bcf8c6f9a700818 == 8d062ad3^{tree}.
  • Image: us-central1-docker.pkg.dev/based-hardware-dev/staging/backend@sha256:18b8cf414566743aaee20bd2559695ec7b4536a75ec609fbc139f008bbf7ecf9.
  • Batch worker: sha256:0954c71c87f5, 0 replicas. Staging is plain (no warm instances or overrides).
  • Deploy log: data/run-2026-10-19-legacy-retire/lane01/m3/deploy-final2.log (omi-workspace).

Product invariants affected

INV-DATA-1: integration carries lane 7's (#22430) edits to .github/workflows/gcp_*.yml. They add the prod-train concurrency/lock lines (B5) and, in gcp_diarizer.yml, the worker-digest promotion. No Firebase or Firestore project, auth authority or serving endpoint changes. Production-family artifacts stay on based-hardware.

Line-count exceptions

Line-Count-Exception: backend/routers/sync.py | 3881 -> 3966 | lane 10 legacy-dark fence wiring at the legacy call sites (#22495) plus the M3 review fixes (off-loop mode read, final-pass ACK); the file shrinks with the C6/C11 deletions
Line-Count-Exception: backend/database/firestore_index_registry.py | 2196 -> 2200 | the legacy-dark zero-lost census index (sync_content_ledger created_at, lost_recordings.py soak check 5)

Failure class

Integration carries fix commits, and each declares its own class. For this merge:

Failure-Class: none
UI-Evidence: none -- backend/CI retirement work plus sync merges; the UI changes are main PRs that carried their own evidence

🤖 Generated with Claude Code

Git-on-my-level and others added 20 commits October 19, 2026 00:09
…, retry, reasons, runtime percent) (#22420)

Lane-1 stubs for the legacy-sync retirement swarm (contracts (a), (b), (d), (e), (f)):

- database/outbox.py: OutboxKind, Outcome, Claim, EnqueueResult, SweepCounts, Outbox protocol,
  outbox_for selector (NotImplementedError until lane 9's Firestore outbox).
- utils/workers/consumer.py: Role, Result (validated), QueueConsumer protocol, run_push/run_pull
  drivers and the 200/409-only http_response mapping; re-exports Outcome/Claim.
- utils/workers/retry.py: ExpectedRetry and retry_response (409 {"status":"retry","reason":...}).
- utils/observability/reasons.py: ReasonFamily, RetryReason, ConsumerReason, RampReason,
  reason_label with omi_reason_unknown_total{family}.
- utils/rollout/runtime_percent.py: signatures only (lane 6).
- routers/enrichment.py, routers/batch_provider_stt.py: empty routers (lanes 9 and 8); mounted
  after #22388's main.py edit reaches integration.
- scripts/cross_service_contract.py: TaskEdges enrichment and provider-stt; registrations of
  task-target-retry-semantics (lane 4) and staging-mirrors-prod (lane 2) via a lazy loader of
  scripts/cross_service_checks/<module>.py. Known edge-declared gaps until lane 7's ops file.

No behaviour change: nothing on main calls the new modules.

Co-authored-by: Claude Opus 5.5 <[email protected]>
…importers land

The lane-1 stubs (#22420) are imported only by tests and by lanes' in-flight PRs. Whether
they pass the backend dead-code ratchet depended on incidental docstring mentions, so a lane
that rewrote reasons.py (#22422) made utils/rollout/runtime_percent.py dead and every lane push
failed. Allowlist all seven stub files explicitly. Each reason carries an expiry: delete at the
M3 merge.

Data allowlist only; no workflow change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… ratchets (#22437)

Lead rulings 10-19 ~07Z (lane 9 question), contracts (a)/(b) amended in the KB:
- run_push maps a not-due claim_key (Outcome.DEFERRED, row already re-armed and woken by the
  outbox) to 200 {"status":"deferred","reason":"not_due"}; DISCARDED maps to 200 superseded.
- Result.available_at is required for RETRY and for a DEFERRED returned by process(); a
  deferring consumer without it raises before any row write.
- Outbox gains wake(row_id, wake_token), idempotent on the pair, for transactional enqueuers
  after commit; enqueue without tx, defer, and not-due claim_key create the wake themselves.

Test selection: changed backend Python selects test_reason_label_enums.py, and batch/enrichment/
workers/outbox modules select test_batch_stage_env_ratchet.py (lane 14, #22422), so a PR adding
a violation fails in its own CI. The lane-1 stub modules map to their own tests.

Co-authored-by: Claude Opus 5.5 <[email protected]>
…and GPU paired-run gates (#22426)

* feat(parity): contract (j) parity gate, (h) soak checks, F6 corpus and GPU paired-run gates

Lane 5 of the legacy-retire swarm (M1 slice):
- scripts/parity/parity_gate.py: rows 1-8 of contract (j) on --surface staging
  and --surface prod-shadow (rows 3-6 gate ladder ADVANCE), parity_report.json,
  PARITY_PASS/FAIL/PENDING last line, data_loss for rows 5/7 (ROLLBACK_ZERO).
- scripts/parity/soak_check.py: the ten 12h legacy-dark soak checks; the
  lost-recording census must start at draining; all four legacy queues
  including sync-backfill-fresh; read-only live collectors.
- scripts/parity/fleet_sample.py: rows 3/4 from the fleet gate's JSON sample
  (strict 121s dispatch breach) and the gate's data-loss tokens.
- testing/quality_corpus: pinned public corpus (AMI/LibriSpeech/VoxConverse +
  silence), production-chain runner, scorer, and the paired runs gating
  #22368 (flight batching: qualify receipt re-verified plus chain pair) and
  #22358 (short-speech skip: fired units vs full diarizer), with an L4 Job
  template for staging.

No GCP access in tests; reports carry aggregates and opaque keys only.

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

* test(parity): load scipy/jiwer at import so timed unit calls stay under the CPU guard

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…lay driver (#22428)

* feat(staging): David-only mirror, synthetic population and replay driver (lane 4)

Swarm lane 4 (legacy-retire), contracts (i) and (j) inputs.

- testing/loadgen/profile.json + refresh_profile.py: prod upload arrival
  shape from ro-prod Prometheus aggregates only (k>=20 floor, no uids):
  ~219 accepted uploads/min, hour-of-day curve, platform and lane mix,
  recording-age CDFs, VAD speech share. Unmeasured fields stay under
  `assumed` with their basis.
- testing/loadgen/population.py: deterministic pseudo-owner population
  (steady/burst/reverse/shuffled), relative time shifts so names are minted
  at send time, silence pads and near-silent files, backlog share from the
  profile, N-owner burst mode.
- testing/loadgen/mirror_codec.py: staging-mirror envelope (AES-GCM, key
  from the staging-only secret, object name as AAD), byte-compatible prod
  per-uid decrypt with an explicit secret, chunk/raw upload -> WAL upload
  bodies without decoding, pendant `opus_fs320` filename support.
- scripts/staging/mirror_owner_recordings.py: owner pinned by three
  David-only prod allowlists, read-only prod facade (list/get), plaintext
  only in memory, sealed copies to based-hardware-dev-staging-mirror,
  aggregate-only run record.
- scripts/staging/replay.py: plan/run CLI through the real
  /v2/sync-local-files (+ capture manifest for fresh device-bound uploads,
  seeded only behind the staging fence); refuses non-staging targets and
  any host other than in-cluster or m1-mac-studio.
- testing/loadgen/staging_replay_job.yaml: in-cluster Job template.

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

* test(staging): keep replay materialize test inside the fast-unit CPU budget

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…ct h) (#22429)

* feat(sync): legacy-dark mode, double-processing fence and drain census (contract h)

Behaviour-neutral at on: nothing calls the module yet. Adds the
legacy_sync mode read (fails to on), the ledger-row fence for content
legacy already owns, the dark-entry census verdict, the drain census
script, the queue capture/recreate script and the runbook.

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

* fix(sync): resolve the legacy_sync reader at call time until the (f) module lands

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

* docs(sync): legacy-dark runbook records the lead rulings on capture and the dark sweep

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
… 9, C2 slice 1) (#22431)

* refactor(enrichment): move the sr- outbox into utils/enrichment (C2 slice 1)

Plan C2, swarm lane 9. Pure move, no behaviour change:

- utils/sync/reprocess.py        -> utils/enrichment/outbox.py
- utils/sync/enrichment_custody.py -> utils/enrichment/custody.py
- utils/sync/enrichment_scan.py  -> utils/enrichment/scan.py

The old paths become sys.modules aliases of the new modules, so every
importer, mock.patch target and monkeypatch keeps reaching the same module
object. A star import gives pyright the public names. Batch projection
imports the new path; the frozen prod-track files (serving.py,
routers/batch_pipeline.py, batch_pipeline/enrichment.py) keep the shim until
their PRs reach integration.

Collection, document ids, field names and the sr- task prefix are unchanged
(contract (b) invariant 7). The query-shape driver and background-task
baseline follow the moved function.

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

* refactor(enrichment): drop the test-only custody and scan aliases

Only tests imported utils.sync.enrichment_custody and enrichment_scan, so the
dead-code ratchet counts the aliases as new dead files. The tests now import
utils.enrichment.scan directly; utils.sync.reprocess keeps its alias for the
production importers.

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

* test(enrichment): import the probe modules at collection time

The fast-unit CPU guard charged utils.cloud_tasks' first import to the probe
test's call phase (0.53s > 0.30s) once this file was selected. Module-level
imports keep the assertions unchanged and the call phase cheap.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
#22440)

Lane 12 (Postgres A0/A1, #22434) imports psycopg 3 lazily in database/jobstore/connection.py;
runtime use needs it locked. Lane 1 owns the locks in the legacy-retire swarm.

Added to requirements.txt and spliced into the five backend pylocks from
scripts/update-python-lock.sh output: only the psycopg and psycopg-binary blocks. The regenerate
also floated gitpython, pyjwt and tornado; those unrelated upgrades are deliberately left out.

Verified: uv pip install 'psycopg[binary]==3.2.10' into the backend venv; `import psycopg` ->
3.2.10, pq impl binary.

Co-authored-by: Claude Opus 5.5 <[email protected]>
…odule

#22431 moved FirstSummaryCallbackPending to utils.enrichment.outbox (utils.sync.reprocess is
now a sys.modules alias), so the class's __module__ changed. EXPECTED_RETRIES in
routers/batch_pipeline.py still matched ('utils.sync.reprocess', ...), and the enrichment
route answered 500 instead of 409 callback_pending. Fast 500s are the pattern that let Cloud
Tasks throttle sync-jobs (10-18 18:14Z) and sync-backfill (10-19 04:52Z). Lane 4 confirmed the
regression on integration 7da2935.

Re-key on utils.enrichment.outbox. The new test raises the class imported from its defining
module and from the alias, and both must map to callback_pending. The existing AST test
(class defined in the keyed module) now holds again.

Verified: pytest tests/unit/test_batch_pipeline_serving.py, 39 passed (unit).

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…utral) (#22433)

* feat(batch): C8 provider-STT stage core (lane 8 slice 1, behaviour-neutral)

Adds the batch provider-STT stage for languages Parakeet cannot serve, so
batch never needs the legacy fallback for them:

- resolve_route(): admission-time stt_route/provider_reason/provider_service
  (contract (c) fields). Unknown language is 'multi' -> Parakeet, as legacy.
  BYOK never changes the STT route (sync prerecorded never used BYOK keys).
- enqueue_in_transaction(): writes a provider unit as provider_pending with
  merge_pending set, outside the GPU DRR ring, keeping the owner revision
  fence and late-capture watermark. Intended for an admit() enqueue hook.
- ProviderSttStore/ProviderSttStage: paid-once job-row intent
  (pending -> running CAS mints the token), one Modulate call with client
  retries disabled, deterministic per-token result object, settle to the
  same result_ready transition Scheduler.complete performs. Redelivery
  reconciles, never re-spends; vendor failure and abandoned intents settle
  failed_held (never 'held', so quarantine recovery cannot pay twice).

Nothing imports the new module yet: intake wiring, the queue consumer and
the router follow once the lane-1 stubs and the admit() hook land.
Expected C8 traces are pinned under pipeline_sim_goldens_pending/ with a
strict xfail until the sim configs exist.

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

* refactor(batch): route the intake language decision through provider_stt.resolve_route

Behaviour-neutral at legacy_sync 'on': unknown and 'multi' languages keep
today's legacy fallback explicitly, and a parametrized test pins the old and
new conditions equal for every language class with and without BYOK. This is
the seam the C8 provider route replaces in draining/dark.

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

* test(batch): keep the pending C8 golden check inside the fast-unit CPU budget

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…n lock (B5), worker digest promotion, OMI_ROLE map (B8) (#22430)

* feat(deploy): ops file + config-train (B4), prod-train lock (B5), release-tree check

B4: backend/deploy/ops/{prod,staging}.yaml hold the ops-owned values the
trains must not touch: the sync-jobs-fresh / sync-backfill-fresh re-points
from the 10-18 and 10-19 queue stalls, recovery queue 16/8, the fresh queues'
rates and retries, and service-level scaling (backfill as bounds only while
redis_guard owns it). backend/scripts/ops_train.py plans against the serving
revision (status.traffic, never spec.template), refuses when the template
differs from the serving revision outside ops keys, routes every env change to
its new named revision explicitly (backend-sync-backfill pins traffic) and
verifies it serves. config_train.yml runs plan/apply behind the prod approval
gate. Live ro-prod plan of the Cloud Run half is zero-diff.

B5: every prod deploy writer (backend, listen, LLM gateway, pusher, diarizer
/batch worker, parakeet, config-train) takes the prod-train concurrency group;
break_glass_lock falls back to the pre-B5 per-target lock. The deployment
concurrency policy evaluates the group expressions and enforces both.
backend/scripts/prod_train_lock.py reads the lock from active runs plus their
deployment environment for the ramp controller (fail closed on unknown).

Promotion identity (contract (i)): check_release_tree.py asserts the main merge
tree equals the staging-qualified OMI_RELEASE_TREE read from serving revisions.

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

* feat(deploy): promote batch-worker images by digest with a tree check (B7)

gcp_diarizer.yml labels every image with org.opencontainers.image.revision and
omi.release.tree, and accepts image_digest for batch-pipeline-worker: an
already-built registry digest deploys without the 4.7 GB rebuild only when
check_release_tree.py image confirms its tree equals the admitted source tree.

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

* feat(backend): OMI_ROLE role map with route census (B8)

app_roles.py lists every router in today's mount order with its roles (api,
workers, realtime; default all is behaviour-neutral). The census test pins the
all role to main.py's include order, requires every TaskEdge and backend
Scheduler target to be mounted by workers and every websocket router by
realtime. main.py switches to mount_routers once #22388's main.py edit reaches
integration (frozen until then).

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

* chore(ci-budget): record the image_digest dispatch input

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

* test(backend): census tolerates lane 1's not-yet-mounted stub routers (shrink-only)

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
… 2a) (#22449)

* feat(sync): legacy-dark mode, double-processing fence and drain census (contract h)

Behaviour-neutral at on: nothing calls the module yet. Adds the
legacy_sync mode read (fails to on), the ledger-row fence for content
legacy already owns, the dark-entry census verdict, the drain census
script, the queue capture/recreate script and the runbook.

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

* fix(sync): resolve the legacy_sync reader at call time until the (f) module lands

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

* docs(sync): legacy-dark runbook records the lead rulings on capture and the dark sweep

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

* feat(sync): legacy_dark reads the (f) stub statically; an unimplemented reader serves on quietly

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

* docs(sync): legacy-dark auto-proceed gates for pre-authorized deletion (David 10-19)

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…ry invariant (#22453)

* test(staging): F1 Cloud Tasks throttle model + task-target retry invariant (lane 4)

Contract (d), plan F F1, cross-plan L5. First merges after the stubs.

- testing/fakes/cloud_tasks_queue.py: virtual-clock Cloud Tasks queue
  (token bucket, concurrency, retry backoff/max attempts, named-task
  dedupe) with an AIMD system throttle on 429/503 or a high fast-5xx
  share; a config PATCH caps but never resets it. Scenarios
  enrichment_fast_500_throttle (10-18 18:14Z sync-jobs) and
  sync_backfill_0452 (10-19 04:52Z sync-backfill) drive the REAL
  routers.batch_pipeline.enrichment_response for an expected
  first-summary wait. At 733a74a^ (pre-#22371, 500) the 1h run strands
  10,002 direct jobs at 0.1/s (prod 10-18: 10,399 at 0.1/s) and 2,322
  backfill jobs (prod 04:52Z: 3,552); at 733a74a (409) both keep the
  configured rate and drain.
- scripts/cross_service_checks/task_targets.py:
  check_task_target_retry_semantics(ctx), registered by #22420. AST scan
  of each TaskEdge handler and the router helpers it calls: 429/503
  anywhere, 500 outside an except-Exception fallback, ExpectedRetry not
  answered by retry_response. Keys carry no line numbers.

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

* chore(contract): accept the 12 existing task-target retry violators (lane 4, contract (d))

Lane 1 ruling: F1 carries its own known-gap entries. Keys are the
contract (d) violator table plus the audit-only finalization and
account-deletion targets; new keys still fail.

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

* fix(staging): mirror run record no longer deep-copies the stats lock

dataclasses.asdict deep-copies a threading.Lock and raised after the copy
finished, so the first live run wrote objects and the manifest but no
workspace record. Idempotent rerun fills it in.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
A change to routers/batch_pipeline.py selected 11 guard tests and none of its route tests, so
the stale EXPECTED_RETRIES key that #22431 left behind (callback_pending answered 500, the
Cloud Tasks stall pattern) had no changed-file test on a router edit. routers/batch_pipeline.py,
routers/sync.py and utils/sync/reprocess.py now select test_batch_pipeline_serving.py, the
reprocess/enrichment suites, and lane 4's retry-semantics and queue-model tests once those exist.
utils/enrichment/ stays unmapped on purpose, so it keeps the full-suite fallback.

Verified: selector spot check (routers/batch_pipeline.py -> 15 tests incl.
test_batch_pipeline_serving.py; utils/enrichment/outbox.py -> full suite); selector tests 16
passed (unit).

Co-authored-by: Claude Opus 5.5 <[email protected]>
…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]>
… 9, C2 slices 2-3; absorbs #21968) (#22444)

* refactor(enrichment): move the sr- outbox into utils/enrichment (C2 slice 1)

Plan C2, swarm lane 9. Pure move, no behaviour change:

- utils/sync/reprocess.py        -> utils/enrichment/outbox.py
- utils/sync/enrichment_custody.py -> utils/enrichment/custody.py
- utils/sync/enrichment_scan.py  -> utils/enrichment/scan.py

The old paths become sys.modules aliases of the new modules, so every
importer, mock.patch target and monkeypatch keeps reaching the same module
object. A star import gives pyright the public names. Batch projection
imports the new path; the frozen prod-track files (serving.py,
routers/batch_pipeline.py, batch_pipeline/enrichment.py) keep the shim until
their PRs reach integration.

Collection, document ids, field names and the sr- task prefix are unchanged
(contract (b) invariant 7). The query-shape driver and background-task
baseline follow the moved function.

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

* refactor(enrichment): drop the test-only custody and scan aliases

Only tests imported utils.sync.enrichment_custody and enrichment_scan, so the
dead-code ratchet counts the aliases as new dead files. The tests now import
utils.enrichment.scan directly; utils.sync.reprocess keeps its alias for the
production importers.

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

* test(enrichment): import the probe modules at collection time

The fast-unit CPU guard charged utils.cloud_tasks' first import to the probe
test's call phase (0.53s > 0.30s) once this file was selected. Module-level
imports keep the assertions unchanged and the call phase cheap.

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

* fix(enrichment): own the sr- callback and absorb lifecycle fences (C2 slice 3)

Plan C2, swarm lane 9. Batch enrichment no longer imports legacy
transcription (utils/sync/pipeline.py):

- utils/enrichment/callback.py: enrich_conversation, extracted verbatim from
  pipeline._reprocess_conversation_after_update with its webhook helper,
  persistence fence and lineage sentinel. pipeline.py is frozen behind
  #21932/#20662 and keeps its copy for the non-coalescing direct path, so
  test_enrichment_callback_parity.py (a static tripwire, labelled as such)
  keeps the two bodies identical until C11 deletes the legacy one. The new
  copy logs no conversation id.
- utils/enrichment/custody.py now owns discard_blocked. The batch adapter
  re-exports it for its existing importers.
- Absorbs #21968 (lead ruling 10-19): a SyncConversationPersistenceFenced
  from the callback settles the claim as superseded. The obligation is
  retired when no newer mark landed and re-armed when one did, and the
  handler ACKs 200 instead of answering 500 to a delivery that can never win.
  Other errors keep their taxonomy. #21968's conversation_id log line is not
  carried; the event is logged without identifiers.

Failure-Class: none

Verification (local unit, serial, nice 19):
- test_enrichment_callback_fence 4 passed (fenced+unchanged -> retired;
  fenced+newer mark -> re-armed; ValueError propagates; the default callback
  is the package)
- test_enrichment_callback_parity 3 passed
- test_batch_pipeline_serving 31 passed
- test_listen_finalization_cloud_tasks 278 passed
- test_sync_reprocess_coalesce 88 passed
- test_sync_enrichment_custody 10 passed
- test_background_task_ratchet, test_llm_gateway_coverage_guardrails and
  test_generated_compute_inventory_guardrails passed
- pyright 0 errors
- test_sync_reprocess_emulator now patches the package callback (CI emulator lane)

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

* feat(enrichment): Firestore Outbox for OutboxKind.ENRICHMENT (C2 slice 2)

Plan C2 / contract (b), swarm lane 9. database/outbox_firestore.py
implements the Outbox protocol over sync_reprocess_outbox, row-compatible
with mark/run: same collection, document ids, field names and sr- names.
Additive fields: policy_id, claim_attempts, a transient summary_seen_by.

- lease_token is the per-claim owner uuid and wake_token is task_token.
  heartbeat/ack/defer/release are fenced on both (invariant 1).
- claim_key: privacy discard first (invariant 6), then demand admission,
  a stale or busy check, and a not-due re-arm that wakes itself and returns
  DEFERRED. Wake ownership follows the lead's 10-19 ruling: this
  implementation creates the tasks through the existing _enqueue.
- ack keeps today's finish rules: retire when unchanged, a dormant receipt
  when record_summary marked the lease, re-arm when the version moved.
- enqueue shares mark's CAS operation (mark_update), with explicit
  available_at and min/max coalescing (invariant 3). With tx= it writes in
  the caller's transaction and returns the wake token; the caller calls
  wake() after commit (invariants 4-5). wake() is idempotent per token.
- sweep delegates to the existing sweep with a privacy discard hook. Pull
  claim() goes through the new utils.enrichment.outbox.due_rows
  (single-field due_at index), registered in the query-shape drivers.

Batch projection's mark_enrichment now calls enqueue(tx=...) and then
wake(), using its own client for both. A backfill binding is still resolved
only for a new row (new_dispatch callable), so a coalesced append never
raises on a missing backfill env, as before.

database.outbox.outbox_for is lane 1's stub; firestore_outbox(kind) is the
implementation it should return (wiring requested from the captain).

Verification (local unit, serial, nice 19):
- test_outbox_firestore 13 passed
- test_batch_pipeline_projection 40 passed
- test_sync_reprocess_coalesce 88 passed
- test_firestore_query_shapes 481 passed
- the outside-query, runtime-witness and index-oracle suites passed
- test_listen_finalization_cloud_tasks 278 passed
- pyright 0 errors
The emulator conformance suite is lane 12's and has not landed yet.

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

* feat(enrichment): outbox_for selects the Firestore enrichment outbox

Lane 1 signed off on this one-function edit of its stub (10-19): in this
window the selector always returns the Firestore implementation; the
BATCH_JOBSTORE_MODE switch is lane 12's.

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

* fix(enrichment): match moved retry classes so callback-pending stays 409

#22371 classifies expected enrichment retries by (defining module, class
name). #22431 moved FirstSummaryCallbackPending to utils.enrichment.outbox,
so on integration a callback-pending delivery fell through to the
unexpected branch and answered 500. That is the fast-5xx shape that
throttled the queues on 10-18 and 10-19. Match the new defining modules,
and keep the legacy pipeline fence until pipeline.py is deleted.

Failure-Class: none

Verification: test_batch_pipeline_serving 38 passed (it failed with
500 != 409 before this change on the merged integration tree).

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

* feat(enrichment): FirestoreOutbox factory with injected client, privacy check and wake

For lane 12's outbox conformance suite (build_outbox_backend('emulator')):
FirestoreOutbox(kind, client=, privacy_blocked=, create_wake=) binds every
CAS, the sweep and every wake to the injected seams. The default instance
keeps the production paths (discard_blocked, _enqueue, the shared client).
outbox._cas is the client-explicit CAS behind _mutate, and sweep takes
client=/wake= for the same purpose.

A not-due claim_key deferral leaves claim_attempts untouched (attempt stays
1 on the first real claim), as reprocess does today; there is a test for it.

Verification: test_outbox_firestore 16 passed, test_batch_pipeline_projection
40, test_sync_reprocess_coalesce 88, test_firestore_query_shapes 481,
test_sync_enrichment_custody 10; pyright 0 errors.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…(contract (i)) (#22432)

* feat(staging): human-tier bootstrap and staging queue script (contract (i), S1)

bootstrap_iam.sh: one-time David-run script creating staging-* SAs, the
named Firestore DB, staging buckets, AR repo, staging-* secrets (random or
copied from dev test keys, payloads never printed), staging-scoped grants,
GKE namespace RBAC, optional Memorystore (S2), and an IAM deny policy on
based-hardware. Dry run by default; --rollback --apply undoes it.

create_queues.sh: dev-operator creation of the nine staging-* Cloud Tasks
queues.

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

* feat(staging): S2 in-cluster Redis in bootstrap; drop Memorystore path

David chose in-cluster Redis (StatefulSet in namespace staging). Bootstrap
now generates staging-redis-password, writes it to the k8s Secret
staging/staging-redis, and grants agent-dev-operator compute.networkUser
on the dev subnet so staging Cloud Run reaches Redis by Direct VPC egress.

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

* feat(staging): boot-time isolation fence and staging named-DB allowance

utils/staging_fence.assert_staging_isolation() refuses to start a process
with OMI_DEPLOYMENT=staging whose env reaches prod: project ids, database,
Firebase auth project and signer, non-private Redis host, committed sha256
hashes of prod data-plane identifiers, and any based-hardware (non -dev)
reference. Counts omi_staging_fence_total{reason}; never logs values.

database/_client.py runs the fence before building any Firestore client and
allows FIRESTORE_DATABASE_ID=staging only for staging in based-hardware-dev.

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

* feat(staging): staging overlay, staging-mirrors-prod check, deploy.sh

- runtime_env/staging.overlay.yaml: staging = composed prod + allowlisted
  transforms (service names, identity, network, env_all, queue_map,
  secret_map). compose_runtime_env.py --env staging composes it to a
  separate file (runtime_env.yaml unchanged) and runs the staging fence
  over every service's env; any prod-pointing value fails compose.
- scripts/cross_service_checks/staging.py: invariant staging-mirrors-prod
  with STAGING_DIFF_ALLOWLIST (registered by lane 1).
- deploy/staging/deploy.sh: GCS lock, git-archive of the integration SHA,
  fence tests + mirror check on that tree, in-cluster Redis (S2), Cloud
  Build as staging-builder, declarative gcloud run deploy, serving verify
  of OMI_BACKEND_RELEASE_SHA / OMI_RELEASE_TREE. Plus render_cloud_run.py,
  cloudbuild.yaml, redis.yaml; staging-account-deletion queue; builder
  read on the gcr.io base-image repo.
- staging_fence: pyright fixes; prod project number in the reference rule.

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

* test(staging): keep staging tests under the fast-unit CPU guard

Load runtime_env YAML with libyaml's SafeLoader when available (output
unchanged; compose --check passes), compose only prod in the
staging-mirrors-prod check, and import database._client at collection.

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

* feat(staging): lane 4 accessor on staging encryption and admin keys

agent-dev-operator gets secret-level secretAccessor on
staging-encryption-secret (mirror re-encryption) and staging-admin-key
(synthetic-user replay) only.

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

* fix(staging): explicit kubeconfig cleanup in bootstrap (RETURN trap fired under set -u)

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

* feat(staging): batch worker on dev's idle parakeet-pool L4s; redis scheduling

- charts/batch-pipeline-worker/staging_omi_batch-pipeline-worker_values.yaml:
  prod worker settings, staging image/SA/bucket/data plane, 2 replicas on
  parakeet-pool (never engine-pool).
- deploy/staging/worker_post_render.py: adds the staging identity and fence
  env to the shared chart's worker container (no chart edit).
- deploy.sh --with-worker: helm template + post-render + kubectl apply,
  rollout wait, release annotations; --teardown removes the worker.
- bootstrap_iam.sh: k8s secret staging/staging-batch-worker and worker
  accessor on staging-huggingface-token.
- redis.yaml: drop the default-pool selector (pool at max size).

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

* feat(staging): deploy.sh recreates a Pending staging-redis pod after a template change

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

* feat(staging): Cloud Build from an uploaded archive with --no-source

The agent can write objects in the staging bucket but cannot read bucket
metadata, which 'builds submit <dir>' needs. deploy.sh uploads the git
archive and the build's first step fetches it as staging-builder.

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

* fix(staging): build source straight from git archive (no macOS AppleDouble files)

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…end Store conformance (#22434)

* feat(jobstore): A0/A1 Postgres doc-mode Store, migrations, three-backend Store conformance

Adds database/jobstore (connection pool capped at 4, expand-only versioned
migrations with checksum + advisory lock, PostgresStore over the batch Store
protocol, SERIALIZABLE with bounded retry), testing/store_fixtures.py (the
store_backend fixture over sim, Firestore emulator and Postgres, local PG16
on a private unix socket) and tests/integration/test_store_conformance.py.
Postgres in CI needs an unnamed .github change (S6), so the postgres
parameter skips in GitHub CI and is proven locally.

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

* chore(jobstore): wire package imports so the dead-code ratchet sees the modules reachable

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

* chore(jobstore): public transaction helpers, typed fixture cleanup

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

* test(pipeline-sim): SimStore matches FirestoreStore on ready_predecessor, validation, conversation writes and projection scan

Closes the four gaps the Store conformance suite had strict-xfailed.

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

* chore(jobstore): psycopg is not in the lockfile yet; scope the pyright ignore to its imports

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

* chore(jobstore): keep the psycopg pyright ignores on the import line

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

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Git-on-my-level and others added 2 commits October 19, 2026 16:37
…ce on integration

#22446 (main) allowed the reason-ratio alert to land before its producers, with a test that
fails once a producer is declared. The lane-1 stub (#22420) already declares
omi_reason_unknown_total, so after the #22388 sync every integration PR failed
test_pending_backend_alert_metric_allowances_expire_when_the_producer_lands. Keep only
omi_reason_total pending; lane 14 (#22422) removes it when it lands the denominator.

Verified: pytest tests/unit/test_monitoring_alert_rule_contract.py, 60 passed (unit).

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

sync-backfill-lifecycle hard-coded SYNC_TASKS_QUEUE / SYNC_BACKFILL_TASKS_QUEUE
=sync-backfill, so every prod train re-pointed backend-sync-backfill (and
backend-sync's SYNC_BACKFILL_TASKS_QUEUE) at the queue retired after the
10-19 04:52Z stall; post_train_queue.sh re-applied the fix by hand. In prod the
worker now reads both values from backend/deploy/ops/prod.yaml through
ops_train.py render-env in the reviewed deploy-control source, failing closed
if they are missing. Dev keeps sync-backfill.

Failure-Class: none

Co-authored-by: Claude Opus 5.5 <[email protected]>
Git-on-my-level and others added 6 commits October 19, 2026 03:22
… retries (lane 9, C3) (#22462)

* refactor(enrichment): move the sr- outbox into utils/enrichment (C2 slice 1)

Plan C2, swarm lane 9. Pure move, no behaviour change:

- utils/sync/reprocess.py        -> utils/enrichment/outbox.py
- utils/sync/enrichment_custody.py -> utils/enrichment/custody.py
- utils/sync/enrichment_scan.py  -> utils/enrichment/scan.py

The old paths become sys.modules aliases of the new modules, so every
importer, mock.patch target and monkeypatch keeps reaching the same module
object. A star import gives pyright the public names. Batch projection
imports the new path; the frozen prod-track files (serving.py,
routers/batch_pipeline.py, batch_pipeline/enrichment.py) keep the shim until
their PRs reach integration.

Collection, document ids, field names and the sr- task prefix are unchanged
(contract (b) invariant 7). The query-shape driver and background-task
baseline follow the moved function.

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

* refactor(enrichment): drop the test-only custody and scan aliases

Only tests imported utils.sync.enrichment_custody and enrichment_scan, so the
dead-code ratchet counts the aliases as new dead files. The tests now import
utils.enrichment.scan directly; utils.sync.reprocess keeps its alias for the
production importers.

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

* test(enrichment): import the probe modules at collection time

The fast-unit CPU guard charged utils.cloud_tasks' first import to the probe
test's call phase (0.53s > 0.30s) once this file was selected. Module-level
imports keep the assertions unchanged and the call phase cheap.

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

* fix(enrichment): own the sr- callback and absorb lifecycle fences (C2 slice 3)

Plan C2, swarm lane 9. Batch enrichment no longer imports legacy
transcription (utils/sync/pipeline.py):

- utils/enrichment/callback.py: enrich_conversation, extracted verbatim from
  pipeline._reprocess_conversation_after_update with its webhook helper,
  persistence fence and lineage sentinel. pipeline.py is frozen behind
  #21932/#20662 and keeps its copy for the non-coalescing direct path, so
  test_enrichment_callback_parity.py (a static tripwire, labelled as such)
  keeps the two bodies identical until C11 deletes the legacy one. The new
  copy logs no conversation id.
- utils/enrichment/custody.py now owns discard_blocked. The batch adapter
  re-exports it for its existing importers.
- Absorbs #21968 (lead ruling 10-19): a SyncConversationPersistenceFenced
  from the callback settles the claim as superseded. The obligation is
  retired when no newer mark landed and re-armed when one did, and the
  handler ACKs 200 instead of answering 500 to a delivery that can never win.
  Other errors keep their taxonomy. #21968's conversation_id log line is not
  carried; the event is logged without identifiers.

Failure-Class: none

Verification (local unit, serial, nice 19):
- test_enrichment_callback_fence 4 passed (fenced+unchanged -> retired;
  fenced+newer mark -> re-armed; ValueError propagates; the default callback
  is the package)
- test_enrichment_callback_parity 3 passed
- test_batch_pipeline_serving 31 passed
- test_listen_finalization_cloud_tasks 278 passed
- test_sync_reprocess_coalesce 88 passed
- test_sync_enrichment_custody 10 passed
- test_background_task_ratchet, test_llm_gateway_coverage_guardrails and
  test_generated_compute_inventory_guardrails passed
- pyright 0 errors
- test_sync_reprocess_emulator now patches the package callback (CI emulator lane)

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

* feat(enrichment): Firestore Outbox for OutboxKind.ENRICHMENT (C2 slice 2)

Plan C2 / contract (b), swarm lane 9. database/outbox_firestore.py
implements the Outbox protocol over sync_reprocess_outbox, row-compatible
with mark/run: same collection, document ids, field names and sr- names.
Additive fields: policy_id, claim_attempts, a transient summary_seen_by.

- lease_token is the per-claim owner uuid and wake_token is task_token.
  heartbeat/ack/defer/release are fenced on both (invariant 1).
- claim_key: privacy discard first (invariant 6), then demand admission,
  a stale or busy check, and a not-due re-arm that wakes itself and returns
  DEFERRED. Wake ownership follows the lead's 10-19 ruling: this
  implementation creates the tasks through the existing _enqueue.
- ack keeps today's finish rules: retire when unchanged, a dormant receipt
  when record_summary marked the lease, re-arm when the version moved.
- enqueue shares mark's CAS operation (mark_update), with explicit
  available_at and min/max coalescing (invariant 3). With tx= it writes in
  the caller's transaction and returns the wake token; the caller calls
  wake() after commit (invariants 4-5). wake() is idempotent per token.
- sweep delegates to the existing sweep with a privacy discard hook. Pull
  claim() goes through the new utils.enrichment.outbox.due_rows
  (single-field due_at index), registered in the query-shape drivers.

Batch projection's mark_enrichment now calls enqueue(tx=...) and then
wake(), using its own client for both. A backfill binding is still resolved
only for a new row (new_dispatch callable), so a coalesced append never
raises on a missing backfill env, as before.

database.outbox.outbox_for is lane 1's stub; firestore_outbox(kind) is the
implementation it should return (wiring requested from the captain).

Verification (local unit, serial, nice 19):
- test_outbox_firestore 13 passed
- test_batch_pipeline_projection 40 passed
- test_sync_reprocess_coalesce 88 passed
- test_firestore_query_shapes 481 passed
- the outside-query, runtime-witness and index-oracle suites passed
- test_listen_finalization_cloud_tasks 278 passed
- pyright 0 errors
The emulator conformance suite is lane 12's and has not landed yet.

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

* feat(enrichment): outbox_for selects the Firestore enrichment outbox

Lane 1 signed off on this one-function edit of its stub (10-19): in this
window the selector always returns the Firestore implementation; the
BATCH_JOBSTORE_MODE switch is lane 12's.

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

* feat(enrichment): /v2/enrichment/run on the outbox consumer, 409-only retries (C3)

Plan C3 / contracts (a) and (d), swarm lane 9.

- utils/enrichment/consumer.py: EnrichmentConsumer, a QueueConsumer for
  OutboxKind.ENRICHMENT (workers role; 120s lease, 30s heartbeat on every
  lease). It mirrors reprocess.run outcome for outcome, with settlement
  through the Outbox calls:
  - processed -> DONE (ack; a dormant receipt via record_summary);
  - superseded or lifecycle fence -> DISCARDED;
  - repair race -> outbox.repair;
  - live target or missing conversation -> DEFERRED +120s;
  - redirect -> custody transfer;
  - empty budget spent -> retired;
  - callback pending or empty output -> RETRY callback_pending (409; release
    keeps the wake for the queue retry).
- routers/enrichment.py: POST /v2/enrichment/run with OIDC for the
  enrichment queue (TaskEdge enrichment). It accepts the legacy
  {"kind":"sync_reprocess",...} payload, so rows bound to either handler
  drain. 400 for a malformed task; 500 only for unexpected exceptions.
- config/enrichment.py: ENRICHMENT_ROUTE (sync_handler | enrichment_queue,
  default sync_handler) is the deployment default for the policy field
  enrichment_route until E1 records it per unit. ENRICHMENT_TASKS_* is the
  queue binding. An incomplete binding falls back to the sync handler and
  is counted through record_fallback.
- valid_dispatch_binding and _enqueue accept both handler paths (contract
  (b) invariant 7).

The router mount in main.py is lane 1's. Queue spec for lane 7: enrichment,
max-concurrent 50, 25/s, backoff 10-300s, unlimited attempts.

Verification (local unit, serial, nice 19):
- test_enrichment_route 12 passed (409 callback_pending keeps the wake;
  fence -> superseded; live defer -> new wake; 400s; stale wake -> 200;
  unexpected -> 5xx with the lease kept; route binding with fallback)
- test_outbox_firestore 14 passed
- test_sync_reprocess_coalesce 88 passed
- test_cross_service_deploy_contract and test_background_task_ratchet passed
- pyright 0 errors

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

* fix(enrichment): match moved retry classes so callback-pending stays 409

#22371 classifies expected enrichment retries by (defining module, class
name). #22431 moved FirstSummaryCallbackPending to utils.enrichment.outbox,
so on integration a callback-pending delivery fell through to the
unexpected branch and answered 500. That is the fast-5xx shape that
throttled the queues on 10-18 and 10-19. Match the new defining modules,
and keep the legacy pipeline fence until pipeline.py is deleted.

Failure-Class: none

Verification: test_batch_pipeline_serving 38 passed (it failed with
500 != 409 before this change on the merged integration tree).

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

* feat(enrichment): FirestoreOutbox factory with injected client, privacy check and wake

For lane 12's outbox conformance suite (build_outbox_backend('emulator')):
FirestoreOutbox(kind, client=, privacy_blocked=, create_wake=) binds every
CAS, the sweep and every wake to the injected seams. The default instance
keeps the production paths (discard_blocked, _enqueue, the shared client).
outbox._cas is the client-explicit CAS behind _mutate, and sweep takes
client=/wake= for the same purpose.

A not-due claim_key deferral leaves claim_attempts untouched (attempt stays
1 on the first real claim), as reprocess does today; there is a test for it.

Verification: test_outbox_firestore 16 passed, test_batch_pipeline_projection
40, test_sync_reprocess_coalesce 88, test_firestore_query_shapes 481,
test_sync_enrichment_custody 10; pyright 0 errors.

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

* test(enrichment): a not-due wake re-arms and answers 200 not_due

Exercises #22437's claim_key DEFERRED mapping end to end through
/v2/enrichment/run: the outbox re-arms with a new wake and the delivery is
consumed, not retried.

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

* test(enrichment): load the callback at collection time in the route tests

The fast-unit CPU guard charged process_conversation's first import to the
first route test (6.8s > 0.30s).

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
 sync)

Conflict in .github/actions/sync-backfill-lifecycle/action.yml: main's #22460 and lane 7's B4
(#22455) both stop trains re-pointing backfill at the retired sync-backfill queue. Resolved to
one resolution step (ops-queues): prod reads the ops file (fail-closed, lane 7); other projects
take the manifest's SYNC_BACKFILL_TASKS_QUEUE/SYNC_TASKS_QUEUE (main), sync-backfill only as
default. The queue reconcile step keeps main's manifest-driven queue name. #22460's test is
adapted to the single resolution step.
…ue (#22460)

main's #22460 moved prod SYNC_TASKS_QUEUE to sync-jobs-fresh, so deleting only the sync-jobs
mapping no longer leaves the prod queue unmapped. Unmap both legacy names.

Verified: test_staging_overlay.py + test_staging_fence.py 33 passed; staging-mirrors-prod 0 diffs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ad selection (#22475)

* test(staging): F1 Cloud Tasks throttle model + task-target retry invariant (lane 4)

Contract (d), plan F F1, cross-plan L5. First merges after the stubs.

- testing/fakes/cloud_tasks_queue.py: virtual-clock Cloud Tasks queue
  (token bucket, concurrency, retry backoff/max attempts, named-task
  dedupe) with an AIMD system throttle on 429/503 or a high fast-5xx
  share; a config PATCH caps but never resets it. Scenarios
  enrichment_fast_500_throttle (10-18 18:14Z sync-jobs) and
  sync_backfill_0452 (10-19 04:52Z sync-backfill) drive the REAL
  routers.batch_pipeline.enrichment_response for an expected
  first-summary wait. At 733a74a^ (pre-#22371, 500) the 1h run strands
  10,002 direct jobs at 0.1/s (prod 10-18: 10,399 at 0.1/s) and 2,322
  backfill jobs (prod 04:52Z: 3,552); at 733a74a (409) both keep the
  configured rate and drain.
- scripts/cross_service_checks/task_targets.py:
  check_task_target_retry_semantics(ctx), registered by #22420. AST scan
  of each TaskEdge handler and the router helpers it calls: 429/503
  anywhere, 500 outside an except-Exception fallback, ExpectedRetry not
  answered by retry_response. Keys carry no line numbers.

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

* chore(contract): accept the 12 existing task-target retry violators (lane 4, contract (d))

Lane 1 ruling: F1 carries its own known-gap entries. Keys are the
contract (d) violator table plus the audit-only finalization and
account-deletion targets; new keys still fail.

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

* fix(staging): mirror run record no longer deep-copies the stats lock

dataclasses.asdict deep-copies a threading.Lock and raised after the copy
finished, so the first live run wrote objects and the manifest but no
workspace record. Idempotent rerun fills it in.

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

* feat(staging): archive mirror reads only chunks/<owner>/ and can spread across history

David's 10-19 grant is conditioned to chunks/<uid>/ in omi-private-cloud-sync;
the mirror no longer lists raw-sync/ or raw-mobile-batch/ there. --family,
--spread and --max-group-mb pick parity conversations evenly across his
capture history (rows 1b/2) instead of only the newest.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…legates to the consumer (lane 9) (#22476)

* refactor(enrichment): move the sr- outbox into utils/enrichment (C2 slice 1)

Plan C2, swarm lane 9. Pure move, no behaviour change:

- utils/sync/reprocess.py        -> utils/enrichment/outbox.py
- utils/sync/enrichment_custody.py -> utils/enrichment/custody.py
- utils/sync/enrichment_scan.py  -> utils/enrichment/scan.py

The old paths become sys.modules aliases of the new modules, so every
importer, mock.patch target and monkeypatch keeps reaching the same module
object. A star import gives pyright the public names. Batch projection
imports the new path; the frozen prod-track files (serving.py,
routers/batch_pipeline.py, batch_pipeline/enrichment.py) keep the shim until
their PRs reach integration.

Collection, document ids, field names and the sr- task prefix are unchanged
(contract (b) invariant 7). The query-shape driver and background-task
baseline follow the moved function.

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

* refactor(enrichment): drop the test-only custody and scan aliases

Only tests imported utils.sync.enrichment_custody and enrichment_scan, so the
dead-code ratchet counts the aliases as new dead files. The tests now import
utils.enrichment.scan directly; utils.sync.reprocess keeps its alias for the
production importers.

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

* test(enrichment): import the probe modules at collection time

The fast-unit CPU guard charged utils.cloud_tasks' first import to the probe
test's call phase (0.53s > 0.30s) once this file was selected. Module-level
imports keep the assertions unchanged and the call phase cheap.

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

* fix(enrichment): own the sr- callback and absorb lifecycle fences (C2 slice 3)

Plan C2, swarm lane 9. Batch enrichment no longer imports legacy
transcription (utils/sync/pipeline.py):

- utils/enrichment/callback.py: enrich_conversation, extracted verbatim from
  pipeline._reprocess_conversation_after_update with its webhook helper,
  persistence fence and lineage sentinel. pipeline.py is frozen behind
  #21932/#20662 and keeps its copy for the non-coalescing direct path, so
  test_enrichment_callback_parity.py (a static tripwire, labelled as such)
  keeps the two bodies identical until C11 deletes the legacy one. The new
  copy logs no conversation id.
- utils/enrichment/custody.py now owns discard_blocked. The batch adapter
  re-exports it for its existing importers.
- Absorbs #21968 (lead ruling 10-19): a SyncConversationPersistenceFenced
  from the callback settles the claim as superseded. The obligation is
  retired when no newer mark landed and re-armed when one did, and the
  handler ACKs 200 instead of answering 500 to a delivery that can never win.
  Other errors keep their taxonomy. #21968's conversation_id log line is not
  carried; the event is logged without identifiers.

Failure-Class: none

Verification (local unit, serial, nice 19):
- test_enrichment_callback_fence 4 passed (fenced+unchanged -> retired;
  fenced+newer mark -> re-armed; ValueError propagates; the default callback
  is the package)
- test_enrichment_callback_parity 3 passed
- test_batch_pipeline_serving 31 passed
- test_listen_finalization_cloud_tasks 278 passed
- test_sync_reprocess_coalesce 88 passed
- test_sync_enrichment_custody 10 passed
- test_background_task_ratchet, test_llm_gateway_coverage_guardrails and
  test_generated_compute_inventory_guardrails passed
- pyright 0 errors
- test_sync_reprocess_emulator now patches the package callback (CI emulator lane)

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

* feat(enrichment): Firestore Outbox for OutboxKind.ENRICHMENT (C2 slice 2)

Plan C2 / contract (b), swarm lane 9. database/outbox_firestore.py
implements the Outbox protocol over sync_reprocess_outbox, row-compatible
with mark/run: same collection, document ids, field names and sr- names.
Additive fields: policy_id, claim_attempts, a transient summary_seen_by.

- lease_token is the per-claim owner uuid and wake_token is task_token.
  heartbeat/ack/defer/release are fenced on both (invariant 1).
- claim_key: privacy discard first (invariant 6), then demand admission,
  a stale or busy check, and a not-due re-arm that wakes itself and returns
  DEFERRED. Wake ownership follows the lead's 10-19 ruling: this
  implementation creates the tasks through the existing _enqueue.
- ack keeps today's finish rules: retire when unchanged, a dormant receipt
  when record_summary marked the lease, re-arm when the version moved.
- enqueue shares mark's CAS operation (mark_update), with explicit
  available_at and min/max coalescing (invariant 3). With tx= it writes in
  the caller's transaction and returns the wake token; the caller calls
  wake() after commit (invariants 4-5). wake() is idempotent per token.
- sweep delegates to the existing sweep with a privacy discard hook. Pull
  claim() goes through the new utils.enrichment.outbox.due_rows
  (single-field due_at index), registered in the query-shape drivers.

Batch projection's mark_enrichment now calls enqueue(tx=...) and then
wake(), using its own client for both. A backfill binding is still resolved
only for a new row (new_dispatch callable), so a coalesced append never
raises on a missing backfill env, as before.

database.outbox.outbox_for is lane 1's stub; firestore_outbox(kind) is the
implementation it should return (wiring requested from the captain).

Verification (local unit, serial, nice 19):
- test_outbox_firestore 13 passed
- test_batch_pipeline_projection 40 passed
- test_sync_reprocess_coalesce 88 passed
- test_firestore_query_shapes 481 passed
- the outside-query, runtime-witness and index-oracle suites passed
- test_listen_finalization_cloud_tasks 278 passed
- pyright 0 errors
The emulator conformance suite is lane 12's and has not landed yet.

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

* feat(enrichment): outbox_for selects the Firestore enrichment outbox

Lane 1 signed off on this one-function edit of its stub (10-19): in this
window the selector always returns the Firestore implementation; the
BATCH_JOBSTORE_MODE switch is lane 12's.

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

* feat(enrichment): /v2/enrichment/run on the outbox consumer, 409-only retries (C3)

Plan C3 / contracts (a) and (d), swarm lane 9.

- utils/enrichment/consumer.py: EnrichmentConsumer, a QueueConsumer for
  OutboxKind.ENRICHMENT (workers role; 120s lease, 30s heartbeat on every
  lease). It mirrors reprocess.run outcome for outcome, with settlement
  through the Outbox calls:
  - processed -> DONE (ack; a dormant receipt via record_summary);
  - superseded or lifecycle fence -> DISCARDED;
  - repair race -> outbox.repair;
  - live target or missing conversation -> DEFERRED +120s;
  - redirect -> custody transfer;
  - empty budget spent -> retired;
  - callback pending or empty output -> RETRY callback_pending (409; release
    keeps the wake for the queue retry).
- routers/enrichment.py: POST /v2/enrichment/run with OIDC for the
  enrichment queue (TaskEdge enrichment). It accepts the legacy
  {"kind":"sync_reprocess",...} payload, so rows bound to either handler
  drain. 400 for a malformed task; 500 only for unexpected exceptions.
- config/enrichment.py: ENRICHMENT_ROUTE (sync_handler | enrichment_queue,
  default sync_handler) is the deployment default for the policy field
  enrichment_route until E1 records it per unit. ENRICHMENT_TASKS_* is the
  queue binding. An incomplete binding falls back to the sync handler and
  is counted through record_fallback.
- valid_dispatch_binding and _enqueue accept both handler paths (contract
  (b) invariant 7).

The router mount in main.py is lane 1's. Queue spec for lane 7: enrichment,
max-concurrent 50, 25/s, backoff 10-300s, unlimited attempts.

Verification (local unit, serial, nice 19):
- test_enrichment_route 12 passed (409 callback_pending keeps the wake;
  fence -> superseded; live defer -> new wake; 400s; stale wake -> 200;
  unexpected -> 5xx with the lease kept; route binding with fallback)
- test_outbox_firestore 14 passed
- test_sync_reprocess_coalesce 88 passed
- test_cross_service_deploy_contract and test_background_task_ratchet passed
- pyright 0 errors

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

* fix(enrichment): match moved retry classes so callback-pending stays 409

#22371 classifies expected enrichment retries by (defining module, class
name). #22431 moved FirstSummaryCallbackPending to utils.enrichment.outbox,
so on integration a callback-pending delivery fell through to the
unexpected branch and answered 500. That is the fast-5xx shape that
throttled the queues on 10-18 and 10-19. Match the new defining modules,
and keep the legacy pipeline fence until pipeline.py is deleted.

Failure-Class: none

Verification: test_batch_pipeline_serving 38 passed (it failed with
500 != 409 before this change on the merged integration tree).

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

* feat(enrichment): FirestoreOutbox factory with injected client, privacy check and wake

For lane 12's outbox conformance suite (build_outbox_backend('emulator')):
FirestoreOutbox(kind, client=, privacy_blocked=, create_wake=) binds every
CAS, the sweep and every wake to the injected seams. The default instance
keeps the production paths (discard_blocked, _enqueue, the shared client).
outbox._cas is the client-explicit CAS behind _mutate, and sweep takes
client=/wake= for the same purpose.

A not-due claim_key deferral leaves claim_attempts untouched (attempt stays
1 on the first real claim), as reprocess does today; there is a test for it.

Verification: test_outbox_firestore 16 passed, test_batch_pipeline_projection
40, test_sync_reprocess_coalesce 88, test_firestore_query_shapes 481,
test_sync_enrichment_custody 10; pyright 0 errors.

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

* test(enrichment): a not-due wake re-arms and answers 200 not_due

Exercises #22437's claim_key DEFERRED mapping end to end through
/v2/enrichment/run: the outbox re-arms with a new wake and the delivery is
consumed, not retried.

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

* test(enrichment): load the callback at collection time in the route tests

The fast-unit CPU guard charged process_conversation's first import to the
first route test (6.8s > 0.30s).

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

* fix(batch): recover-quarantine kill switch answers 409; legacy sr- delegates to the consumer

Contract (d), swarm lane 9:
- /v2/batch-pipeline/recover-quarantine returned 503 for "recovery
  disabled" (host or owner). Cloud Tasks system-throttles a queue that
  sees fast 5xx/503 (10-18 18:14Z, 10-19 04:52Z stalls). A switched-off
  target now answers 409 {"status":"retry","reason":"kill_switch_off"}.
  Behaviour is otherwise unchanged: the intent stays prepared, nothing is
  spent, and the queue retries.
- enrichment_response (the legacy /v2/sync-jobs/run sync_reprocess
  delivery) runs through the C3 EnrichmentConsumer when
  ENRICHMENT_ROUTE=enrichment_queue, so one lever moves new rows onto the
  enrichment queue and drains old bindings through the same state
  machine. Default sync_handler keeps today's reprocess.run path.

Failure-Class: none

Verification (local unit, serial, nice 19):
- test_batch_pipeline_quarantine_recovery 67 passed (the disabled-host,
  -cohort and -missing cases assert 409 kill_switch_off)
- test_enrichment_route 14 passed (incl. legacy-handler delegation)
- test_batch_pipeline_serving 39 passed
- test_revision_drain_harness 7 passed
- test_cross_service_deploy_contract 18 passed

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Git-on-my-level and others added 9 commits October 21, 2026 17:57
Main's role-image dependency probe (python role images) checks every third-party
module reachable from the pusher entrypoint. On integration, database.users reaches
database.jobstore through batch_pipeline_purge -> batch_pipeline_shadow_hook. The
import is lazy, but the probe requires psycopg to be installed. The pin matches
backend/requirements.txt and pylock.runtime.toml (#22440). Only the pusher lock changes.

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

#22226's test patched CONVERSATION_STRUCTURE_TIMEOUT_SECONDS to 0.1s, under the
real-clock ratchet's 0.5s floor, turning Backend unit guardrails red on main.
Scale the per-attempt deadline to 0.5s and the slow turn to 0.75s: still past
one attempt and inside the mount's 3x recovery budget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 1f62393)
Final main merge before the M3 integration->main PR (main moved 131 commits past
sync 15's base 31756b9). Resolutions:
- routers/sync.py: keep integration's batch_attempted bookkeeping and main's
  durable-batch-owner policy override (replace(candidate_policy, batch_enabled=True)).
- utils/batch_pipeline/intake.py: main's owner-load filter (policy.batch_enabled)
  returns to legacy only while legacy_sync is on; when draining/dark the upload stays
  on batch (contract (h)). Main's prerecorded language guard likewise applies only
  with legacy on; otherwise the C8 provider-STT route serves unsupported speech.
  input_language is always computed (main's per-unit language resolution uses it).
- utils/batch_pipeline/errors.py: keep the reasons.py enums; add
  WorkerValidationReason.UNSUPPORTED_LANGUAGE (main's new reason).
- retention.py: integration's mirror_refresh plus main's shadow-artifact delete.
- policy/guard.py, route_policy_manifest.yaml, GMP sync regex and its test,
  feature-flags.yaml (main's newer EPISODES_* rows win), registry re-rendered,
  label-debt ratchet (+1 episodes metrics row).
- tests: BatchUnitPolicy(batch_enabled=True, ...) for main's batch_enabled filter.
M3 prep in the same commit:
- .github/ci-budget.yaml: +1 p50 minute on four gcp_backend.yml jobs whose
  triggers B5 widened (check_ci_budget --base origin/main now passes).
- dead-code backend allowlist: remove the 7 swarm contract-stub entries (L01-4);
  every one now has importers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Integration's retention pass records touched artifact ids for the A2 mirror
refresh; main's new shadow cleanup test used an id-less fake.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's desktop changes shipped with their own fragments, which main has already
consolidated into releases. The gate compares against integration, so it needs one here.

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

Main's pipeline_sim now traces WorkItem.shadow; the only golden change is
"shadow": false on each provider_stt item (7 per file).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…probe proof (lead cfcaba)

- #23038's intake tests pass a real BatchUnitPolicy: integration's intake records the
  route with dataclasses.replace (contract (c)), which a SimpleNamespace cannot take.
- New test_legacy_off_keeps_language_probe_and_never_parakeet_for_unsupported: with
  legacy sync draining or dark, a declared unsupported language takes the C8 provider
  (Modulate) route and never Parakeet; unknown speech is not sent to legacy, runs the
  bounded language-ID probe on the CPU host and is frozen 'und' when uncertain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ok runs (lead 66dba9)

test_pre_push_ci_verified.py's clean_env copied os.environ, so a lane push with
PRE_PUSH_BASE_BRANCH=integration/legacy-retire (swarm push-lane) made five temp-repo
hook runs look for that branch and fail. Pop PRE_PUSH_BASE_BRANCH and OMI_PR_BODY_FILE.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…M3 merge)

Integration builds ALLOWED_REASONS from the FallbackReason enum and main's baseline
now uses LIVE_STT_FAILURE_REASONS, so the merged import was unused (pyright
reportUnusedImport in the backend typecheck gate).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level and others added 7 commits October 21, 2026 23:02
…s shadow env reads (M3 merge)

- backend/deploy/ops/{prod,staging}.yaml: DREAM_AGENT_PASSES_PER_DAY 6 -> 48 on
  backend-sync-backfill, matching main's #23016 manifest change; test_config_train
  requires the ops file and the prod manifest to agree.
- batch_stage_env_baseline.json: main's batch shadow reads (compute_client.shadow_from_env,
  ShadowRunner.__init__), annotated.

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

fleet_gate (omi-workspace 3172987) added two verdict tokens:
unsafe_parakeet_language_route (cohort audio routed to Parakeet in an
unknown/unsupported language) and language_route_unknown (completed units
without route evidence). Both are deliberate fail-closed verdicts like
recovery_spend_unknown and quarantine_projection_p95_unknown, not gate read
errors, so the closed COHORT_FAIL list must roll back one step on them;
unclassified they HOLD as "gate unavailable" (C1) and a failing cohort stays
on. Tests pin both tokens in FLEET_GATE_VERDICT_FAIL_TOKENS and assert
ROLLBACK_ONE, not hold.
…weep + draining gates (#23082)

* fix(sync): M3 review (Luna) — read the legacy mode off the loop; ACK a legacy final-pass owner like intake

- sync_local_files_v2 read legacy_dark.current_mode() on the event loop, where the
  ramp cache never waits: a cold instance served the 'on' default and could admit
  legacy work after the ramp went draining/dark. Read it through run_blocking, as
  batch intake does, so the first read gets its bounded cold wait.
- In draining/dark, a conversation owned by legacy_final_pass_v1 with no content-ledger
  row fell through to admission_refused (error log, retry_later). Give it intake's
  ACK (LEGACY_ACTIVE: the shipped in-progress 409); still no legacy job.

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

* fix(provider-stt): M3 review (GLM P1) — sweep the provider-STT outbox; gate draining on C8 and final-pass re-home

- routers/enrichment.maintain() also sweeps outbox_for(PROVIDER_STT): intake swallows a
  lost post-commit wake and relies on this sweep (contract (b), invariant 4), which had no
  invoker. Its failure is counted and isolated from the enrichment and summary-debt halves.
- DRAINING_PRECONDITIONS gains provider_stt_live (queue, PROVIDER_STT_TASKS_* env and the
  maintenance job live in prod) and legacy_final_pass_rehomed (lead ruling b209a5), so
  ramp_set cannot leave 'on' before either; the runbook lists both.
Prod stays legacy_sync 'on' after M3, where intake never creates provider units.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…t failures (#23083)

## Summary
- ramp controller: classify the P26 language-route gate tokens as cohort
failures

Branch `lr/06-ramp-tokens` into `integration/legacy-retire`.

fleet_gate (omi-workspace 3172987) added the verdict tokens
`unsafe_parakeet_language_route` and `language_route_unknown`. Both are
deliberate fail-closed cohort verdicts (like `recovery_spend_unknown`),
not
gate read errors, so they join `COHORT_FAIL_TOKENS` (ROLLBACK_ONE); left
unclassified the controller HOLDs as "gate unavailable" (C1) and a
failing
cohort stays on. No other gate, floor, or list is changed.

## Lane / contract
Lane 06, contract(s) g (fleet-gate verdict tokens -> controller action);
owner sign-offs for edits to other lanes' files: none

## Product invariants affected
- INV-DATA-1: path match only, inherited from integration/main merges;
this PR's own diff does not touch its locked paths.
This change does not alter the Firebase/Firestore project or serving
endpoints.

## Verification
94 targeted checks passed in `tests/unit/test_ramp_controller.py`
(backend/test.sh with BACKEND_UNIT_TEST_FILE_LIST, local .venv layer,
omi-heavy/nice), including new parametrized cases asserting both tokens
ROLLBACK_ONE and never HOLD as gate-unavailable. Not run locally: the
full PR CI matrix; no gate/script under infra/rollout changed here.

## Rollback
Revert the commit; the classification is pure closed-list membership in
ramp_controller.py, no flag or migration involved.

Failure-Class: none


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/23083?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/23083?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F23083&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
…the backend stack lock; prod ledger cutover joins prod-train (B5) (#23086)

- config_train.yml: break-glass falls back to deploy-backend-stack-<env>, the lock a
  break-glass gcp_backend.yml run takes; both mutate the same Cloud Run services and queues.
- sync_ledger_fence_cutover.yml: its comment requires sharing the backend mutation domain,
  but B5 moved prod backend deploys to prod-train. Prod now takes prod-train, with a
  break_glass_lock input that falls back to the backend stack lock (gcp_backend.yml's shape).
- check-deployment-concurrency.py: the cutover script is a recognized writer, has a lock
  contract and is an audited prod-train writer; config_train's break-glass lock updated.
- ci-budget: cutover trigger change recorded (+1 p50 minute, rationale); the cutover
  workflow test asserts the new group.
David named B4/B5; lead ruling 5f60b3 places both inside that naming.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Main moved 108 commits past the M3 prep merge (b859b78); one conflict:
- backend/utils/stt/live_reason.py: keep integration's LiveSttReason-backed sets and add
  main's #23074 local-delivery death reasons (send_queue_full, replay_send_stalled,
  delivery_expired) as LiveSttReason members plus main's LOCAL_DELIVERY_* constants.
Label-debt ratchet: +2 rows (#23074 breaker trip causes), for lane 14.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ration enums; break the live_reason import cycle (M3 final merge)

- FallbackReason gains send_queue_full, replay_send_stalled, delivery_expired (already in
  LiveSttReason), so record_fallback keeps them instead of 'other'.
- fallback.initialize_live_stt_exhausted_children builds the live failure set from the
  LiveSttReason enum: it runs at import, and importing utils.stt.live_reason there cycles
  when live_reason loads first (main's provider_resilience import order).
- test_reason_label_enums: the live vocabulary is 36 with #23074.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level and others added 2 commits October 22, 2026 02:54
…ls.observability (M3 final merge)

routers.chat -> utils.stt.provider_resilience -> utils.stt.live_reason now imports
utils.observability.reasons (main #23074 x integration's reason enums). The chat router
harness stubs utils.observability as a plain module, so ~60 chat/messaging tests failed
with 'utils.observability is not a package'. Load reasons.py once per process (it
registers omi_reason_total) and install it under the stub.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main moved 16 commits past 34ce402 while #23096 ran CI; the only conflict was the
generated backend/docs/feature-flag-registry.md, re-rendered as of 2026-10-21
(check_feature_flag_registry.py passes). CI budget vs main and the label ratchet pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level and others added 2 commits October 22, 2026 04:01
…ichment callback (M3 final round 2)

Main 4c7ccd0 switched the legacy copy (utils/sync/pipeline._reprocess_conversation_after_update)
to lifecycle_service.rule_discard_outcome so admitted first-summary wakes stop looping on
review rows; test_enrichment_callback_parity requires the C2 enrichment copy to match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the CPU guard (2nd trip)

1.16-1.28s CPU on integration CI shard 2 in two consecutive runs of #23133 (0.25s
locally; green on main's shards). Second trip -> allowlist per the lane-1 flake policy,
with a removal note.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level marked this pull request as ready for review October 21, 2026 23:49
@Git-on-my-level
Git-on-my-level merged commit f561c18 into main Oct 21, 2026
127 of 136 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-21T23:52:36.866598Z 8d062ad Draft marked ready
ℹ️ 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
Git-on-my-level deleted the integration/legacy-retire branch October 21, 2026 23:50
Git-on-my-level added a commit that referenced this pull request Oct 22, 2026
… legacy is draining/dark (P46, lead b209a5) (#23129)

## What changed and why

Retargeted to `main` after M3 (#22427) merged (lead ruling c7d947:
merging into integration first would have re-gated M3's staging check);
the branch's base c13818a is contained in main's merge commit, and
main's line counts for the two declared files match the exceptions
below.

After legacy sync goes `draining`/`dark`, a conversation whose
`record_lane_owner` is still `legacy_final_pass_v1` routes LEGACY, no
legacy job may be created, and every later upload for it is answered
with the in-progress 409 (router fence and batch intake alike), so the
phone keeps that WAL audio for good (M3 Luna review, verified by lane 1;
lead ruling b209a5 made the re-home a gate for the draining/dark step).
This PR is the re-home: `utils/sync/final_pass_rehome.py` moves the
owner to `batch_sync_v1` with the same revision-fenced
`claim_record_lane_owner` CAS every owner transition uses, when no live
legacy job holds the uid, and the upload is then admitted through the
unchanged batch intake. It is wired at both routing points,
`registered_record_response` (the route the router follows; it now
receives the mode the router already read) and intake's own
`legacy_final_pass_v1` branch (the no-owner-discovery dark path). A held
re-home keeps today's ACK, so the client retries.
`scripts/legacy_dark/final_pass_rehome.py` sweeps the pre-flip stock
(dry run by default) and is the evidence for the
`legacy_final_pass_rehomed` precondition; it needs the new
`conversations.record_lane_owner` collection-group field index (registry
+ regenerated manifest). Prod stays `on`: nothing here runs at `on`
except the explicit operator sweep.

**Is the state reachable?** Yes, three ways, all from code on
integration:
1. `live_upload.registered_record_response` claims
`legacy_final_pass_v1` for an ownerless conversation's first WAL upload
whenever the uid's batch policy is not enabled (the batch ramp before
100%, and owner-load narrowing after). Every such conversation keeps
that owner; its later WAL segments (a late tail, a reconnect after a
long offline period, a retry) route LEGACY.
2. `transcription_shadow._claim_shadow_owner` claims it before the final
pass transcribes. The pass is an in-process background task with no
durable retry (`maybe_start_shadow` -> `start_background_task`; an
exception only logs `outcome=failed`), and nothing clears the owner on
completion or death: `_write_processing_result` preserves
`record_lane_owner`, and no code path pops it. A completed or dead final
pass leaves the owner on the conversation forever.
3. A legacy sync job that died leaves its ledger claim to expire but
never changes the conversation owner.
The M2 staging cycle did not exercise this state:
`omi_legacy_dark_ack_total` rose by 0 during `dark` (no legacy-owned
content was re-uploaded) because the m2reh3/m2reh4 replay conversations
were batch-routed, so the 244/244 zero-lost result neither covers nor
contradicts it. The lane 1 M3 verification states the 409 behaviour in
both call sites. Sizing the prod stock needs the new index
(`final_pass_rehome --env prod` dry run on `ro-prod` after
`reconcile_firestore_indexes.py --provision-missing`); once this
deploys, `omi_legacy_dark_ack_total{reason="legacy_final_pass_rehomed"}`
is the live count.

**No new owner after the gate (M3 re-review scope add, forwarded by the
lead).** Both writers of `legacy_final_pass_v1` minted owners without
reading `legacy_sync`, so the re-home gate could be passed and new
stranded owners created afterwards. Second commit:
`transcription_shadow._claim_shadow_owner` outside `on` makes no claim
and starts no pass for an unowned conversation (it stays unowned for
batch admission to claim; an owner that already exists keeps its pass
until the next upload re-homes it), and `live_upload`'s ownerless-upload
claim for a narrowed uid (batch policy off) takes `batch_sync_v1`
outside `on` (intake widens such an upload onto batch anyway); the mode
is read only when the policy would otherwise pick legacy.

**Luna round 2 (FIX-FIRST, the round cap) and the fixes, fourth
commit.** Both P1s share one root: the re-home was not serialized with
legacy job creation, and the 300 s grace was assumed, not enforced.
- P1, stale `on` outliving the grace: the router now re-reads the legacy
mode before creating a legacy job whenever its first read is older than
`legacy_dark.ADMISSION_REVALIDATE_SECONDS` (60 s). With the 30 s ramp
cache no stale `on` can create a legacy job later than 90 s after a
flip, so the 300 s grace on upload re-homes is a hard bound with margin
(asserted by test: grace > revalidate + cache TTL). The re-read is a
cached, off-loop read; `on` gains no write.
- P1, the sweep racing live admission at `on`: the sweep cannot
serialize with an in-flight legacy upload from an operator shell, so its
`--apply` now refuses `on` and the grace, and runs only when the ramp
serves `draining`/`dark` at least 300 s past its last write
(`served_ramp` reads the env entry as `ramp_set --show` does). There
legacy admission is quiesced (no new legacy job can start beside the
sweep), the per-uid ledger probe is exact for what remains, and the
upload path re-homes anything still held later. A dry run at `on` sizes
the stock. **This changes what the `legacy_final_pass_rehomed` draining
precondition can mean** (it is confirmed on leaving `on` when the
re-home serves on every revision and the dry run has sized the stock;
the sweep is applied in `draining` and must read `CLEAR` before `dark`):
the ramp_controller text and the runbook (`on` → `draining` and
`draining` → `dark`) say so. Lead ruling requested on the bus; the gate
id and `ramp_set` mechanics are unchanged.
- P2: the quiet-window count holds a uid only for recent legacy ledger
rows; `batch_v1` and `stt_cap_hold_v1` rows no longer keep active users
uncleared.
- Tests: a stale mode read is re-validated before a legacy job (draining
by then means the fence, no job) and a young read is taken once; the
grace/revalidate/TTL invariant; `apply_refusal` over `on` / unknown /
inside the grace / draining at the grace / dark; `served_ramp` parsing;
`main --apply` at `on` refuses before touching a conversation; recent
batch and cap-hold rows do not hold a uid.

**Luna round 1 (FIX-FIRST) and the fixes, third commit.**
- P1, stale mode at the flip: a request that read `on` just before the
flip can still create a legacy job after it, invisible to the live-job
probe until created, while a draining request re-homes the same
conversation. `upload_rehome` now holds until the ramp document is
`FLIP_GRACE_SECONDS` (300) old (`legacy_dark.mode_age_seconds`; an
unknown age holds); every such request is long over by then (the mode is
read once per request from a 30s cache), so the probe sees every
boundary job before any re-home. Both upload call sites go through
`upload_rehome`.
- P1, stale sweep cache: the sweep runs at `on` beside live legacy
admission, so its ledger probe is read fresh for every conversation (no
per-uid cache) and any ledger row created in the last `QUIET_SECONDS`
(600) holds the uid as well.
- P2, false CLEAR under `--limit`: a capped scan reports `PARTIAL` (exit
1), never `CLEAR`.
- Tests: grace hold at 0 s / 299 s / unknown with no read, re-home at
the grace, `mode_age_seconds` parsing and fail-closed, intake receives
the mode through `upload_rehome`, the probe is fresh (a job that starts
mid-sweep is seen) and counts recent rows, a capped sweep is PARTIAL.

**Fences kept.**
- Never two owners: one CAS per call; a lost CAS re-reads once and
follows a batch winner or holds (never a second CAS). A live legacy job
for the uid holds (legacy jobs record no conversation id, so the uid's
Redis pending index is the lease; an unavailable probe holds, as
`legacy_owner_job_present` does). `promote_final_pass_if_current`
refuses a batch-owned conversation, so a final pass still running when
the owner moves cannot promote over batch's work (new `rehomed` fence
case).
- Privacy: a tombstone (`is_soft_deleted`) or a deleting account
(`account_deletions`) gets no new route; admission then runs the
unchanged intake privacy authorization. An unowned row is admission's to
claim, never this helper's.
- Binding and predecessor fences: untouched, because the upload is
admitted through the existing `accept_batch_upload` -> `admit` path
after the owner change; the helper writes only `record_lane_owner`.
- Idempotency: a batch owner answers `already_batch` with no probe and
no write; the second upload after a re-home follows `batch_sync_v1`
directly.
- `on` is today's path byte for byte: `upload_rehome` is inert at `on`,
intake returns its legacy receipt at `on`, and the route does no read,
probe or write there.

## Product invariants affected

none. No path in this PR is listed on a locked invariant. In spirit it
serves INV-CAP-1 (retained pendant audio now gets a serving owner
instead of an indefinite hold); nothing here discards audio.

## How it was verified

Repository `BasedHardware/omi`, branch `lr/46-rehome` on
`origin/integration/legacy-retire` c13818a, worktree
`/Volumes/Ephemeral/scratch/worktrees/omi/lr46-rehome`. Layer: backend
unit tests only; no staging or prod run, no live service touched.

- `BACKEND_PYTEST_WORKERS=4 BACKEND_UNIT_TEST_FILE_LIST=<list> bash
backend/test.sh` under `omi-heavy`/`nice -n 19`:
- round 1 (9 files: `test_final_pass_rehome`, `test_batch_provider_stt`,
`test_legacy_dark_router`, `test_final_pass_promotion`,
`test_legacy_dark`, `test_record_admission_review_fixes`,
`test_firestore_indexes`, `test_ramp_controller`,
`test_reason_label_enums`): 8 files green; `test_final_pass_rehome`
failed 6 (test harness: explicit `OMI_ENV_STAGE`, live admission for the
no-loaded-owner route), fixed, then 28/28.
- round 3 (10 consumer files: `test_batch_pipeline_intake`,
`test_mobile_standard_batch`, `test_sync_cloud_tasks`,
`test_transcription_shadow`, `test_batch_ramp`,
`test_cap_hold_batch_admission`, `test_batch_audio_language`,
`test_legacy_dark_lost_recordings`, `test_sync_v2`,
`test_speaker_audio`): 590 passed.
- after the scope-add commit: `test_final_pass_rehome` 36/36, and
`test_record_admission_review_fixes`, `test_transcription_shadow`,
`test_batch_provider_stt`, `test_mobile_standard_batch`, `test_sync_v2`
green (the existing shadow-claim tests pass unchanged at `on`).
- `scripts/pr-preflight --lane local --base
origin/integration/legacy-retire` on the first commit: 35 checks passed
(index guard, line-count ratchet with the two exceptions below,
failure-class protocol, dead-code ratchet, import purity, route
baseline); the pre-push pyright phase passed on the push.
- `python3 backend/scripts/generate_firestore_indexes.py --write`: the
manifest gains only the `conversations.record_lane_owner` field override
(`test_firestore_indexes` green).
- Not verified: the sweep against a real Firestore (needs the
provisioned index and an operator tier), and the prod stock size.

## Tests

- `tests/unit/test_final_pass_rehome.py` (new): the loop closed
(`test_dark_upload_for_a_stranded_final_pass_owner_no_longer_loops`:
first upload re-homes and routes BATCH, second follows the batch owner,
one CAS), the live-job hold (1, 3, unavailable), batch-owner idempotency
with no probe or write, unowned/missing/deleted/deleting-account left
alone, the lost-CAS race (one attempt, held or follows a batch winner,
no ack), dry run stops before the CAS, `on` inert, the mode read off the
loop when the caller has none, the Redis probe fails closed, the sweep
(outcome counts and CLEAR verdict, dry run never writes, the ledger
probe counts ACTIVE and retryable legacy rows once per uid and fails
closed, `--apply` refuses a read-only tier), and the scope add (an
ownerless upload for a narrowed uid claims batch outside `on` and legacy
at `on` with no mode read; the shadow final pass takes no new owner and
starts no pass outside `on`, with live admission on or off, keeps an
existing legacy owner's pass, and claims as before at `on`).
- `tests/unit/test_batch_provider_stt.py`: intake re-homes then admits
(`rehomed`, `already_batch`), a held re-home keeps the in-progress ACK
with no batch unit, `on` keeps the legacy receipt.
- `tests/unit/test_legacy_dark_router.py`: a re-homed BATCH route in
draining/dark reaches batch intake with batch enabled, never the fence
or a legacy job, and the router hands its mode to the route; the held
case keeps lane 1's ACK test.
- `tests/unit/test_final_pass_promotion.py`: `rehomed` fence, the race
with a still-live final pass from the promotion side.

## UI evidence

UI-Evidence: none -- backend only.

## Line-count exception

Line-Count-Exception: backend/routers/sync.py | 3966 -> 3977 | The
router hands the legacy mode it already read to the record route (one
kwarg plus its comment) and re-reads a mode older than
ADMISSION_REVALIDATE_SECONDS before creating a legacy job (review round
2); the re-home itself lives in utils/sync/final_pass_rehome.py and
utils/batch_pipeline/live_upload.py, and C11 deletes the legacy runner
from this file.
Line-Count-Exception: backend/database/firestore_index_registry.py |
2200 -> 2206 | One FieldIndexRequirement row for the
conversations.record_lane_owner collection-group index, in the registry
every declared index must live in (the lost-recordings census index
landed the same way).

## Failure class (fixes)

The legacy-dark switch (`legacy_sync` = `draining`/`dark`) was inert for
exactly the conversations it needed to move: leftover flag-on state (the
`legacy_final_pass_v1` owner) kept routing new uploads into the gated
legacy path, which could no longer serve them. The fix branches on the
mode before following that owner, re-homes the leftover state so new
work takes the ungated batch path, and pins it with tests that set the
mode off while the leftover owner is present.

Failure-Class: FC-kill-switch-keeps-the-gated-path
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.

2 participants