Repository navigation
Keep viewer images on screen; share one image cache - #159
Merged
Merged
Conversation
kommander
force-pushed
the
fix/viewer-image-cache
branch
2 times, most recently
from
November 18, 2026 23:09
d7c3d3f to
15f4eed
Compare
…e transcript The full-screen viewer showed Opening/Downloading or the pager spinner when you came back to a file image (paging back, reopening, after a resume) and re-read the original each visit. Offline, every page that needed a check failed. - AgentImageCache (new dependency): one identity per image (server + absolute path, or media:<hash>). A validated file stays fresh, with no timer, until AgentFileChecks.invalidate (session open or resume, run state change, settled reply) bumps the server's epoch. A fresh file opens with no request or decode. Decoded pixels stay in the shared memory budget. After each preview write, disk copies are trimmed oldest-first until the whole app cache fits StorageManager.getCacheQuotaBytes (read off the main thread). With no quota (error or <= 0) nothing is trimmed and Android cleans up. Downloads still being written are skipped. Decodes coalesce and downloads to one destination run one at a time. - AgentFileViewerModel shows resident pixels or the decoded disk copy first and checks behind them. With a disk copy that has validators, the check is a single conditional GET (no range probe): a 304 keeps the pixels, a 200 replaces them, a failed check keeps them, a 404 fails. Video and audio still probe first, for streaming. - FullscreenViewer: only the selection and its ±1 neighbours hold full-size pixels. Neighbours are decoded ahead from disk copies or inline bytes (NeighbourPrepared, no network). A file page with no full-resolution pixels opens on its transcript preview at the file's size until the full image decodes (placeholderSize), so zoom and fit don't change when the full image arrives. - AgentImagePreviews writes its bytes and validators to the viewer's disk copy. A preview whose pixels were dropped reads that copy back (as is while fresh, confirmed by a conditional GET, or as is when the server can't be reached), not the whole original. A local read never extends freshness. Ported from debug/device-swipe-trace 3c21cbb3, e81d7472, 773cbcd3 and 36dbc563, without Session Media and without the ViewerTrace/ImageTrace/ SwipeTrace diagnostics, onto dev. Decoded pixels live in dev's Coil-backed DecodedImageCache, so the two cache tests use a MemoryCache with weak references off. Review fixes on top: a disk read is capped at MAX_BYTES, trim skips files still being written, and a changed file's decode never joins one of its previous copy. Tests: 9 new MediaReferenceTests. aStaleCopyIsCheckedByOneConditionalGet... fails on the probe-first path (2 requests, not 1). With their fix reverted in place, revisitedFileImagePagesComeBack..., selectingAPageDecodesItsNeighbours..., aFileImageOpensOnItsSharedPreview... and aFileThatNeedsACheck... fail. The other 4 cover the new cache. ComposerPhotoViewerTests now expects the neighbour decoded ahead (parity row updated). Verified: - ./gradlew --continue assembleDebug lintDebug testDebugUnitTest on dev: all modules pass. The only failure is AttachmentCameraLensTests, which expects "1.6×" and gets "1,6×" from this machine's en_DE locale. This change doesn't touch it. - Emulator (Medium_Phone_API_35, read-only, port 5640) against session-lab's images checkpoint (11-page transcript gallery). Opened, swiped forward and back across all pages, closed and reopened, resumed, then went offline (airplane mode) after a resume and after a cold start. No spinner or blank page on any revisit. Reopening draws the image at once with 0 file reads. After a resume, revisiting all 10 cached files over 30 swipes sent exactly one conditional GET per file (10 x 304): no 206, no 200, no spinner. Offline: the viewer and transcript images come from disk copies with 0 reads.
kommander
force-pushed
the
fix/viewer-image-cache
branch
from
November 18, 2026 23:09
15f4eed to
1c51f07
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Revisiting a file image in the full-screen viewer (paging back, reopening, after a resume) showed Opening/Downloading or a spinner and re-read the original. Offline, pages that needed a check failed.
AgentImageCache: one identity per image. A validated file stays fresh, with no timer, untilAgentFileChecks.invalidate(open/resume/run state/settled reply). Decodes coalesce; disk copies are shared with transcript previews. Disk copies are trimmed oldest-first to keep the app cache withinStorageManager.getCacheQuotaBytes; with no quota, nothing is trimmed.Port of 3c21cbb3, e81d7472, 773cbcd3, 36dbc563 without Session Media or debug tracing.
Verified: full assemble, lint and unit tests (only
AttachmentCameraLensTestsfails locally, because of the en_DE locale; untouched). 9 newMediaReferenceTests(the disk test injects the quota); 5 fail with their fix reverted. Emulator against session-labimages(10-file gallery): after a resume, revisiting every page sent exactly one 304 per file, with no 206, no 200 and no spinner. Close/reopen and offline: 0 reads, no blank pages.