Repository navigation
fix(sync): keep one recording's custody wait from pausing the whole upload queue - #24853
Conversation
…pload queue record_capture_pending is a per-conversation wait (the registered record cannot prove WAL coverage yet), but it answered 503 with Retry-After: 30. Shipped apps read any 5xx carrying Retry-After as an account-wide backendBusy pause, and the drain picks the oldest WAL first, so one stuck conversation stalled every other upload on the phone. On 2026-11-07 one conversation took 517 of ~678 sampled 503s. - backend: drop Retry-After from the record_capture_pending 503. Shipped clients then skip that WAL for the pass (no retry budget spent) and keep draining the rest. - app: carry the closed record_capture_pending body code on the 5xx exception and never turn it into an account pause. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
Codex Review Summary: ✅ CompletedThis 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.
All reported issues were addressed across 8 files
You’re at about 90% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f1f22cbde1
ℹ️ 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".
- drop @VisibleForTesting from syncUploadServerWaitReasonCode (production caller) - report record_capture_pending as a deferred upload, not a failure - document the old-client 2-30s unscoped-5xx pause in the backend comment - remove the accidentally committed .agent-brief guard state file Failure-Class: FC-shared-backoff-conflated-independent-budgets Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
…ccount Review (Luna): keep server-side pacing for the record_capture_pending wait without restoring the account-wide Retry-After pause. - backend: memoize conversation-level waits (record_jobs_missing, reservation_pending) in Redis for 30s per (uid, conversation); a repeat upload in that window gets the same 503 before any file save, archive or decode. Redis errors fall through to the full check. - backend: the 503 body carries retry_after_seconds. - app: hold only that conversation's WALs out of the drain for the body's wait (in memory, capped at 300s), and skip the unscoped 5xx streak pause for it, so other recordings keep draining. Failure-Class: FC-shared-backoff-conflated-independent-budgets Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
conversation_pending takes an optional conversation id (it can be unresolved); make it public since the diagnostics test exercises it. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
|
Generated by Claude Code |
A record_capture_pending 503 from a server still on the old response (Retry-After, no retry_after_seconds) suppressed both the account cooldown and the 5xx streak pause but deferred nothing. Fall back to Retry-After, then a 30s default, and keep the streak pause when the wait cannot be held per recording. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
…ng id (#24881) <!-- claude-projects-attribution: {"github_login":"Git-on-my-level"} --> _Requested by **David** · [project thread](https://claude.ai/code/project/chan_01DkCywHd8HiN61t59mu7kXF?thread=cmsg_01DkCywHd8HiN61t59mu7kXFGu7Ct3VDDM5taHZakAHEDE)_ ## What changed and why After #24853 shipped, `record_capture_pending` 503s on `/v2/sync-local-files` held steady at about 2.3k per 15 minutes on 2026-11-07, roughly half `record_jobs_missing` and half `audio_coverage_unproven`. Three questions couldn't be answered from the logs: - whether that was one recording retried thousands of times or thousands of recordings; - which drain admission retry reason a stuck upload was hitting, since neither log line carried a per-recording key; - why coverage failed. Answering any of them meant row-level reads of user data. This is a log-only change: - `event=sync_record_upload outcome=pending` adds `record=<16 hex>`. That's a prefix of the record content hash `sha256("record-v1:{uid}:{cid}")`, which is also the intake key `bp_<content>`. A wait raised before the record identity is known logs `record=-`. - `event=batch_live_admission outcome=retry` adds the same `record=<16 hex>` key, taken from the record_pending job's `record_content_id`, so a pending upload can be joined to its drain retry reason. - New `event=sync_record_coverage outcome=unproven cause=<cause>` before an `audio_coverage_unproven` wait, with a static cause: - `wal_audio_outside_record`: the WAL has audio before or between the record's units. - `wal_audio_past_record`: the WAL runs past the record's last unit. - `audio_bytes_differ`: the overlapping samples differ. - `record_unit_exhausted`: no overlapping record samples were left. This separates a phone holding audio the record lacks from a decode or alignment mismatch, and the two need different fixes. The key is a one-way hash. No uid, conversation id, audio or error text is logged. Status codes, bodies, retention and admission behavior are unchanged. ## Product invariants affected none ## How it was verified - `backend/`: `python -m pytest tests/unit/test_sync_admission_diagnostics.py tests/unit/test_record_drain_barrier_backoff.py tests/unit/test_record_drain_privacy_defer.py` → 42 passed. - `scripts/backend-python-format --write` on the changed files. - `scripts/pr-preflight --pr-body-file` → 36 checks passed. ## Tests - `test_sync_admission_diagnostics.py`: - Every pending reason logs the expected `record=` key: the content prefix, or `-` for an owner-context mismatch. Neither the uid nor the conversation id appears in the line. - `_covered` logs no cause when the audio is covered. It logs the right cause for WAL audio before the record, after the record, or with differing bytes. - `test_record_drain_barrier_backoff.py`: the drain retry line ends with the job's `record=` content prefix and doesn't contain the owner id. ## UI evidence UI-Evidence: none -- no UI change 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
Requested by David · project thread
What changed and why
On 2026-11-07, POST /v2/sync-local-files answered mostly 503s (sampled load-balancer logs: ~678 503s against 8 202s), and 517 of those 503s were uploads for a single conversation. The 503 is
record_capture_pending, a per-conversation custody wait: the registered record cannot yet prove it covers the phone's WAL. It was sent withRetry-After: 30.Shipped apps treat any 5xx with a Retry-After as an account-wide
backendBusypause (sync_upload_gate.dart), and the drain starts with the oldest WAL. So one stuck conversation got retried first on every pass, paused the whole account for 30s, and stopped every other recording from uploading. That matches the multi-hour upload tail seen in the capture-to-Home timeline.record_capture_pendingno longer sends Retry-After. Shipped clients then handle it as an unscoped 5xx: that WAL stays pending without spending its retry budget, gets skipped for the rest of the pass, and the drain keeps uploading other recordings (with the existing short 2–30s streak pause).record_capture_pendingbody code, and the upload gate never turns that code into an account pause, even if a server sends Retry-After again. The upload is recorded as a deferred upload, not a failure.retry_after_seconds: 30. New apps hold only that conversation's WALs out of the drain for that long (in memory, capped at 300s) and skip the unscoped-5xx streak pause for it.record_jobs_missing,reservation_pending) in Redis for 30s per (uid, conversation). A repeat upload in that window gets the same 503 before any file save, archive or decode, so a hot loop from an old client costs almost nothing. Redis errors are a cache miss and run the full check.This PR does not unstick the conversation that is waiting. That root cause is tracked separately.
Product invariants affected
How it was verified
backend/:python -m pytest tests/unit/test_sync_admission_diagnostics.py→ 13 passed. A wider sync/batch set (test_sync_v2, test_batch_intake_outcome, test_legacy_dark_router, test_mobile_standard_batch, test_sync_cloud_tasks, test_sync_capture_time_skew, test_batch_language_eligibility, test_cap_publication_retry) gives 684 passed and 20 failed. The same 20 fail on the unmodified base in the same environment, so they are environment failures and not caused by this change.scripts/pr-preflight --pr-body-file→ 48 checks passed.Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 2707 -> 2714 | per-recording wait wiring in the existing drain loop; the deferral lives in recording_wait_deferrals.dart
Line-Count-Exception: backend/routers/sync.py | 3812 -> 3816 | one early return for the memoized wait before upload work
Tests
backend/tests/unit/test_sync_admission_diagnostics.py: asserts therecord_capture_pending503 has no Retry-After.app/test/unit/sync_upload_gate_test.dart:record_capture_pending503 with Retry-After leaves the limiter clear;app/test/unit/recording_wait_deferrals_test.dart:record_capture_pendingbody carries pacing.backend/tests/unit/test_sync_admission_diagnostics.py:UI evidence
UI-Evidence: none -- no UI change
Failure class (fixes)
Failure-Class: FC-shared-backoff-conflated-independent-budgets
🤖 Generated with Claude Code
https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS