Skip to content

chore(app): log the server reason on sync upload HTTP failures - #26506

Merged
aryanorastar merged 2 commits into
mainfrom
chore/sync-503-reason-log
Nov 30, 2026
Merged

aryanorastar merged 2 commits into
mainfrom
chore/sync-503-reason-log

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

A customer's shared debug log had hundreds of identical Local upload HTTP failure: SyncUploadHttpException(status=503): Server is temporarily unavailable lines and nothing else. The app already parses the response's reason code, Retry-After and recording-scoped wait into SyncUploadHttpException, but the failure line wrote only the status and batch fields. Support could not tell an Omi refusal (for example record_capture_pending) from platform shedding without server logs, and per-account server logs aren't joinable today.

This writes reasonCode, retryAfterSeconds and recordingWaitSeconds into that existing line when the server supplied them. They are server-defined tokens and numbers, not user content. An absent reasonCode on a 5xx now means a platform response with no Omi reason.

Refs #21943.

Product invariants affected

  • INV-CAP-1: path-matched only (app/lib/services/wals/local_wal_sync.dart). This is a log-field change; frame delivery, retention, retry and upload decisions are unchanged.

How it was verified

  • flutter test --no-pub test/unit/wal_upload_resilience_test.dart --plain-name 'server reason and pacing' passes. With the local_wal_sync.dart change reverted, the same test fails: Expected: 'sync_dispatch_busy', Actual: <null>.
  • flutter test --no-pub test/unit/wal_upload_resilience_test.dart test/unit/local_wal_sync_test.dart test/unit/sync_upload_gate_test.dart: 245 passed.
  • flutter analyze --no-pub on both changed Dart files: no issues. dart format --line-length 120: no changes.
  • make preflight: 27 checks passed.
  • Not exercised on a simulator or device: the change only adds fields to an existing debug-log line, and the test reads the real log file written by the production drain.

Tests

New a 503 failure line in the shared debug log carries the server reason and pacing in app/test/unit/wal_upload_resilience_test.dart. It drives the production LocalWalSyncImpl drain through SyncUploadGate with an injected uploader that returns a 503 with a reason code and Retry-After, then reads the shared debug log file. It also asserts that an absent server field stays absent.

Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 3362 -> 3366 | three optional fields on the existing failure log line plus one comment; splitting the drain is out of scope for a log-only change

UI evidence

UI-Evidence: none -- debug-log fields only, no UI change

Failure class (fixes)

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

A shared debug log showed hundreds of identical "Local upload HTTP failure:
SyncUploadHttpException(status=503): Server is temporarily unavailable" lines
and nothing else. The app already parses the response's reason code, Retry-After
and recording-scoped wait into SyncUploadHttpException, but the failure line only
wrote the status and batch fields. Support could not tell an Omi refusal (for
example record_capture_pending) from platform shedding without server logs.

Write reasonCode, retryAfterSeconds and recordingWaitSeconds into the existing
failure line when the server supplied them. They are server-defined tokens and
numbers, no user content. An absent reasonCode now means a platform 5xx.

Verification:
- New test in wal_upload_resilience_test.dart drives the production drain with a
  503 carrying reasonCode + Retry-After and reads the shared debug log file. It
  fails without the change (Expected 'sync_dispatch_busy', Actual null) and
  passes with it.
- flutter test test/unit/wal_upload_resilience_test.dart
  test/unit/local_wal_sync_test.dart test/unit/sync_upload_gate_test.dart: 245 passed.
- flutter analyze on both files: no issues. make preflight: passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member

The production change is correct and tightly scoped; nothing blocking, a few small suggestions below.

  • app/lib/services/wals/local_wal_sync.dart:2975-2978 — the three new fields are added to the existing Local upload HTTP failure line only when non-null, and the retry/backoff branch at line 2980 is untouched. I traced every source of SyncUploadHttpException.reasonCode (app/lib/backend/http/api/conversations.dart:1387-1420): all of them are closed tokens (the SyncUploadRefusalBody.reasonCode allowlist, the too_large / recording-capture-pending literals, and syncUploadServerWaitReasonCode, which only ever returns record_capture_pending). So the "server-supplied tokens only" comment is accurate and no server free text lands in the shared debug log.
  • app/test/unit/wal_upload_resilience_test.dart:1159-1193 — drives the real drain and reads the log file the production code wrote, and asserts the absent-field case too. Same pattern as the existing DebugLogManager tests in local_wal_sync_test.dart / ring_custody_download_test.dart. Good regression coverage.
  • app/changelog/unreleased/20261127-sync-upload-failure-reason-log.json — kind: none matches the existing fragments; appropriate for a log-only change.

Notes (non-blocking):

  • Test nit: reasonCode: 'sync_dispatch_busy' is not a token the 5xx parser currently attaches to this exception (that path only yields record_capture_pending). The assertion still works, but using record_capture_pending plus recordingWaitSeconds: N would also cover the third new field, which is currently unasserted.
  • The single-WAL refusal path (local_wal_sync.dart:3264, single_wal_terminal_http_refusal) still logs only statusCode; carrying the bounded reason there too would make the two paths symmetric in a follow-up.
  • No throttling of this line, so a customer in the original scenario still gets hundreds of identical entries, now with three more fields each. Not a blocker; a per-drain dedupe would be a separate change if log size matters.

Security: nothing new leaves the device beyond closed tokens and integers that the shared debug log already accompanies. Performance: three extra map entries on an existing log write, no new I/O.

USER IMPACT: nothing visible in the app; support engineers reading a shared debug log will now see why a sync upload was refused (a recording-side wait versus a platform outage) without needing server-side logs.

Still want as a reviewer: an assertion for recordingWaitSeconds (first note). Fine to fold in before the PR leaves draft.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added flutter flutter work positive-signal Automation verified a genuine fix/quality contribution labels Nov 27, 2026
Review asked for a recordingWaitSeconds assertion. The test now uses the
realistic recording-scoped refusal (record_capture_pending with Retry-After and
a 30-minute recording wait) and asserts all three fields. A second case, a plain
platform 503, asserts that none of them appear, so an absent reasonCode keeps
meaning "no Omi reason".

Verification: removing the recordingWaitSeconds line from local_wal_sync.dart
fails the test (Expected 1800, Actual null). With it restored, the
wal_upload_resilience, local_wal_sync and sync_upload_gate suites pass (245).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Pushed 7e24fde: test-only change.

  • The test now uses the realistic recording-scoped refusal: record_capture_pending with Retry-After 30 and recordingWaitSeconds: 1800. It asserts all three fields. A second case, a plain platform 503, asserts that none of them appear.
  • Mutation check: removing the recordingWaitSeconds line from local_wal_sync.dart fails it (Expected: <1800>, Actual: <null>). With the line restored, wal_upload_resilience_test, local_wal_sync_test and sync_upload_gate_test pass (245).
  • Left for follow-ups, as suggested: the same reason fields on the single-WAL refusal line (single_wal_terminal_http_refusal), and per-drain dedupe of repeated failure lines.

@Git-on-my-level

Copy link
Copy Markdown
Member

Since my last review: addressed (the test now asserts recordingWaitSeconds and uses the recording-scoped refusal the 5xx parser actually attaches, verified on 7e24fde) · still open (nothing blocking; the single-WAL refusal line and per-drain dedupe remain agreed follow-ups) · newly introduced (none).

This is ready from my side once it leaves draft; the production change is unchanged and the test now covers every field it adds.

  • app/test/unit/wal_upload_resilience_test.dart:1160-1199 — the scoped case builds SyncUploadHttpException(503, ..., reasonCode: recordCapturePending, retryAfterSeconds: 30, recordingWaitSeconds: 1800) from the real constant in sync_upload_refusal.dart and asserts all three keys; the plain-503 case asserts all three are absent. That is the realistic shape the server sends for a recording-scoped wait, so the test now matches what support will see in a customer log. The failureLine() helper keeps the original semantics (real drain, then read the log file the production code wrote).
  • app/lib/services/wals/local_wal_sync.dart:2975-2978 — byte-identical to the head I reviewed earlier; the retry/backoff branch at line 2980 is untouched.
  • app/changelog/unreleased/20261127-sync-upload-failure-reason-log.json — unchanged, kind: none still appropriate for a log-only change.

Checks on this head are green (Dart Analyze & Tests, Formatting, Hygiene, CodeQL among 48 runs, none failed).

Security: unchanged; only closed tokens and integers are added to the shared debug log. Performance: no change from the prior head.

USER IMPACT: none — internal change; support reading a shared debug log will see why a sync upload was refused without server-side logs.

Nothing further from me. Leaving for human maintainer review before merge given the draft state.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar
aryanorastar marked this pull request as ready for review November 28, 2026 16:09
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-28T16:09:19.738768Z
We couldn’t complete this review. Comment @codex review to try again.
7e24fde Draft marked ready
ℹ️ 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@aryanorastar
aryanorastar merged commit 84a7b53 into main Nov 30, 2026
52 checks passed
@aryanorastar
aryanorastar deleted the chore/sync-503-reason-log branch November 30, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants