Skip to content

perf(platform): serve chat and task image thumbnails instead of originals #5298

Open

Description

@tale-code-bot

Part of #5251 (the in-app image audit of part 3 of #4686). Claims checked at tale-project/tale 24a091dddf6d1d7f81aaaa214cd0523806d8c049 (feature-train).

What happens

Chat and task image thumbnails load the original upload and scale it down in the browser:

  • composer attachments: services/platform/app/features/chat/components/composer-attachments.tsx:85-89 (<img src={url}> in a 36×36 tile, size-full object-cover);
  • message attachments: services/platform/app/features/chat/components/message-parts.tsx:219-223 (size-9, 36×36);
  • task and file attachments: services/platform/app/features/shared/files/file-displays.tsx:206-210 (size-9, 36×36);
  • generated images and artifacts in a message: services/platform/app/features/chat/components/message-artifacts.tsx (at most 256 px wide, from 1024×1024 or 1536×1024 sources).

The URL is the presigned object-store URL of the original (getFileUrl, services/platform/backend/domains/files/service.ts). The client compresses an upload only above 1 MB, to at most 2048 px (services/platform/lib/utils/compress-image.ts:7-12), so a 36 px tile can download a 2048 px image of up to 1 MB: about 28 times the width a DPR 2 screen needs, several hundred times the pixels. No thumbnail, variant or srcset exists in the platform.

Proposed change

Store a small variant beside each chat and task image when it is uploaded (or derive it on first read), sized for the 36 px tile at DPR 2 and for the 256 px artifact preview, and point the tiles at it; the lightbox keeps the original. sharp is already in the lock files (a platform devDependency today); the shared encoder of part 1 (@tale/ui/images/encode, @tale/ui/images/responsive) holds the format and budget policy.

Acceptance criteria

  • Composer, message and task attachment tiles load a variant no wider than twice their CSS size; the lightbox still opens the original.
  • Generated images and artifacts in a message load a variant sized for their preview.
  • A test pins the variant size, and existing attachments without a variant still render.

Activity

  1. added
    perf
    agent-ready
    on Nov 2, 2026
  2. yannickmonney commented on Nov 14, 2026

    @yannickmonney
    Contributor

    Decision

    Chat and task image tiles and message artifacts load small server-side copies (variants) of each image. A background job writes them, keyed by the original's blob ref. They are read only through the same access check as the original, and deleted whenever the original's bytes are deleted. The lightbox always opens the original. The work is based on release/0.6 (feature-train), where the shared image policy and encoder live.

    The rule (new FILE-R11): an image's small copies are read like the image, carry none of its metadata, and are deleted when its bytes are deleted.

    Answers

    • Store at upload or derive on first read? Both, in one mechanism. A job enqueued at registration writes the variants. A read that finds none for an older image enqueues the same job and serves the original until the variant is ready. Nothing is decoded on the request path, and no mass migration runs.
    • Tile size: 72x72 px, cropped from the centre, WebP, at most 16 KiB.
    • Preview size: fits inside 512x512 px, never enlarged, WebP, at most 120 KiB.
    • Lightbox: the API keeps the original url and adds variantUrl. Tiles render variantUrl ?? url; the lightbox and gallery use url.
    • Existing attachments: they render from the original until their variant exists.
    • Expired links: the link-renewal hook treats variantUrl as one of the file's links. An expired variant is renewed, so the tile stays on the small copy. It falls back to the original only when a renewed variant still fails.
    • Converted and skipped files: PNG, JPEG, WebP and single-frame GIF get variants. SVG, animated images, files over 25 MB and images over 40 MP are skipped. EXIF orientation is applied and all metadata is stripped.
    • sharp: becomes a runtime dependency of the platform. The runner image keeps its glibc binaries.

    Rationale
    A thumbnail is a copy of a user's image, so it passes the same read check and is deleted with the original in every byte-deleting lane, with a blobRefHeld backstop sweep. The job checks that its source is still held before it writes, so a deleted image does not get a new copy. Decoding untrusted uploads in a limited background job keeps decompression bombs and EXIF/GPS leaks off the request path. Renewing expired variant links, rather than falling back at once, keeps the saving in long sessions.

    Rejected alternatives: resizing on the read request, resizing in the client at upload, an external resizer, a design with no variant table, the ladder widths, AVIF, a one-shot backfill, keying by file row, and falling back to the original before renewing.

    Implementation units (base: feature-train)

    1. feat(ui): IN_APP_IMAGE_VARIANTS in the shared policy (S).
    2. feat(platform): the app.image_variants table and job, enqueued from registration, with the held-source check, deletion with the source in every lane, the backstop sweep, sharp as a runtime dependency, and FILE-R11 (L).
    3. feat(platform): /files/urls and /files/:id/url return variantUrl behind the read check and enqueue missing variants lazily (M).
    4. perf(platform): the tiles request tile and artifacts request preview. The renewal hook renews variant links. The lightbox stays on the original. A manual box ships with it (M).

    #5300 and #5301 reuse the same table, job and deletion helper.

    Cross-issue amendments (decisions taken together with #4208, #5303):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyperf

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions