Repository navigation
Description
Summary
A chat keeps the presigned links of its images for as long as the page stays open, but each link lives 15 minutes. After that, the images in the messages still show, because they were already loaded, but opening one shows a broken image in Image preview. Its link now answers 403, and nothing fetches a new one. Found while checking the report "… one image is broken and cannot be viewed" on main 7d7b1ee98 (2026-11-04). The main cause of that report is filed as #5358; this is a second way to reach the same symptom.
What the code does today (main 7d7b1ee98)
- Presigned links live 15 minutes:
DEFAULT_PRESIGN_TTL_SEC = 15 * 60(services/platform/backend/core/lib/storage/object_store.ts:703-704); observedX-Amz-Expires=900. - A message's image links come from
files/queries:getFileUrls(services/platform/app/lib/backend/documents.ts:225-244). The query has no options of its own, so the app defaults apply:staleTime5 minutes,gcTime15 minutes, no refetch interval, and refetch on window focus only for a query in error (services/platform/app/router.tsx:26-50). A chat that stays mounted keeps its first links. - The message gallery tracks links that fail to load and falls back to a file card (
services/platform/app/features/chat/components/message-artifacts.tsx:150-196). The preview dialog gets the same link and shows whatever it loads (services/platform/app/features/chat/components/message-artifacts.tsx:218-230).
What was observed
Local stack (MinIO as the object store). A chat with two generated images was left open in one tab:
| Time (UTC) | What happened |
|---|---|
| 11:05:58 | The page's two image links were signed (re-read by the page at that time) |
| 11:16:32 | Both links fetched again: 200 |
| 11:21:09 | Both links: 403. The page still held the 11:05:58 links; both images were still visible in the message |
| 11:21:16 | Clicking the first image opened Image preview with a broken image (file name as alt text, 0 px wide) |
Not examined: other surfaces that show stored images through the same query (task attachments, documents), phones with the app in the background for a long time, and a production object store other than MinIO.
Options (no preference)
- Refetch file links on an interval shorter than their lifetime, but only while a chat shows images.
- Refetch a link when an image or the preview fails to load, once, before falling back.
- Give each file-link query a
staleTimebelow the link lifetime, and refetch on focus as well. - Serve images through an app route that signs a fresh link on every request (
302to the store, or proxied). - Sign links for longer, and keep the client's cache within that lifetime.
Related
- bug(platform): a generated image can show twice in chat, once as a broken placeholder — the model writes the image's s3: ref as Markdown #5358 (a generated image shown twice, once broken), perf(platform): serve chat and task image thumbnails instead of originals #5298 (thumbnails instead of originals in chat)
Activity
fix(platform): renew file links that run out while a page stays open
fix(platform): renew file links that run out while a page stays open