Skip to content

fix(sync): acknowledge expiry-retired legacy handles held in custody - #22483

Merged
Git-on-my-level merged 6 commits into
mainfrom
lane/onthway-retired-ack
Oct 19, 2026
Merged

Git-on-my-level merged 6 commits into
mainfrom
lane/onthway-retired-ack

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

Expiry retirement (Oct 15–17) removed accepted legacy sync jobs without processing them. Their Redis jobs are gone and their content claims are retryable with no job id, so GET /v2/sync-local-files/{id} returns 404 for those handles forever. The bytes are restored and on temporary hold server-side.

The released app confirms a missing job only with a second 404 at least 5 minutes later in the same process. Its poller orders never-polled handles first, by job id. With thousands of dead handles, each app session spends the 18/min budget on first-404s of the lexically first dead handles and never confirms any of them.

Production evidence (ro-prod, 24h, aggregates):

  • Fleet: 86% of all status 404s (217k) hit retired handles, from 236 owners.
  • One heavily affected account: 3,013 polls of retired handles, all 404, covering only id prefixes 0–4. It made zero polls of any of its 1,860 recent bp_ uploads, although the server completed them. The "On the Way" list grows with every new recording.

This change adds an archival acknowledgement:

  • The route answers with status: completed, an empty result, zero segments and reason_code: sync_retired_preserved.
  • It applies only to a handle recorded in sync_retired_handles/{handle} (uid, job_id, content_id, campaign) whose owner is admitted in sync_retired_handle_owners/{uid} (enabled: true).
  • It runs only after the Redis job and the existing durable-completion reconciliation both decline, and behind the same account fence.
  • completed is the only status released apps treat as terminal without retrying. failed triggers a re-upload, and an unknown status polls forever. The phone marks the WAL synced and keeps its local copy for autoRemoveSyncedCopiesDays (30 by default).
  • It is read-only. The ledger stays retryable for operator redrive, and a later real completion wins.
  • Lookup errors fail open to the existing 404. Kill switch: SYNC_RETIRED_HANDLE_ACK_ENABLED (unset means on).
  • No owner documents exist yet, so this is inert until an operator admits an owner. The pilot is one account; fleet admission waits on its gates.

Product invariants affected

none

Failure class (fixes)

Failure-Class: new

Line count

Line-Count-Exception: backend/routers/sync.py | 3784 -> 3788 | four-line call into the new retired_handle_ack module at the existing 404 branch; logic lives outside the router

Verification

  • pytest tests/unit/test_sync_retired_handle_ack.py tests/unit/test_sync_completed_status.py: 117 passed. The new tests use the real HTTP route with strict Firestore transactions. They cover: ack with no mutation, unknown handle, unadmitted or false owner, another owner's handle, a record bound to another handle, kill-switch values, real completion winning, a live Redis job not shadowed, deleted account, lookup failure failing open, and bp_ out of scope.
  • make preflight: pass.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 4 commits October 19, 2026 18:02
Expiry retirement (Oct 15-17) left accepted legacy uploads with no Redis job
and a retryable ledger claim, so their status polls 404 forever. Phones confirm
a 404 only after a second miss five minutes later in the same process, which a
large dead backlog never reaches. The rows stay On the Way, and the poll budget
starves status checks for new uploads.

For handles recorded in sync_retired_handles whose owner is admitted in
sync_retired_handle_owners, the status route now answers completed with an
empty result and reason_code sync_retired_preserved. It does so only after
Redis and durable-completion reconciliation decline, and behind the account
fence. Read-only; lookup errors fail open to 404. Kill switch:
SYNC_RETIRED_HANDLE_ACK_ENABLED.

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-19T13:06:18.833563Z 3b89119 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: b0adf6ffb0

ℹ️ 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 +82 to +83
if not _valid_id(record.get('content_id'), 256):
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.

P2 Badge Resolve redriven receipts through the retired alias

When custody is redriven under a new job ID before the phone polls, get_completed_legacy_status() cannot find the completion: it only derives content_id from Redis or sync_redrive_required, then falls back to matching the requested job ID. Although this retired-handle record contains the required content_id, the code only validates and discards it, so the route returns the synthetic empty completion instead of the real result; the client then stops polling without receiving the completed receipt's new/updated conversation IDs. Use this alias to check the durable ledger before issuing the archival acknowledgement.

Useful? React with 👍 / 👎.

Comment on lines +88 to +90
# Same account fence as durable completion: a deleted or blocked
# account never receives a synthetic terminal status.
assert_batch_write_allowed(client, transaction, uid, conversation_ids=())

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 conversation-level privacy denial before acknowledging

When durable reconciliation finds a real receipt whose result target is now privacy-blocked—for example, a deleted conversation or an opted-out recording—get_completed_legacy_status() deliberately declines it after fencing those conversation IDs. The route then reaches this fallback, whose empty conversation_ids check succeeds for the same account and returns a synthetic completion, bypassing that denial; the client marks the WAL synced and may later delete its retained audio. Propagate the earlier privacy denial or fence the real receipt's targets before acknowledging.

Useful? React with 👍 / 👎.

Comment on lines +79 to +83
record = handle.to_dict() if getattr(handle, 'exists', False) else None
if not isinstance(record, dict) or record.get('uid') != uid or record.get('job_id') != job_id:
return None
if not _valid_id(record.get('content_id'), 256):
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.

P2 Badge Require current custody proof before acknowledging

When an admitted owner's handle document is incomplete, belongs to a different preservation campaign, or remains after its temporary custody hold expires, this validation still treats it as proof of preservation because it checks only uid, job_id, and the shape of content_id; the documented campaign field and any active custody state are ignored. Such a stale or partially imported row produces a terminal completion, after which released clients stop retrying and may delete their last local copy even though the server no longer holds the bytes. Validate the expected campaign and a current custody marker before returning the acknowledgement.

Useful? React with 👍 / 👎.

Git-on-my-level and others added 2 commits October 19, 2026 19:44
Unit harnesses stub google.cloud; a stubbed transaction result must fall back
to the pre-existing 404 rather than fail response validation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit d77e441 into main Oct 19, 2026
56 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/onthway-retired-ack branch October 19, 2026 13:10
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
…22450, #22497 sync)

E1 (batch policy snapshot) conflicted with legacy-retire in 7 files; per-owner resolutions:
- lane 8: database/batch_pipeline_intake.py, utils/batch_pipeline/intake.py, live_upload.py
  (E1 policy= + admit enqueue=/adopt= hooks), provider_stt.py (enqueue hook takes policy=).
- lane 9: utils/sync/reprocess.py stays the alias shim; E1's first-summary policy snapshot is
  ported into utils/enrichment/outbox.py (mark_update/run), outbox_firestore claim_key/consumer
  and projection.mark_enrichment; config/policy/guard.py RESOLUTION_EDGES moved to the outbox
  (lead sign-off, Sol FYI).
- lane 6: config/batch_live_preview.py takes E1; config/policy/batch.py reads the _ramp
  runtime percents in resolve_batch_policy when flags is None (lead sign-off; Sol no objection).
  test_runtime_percent.py covers ramp wins/recorded, env fallback, explicit flags never read
  _ramp, retire clamped after runtime batch, and source-blind policy_id.
- lane 1: routers/batch_pipeline.py drops the env read (E1) and keeps the 409 kill switch.

Verified (unit, m5): runtime_percent, batch_unit_policy (E1 guard), batch_stage_policy,
batch_pipeline_serving, quarantine_recovery, batch_provider_stt, outbox_firestore,
enrichment_route, task_target_retry_semantics, app_roles census: 359 passed, 3 xfailed.
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