GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(app): opt into experimental-media-uri and keep draft media bytes local by kitlangton · Pull Request #59104 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Oct 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

What it does

Desktop and web ask for media:<hash> refs, so a long session with screenshots stops re-sending every image as base64 each time it loads. Images load on demand through a cache instead. It's experimental: nothing changes until a session's location turns on experimental.media_blob, which is off by default. Until then the server keeps sending inline data.

Replaces #58743, which GitHub marked merged into its stack base while the stack was being reordered. Nothing from it reached dev.

Stack, built on the merged #58656: write (#58741, merged) → wire (#59103) → app (this PR) → backfill (#58742, optional, can land later).

Why

Inline media is a third larger than its bytes and arrives again on every message read, for every image in the session. With refs, each image is fetched once per server and cached. Before → after bytes per load have not been measured yet.

How it works

  1. Only the three reads that can return refs (message.list, session.message.get, session.inbox.list) send X-OpenCode-Capabilities: experimental-media-uri, as a per-call header. Every other request stays exactly as before, so no new CORS preflights. Export passes { mediaRefs: false }, so exported sessions always carry inline bytes.
  2. A per-server cache fetches bytes through experimental.media.get with the server's Basic auth, turns them into object URLs, and keeps each URL until the server switches or the app closes, so images on screen, in a preview or in a draft never break. Message attachments render from it.
  3. Drafts own their bytes. A media: image restored into the composer is kept as a draft reference with an empty URL (the same shape as a draft-store id, so older builds still read the draft) and is copied into the local draft store on the first save, so server-side cleanup can't break a draft. Submitting always sends bytes.
  4. Undoing a queued prompt, reverting one that hasn't been delivered yet, and editing a queued prompt all end in an inbox cancel, and the cancel sweeps blobs nothing else references. Each one first copies the prompt's media: bytes through the cache into local draft blobs. If undo or revert can't load them, they show an error and leave the prompt queued. Edit swaps in the local copies as they load.

Flag off (the default) and older servers

The server ignores the capability unless experimental.media_blob is on, so these three reads return the same inline attachments as today. The only request difference is that header on those three GETs. Restoring attachments into the composer follows the old rule exactly (source.type === "inline" || data non-empty), so URI-sourced attachments with inline bytes still come back on revert, fork and recall.

Risk

App UI and draft persistence. If a media load fails, the image shows as unavailable and the draft stays intact. Tool-result images are not shown from refs yet. Legacy /api/media/ URLs are not supported; only media:<hash> refs are. Not verified end-to-end in the desktop app against a live server with the flag on.

Proof

  • bun run test:unit (packages/app): 923 pass. New cases: the capability header goes only on the three ref reads (and is dropped with mediaRefs: false), export requests inline media, a URI-sourced attachment with inline bytes restores, and a restored media: image encodes and decodes through the draft schema.
  • bun test src (packages/session-ui): 318 pass.
  • bun typecheck (app, session-ui): clean.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot added the contributor label Oct 25, 2026
This was referenced Oct 25, 2026
feat(server): add experimental GET /api/experimental/media/:hash and opt-in experimental-media-uri capability #59103
Merged
feat(core): add byte-preserving offline media_blob backfill for legacy rows #58742
Closed
feat(app): opt into experimental-media-uri and keep draft media bytes local #58743
Merged
@kitlangton
kitlangton force-pushed the media-app branch 2 times, most recently from 942f3e7 to 1f0a9e1 Compare October 26, 2026 01:05
Base automatically changed from media-wire to dev October 26, 2026 04:33
@kitlangton
kitlangton force-pushed the media-app branch from 1f0a9e1 to 5072f77 Compare October 26, 2026 05:01
kitlangton added 6 commits October 28, 2026 09:08
@kitlangton
feat(app): opt desktop and web into experimental-media-uri with LRU b…
99d109a
…lob cache
@kitlangton
fix(app): keep draft media bytes local, resolve media: refs through t…
f83c901
…he media loader, and submit bytes
@kitlangton
fix(app): take stored media as the media:<hash> refs the server sends
b01bb49
The server sends media:<hash> refs, never route paths, and user files keep
their source, so drop the legacy route parsing and the origin fallback.
@kitlangton
fix(app): pin media: attachments before cancelling their inbox item
bcf0e28
Reverting an undelivered prompt, undoing a queued prompt and editing one all end in an inbox cancel that sweeps blobs nothing else references. Each now copies its media: bytes through the media cache into local draft blobs first; revert and undo leave the prompt queued when the bytes cannot load.
@kitlangton
fix(app): resolve rebase fallout (draft shadowing, BlobReference export)
d9d110c
@kitlangton
fix(app): send the media-ref capability only on message and inbox rea…
8a1deb4
…ds, keep exports inline, and persist media refs without a URL
@kitlangton
kitlangton force-pushed the media-app branch from 5072f77 to 8a1deb4 Compare October 28, 2026 16:18
@kitlangton
Merge branch 'dev' into media-app
c609a94
@kitlangton
kitlangton marked this pull request as ready for review October 28, 2026 16:50
@kitlangton
kitlangton requested review from Brendonovich and Hona as code owners October 28, 2026 16:50
opencodejr[bot]
opencodejr Bot reviewed Oct 28, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach looks sound. Only the three ref-capable reads (message.list, session.message.get, session.inbox.list) get the capability header, export opts out, and the undo and undelivered-revert paths copy media: bytes locally before cancelling the inbox item, so a failed copy leaves the prompt queued. I couldn't test it end to end because there's no web/desktop app harness here with experimental.media_blob on. Unit tests (app 923, session-ui 318) and tsc -b for both packages pass.

Public API: unchanged. The server API, SDK, plugin API, config and CLI are untouched. The app sends the existing X-OpenCode-Capabilities: experimental-media-uri header on three reads, and session-ui's internal DataProvider gains optional readMedia/peekMedia props.

One concern is worth fixing, noted inline: the cache revokes object URLs that rendered attachments and drafts still use.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/app/src/runtime/server/media.ts Outdated
const touch = (hash: string, url: string) => {
if (urls.has(hash)) urls.delete(hash)
urls.set(hash, url)
while (urls.size > maxEntries) {

@opencodejr opencodejr Bot Oct 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eviction calls URL.revokeObjectURL on URLs that other code may still be holding:

  • CurrentUserMessageDisplay keeps the loaded URL in resolvedUrl, and clicking the image opens ImagePreview with that same URL.
  • resolveBlobUrl returns it to the composer for media: draft images.

The cache is shared per server, so once more than 128 distinct images have loaded (exactly the long screenshot sessions this targets), older images have dead srcs. You'd see a broken preview, a broken image after a re-mount, or a broken composer thumbnail, with no reload, because peek misses but the component never calls load again.

Two ways to fix it: only revoke entries nothing currently holds (a refcount or release from the component's onCleanup), or have consumers re-load when a URL might have been evicted.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@kitlangton kitlangton Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7709085. The cache no longer evicts. Every object URL it hands out stays valid until the server cache is disposed (server switch or teardown), so rendered attachments, ImagePreview and composer drafts can never hold a revoked URL. Refcounting would have needed a release from every consumer, and the composer and submit paths have no clear lifetime to release from. Images are still fetched only when they are viewed, so memory stays below the old inline data: payloads. Added a test that loads 200 images and checks the first URL still resolves until dispose.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kitlangton
fix(app): keep media object URLs valid until the server cache is disp…
7709085
…osed

Clean the anti-slop lint findings in the files this branch touches.
opencodejr[bot]
opencodejr Bot reviewed Oct 28, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit fixes the earlier object-URL revocation point: the media cache now keeps object URLs until the server's cache is disposed, so images that are still on screen, open in a preview or in a draft stay valid. That holds a server's images in memory while it's connected, which is about what the inline base64 data cost before. The rest of the commit is formatting, lint suppressions and type tightening. I found nothing new worth blocking on. The description still says the cache "revokes the oldest beyond 128", which is no longer true.

I couldn't run it in the app against a live server with the flag on. Unit tests (app 924, session-ui 318) and tsc -b for both packages pass.

Public API: unchanged.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kitlangton
kitlangton merged commit f822b10 into dev Oct 28, 2026
22 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@kitlangton
kitlangton deleted the media-app branch October 28, 2026 17:23
@BrewTestBot BrewTestBot mentioned this pull request Oct 29, 2026
opencode 2.2.1 Homebrew/homebrew-core#322019
Merged
1 task done
@kitlangton kitlangton mentioned this pull request Oct 29, 2026
feat(tui): load stored images by reference, like desktop #60116
Merged
@github-actions github-actions Bot mentioned this pull request Oct 29, 2026
Tool release: OpenCode 2 v2.2.1 (was v2.2.0) agent-sh/agnix#1748
Closed
@wc4440222 wc4440222 mentioned this pull request Oct 29, 2026
[V2 Desktop] Pasted images show no thumbnail when the active model is text-only #54991
Closed
@amrkmn amrkmn mentioned this pull request Oct 29, 2026
opencode 2.2.1 amrkmn/homebrew-tap#1191
Closed
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments
@Hona Hona Awaiting requested review from Hona
@Brendonovich Brendonovich Awaiting requested review from Brendonovich

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@kitlangton
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.