Daily use 9: Image load retry (#493) #541

Closed
charles wants to merge 0 commits from dailyuse-9-image-load-retry into dailyuse
Owner

What was built

Failed image loads are now retried the way the web app's ImageCacheUtils.ts retries them (spec §3.10, feat/messaging/utils/ImageCacheUtils.ts:37-43,93-94,177-232,416-433):

  • ImageState::Failed { attempts, cycle, retry_at } is tracked per URL. A request at or after retry_at loads the image again, and a request before then fetches nothing.
  • Each cycle allows 2 retries. The delay is min(d + 2·d·random, 10 s) and starts at d = 1 s. After a failed cycle comes a cooldown, failure_cooldown(cycle) = min(60 s, 2 s · 2^(cycle−1)), and the next cycle's delay starts again at 1 s. A success resets everything.
  • Every failure is retried the same way, a 404 included. The original never sees a status code.
  • Window focus calls Images::wake_on_focus(), which makes every failed image due at once (cooldowns included, as wakeRecoveries does) at most once per 15 s (FOCUS_WAKE_INTERVAL). Loads in flight are left alone.
  • The fallback (initials, default avatar, placeholder) shows meanwhile, because get returns None until a load succeeds.
  • The shell subscribes to Images::next_retry(). When that time comes, UiMessage::ImagesDue re-requests the images on screen, so only images that are still shown are retried. This matches the original's recoveries, which run only while something waits for the image.
  • with_clock and with_random inject the time and the jitter. The default jitter is a RandomState hash (no new dependency).

Tests

  • crates/fluxer-ui/tests/image_retry.rs: retry_schedule_matches_original (fixed RNG), delay_is_capped_at_ten_seconds, cooldown_doubles_to_60s, focus_wakes_due_retries_throttled_15s, success_replaces_fallback, request_while_cooling_down_does_not_refetch, not_found_is_retried_like_any_failure and forgetting_resets_the_schedule. Before the implementation they failed to compile; now they pass.
  • Updated unit tests in images.rs.
  • FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci passes locally. No FLUXER_DESKTOP_TESTS tests apply to this change.

Deviations from the plan

  • crates/fluxer-ui/src/message.rs gains one variant, UiMessage::ImagesDue, for the retry timer. That file is not in the task's Files list.
  • iced's thread-pool executor has no timer, so retry_due in app.rs spawns a short-lived thread that sleeps until the retry is due. This is not I/O, but please review it.
  • An image larger than the whole pixel budget was previously Failed. It is now ImageState::TooLarge and is never retried, because retrying it would only refetch from the cache forever.
  • The "network online" wake from the original is not implemented: the UI has no online signal. The 30 s load timeout already exists in fluxer_platform::images::ImageCache (REQUEST_TIMEOUT).

Closes #493
Closes #209

🤖 Generated with Claude Code

## What was built Failed image loads are now retried the way the web app's `ImageCacheUtils.ts` retries them (spec §3.10, `feat/messaging/utils/ImageCacheUtils.ts:37-43,93-94,177-232,416-433`): - `ImageState::Failed { attempts, cycle, retry_at }` is tracked per URL. A request at or after `retry_at` loads the image again, and a request before then fetches nothing. - Each cycle allows 2 retries. The delay is `min(d + 2·d·random, 10 s)` and starts at d = 1 s. After a failed cycle comes a cooldown, `failure_cooldown(cycle)` = `min(60 s, 2 s · 2^(cycle−1))`, and the next cycle's delay starts again at 1 s. A success resets everything. - Every failure is retried the same way, a 404 included. The original never sees a status code. - Window focus calls `Images::wake_on_focus()`, which makes every failed image due at once (cooldowns included, as `wakeRecoveries` does) at most once per 15 s (`FOCUS_WAKE_INTERVAL`). Loads in flight are left alone. - The fallback (initials, default avatar, placeholder) shows meanwhile, because `get` returns `None` until a load succeeds. - The shell subscribes to `Images::next_retry()`. When that time comes, `UiMessage::ImagesDue` re-requests the images on screen, so only images that are still shown are retried. This matches the original's recoveries, which run only while something waits for the image. - `with_clock` and `with_random` inject the time and the jitter. The default jitter is a `RandomState` hash (no new dependency). ## Tests - `crates/fluxer-ui/tests/image_retry.rs`: `retry_schedule_matches_original` (fixed RNG), `delay_is_capped_at_ten_seconds`, `cooldown_doubles_to_60s`, `focus_wakes_due_retries_throttled_15s`, `success_replaces_fallback`, `request_while_cooling_down_does_not_refetch`, `not_found_is_retried_like_any_failure` and `forgetting_resets_the_schedule`. Before the implementation they failed to compile; now they pass. - Updated unit tests in `images.rs`. - `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` passes locally. No `FLUXER_DESKTOP_TESTS` tests apply to this change. ## Deviations from the plan - `crates/fluxer-ui/src/message.rs` gains one variant, `UiMessage::ImagesDue`, for the retry timer. That file is not in the task's Files list. - iced's thread-pool executor has no timer, so `retry_due` in `app.rs` spawns a short-lived thread that sleeps until the retry is due. This is not I/O, but please review it. - An image larger than the whole pixel budget was previously `Failed`. It is now `ImageState::TooLarge` and is never retried, because retrying it would only refetch from the cache forever. - The "network online" wake from the original is not implemented: the UI has no online signal. The 30 s load timeout already exists in `fluxer_platform::images::ImageCache` (`REQUEST_TIMEOUT`). Closes #493 Closes #209 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Failed image loads are retried as the web app's ImageCacheUtils.ts
(feat/messaging/utils/ImageCacheUtils.ts:37-43,177-232,416-433): two
retries a cycle at min(d + 2*d*random, 10 s) from d = 1 s, then a
cooldown of min(60 s, 2 s * 2^(cycle-1)); window focus wakes failed
images at most once per 15 s; a 404 is retried like any failure. The
shell requests the shown images again when the next retry is due.

Refs #493

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Author
Owner

Independent review: Daily use 9, Image load retry (58fda4d)

Scope: git diff f2de7cd..origin/dailyuse-9-image-load-retry (images.rs, app.rs, message.rs, README, tests/image_retry.rs).

Plan tests: all six named tests exist in crates/fluxer-ui/tests/image_retry.rs with the spec's values (fixed RNG 0.5 → 2 s, 4 s; cap 10 s; cooldowns 2/4/8/16/32/60; focus throttle 15 s; 404 retried; fallback until success; no refetch while cooling down). There are also two extra tests (delay_is_capped_at_ten_seconds, forgetting_resets_the_schedule).
Interfaces: ImageState::Failed { attempts, cycle, retry_at }, the formula, the cooldown, the 15 s focus wake and the fallback all match the plan. Nothing in the tree outside images.rs matches on ImageState::Failed, so the variant shape change breaks no other task.
Invariants: no new I/O path in fluxer-ui (the timer thread only sleeps), no new dependency, no fixtures, no secrets. The jitter clamp and checked_add handle a non-finite or out-of-range RNG without panicking.
Parity, checked against fluxer_app/src/features/messaging/utils/ImageCacheUtils.ts:

  • retryDelayForAttempt (177-181): the delay is stored and grows as min(d + 2·d·r, 10 s). Matches.
  • scheduleRetryOrFail/failEntry (149-156, 206-232): 2 retries, then the cycle count goes up, the delay resets to 1 s and the cooldown is failureCooldownMs (93-94), with cycle 0 giving 2 s. Matches.
  • wakeRecoveriesOnAttention (428-433): the first focus always wakes (-Infinity), then at most once per 15 s; it wakes cooldowns and pending in-cycle retries. Matches.
  • settleLoaded (158-175): a success resets the schedule. Matches.

Findings

  1. (minor) The 30 s load timeout is handled differently. In the original, a timeout calls failEntry (187-190), which ends the cycle and goes straight to the cooldown. Here the reqwest timeout is an ordinary ImageError, so it uses up one in-cycle retry, roughly 1–3 s later. The effect is a few extra fetches on a dead connection. Follow-up material.
  2. (minor) The original's online wake (438) is not implemented (deviation 4), and neither is its "offline: wait for online without spending retries" (220-223). After a long outage, an image can stay on its fallback for up to 60 s once the connection is back, unless the window is focused. The plan's Interfaces list only the focus wake, so this does not block. Suggest a follow-up issue (gateway reconnect could serve as the online signal).
  3. (minor) retry_due spawns one OS thread for every distinct next_retry() value. A replaced timer's thread keeps sleeping until its own deadline, at most 60 s. When many images fail at staggered times (for example a member list of avatars while offline), dozens of idle threads can exist briefly. This is harmless, but an iced time::every, or a single long-lived timer thread fed through a channel, would bound it.
  4. (minor, accepted deviation) crates/fluxer-ui/src/message.rs is outside the Files list. No parallel Phase-0 branch touches it, and the later tasks that edit fluxer-ui (28, 35) depend on 9, so there is no ownership conflict. Deviation 3 (TooLarge, never retried) is sound: the original has no pixel budget, and retrying would loop on the cache.
  5. (note) In the original, in-cycle retries run on a timer even when nothing shows the image. Here only images still on screen are retried. The difference cannot be seen, so this is not a defect.

Review Focus: no item belongs to Task 9.
Local gate: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci in a clean review worktree: green (exit 0; screenshot tests and image_retry (8 tests) passed).

Verdict: Approve: 0 blocking, 4 minor findings and 1 note. Suggest follow-up issues for 1 and 2.

## Independent review: Daily use 9, Image load retry (`58fda4d`) Scope: `git diff f2de7cd..origin/dailyuse-9-image-load-retry` (images.rs, app.rs, message.rs, README, tests/image_retry.rs). **Plan tests:** all six named tests exist in `crates/fluxer-ui/tests/image_retry.rs` with the spec's values (fixed RNG 0.5 → 2 s, 4 s; cap 10 s; cooldowns 2/4/8/16/32/60; focus throttle 15 s; 404 retried; fallback until success; no refetch while cooling down). There are also two extra tests (`delay_is_capped_at_ten_seconds`, `forgetting_resets_the_schedule`). **Interfaces:** `ImageState::Failed { attempts, cycle, retry_at }`, the formula, the cooldown, the 15 s focus wake and the fallback all match the plan. Nothing in the tree outside images.rs matches on `ImageState::Failed`, so the variant shape change breaks no other task. **Invariants:** no new I/O path in fluxer-ui (the timer thread only sleeps), no new dependency, no fixtures, no secrets. The jitter clamp and `checked_add` handle a non-finite or out-of-range RNG without panicking. **Parity, checked against `fluxer_app/src/features/messaging/utils/ImageCacheUtils.ts`:** - `retryDelayForAttempt` (177-181): the delay is stored and grows as `min(d + 2·d·r, 10 s)`. Matches. - `scheduleRetryOrFail`/`failEntry` (149-156, 206-232): 2 retries, then the cycle count goes up, the delay resets to 1 s and the cooldown is `failureCooldownMs` (93-94), with cycle 0 giving 2 s. Matches. - `wakeRecoveriesOnAttention` (428-433): the first focus always wakes (`-Infinity`), then at most once per 15 s; it wakes cooldowns and pending in-cycle retries. Matches. - `settleLoaded` (158-175): a success resets the schedule. Matches. **Findings** 1. (minor) The 30 s load timeout is handled differently. In the original, a timeout calls `failEntry` (187-190), which ends the cycle and goes straight to the cooldown. Here the reqwest timeout is an ordinary `ImageError`, so it uses up one in-cycle retry, roughly 1–3 s later. The effect is a few extra fetches on a dead connection. Follow-up material. 2. (minor) The original's `online` wake (438) is not implemented (deviation 4), and neither is its "offline: wait for online without spending retries" (220-223). After a long outage, an image can stay on its fallback for up to 60 s once the connection is back, unless the window is focused. The plan's Interfaces list only the focus wake, so this does not block. Suggest a follow-up issue (gateway reconnect could serve as the online signal). 3. (minor) `retry_due` spawns one OS thread for every distinct `next_retry()` value. A replaced timer's thread keeps sleeping until its own deadline, at most 60 s. When many images fail at staggered times (for example a member list of avatars while offline), dozens of idle threads can exist briefly. This is harmless, but an iced `time::every`, or a single long-lived timer thread fed through a channel, would bound it. 4. (minor, accepted deviation) `crates/fluxer-ui/src/message.rs` is outside the Files list. No parallel Phase-0 branch touches it, and the later tasks that edit fluxer-ui (28, 35) depend on 9, so there is no ownership conflict. Deviation 3 (`TooLarge`, never retried) is sound: the original has no pixel budget, and retrying would loop on the cache. 5. (note) In the original, in-cycle retries run on a timer even when nothing shows the image. Here only images still on screen are retried. The difference cannot be seen, so this is not a defect. Review Focus: no item belongs to Task 9. Local gate: `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` in a clean review worktree: green (exit 0; screenshot tests and `image_retry` (8 tests) passed). **Verdict:** Approve: 0 blocking, 4 minor findings and 1 note. Suggest follow-up issues for 1 and 2.
Author
Owner

Merged into dailyuse at 863726f (combined merge of the first twelve Daily use tasks).

Merged into `dailyuse` at 863726f (combined merge of the first twelve Daily use tasks).
charles closed this pull request 2026-11-14 13:04:06 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.