Skip to content

feat: scope legacy sync retirement to the batch cohort - #24219

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/legacydark
Nov 1, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/legacydark

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Partial legacy retirement currently applies to an entire environment, and language exclusion can leave unsupported uploads with neither batch nor legacy accepting them. This change scopes retirement to the deployed batch-percent bucket, threads the owner through upload/final-pass/cap-hold/sequencer decisions, and keeps the content ledger fence unchanged.

The runtime mode and legacy-sync percent come from one snapshot. Missing scope or a read error serves on; rollback remains one legacy_sync=on write. The env-set generator forces language exclusion off for every draining/dark Cloud Run entry, and admission has a runtime backstop during env-update skew. Partial sequencer sweeps rotate dark entries without claiming or dispatching them. Bulk rehome refuses partial scope.

All serving readers must carry this implementation before any partial mode write: older readers interpret the mode globally. This PR does not merge or deploy the Plan C deletion drafts or change live STT eligibility.

Per the lead's correction to the brief, retirement uses the deployed batch hash
and is clamped to batch percent. Equal/lower-percent tests prove membership
nesting. Explicit legacy-percent writes above batch are refused; batch rollback
clamps retirement without another write. The existing ramp controller holds
while legacy mode is non-on.

Validation

  • Focused backend suites run through bin/omi-heavy, nice -n 19, and backend/test.sh with explicit file lists. They cover every integer percent, owner-scoped fences, safe exclusion, C8 routing and golden replay in draining/dark, ledger custody, cap-hold ladder debit and projection.
  • New synthetic provider conformance cases pass on simulator, Firestore emulator and Postgres: one provider call, durable failure holds, duplicate delivery and ordered merge. The actual provider-outbox emulator suite also passes its three privacy/claim/sweep cases. Vendor/VAD/artifact leaves are doubles; this is not real ASR quality proof.
  • Full local Cloud Tasks gauntlet process scenarios passed. Its final shard-spread test first failed the contention-count assertion; one isolated rerun passed all five tests. No test was skipped or loosened to obtain that result.
  • Broader Store/Outbox conformance remains incomplete: three Firestore outbox cases fail (coalesced-wake timing and failed-wake handling), with four applicability skips. The same three outbox failures reproduce on immutable main 9a7770354c4c (78 passed, three failures, three applicability skips); relevant outbox sources are unchanged. This is a release hold, not a full conformance qualification.

Release holds

C8 is locally exercised, not fully qualified for C9. Real phone/Watch Process Now visibility, serving ladder debit, deployed provider queue/maintenance bindings, selected-cohort drain evidence, multilingual ASR quality, and the C9 dark soak remain required. No production or remote dev data was accessed. Staging was not used.

Product invariants affected

  • INV-DATA-1: preserve audio custody and durable ownership; retain existing completed/held/active/stranded fences.
  • INV-MEM-4: preserve transcript admission, assignment and projection behavior while scoping legacy retirement.

Failure-Class: none

View guided diff Turn on auto-fix

Keep owners outside the retirement percent on legacy, preserve durable fences,
and couple draining/dark env sets to safe batch language admission. Qualify C8
with synthetic provider custody, multilingual golden and ladder debit checks.

@cubic-dev-ai cubic-dev-ai 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.

9 issues found across 35 files

Confidence score: 2/5

  • In final_pass_rehome.py, served_ramp lets --apply rehome every legacy-owned conversation at legacy-sync=100, even after the batch is rolled back to 25%. Make the apply path honor the batch scope.
  • The gate in legacy-dark.md measures the whole environment, so it cannot verify safety for selected owners. Add and document a selected-cohort census or gate before requiring partial-scope rollout.
  • In ramp_set.py, an explicit positive --legacy-percent can be rejected when _ramp omits batch-pipeline, because the nesting check treats the missing value as 0. Compare against the deployed batch percentage.
  • test_batch_admission_language_router.py now covers only ON, so regressions in the DRAINING/DARK batch intake path can go unnoticed. Add a separate end-to-end case that checks batch intake and no legacy job is created.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/tests/unit/test_batch_audio_language.py">

<violation number="1" location="backend/tests/unit/test_batch_audio_language.py:606">
P2: This stub does not enforce the new owner-scope contract: because `uid` is optional and ignored, the test remains green if `accept_upload` stops forwarding the upload owner to `current_mode`. Require the UID and assert that it equals `synthetic-owner` so this test protects cohort scoping.</violation>
</file>

<file name="backend/tests/unit/test_batch_provider_stt.py">

<violation number="1" location="backend/tests/unit/test_batch_provider_stt.py:507">
P2: The new unknown-language test never exercises an `und` input: both configs use `language='multi'` and `worker_language='und'`. Define the `und` case from an actual unknown declaration and regenerate its golden, or assert the normalization explicitly.</violation>
</file>

<file name="backend/tests/unit/test_batch_admission_language_router.py">

<violation number="1" location="backend/tests/unit/test_batch_admission_language_router.py:81">
P2: This narrows the real sync-router/intake test to `ON`, so regressions in the new `DRAINING`/`DARK` batch path will no longer be caught. Add a separate end-to-end case asserting batch intake occurs and no legacy job is created for both retirement modes.</violation>
</file>

<file name="backend/docs/runbooks/legacy-dark.md">

<violation number="1" location="backend/docs/runbooks/legacy-dark.md:53">
P2: This partial-scope rule has no executable acceptance path: the only documented dark gate measures the whole environment, not selected owners. Add and document a selected-cohort census or gate before requiring partial dark evidence.</violation>
</file>

<file name="backend/tests/unit/test_runtime_percent.py">

<violation number="1" location="backend/tests/unit/test_runtime_percent.py:166">
P2: This test does not verify the “without changing percent” contract: after the refresh it checks only the mode, which remains `on` even if the rollback rewrites the percentages. Assert the snapshot retains both `legacy-sync` and `batch-pipeline` at 100.</violation>
</file>

<file name="backend/scripts/rollout/ramp_set.py">

<violation number="1" location="backend/scripts/rollout/ramp_set.py:55">
P2: `type=float` accepts values outside 0..100 and non-finite values, while dry-run planning reports them as valid because store validation only runs on apply. Validate a finite 0..100 value during parsing or in `plan_change`.</violation>

<violation number="2" location="backend/scripts/rollout/ramp_set.py:105">
P2: An explicit positive `--legacy-percent` cannot be written when `_ramp` omits `batch-pipeline`, because the downstream nesting check treats the missing value as 0 rather than the deployed batch percentage. Compare against the effective batch value or require and persist that value before accepting the legacy scope.</violation>
</file>

<file name="backend/scripts/legacy_dark/final_pass_rehome.py">

<violation number="1" location="backend/scripts/legacy_dark/final_pass_rehome.py:161">
P1: `served_ramp` treats `legacy-sync=100` as a full-scope sweep without checking the batch scope. After a batch rollback to 25%, runtime clamps retirement to 25%, but `--apply` can still rehome every legacy-owned conversation; require both effective scopes to be 100 before allowing this bulk sweep.</violation>
</file>

<file name="backend/testing/pipeline_sim/trace.py">

<violation number="1" location="backend/testing/pipeline_sim/trace.py:465">
P2: These two characterization scenarios exercise identical runtime inputs, so `legacy_retirement_und` does not test normalization of an `und` preference and can remain green while that path regresses. Give the scenarios distinct inputs or remove the redundant golden; modeling raw preference normalization may require an additional simulation field.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

),
# The real intake normalizes an unrecognized und preference to multi.
'legacy_retirement_und': lambda: _config(
'legacy_retirement_und', language='multi', worker_language='und', legacy_sync='draining'

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: These two characterization scenarios exercise identical runtime inputs, so legacy_retirement_und does not test normalization of an und preference and can remain green while that path regresses. Give the scenarios distinct inputs or remove the redundant golden; modeling raw preference normalization may require an additional simulation field.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/testing/pipeline_sim/trace.py, line 465:

<comment>These two characterization scenarios exercise identical runtime inputs, so `legacy_retirement_und` does not test normalization of an `und` preference and can remain green while that path regresses. Give the scenarios distinct inputs or remove the redundant golden; modeling raw preference normalization may require an additional simulation field.</comment>

<file context>
@@ -456,6 +456,14 @@ def _config(name: str, *, seed: int = 7, workload: dict | None = None, **changes
+    ),
+    # The real intake normalizes an unrecognized und preference to multi.
+    'legacy_retirement_und': lambda: _config(
+        'legacy_retirement_und', language='multi', worker_language='und', legacy_sync='draining'
+    ),
     # Provider errors for a window: retries exhaust attempts -> quarantine -> one paid recovery each.
</file context>

yield audio_unit(100, b'\x01\x00' * 16000)

monkeypatch.setattr(intake.legacy_dark, 'current_mode', lambda: LegacySyncMode(mode))
monkeypatch.setattr(intake.legacy_dark, 'current_mode', lambda uid=None: LegacySyncMode(mode))

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: This stub does not enforce the new owner-scope contract: because uid is optional and ignored, the test remains green if accept_upload stops forwarding the upload owner to current_mode. Require the UID and assert that it equals synthetic-owner so this test protects cohort scoping.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_batch_audio_language.py, line 606:

<comment>This stub does not enforce the new owner-scope contract: because `uid` is optional and ignored, the test remains green if `accept_upload` stops forwarding the upload owner to `current_mode`. Require the UID and assert that it equals `synthetic-owner` so this test protects cohort scoping.</comment>

<file context>
@@ -603,7 +603,7 @@ def stage(work, body):
         yield audio_unit(100, b'\x01\x00' * 16000)
 
-    monkeypatch.setattr(intake.legacy_dark, 'current_mode', lambda: LegacySyncMode(mode))
+    monkeypatch.setattr(intake.legacy_dark, 'current_mode', lambda uid=None: LegacySyncMode(mode))
     monkeypatch.setattr(intake, 'resolve_route', spy_route)
     monkeypatch.setattr(intake, 'FirestoreStore', lambda _: MemoryStore())
</file context>

Comment thread backend/utils/batch_pipeline/intake.py Resolved


@pytest.mark.parametrize('name', ['legacy_retirement_multi', 'legacy_retirement_und'])
def test_unknown_language_goldens_pin_worker_barrier_and_retained_recovery(name):

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: The new unknown-language test never exercises an und input: both configs use language='multi' and worker_language='und'. Define the und case from an actual unknown declaration and regenerate its golden, or assert the normalization explicitly.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_batch_provider_stt.py, line 507:

<comment>The new unknown-language test never exercises an `und` input: both configs use `language='multi'` and `worker_language='und'`. Define the `und` case from an actual unknown declaration and regenerate its golden, or assert the normalization explicitly.</comment>

<file context>
@@ -484,6 +485,37 @@ def test_provider_golden_is_pinned_by_the_simulation(name):
+
+
[email protected]('name', ['legacy_retirement_multi', 'legacy_retirement_und'])
+def test_unknown_language_goldens_pin_worker_barrier_and_retained_recovery(name):
+    golden = _golden(name)
+    assert golden['segments']
</file context>



@pytest.mark.parametrize('mode', list(LegacySyncMode))
@pytest.mark.parametrize('mode', [LegacySyncMode.ON])

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: This narrows the real sync-router/intake test to ON, so regressions in the new DRAINING/DARK batch path will no longer be caught. Add a separate end-to-end case asserting batch intake occurs and no legacy job is created for both retirement modes.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_batch_admission_language_router.py, line 81:

<comment>This narrows the real sync-router/intake test to `ON`, so regressions in the new `DRAINING`/`DARK` batch path will no longer be caught. Add a separate end-to-end case asserting batch intake occurs and no legacy job is created for both retirement modes.</comment>

<file context>
@@ -78,14 +78,14 @@ async def route(world, mode):
 
 
[email protected]('mode', list(LegacySyncMode))
[email protected]('mode', [LegacySyncMode.ON])
 @pytest.mark.parametrize('language', ['auto', 'ja'])
 async def test_actual_sync_router_excludes_before_claim_and_batch_intake(monkeypatch, mode, language):
</file context>

Global zero censuses and the bulk final-pass rehome sweep remain full-retirement
tools. Bulk rehome refuses partial scope; the upload path rehomes the selected
owner with the existing grace and revision fence. A partial dark step still
requires evidence that its selected owners have drained; global zero is not a

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: This partial-scope rule has no executable acceptance path: the only documented dark gate measures the whole environment, not selected owners. Add and document a selected-cohort census or gate before requiring partial dark evidence.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/docs/runbooks/legacy-dark.md, line 53:

<comment>This partial-scope rule has no executable acceptance path: the only documented dark gate measures the whole environment, not selected owners. Add and document a selected-cohort census or gate before requiring partial dark evidence.</comment>

<file context>
@@ -1,6 +1,58 @@
+Global zero censuses and the bulk final-pass rehome sweep remain full-retirement
+tools. Bulk rehome refuses partial scope; the upload path rehomes the selected
+owner with the existing grace and revision fence. A partial dark step still
+requires evidence that its selected owners have drained; global zero is not a
+valid partial-cohort acceptance claim. C9's release holds, including phone/Watch
+Process Now, ladder debit and the full dark soak, are unchanged.
</file context>

def test_missing_retirement_scope_and_invalid_owner_keep_legacy_on(reader, mode):
outcomes, _ = reader
outcomes.append(ramp_doc(legacy_sync=mode))
assert rp.legacy_sync_mode('synthetic-owner') == 'on'

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: This test does not verify the “without changing percent” contract: after the refresh it checks only the mode, which remains on even if the rollback rewrites the percentages. Assert the snapshot retains both legacy-sync and batch-pipeline at 100.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_runtime_percent.py, line 166:

<comment>This test does not verify the “without changing percent” contract: after the refresh it checks only the mode, which remains `on` even if the rollback rewrites the percentages. Assert the snapshot retains both `legacy-sync` and `batch-pipeline` at 100.</comment>

<file context>
@@ -140,11 +140,98 @@ def test_nesting_clamped_at_read_time(reader):
+def test_missing_retirement_scope_and_invalid_owner_keep_legacy_on(reader, mode):
+    outcomes, _ = reader
+    outcomes.append(ramp_doc(legacy_sync=mode))
+    assert rp.legacy_sync_mode('synthetic-owner') == 'on'
+    outcomes[0] = ramp_doc(legacy_sync=mode, percents={'legacy-sync': 100, 'batch-pipeline': 100})
+    rp._cache.invalidate()
</file context>

op.add_argument('--percent', type=parse_percent, action='append', help='NAME=VALUE (repeatable)')
op.add_argument('--legacy-sync', choices=store.LEGACY_SYNC_MODES)
parser.add_argument(
'--legacy-percent', type=float, help='Stable legacy retirement cohort (0..100); requires --legacy-sync'

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: type=float accepts values outside 0..100 and non-finite values, while dry-run planning reports them as valid because store validation only runs on apply. Validate a finite 0..100 value during parsing or in plan_change.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/scripts/rollout/ramp_set.py, line 55:

<comment>`type=float` accepts values outside 0..100 and non-finite values, while dry-run planning reports them as valid because store validation only runs on apply. Validate a finite 0..100 value during parsing or in `plan_change`.</comment>

<file context>
@@ -51,6 +51,9 @@ def build_parser() -> argparse.ArgumentParser:
     op.add_argument('--percent', type=parse_percent, action='append', help='NAME=VALUE (repeatable)')
     op.add_argument('--legacy-sync', choices=store.LEGACY_SYNC_MODES)
+    parser.add_argument(
+        '--legacy-percent', type=float, help='Stable legacy retirement cohort (0..100); requires --legacy-sync'
+    )
     op.add_argument('--lock', metavar='WHO', help='Set locked_by (the controller refuses while set)')
</file context>

return {'legacy_sync': args.legacy_sync}, args.reason or 'unknown'
change: dict[str, Any] = {'legacy_sync': args.legacy_sync}
if args.legacy_percent is not None:
change['percents'] = {'legacy-sync': args.legacy_percent}

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: An explicit positive --legacy-percent cannot be written when _ramp omits batch-pipeline, because the downstream nesting check treats the missing value as 0 rather than the deployed batch percentage. Compare against the effective batch value or require and persist that value before accepting the legacy scope.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/scripts/rollout/ramp_set.py, line 105:

<comment>An explicit positive `--legacy-percent` cannot be written when `_ramp` omits `batch-pipeline`, because the downstream nesting check treats the missing value as 0 rather than the deployed batch percentage. Compare against the effective batch value or require and persist that value before accepting the legacy scope.</comment>

<file context>
@@ -85,10 +92,18 @@ def plan_change(args: argparse.Namespace, entry: dict[str, Any] | None) -> tuple
-        return {'legacy_sync': args.legacy_sync}, args.reason or 'unknown'
+        change: dict[str, Any] = {'legacy_sync': args.legacy_sync}
+        if args.legacy_percent is not None:
+            change['percents'] = {'legacy-sync': args.legacy_percent}
+        return change, args.reason or 'unknown'
     if args.lock:
</file context>

…when retired

Luna round 1 on #24219:
- final_pass_rehome bulk sweep reads the effective (clamped) retirement
  percent, so a batch-only rollback cannot rehome owners outside it.
- Intake always evaluates batch_admission_language and refuses only while
  the owner still has legacy; draining/dark admits excluded uploads and
  keeps the supported-conversation input pin. Language tests updated to
  the cohort contract (shard 3/6 failures).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 2a7369d into main Nov 1, 2026
60 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/legacydark branch November 1, 2026 10:06
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