Repository navigation
feat(sync): legacy-dark mode, fence and drain census (lane 10, contract h) - #22429
Conversation
…s (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]>
…module lands Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…nd the dark sweep Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d983f12f92
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| cap_holds_awaiting_legacy=_safe( | ||
| lambda: _count(client.collection_group('stt_cap_holds')), errors, 'cap_holds_awaiting_legacy' | ||
| ), |
There was a problem hiding this comment.
Count only actionable cap-hold rows
The census counts every stt_cap_holds document, including terminal completed, retained, and purged rows. utils.sync.cap_hold.claim explicitly treats those states as terminal, and retained rows are kept indefinitely rather than deleted, so any account with a historical terminal hold makes cap_holds_awaiting_legacy permanently nonzero and prevents the documented draining → dark transition. Filter for holds that still require legacy processing or use an actionable aggregate instead of counting the collection group unconditionally.
Useful? React with 👍 / 👎.
| value = _prom_scalar(session, project, f'sum(increase(omi_legacy_sync_admissions_total[{ADMISSIONS_WINDOW}]))') | ||
| # The mode gauge proves the code is serving; a counter with no series | ||
| # has never been incremented. | ||
| return 0 if value is None else int(round(value)) |
There was a problem hiding this comment.
Do not treat an absent admission series as zero
When the first admission creates a labeled counter series, its first scraped value is already 1, so increase(...[30m]) can report 0 because Prometheus never observed the initial zero; an admitting instance that terminates before being scraped is missed entirely. The mode gauge can still be present from another process, and this line then reports a clean zero, allowing both confirmation censuses to pass while a legacy inline job admitted during the window is still running. Preinitialize all bounded admission labels on every target and fail closed when the range lacks sufficient coverage.
Useful? React with 👍 / 👎.
| updated_at = _as_utc(row.get('updated_at')) | ||
| if updated_at is not None and (now - updated_at).total_seconds() >= CLAIM_STALE_SECONDS: | ||
| return LegacyOwnership.STRANDED | ||
| return LegacyOwnership.ACTIVE |
There was a problem hiding this comment.
Classify timestamp-less processing claims as stranded
For a processing ledger row with a job_id but a missing or malformed updated_at, this branch returns ACTIVE whenever the caller does not perform the optional Redis-owner lookup. The canonical ledger _claim_transaction instead treats a non-datetime timestamp as replaceable, and the comment below also describes partial rows as stranded. In draining or dark mode the mismatch produces an in-progress acknowledgement forever and prevents batch takeover, leaving that recording unprocessed; only a valid fresh timestamp should establish active ownership.
Useful? React with 👍 / 👎.
| if decision.ownership in (LegacyOwnership.COMPLETED, LegacyOwnership.HELD): | ||
| result = decision.result if isinstance(decision.result, Mapping) else {} | ||
| segments = result.get('total_segments') | ||
| return JSONResponse( | ||
| status_code=202, |
There was a problem hiding this comment.
Preserve a pollable job for held acknowledgements
When the ledger is HELD, this returns HTTP 202 with the old legacy job_id but does not create or complete a Redis job. Released clients treat every 202 as queued and poll that ID rather than trusting the embedded status; after the legacy Redis record expires, durable status reconciliation intentionally rejects held_audio as an unproven completion, so polling returns 404 and the client re-uploads or retains the recording indefinitely. Preserve the existing path's behavior of creating and completing a pollable job, or use a synchronous response contract the clients actually consume.
Useful? React with 👍 / 👎.
| if batch_adopts_stranded: | ||
| return FenceDecision(FenceAction.ADMIT_BATCH, LegacyDarkReason.LEGACY_STRANDED_ADOPTED, ownership, job_id) |
There was a problem hiding this comment.
Keep capped content out of batch adoption
With batch_adopts_stranded=True, this unconditional branch also matches LegacyOwnership.CAPPED, so content whose repeat_failure_pause_until is still in the future is immediately sent back for processing instead of reaching the LEGACY_CAPPED retry response below. That bypasses the repeat-failure pause for the exact poison inputs the cap is intended to suppress and contradicts the runbook's capped-row behavior. Restrict adoption to STRANDED ownership and continue returning the remaining pause for CAPPED rows.
Useful? React with 👍 / 👎.
| if batch_adopts_stranded: | ||
| return FenceDecision(FenceAction.ADMIT_BATCH, LegacyDarkReason.LEGACY_STRANDED_ADOPTED, ownership, job_id) |
There was a problem hiding this comment.
Emit the stranded-adoption metric
The LEGACY_STRANDED_ADOPTED reason is attached to an ADMIT_BATCH decision here, but fence_response records metrics only for ACK and RETRY before falling through for ADMIT_BATCH; repo-wide search finds no other emitter for this reason. Consequently omi_legacy_dark_ack_total{reason="legacy_stranded_adopted"} can never appear even though the runbook lists it as the signal for takeover, hiding whether stranded legacy work was adopted during the dark soak. Record the bounded reason when this adoption decision is made or provide an explicit helper that the batch continuation must invoke.
Useful? React with 👍 / 👎.
| deployed = _prom_scalar(session, project, 'count(omi_legacy_sync_mode)') | ||
| if not deployed: | ||
| errors['legacy_admissions'] = 'mode_gauge_absent' | ||
| return None |
There was a problem hiding this comment.
Require every process to be out of on mode
This only checks that some omi_legacy_sync_mode series exists; because every process exports all three mode labels, count(...) is positive even when a process last served on after a mode-read fallback. If that process creates no admission during the two census snapshots, the script can declare READY, yet a subsequent upload handled by the same failing reader will still take the legacy path in dark mode. Gate on the on gauge being zero across the complete fleet and on no fallback reads during the confirmation window, rather than treating mere metric presence as deployment proof.
Useful? React with 👍 / 👎.
| status_code=409, | ||
| headers={'Retry-After': str(retry_after)}, | ||
| content={ | ||
| 'code': 'sync_content_retry_later', | ||
| 'reason': 'dependency_warming', |
There was a problem hiding this comment.
Return a backoff response released clients recognize
Released Flutter clients special-case only a 409 whose code is sync_content_in_progress; this new sync_content_retry_later 409 falls through as a generic SyncUploadHttpException, ignores Retry-After, and consumes each WAL's bounded retry budget or surfaces a failed Transcribe Later upload. Thus ordinary stranded, capped, or refused admissions during draining can become user-visible failed recordings despite the response claiming the client will retry safely. Use an already-supported scoped backoff contract or ship client handling before enabling this response.
Useful? React with 👍 / 👎.
Lane 10, slice 1 of the legacy-retire swarm (contract (h), "legacy dark"). Targets
integration/legacy-retire.What
backend/utils/sync/legacy_dark.py(new):legacy_syncmode, read through lane 6'sutils.rollout.runtime_percent.legacy_sync_mode(). Any failure serveson, including the module not existing yet;sync_content_ledgerrow the batch intake already reads;omi_legacy_sync_admissions_total{reason},omi_legacy_dark_ack_total{reason},omi_legacy_sync_mode{mode}andomi_legacy_sync_mode_read_total{source}.backend/scripts/legacy_dark/drain_census.py: a read-only census that prints aggregates only and fails closed when a read is unavailable.backend/scripts/legacy_dark/legacy_queues.py: capture, recreate and verify for the four legacy queues. This is the rollback path after queue deletion, and it gets rehearsed on staging at M2.backend/docs/runbooks/legacy-dark.md: modes, preconditions, transitions, the fence table, the soak, deletion and rollback.backend/tests/unit/test_legacy_dark.py: 41 tests.Behaviour
Neutral. No call site imports the module yet. Wiring into
routers/sync.pyandutils/sync/uid_sequencer.pywaits on decision S11 (#21932/#20662 hold those files).Verification
pytest tests/unit/test_legacy_dark.py: 41 passed (unit layer).drain_census --env prodran onro-prodand returned aggregates only (NONZERO, as expected while legacy ison).Failure-Class: none
🤖 Generated with Claude Code