fix(android): timeline thumbnails converge during upload runs #1524

Merged
chris merged 1 commit from fix/android-timeline-thumb-refresh into main 2026-11-15 17:56:10 +01:00
Owner

Defect

While the Android app uploads/backups media, the Fotos timeline showed placeholder tiles (previewStatus == PENDING) with spinners that NEVER flipped to the real thumbnail when the server finished it; newly committed items appeared only after the whole run ended. Both required a manual pull-to-refresh.

Root cause — three stacked gaps (server emission verified healthy, untouched)

  1. SSE transport: ServerEventStream ran on a plain OkHttpClient() — default read timeout 10 s — against a server whose event stream sends no heartbeats (emitter closes only at 30 min). The idle socket was torn down every quiet 10 s; events emitted during the 1–60 s reconnect backoff (thumbnails_ready, timeline_visibility_changed) were lost. The web client (browser EventSource) has no such timeout — an Android-only regression. Verified thumbnails_ready emission is healthy server-side (DerivedAssetResultHandler → WorkerResultService → publishThumbnailsReadyAfterCommit, owner included in viewer set; WorkerResultThumbnailsReadyEventTest covers it).

  2. PENDING cells had no self-healing: ThumbnailCell renders no image request while previewStatus == pending, so the per-cell 6 s×10 retry loop never ran for them; a missed event pinned the spinner until manual refresh.

  3. Engine commits invisible mid-run: TimelineViewModel refreshed only on the active→terminal BackupWorkSnapshot transition — during a multi-minute run nothing refreshed, new items only appeared at run end.

Fix (client-side only, additive)

  • ServerEventStream.streamingClient(): read + call timeouts disabled, connect/write bounded 15 s; pinned by SseTransportTimeoutTest (also guards the 10 s default that broke it).
  • ThumbnailRetryScheduler.startPendingProbes(): bounded slow probe lane for pending cells (60 s × 10, negative attempt numbers, budget separate from the failed-load lane, torn down on status change/dispose/first load callback). Once armed, the cell fetches the thumbnail even while the status still reads pending.
  • BackupEngine gains an additive outcome-only onBatchCommitted(sessionId) hook fired inside the NonCancellable durability epilogue (never on abort/empty run). No upload/commit protocol change; UploadSessionClient untouched (the upload-error lane consumes the same outcomes; we add no changes there). Threaded via AndroidSyncController → container-scoped MutableSharedFlow → factory → TimelineViewModel.backupCommitEvents, which sets windowRefreshRequested through the existing scheduleTargetedRefresh worker (400 ms debounce; no second refresh path). Terminal-snapshot refresh kept as safety net.
  • No UI layout changes (chip layout is PR #1522's scope).

Tests

  • Engine: commit pulse fired once with session id / empty run never fires / aborted run never fires.
  • ViewModel: mid-run convergence without any terminal snapshot, pulse debounce to one cycle, unauthorized guard.
  • Scheduler: pending lanes (cadence, cap, no stacking, cancel, budget separation).
  • Transport: streaming client timeout config.
  • Full :core + :app unit suites green (post-rebase on latest main); app module compiled.

[ISSUE-233]

## Defect While the Android app uploads/backups media, the Fotos timeline showed placeholder tiles (previewStatus == PENDING) with spinners that NEVER flipped to the real thumbnail when the server finished it; newly committed items appeared only after the whole run ended. Both required a manual pull-to-refresh. ## Root cause — three stacked gaps (server emission verified healthy, untouched) 1. **SSE transport**: `ServerEventStream` ran on a plain `OkHttpClient()` — default **read timeout 10 s** — against a server whose event stream sends no heartbeats (emitter closes only at 30 min). The idle socket was torn down every quiet 10 s; events emitted during the 1–60 s reconnect backoff (`thumbnails_ready`, `timeline_visibility_changed`) were lost. The web client (browser EventSource) has no such timeout — an Android-only regression. Verified `thumbnails_ready` emission is healthy server-side (`DerivedAssetResultHandler` → `WorkerResultService` → `publishThumbnailsReadyAfterCommit`, owner included in viewer set; `WorkerResultThumbnailsReadyEventTest` covers it). 2. **PENDING cells had no self-healing**: `ThumbnailCell` renders **no image request** while `previewStatus == pending`, so the per-cell 6 s×10 retry loop never ran for them; a missed event pinned the spinner until manual refresh. 3. **Engine commits invisible mid-run**: `TimelineViewModel` refreshed only on the active→terminal `BackupWorkSnapshot` transition — during a multi-minute run nothing refreshed, new items only appeared at run end. ## Fix (client-side only, additive) - `ServerEventStream.streamingClient()`: read + call timeouts disabled, connect/write bounded 15 s; pinned by `SseTransportTimeoutTest` (also guards the 10 s default that broke it). - `ThumbnailRetryScheduler.startPendingProbes()`: bounded slow probe lane for pending cells (60 s × 10, negative attempt numbers, budget separate from the failed-load lane, torn down on status change/dispose/first load callback). Once armed, the cell fetches the thumbnail even while the status still reads pending. - `BackupEngine` gains an **additive outcome-only** `onBatchCommitted(sessionId)` hook fired inside the NonCancellable durability epilogue (never on abort/empty run). No upload/commit protocol change; `UploadSessionClient` untouched (the upload-error lane consumes the same outcomes; we add no changes there). Threaded via `AndroidSyncController` → container-scoped `MutableSharedFlow` → factory → `TimelineViewModel.backupCommitEvents`, which sets `windowRefreshRequested` through the **existing** `scheduleTargetedRefresh` worker (400 ms debounce; no second refresh path). Terminal-snapshot refresh kept as safety net. - No UI layout changes (chip layout is PR #1522's scope). ## Tests - Engine: commit pulse fired once with session id / empty run never fires / aborted run never fires. - ViewModel: **mid-run convergence without any terminal snapshot**, pulse debounce to one cycle, unauthorized guard. - Scheduler: pending lanes (cadence, cap, no stacking, cancel, budget separation). - Transport: streaming client timeout config. - Full `:core` + `:app` unit suites green (post-rebase on latest main); app module compiled. [ISSUE-233]
fix(android): timeline thumbnails converge during upload runs
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 2s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Deploy review instance (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 5s
Build and Deploy / Android unit tests and debug APK (push) Successful in 1m58s
f185cea8e9
Three stacked gaps kept timeline tiles in the PENDING spinner state while
the device uploaded, and new photos only appeared after the whole run:

1. SSE transport: ServerEventStream ran on a plain OkHttpClient() whose
   default 10 s read timeout tore the heartbeat-less event stream down
   every quiet 10 s; events emitted inside the 1-60 s reconnect backoff
   were lost. streamingClient() disables read+call timeouts (connect and
   write stay bounded); SseTransportTimeoutTest pins the configuration.
2. Pending cells had no self-healing: ThumbnailCell renders no image
   request while previewStatus == pending, so the 6 s x 10 failed-load
   retry never ran for them. ThumbnailRetryScheduler.startPendingProbes
   adds a bounded slow lane (60 s x 10, negative attempt numbers, budget
   separate from the failed-load lane); an armed probe fetches the
   thumbnail even while the status still reads pending.
3. Engine commits were invisible mid-run: TimelineViewModel refreshed
   only on the active->terminal BackupWorkSnapshot transition. The engine
   gains an additive outcome-only onBatchCommitted hook (fired inside the
   NonCancellable durability epilogue, never on abort/empty run), pulsed
   through AndroidSyncController into a container-scoped SharedFlow; the
   factory passes it as TimelineViewModel.backupCommitEvents, which sets
   windowRefreshRequested through the existing scheduleTargetedRefresh
   worker (400 ms debounce, no second refresh path). The terminal
   snapshot refresh remains as the safety net.

Server emission (thumbnails_ready / timeline_visibility_changed) verified
healthy and left untouched; payload and back-compat preserved for web.

Tests: engine commit-pulse (fired / empty run / aborted run), ViewModel
mid-run convergence + debounce + unauthorized guard, scheduler pending
lanes, SSE transport config. Full :core and :app unit suites green.

Refs [ISSUE-233].
chris force-pushed fix/android-timeline-thumb-refresh from f185cea8e9
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 2s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Deploy review instance (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 5s
Build and Deploy / Android unit tests and debug APK (push) Successful in 1m58s
to 4d5f1e1923
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 2s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Deploy review instance (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 5s
Build and Deploy / Android unit tests and debug APK (push) Successful in 6m52s
2026-11-15 17:48:17 +01:00
Compare
chris merged commit f6733c3797 into main 2026-11-15 17:56:10 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1524
No description provided.