Skip to content

legacy-retire lane 10 slice 2b: legacy-dark fence at the legacy call sites - #22495

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

Git-on-my-level merged 14 commits into
integration/legacy-retirefrom
lr/10-slice2b

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

Lane 10, slice 2b: wires the legacy-dark switch (contract (h)) into the legacy call sites. The /v1/sync-local-files retirement moved to the draft deletion PR lr/10-delete-v1 (lead ruling (a), 10-19). At legacy_sync=on the behaviour is unchanged. The _ramp doc does not exist in prod, so lane 6's reader serves on, and any read failure also serves on.

routers/sync.py, v2 upload, outside on:

  • No legacy job is created.
  • Content legacy already owns gets the double-processing fence's answer:
    • completed or held: 202 completed;
    • still processing: the existing 409 sync_content_in_progress that tells the client to follow the owner's job;
    • stranded or capped: 409 retry-later with Retry-After.
  • Anything else gets 409 retry-later and the client keeps its audio. Never 503.
  • The legacy-fresh budget is skipped.
  • omi_legacy_sync_admissions_total{reason} counts every legacy job still created at on.

Sequencer:

  • New owner registration and the pre-sequencer migration branch run only at on.
  • In dark, the sweep stops claiming and dispatching. Enrichment repair (reprocess.sweep) and summary_debt_repair.tick keep running until C4 moves them (lead ruling 10-19).
  • In dark, the wake returns 200 legacy_dark.
  • uid_sequencer.kick and uid_sequencer.sweep do nothing in dark.

Lane / contract

Lane 10, contract (h), consuming (f) legacy_sync_mode. Owner sign-offs: the routers/sync.py and uid_sequencer.py edits are lane 10's (swarm plan §3; they were held until #21932 and #22452 merged).

Product invariants affected

  • INV-DATA-1: a path match only. routers/sync.py is in its path set. This diff changes no production data-plane routing authority (project, database or bucket selection), only legacy admission and sequencer gating.

Verification

Unit layer:

  • test_legacy_dark.py (43) and test_legacy_dark_router.py (6 router-wiring tests through the shared fast-path harness; allowlisted for the fast-unit CPU guard like test_sync_cloud_tasks.py);
  • test_sync_cloud_tasks.py (186), test_sync_v2.py (182), test_sync_backfill_uid_sequencer.py (117), test_stt_cap_dispatch_http.py, test_sync_record_usage.py, test_sync_local_files_async.py, test_sync_fair_use_gate.py, test_sync_silent_failure.py, test_sync_transcription_prefs.py, test_multipart_limits.py, test_background_task_ratchet.py. All v1 tests are unchanged from integration.

test_task_target_retry_semantics.py (5) and test_cross_service_deploy_contract.py (18) pass against integration f482aa3b, which has lane 1's known-gaps update.

Not run locally: the full suite, which CI runs. Staging comes at M2: the on→draining→dark→on cycle under replay.

Rollback

Revert. Runtime rollback needs no deploy: ramp_set.py --legacy-sync on, which takes effect within 30s.

Line-Count-Exception: backend/routers/sync.py | 3820 -> 3857 | legacy-dark fence wiring at the call sites (contract h); the C9/C10/C11 deletion PRs remove ~2.5k lines from this file

Failure-Class: none

🤖 Generated with Claude Code

Git-on-my-level and others added 13 commits October 19, 2026 16:41
…-local-files 410 (lane 10 slice 2b)

routers/sync.py: no legacy job outside on (fence for legacy-owned
content, 409 retry-later otherwise), legacy-fresh skipped, sequencer
registration and pre-sequencer migration only at on, dark sweep stops
claims but keeps enrichment and summary-debt repair, dark wake 200.
uid_sequencer: kick/sweep inert in dark. /v1/sync-local-files returns
410 (7-day census: zero calls); its v1-only tests are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	backend/utils/sync/uid_sequencer.py
# Conflicts:
#	config/feature-flags.yaml
…lr/10-slice2b

# Conflicts:
#	config/feature-flags.yaml
…listed like test_sync_cloud_tasks

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 ⚠️ Failed 2026-10-19T13:58:13.631863Z 72da3e7 New commits
ℹ️ 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: 3336bc2851

ℹ️ 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 thread backend/routers/sync.py
client_device_context.client_device_id,
snapshot_out=record_snapshot,
)
legacy_mode = legacy_dark.current_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.

P1 Badge Await the initial legacy-mode read before admitting

On a cold Cloud Run instance while the ramp is draining or dark, this call runs on the event loop, where _RampCache.snapshot() deliberately starts a refresh without waiting and immediately serves the default on. The first upload on each new instance can therefore pass legacy_allowed and create a legacy job—particularly when batch intake is disabled or a record is legacy-owned—so autoscaling can repeatedly bypass the kill switch. Read current_mode through await run_blocking(db_executor, ...) as batch intake does, or explicitly await the ramp warm-up before evaluating it.

AGENTS.md reference: backend/AGENTS.md:L263-L272

Useful? React with 👍 / 👎.

try:
# Imported per call (a cached module lookup): router test harnesses replace
# ``utils`` wholesale, and a missing reader must serve ``on``, not fail import.
from utils.rollout import runtime_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.

P1 Badge Keep the rollout import at module scope

Move this import back to module scope and update the router test harness to stub the real dependency instead. The new per-call import explicitly violates the backend import convention, hides the production dependency to accommodate test-module replacement, and makes import/source-closure analysis less reliable.

AGENTS.md reference: backend/AGENTS.md:L161-L169

Useful? React with 👍 / 👎.

Comment thread backend/routers/sync.py
await run_blocking(sync_executor, _cleanup_files, paths)
await run_blocking(sync_executor, shutil.rmtree, job_dir, True)
return (
legacy_dark.fence_response(decision, total_files=len(files), lane=lane_decision.lane.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 Return completed ledger hits through a terminal client contract

When this new fence call classifies a legacy row as completed or held, fence_response returns HTTP 202 with the old legacy job_id, but both shipped Flutter and macOS upload clients treat every 202 as queued and ignore the response's status: completed. Because the ledger lasts 45 days while Redis jobs last 24 hours, an older completed hit sends clients to poll an expired job, revert the WAL after 404, and upload it again indefinitely. Return the existing HTTP 200 completed-result shape or materialize a pollable completed job instead of exposing the stale legacy ID.

Useful? React with 👍 / 👎.

Comment thread backend/routers/sync.py
await run_blocking(sync_executor, shutil.rmtree, job_dir, True)
return (
legacy_dark.fence_response(decision, total_files=len(files), lane=lane_decision.lane.value)
or legacy_dark.admission_refused_response()

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 Use a retry response that shipped clients actually throttle

When draining or dark mode reaches this refusal fallback, the response is a 409 sync_content_retry_later with Retry-After, but neither shipped upload client recognizes that code: Flutter treats it as a generic SyncUploadHttpException, while macOS treats every 409 as an ordinary upload failure. Consequently clients retain but repeatedly re-upload the same bytes without honoring the 60-second backoff, depressing the rollout's upload-success SLO and potentially creating a retry storm exactly when the batch route is unavailable. Use an already-supported response contract or deploy client handling before activating this branch.

Useful? React with 👍 / 👎.

Comment thread backend/routers/sync.py
# Legacy-dark (contract (h)): never create a legacy job. Content legacy
# already owns is answered by the fence; anything else keeps its audio.
ledger_row = await run_blocking(db_executor, legacy_dark.read_ledger_row, uid, content_id)
decision = legacy_dark.fence_decision(ledger_row, legacy_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.

P1 Badge Verify that an active ledger owner still has a Redis job

For a fallback upload whose ledger row says processing, this call omits owner_job_present, so fence_decision classifies every claim younger than 48 hours as active even when its Redis job has already expired after 24 hours or was deleted. The route then returns sync_content_in_progress with a nonexistent job ID; shipped clients poll it, confirm 404, re-upload, and receive the same dead owner until the ledger becomes stale. Read the referenced job and pass its presence into the fence so missing owners take the stranded/recovery path.

Useful? React with 👍 / 👎.

Comment thread backend/routers/sync.py
return batch_response
sequencer_registration_started = False

if not legacy_allowed:

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 Resolve legacy record owners instead of permanently refusing them

In draining or dark mode, a conversation stamped record_lane_owner == 'legacy_final_pass_v1' makes registered_record_response return LEGACY, so batch intake is skipped and this new branch looks only for a sync ledger row keyed by the uploaded WAL hash. A legacy live final pass cannot have that upload-derived key before the first upload, while the owner marker is preserved on subsequent conversation writes, so the decision remains unowned and every retry is refused forever even after the final pass finishes. Acknowledge covered/completed legacy-record audio from its durable conversation state or provide an ownership migration path before disabling legacy admission.

Useful? React with 👍 / 👎.

…oves to the C6 deletion PR (lead ruling (a))

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level Git-on-my-level changed the title legacy-retire lane 10 slice 2b: legacy-dark wiring at call sites, /v1 sync 410 legacy-retire lane 10 slice 2b: legacy-dark fence at the legacy call sites Oct 19, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Git-on-my-level
Git-on-my-level merged commit d9617a5 into integration/legacy-retire Oct 19, 2026
23 checks passed
@Git-on-my-level
Git-on-my-level deleted the lr/10-slice2b branch October 19, 2026 14:09
Git-on-my-level added a commit that referenced this pull request Oct 21, 2026
## 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:**
- #23068: main b859b78, the ci-budget bump and the dead-code stub
removal;
   - review fixes #23082 and #23086;
- final main merges #23096 (main 34ce402) and #23133 (main 5406315).
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):**
- CHANGES: 1 P1, fixed in #23082 (provider-STT outbox sweep plus
draining gates).
   - The 2 P2s are recorded below.
- The M1 blocker closure table is in
`data/run-2026-10-19-legacy-retire/review/M3/m1-blocker-closure.md`
(omi-workspace).
4. **Workflows:** all green on this head.
5. **Luna:**
   - Round 1: CHANGES, 2 majors, fixed in #23082.
- Round 2: 4 majors. Two lock fixes are in #23086 (Luna SHIP); two were
routed to dark-step gates.
   - Final-merge resolution: SHIP.

## 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 #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 #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](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant