Skip to content

feat(sync): legacy-dark mode, fence and drain census (lane 10, contract h) - #22429

Merged
Git-on-my-level merged 3 commits into
integration/legacy-retirefrom
lr/10-legacy-dark
Oct 19, 2026
Merged

Git-on-my-level merged 3 commits into
integration/legacy-retirefrom
lr/10-legacy-dark

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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):
    • the served legacy_sync mode, read through lane 6's utils.rollout.runtime_percent.legacy_sync_mode(). Any failure serves on, including the module not existing yet;
    • the predicates call sites will use: legacy admission, sequencer registration, sequencer dispatch;
    • the double-processing fence (h, invariant 4), decided from the sync_content_ledger row the batch intake already reads;
    • the response shapes, all compatible with shipped clients and never 503;
    • the drain-census verdict: two zero reads at least 10 minutes apart;
    • metrics omi_legacy_sync_admissions_total{reason}, omi_legacy_dark_ack_total{reason}, omi_legacy_sync_mode{mode} and omi_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.py and utils/sync/uid_sequencer.py waits on decision S11 (#21932/#20662 hold those files).

Verification

  • pytest tests/unit/test_legacy_dark.py: 41 passed (unit layer).
  • drain_census --env prod ran on ro-prod and returned aggregates only (NONZERO, as expected while legacy is on).

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 2 commits October 19, 2026 13:22
…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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T07:36:11.456511Z d983f12 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 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".

Comment on lines +151 to +153
cap_holds_awaiting_legacy=_safe(
lambda: _count(client.collection_group('stt_cap_holds')), errors, 'cap_holds_awaiting_legacy'
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +113 to +116
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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +256 to +259
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +331 to +335
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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +309 to +310
if batch_adopts_stranded:
return FenceDecision(FenceAction.ADMIT_BATCH, LegacyDarkReason.LEGACY_STRANDED_ADOPTED, ownership, job_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +309 to +310
if batch_adopts_stranded:
return FenceDecision(FenceAction.ADMIT_BATCH, LegacyDarkReason.LEGACY_STRANDED_ADOPTED, ownership, job_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +109 to +112
deployed = _prom_scalar(session, project, 'count(omi_legacy_sync_mode)')
if not deployed:
errors['legacy_admissions'] = 'mode_gauge_absent'
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +354 to +358
status_code=409,
headers={'Retry-After': str(retry_after)},
content={
'code': 'sync_content_retry_later',
'reason': 'dependency_warming',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@Git-on-my-level
Git-on-my-level merged commit 71fec88 into integration/legacy-retire Oct 19, 2026
21 checks passed
@Git-on-my-level
Git-on-my-level deleted the lr/10-legacy-dark branch October 19, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant