Skip to content

fix(sync): keep one recording's custody wait from pausing the whole upload queue - #24853

Merged
Git-on-my-level merged 7 commits into
mainfrom
claude/project-thread-cqxm31
Nov 7, 2026
Merged

Git-on-my-level merged 7 commits into
mainfrom
claude/project-thread-cqxm31

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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 with Retry-After: 30.

Shipped apps treat any 5xx with a Retry-After as an account-wide backendBusy pause (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.

  • Backend: record_capture_pending no 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).
  • App: the 5xx exception now carries the closed record_capture_pending body 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.
  • Per-conversation pacing (review): pacing still happens, but per conversation and never per account.
    • The 503 body carries 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.
    • If the body has no pacing (a server still on the old response, which sends only Retry-After), the app uses Retry-After, and then a 30s default. A recognized wait is never retried without a delay. If the batch has no conversation to hold, the streak pause still applies.
    • The server memoizes 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, so a hot loop from an old client costs almost nothing. Redis errors are a cache miss and run the full check.
    • Why there's no short Retry-After: current builds turn any 5xx Retry-After into an account cooldown, end the drain, and restart oldest-first on cooldown expiry. That reproduces the stall at any length.

This PR does not unstick the conversation that is waiting. That root cause is tracked separately.

Product invariants affected

  • INV-CAP-1: no audio is released. The WAL stays local and pending, as before. Only the account-wide pause goes away.

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.
  • App: Flutter isn't available in the authoring environment, so the Dart tests run in CI. Head 60145aa passed Dart Analyze & Tests.

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 the record_capture_pending 503 has no Retry-After.
  • app/test/unit/sync_upload_gate_test.dart:
    • a record_capture_pending 503 with Retry-After leaves the limiter clear;
    • an unscoped 503 with Retry-After still pauses the account;
    • only the closed body code is parsed.
  • app/test/unit/recording_wait_deferrals_test.dart:
    • a wait holds only its own conversation and expires;
    • a wait is capped at 300s;
    • a recognized wait with no pacing still holds for the 30s default, and a wait with no conversation reports that it was not held;
    • only a record_capture_pending body carries pacing.
  • backend/tests/unit/test_sync_admission_diagnostics.py:
    • conversation-level waits are memoized and repeated, and never hold another conversation;
    • content-level waits are not memoized;
    • an unknown memo value falls through.

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

…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
@Git-on-my-level Git-on-my-level self-assigned this Nov 7, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T17:44:26.601947Z a8cf613 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.

@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.

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

@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: 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
…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

Copy link
Copy Markdown
Member Author

Backend unit shard 3/8 failed on 60145aa because of the per-test CPU timing guard, not a test assertion. tests/unit/test_source_audio_listing.py::test_listing_to_walk_keeps_identical_references_without_reload took 1.04s against a 1.00s budget. This PR doesn't touch that file or its code path, and all 8 tests in the file pass locally. It's a loaded-runner flake, so there's no fix to port. I'll re-run the failed job once the workflow run finishes; GitHub refuses the re-run while other shards are still running.


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
@Git-on-my-level
Git-on-my-level merged commit 9767bd1 into main Nov 7, 2026
63 checks passed
@Git-on-my-level
Git-on-my-level deleted the claude/project-thread-cqxm31 branch November 7, 2026 18:53
Git-on-my-level added a commit that referenced this pull request Nov 7, 2026
…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
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.

2 participants