Repository navigation
fix(sync): acknowledge expiry-retired legacy handles held in custody - #22483
Conversation
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. |
There was a problem hiding this comment.
💡 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".
| if not _valid_id(record.get('content_id'), 256): | ||
| return None |
There was a problem hiding this comment.
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 👍 / 👎.
| # 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=()) |
There was a problem hiding this comment.
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 👍 / 👎.
| 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 |
There was a problem hiding this comment.
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 👍 / 👎.
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]>
…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.
Summary
Expiry retirement (Oct 15–17) removed accepted legacy sync jobs without processing them. Their Redis jobs are gone and their content claims are
retryablewith no job id, soGET /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):
0–4. It made zero polls of any of its 1,860 recentbp_uploads, although the server completed them. The "On the Way" list grows with every new recording.This change adds an archival acknowledgement:
status: completed, an empty result, zero segments andreason_code: sync_retired_preserved.sync_retired_handles/{handle}(uid,job_id,content_id,campaign) whose owner is admitted insync_retired_handle_owners/{uid}(enabled: true).completedis the only status released apps treat as terminal without retrying.failedtriggers a re-upload, and an unknown status polls forever. The phone marks the WALsyncedand keeps its local copy forautoRemoveSyncedCopiesDays(30 by default).retryablefor operator redrive, and a later real completion wins.SYNC_RETIRED_HANDLE_ACK_ENABLED(unset means on).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, andbp_out of scope.make preflight: pass.🤖 Generated with Claude Code