Repository navigation
Description
Sync Health Issues — Root Cause Analysis
Cross-referenced runtime signals (BQ, Crashlytics, Cloud Logging) with code tracing on latest main. Six confirmed issues across backend and mobile client.
Issue 1: 429 Retry Storm on Sync Endpoints
Root cause: Fair-use budget gate returns 429 when minutes exhausted. Client (app/lib/backend/http/api/conversations.dart:410) throws immediately on 429 with zero backoff — no exponential retry, no Retry-After header parsing.
Runtime evidence:
- 3K–13K 429s/day on sync endpoints (last 7 days)
- May 30 burst: 707 429s in a single hour (07:00 UTC)
- Top IP
188.***45: 1,899 429s in 7-hour window (May 30 04:24–11:22 UTC), zero successful requests. Single user who exhausted budget and client retried for 7 hours straight. - All 429s from
backend-syncservice (serverIp34.***00), not upstream proxy.
Code path: app/lib/backend/http/api/conversations.dart:410-411 — throw Exception('Rate limited or budget exhausted') with no retry logic.
Impact: Wasted server resources, degraded UX for rate-limited users.
Issue 2: WAL _getMissingWals Null Race Condition (66 crashes, 29 users)
Root cause: FlashPageWalSyncImpl._getMissingWals reads oldest_flash_page/newest_flash_page indices from device, but indices go stale if device clears pages between read and use.
Crashlytics stack trace: Null check operator used on a null value at flash_page_wal_sync.dart:128. Call path: setDevice → _getMissingWals.
Code path: app/lib/services/wals/flash_page_wal_sync.dart:111-128 — reads page indices, then uses them later without refreshing. Race between setDevice and page access.
Impact: High — 29 users affected, potential data loss from failed sync.
Issue 3: WAL _flush OOM (16 crashes, 4 users)
Root cause: LocalWalSyncImpl._flush accumulates all WAL frames via unbounded List.addAll before writing to disk. On large WALs, this exhausts memory.
Crashlytics stack trace: Out of Memory at List.addAll → _flush.
Code path: app/lib/services/wals/local_wal_sync.dart:240-284 — no chunked writing, entire frame buffer loaded into memory. Secondary issue: writeAsBytes (line 268) has no try-catch.
Impact: Medium — 4 users, crashes on devices with large accumulated WALs.
Issue 4: WAL _chunk Unmodifiable List Bug (12 crashes, 6 users)
Root cause: LocalWalSyncImpl._chunk calls addAll on an unmodifiable list at line 228.
Crashlytics stack trace: Cannot add to an unmodifiable list at local_wal_sync.dart:228. Call path: start → _chunk.
Code path: app/lib/services/wals/local_wal_sync.dart:228 — Dart immutability bug, list returned from const or List.unmodifiable is mutated.
Impact: Medium — 6 users affected.
Issue 5: v2 Sync Token Expiry Mid-Upload (401s)
Root cause: syncLocalFilesV2 multipart uploads can run 30+ minutes. Firebase token is checked before upload starts (app/lib/backend/http/shared.dart:25-49) but NOT refreshed during transfer. Token expires mid-upload → 401 → retry re-uploads from scratch.
Runtime evidence:
- 200–1,300 401s/day on sync endpoints
- 97% on v2 (733 v2 vs 24 v1 in 3 days)
- Top 8 IPs account for 88% of 401s — power users with large sync queues
- Time pattern: spikes at 02:00 (130), 06:00 (106), 07:00 (236 — peak) UTC — overnight sync batches when devices accumulate audio files
- Top IP: 218 401s in a single day
Code path: app/lib/backend/http/shared.dart:240-286 — multipart upload checks token before request, no mid-upload refresh.
Impact: Medium — 8 power users affected, wasted bandwidth from repeated full re-uploads.
Issue 6: v1 Audio Sync Extreme Latency (200–400s)
Root cause: /v1/sync/audio/{id}/urls handler synchronously calls _precache_audio_file() for first uncached audio file. This blocks the HTTP request while performing: GCS chunk listing → parallel chunk download → AES-256-GCM decryption → Opus decode → PCM merge → WAV conversion → GCS cache upload.
Runtime evidence:
- May 27–28: individual requests took 200–400s (max 400.5s at 03:00 UTC May 27)
- All returned 200 OK — requests complete, just extremely slowly
- 85% of slow requests from 2 IPs on same /24 subnet (
136.***69,136.***73) — power users bulk-syncing- IP1: 266 requests >60s, avg 180s, max 393s, 5+ distinct audio IDs
- IP2: 118 requests >60s, avg 216s, max 401s, 5+ distinct audio IDs
- Remaining ~13 IPs at 2–8 slow requests each
Code path: backend/routers/sync.py:260 — synchronous _precache_audio_file() call. v1 /sync-local-files deprecated (PR #7125) but audio URLs endpoints still active without deprecation headers.
Impact: Low — 2 users, deprecated path. Not system-wide.
Latency Profile (last 3 days, BQ)
| Version | Status | Count | p50 | p95 | p99 | Max |
|---|---|---|---|---|---|---|
| v2 | 200 | 168K | 11ms | 36ms | 289ms | 13.6s |
| v2 | 202 | 117K | 112ms | 298ms | 536ms | 6.5s |
| v2 | 429 | 3.8K | 39ms | 59ms | 120ms | 0.5s |
| v1 | 200 | 7K | 55ms | 887ms | 3.1s | 17.3s |
Priority
| # | Issue | Severity | Users |
|---|---|---|---|
| 1 | WAL _getMissingWals null race |
High | 29 |
| 2 | Client 429 backoff missing | Medium | at scale |
| 3 | WAL _flush OOM |
Medium | 4 |
| 4 | WAL _chunk immutable list |
Medium | 6 |
| 5 | v2 token expiry mid-upload | Medium | 8 |
| 6 | v1 audio precache latency | Low | 2 |
Investigation by @mon (runtime signals) and @taro (code tracing) for @beastoin
Activity
beastoin commentedon Jun 2, 2026
Affected Users (Redacted)
Issue 1: 429 Retry Storm
No Firebase UID available — 429s are returned by fair-use budget gate before auth handler logs UID.
188.***45— 1,899 429s, May 30 04:24–11:22 UTC, zero successful requests04N***kp1,aa3***wA3,tif***iD3,ewE***Z33,cOK***RU2Issue 2: WAL
_getMissingWalsNull Race (top 5 of 29 users)Crashlytics installation UUIDs (device IDs, not Firebase UIDs):
A81***EE3362***1F3B41***338F40***5B5631***090Issue 3: WAL
_flushOOM (all 4 users)57E***78B390***12BA4E***857920***E2CIssue 4: WAL
_chunkImmutable List (top 3 of 6 users)B8A***19C00F***265A98***756Issue 5: v2 Token Expiry 401s
No Firebase UID — 401s rejected at auth middleware before UID extraction.
221.***62114.***6836.***243Issue 6: v1 Audio Latency
No Firebase UID — sync audio handler doesn't log UIDs.
136.***69136.***73Same /24 subnet — likely same household.
Instrumentation Gap
Firebase UIDs are not available for issues 1, 5, and 6 because:
installation_uuid(device fingerprint), not Firebase UIDRecommended instrumentation fixes:
by @taro for @beastoin
beastoin commentedon Jun 10, 2026
Closing as not planned per CTO directive (2026-06-10).
by AI for @beastoin