Repository navigation
feat(chat): render on-disk sandbox images in chat markdown - #10361
Conversation
A model that writes `` got "[Image blocked]" before, and "Image not available" after unslothai#10269: the src carries no scheme, so sanitize keeps it and safeMarkdownUrl returns it unchanged -- but the route answers on the Authorization header (_authenticate_header_or_query), so a bare <img src> hits it unauthenticated and 401s. Only tool cards did the authed fetch (tool-ui-python.tsx), so markdown was the one path left. Resolve the src through sandboxFilePath(sandboxSessionIdFor(threadId, projectId)) and fetch it into an object URL before it reaches the DOM: the session segment the model happened to write is discarded and rebuilt from this chat's scope, so a project thread reads the project's workspace. One hook, useSandboxImage, now does that for markdown AND for the Python card, which had its own copy; abort + revokeObjectURL on cleanup in both. Registering `img` replaces Streamdown's default renderer wholesale (its Components map is keyed by tag), so everything that renderer did for a data: image is restated: wrapper, hidden-when-failed, fallback text, hover download. The two features are load-bearing on each other rather than merely compatible: unslothai#10269's early return for `data:`/`blob:` is exactly why the rewritten src survives the way back out, and it returns those unchanged, so scheme-carrying sources never reach this path. .avif joins _SANDBOX_MEDIA_TYPES (a raster codec, and nosniff pins the type either way); .svg stays out on purpose -- the filename is model-chosen, so inline SVG would be same-origin script execution, and a non-image extension stays the download card the file list already renders. Tests included.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c0b4557ae
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…n wins, decoded names, avif parity Three review threads and one manual note, all in the same seam. The session a src RECORDS wins when it names one (r3941897041). Replay shows the model its own tool-result stdout, not the envelope -- and stdout carries real workdir paths, so the sid a model echoes into a URL IS the folder its files were written to. That is exactly what the tool card above the prose already resolves from (the persisted envelope's sessionId); re-deriving from current scope was the one place that disagreed with it, and it broke older answers' images after a project move. sandboxSessionInSrc reads the recorded session back out (path segment, or ?session= under `_`); markdownSandboxImageSrc falls back to this chat's scope only when nothing was recorded. A bare outputs/plot.png still takes project-<id> else threadId, exactly as before. And a dot segment can no longer smuggle a scope: sandboxFileForSrc decodes BEFORE judging (so %2e%2e is caught too) and returns null on `..` -- one dot pops the prepended scope into another chat's folder, two land on another route; a bare `.` is dropped as noise. Download names decode (r3941897043): the tail is split on raw [?#] first, so delimiters keep their meaning, then decodedSegment'd -- `loss curve #1.png` saves under its real name now. .avif joins _IMAGE_EXTS (r3941897045), and the frontend pin now pins set(_SANDBOX_MEDIA_TYPES) == _IMAGE_EXTS outright: what the route serves inline, what a tool call reports inline, and what the frontend renders as an <img> are one set in three files and must not drift apart again. Tests re-pinned for recorded-wins (a moved chat's older answer keeps resolving to the folder named in its own URL even when projectId is set; bare paths still beat scope from project over threadId), the `?session=` form round-trips, dot segments fail honestly, and the decode pin rides the restatement. 6881 pass / 0 fail on the frontend suite, tsc -b clean; backend suites byte-identical to main here.
|
Review round pushed as 7e1e8a0: recorded session wins when a src names one (moved chats keep their images; bare paths still take current scope), dot segments rejected before they can pop the prepended scope, download names decoded after delimiter split, .avif at parity across all three lists with the equality pinned. Frontend 6881 pass / 0 fail, tsc -b clean; backend suites byte-identical to main on this machine (environmental home-dir failures unchanged). |
|
This registers img in STREAMDOWN_COMPONENTS, which swaps Streamdown's renderer for every image in chat markdown, not just sandbox paths, and the decode and onLoad gating is not carried over. Could you confirm the data-URI images from #10269 and plain sized images still render identically before I review? |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e29ac429d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae1d8c1815
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Stored sandbox images load through authenticated requests, and returning to a previous image source no longer reuses its revoked URL. In isolated Studio builds using the same synthetic stored-message fixture against the actual app and file endpoint, the base image request returned 401 and displayed no image; this head returned 200 and displayed the 320×180 PNG. Native Chrome and Edge component retry checks pass. At ae1d8c1, all 6,888 frontend tests, type checks, and the production build pass. The broader backend run has 269 passes and 2 skips, with four Windows-specific failures reproduced on the exact base involving permission bits, open-file unlink, and newlines. Current-head review has no outstanding findings. CI remains queued with no failures observed; other platforms were not run natively. Caption: Base |
…x images Main's unslothai#10361 resolves a model-written `` through sandboxSessionIdFor(threadId, projectId), and this branch made the third argument, the project's current workspace session, required: changing a project's working directory rotates it, and the pre-rotation `project-<id>` answers 410. The merge left that call two arguments short, so the frontend did not typecheck, and a project chat whose folder had been changed would have read its images from the folder before the change. The renderer passes the project row's workspaceSessionId through and holds a sandbox src until the row has loaded, as the sidebar's file cards do. Test added.

TL;DR
A model writes
into its answer. The src carries no scheme, so sanitize keeps it — but keeping it was never the same as being able to fetch it: the route answers on theAuthorizationheader (_authenticate_header_or_query), a bare<img src>401s, and the answer renders "Image not available". Only tool cards had an authed fetch; markdown was the one path left.Scope after rebase (supersedes #10281)
#10281 was closed unmerged because its data-URI half landed on its own as #10269 (
a2a4143). This branch is that PR rebased--ontocurrentmainwith the merged commit dropped, so it now carries only the sandbox-image work: 9 files, +526/−81. No new commits were authored during the rebase; it applied clean.Fix
The src is re-derived from this chat's scope and fetched with auth into an object URL before it reaches the DOM:
sandboxFileForSrcrewrites only scheme-less paths (sanitize dropped every scheme-carrying src already) and discards the sid segment the model happened to write;markdownSandboxImageSrcrebuilds it viasandboxSessionIdFor—project-${projectId}for project threads, else this thread'sremoteId.useSandboxImage, doesauthFetch→createObjectURLfor markdown and the Python card, which had its own copy; abort +revokeObjectURLon cleanup, keyed by url so a stale response can never write state for an old file.imgreplaces Streamdown's default renderer WHOLESALE (its Components map is keyed by tag), so everything that renderer did is restated: wrapper, hidden-when-failed, fallback text, hover download.downloadNamefollows it exactly: a real extension on the path wins whole; otherwise any extension in alt is stripped and one inferred from the blob's type is appended (alt="plot"downloadsplot.png).Why the scheme-less src survives sanitize (fact, read off the installed packages)
hast-util-sanitize'ssafeProtocolreturns true when the first:precedes no/-precedes-no-colon case — i.e. whencolon < 0 || colon > slash, a scheme-less path is never protocol-checked. The bug was never sanitize; it was the missing auth header.The two extension lists agree, in two languages
SANDBOX_INLINE_IMAGE_EXTSmirrors_SANDBOX_MEDIA_TYPES(frontend test readsinference.pyas text and pins it):.avifjoins it (a raster codec;nosniffpins the type either way),.svgstays OUT on purpose — the filename is model-chosen, so inline SVG would be same-origin script execution; non-image extensions stay download cards.What was deliberately NOT ported
The replaced renderer's gating machinery (decoded state, mount-time
completecheck,onLoad/onErrorforwarding, loaded||sized gates): a sandbox image is hidden until the authed fetch lands and fetch state already drives visibility, so nothing here needs a decode gate. What WAS kept — string-level lines with no machinery, pinned by name in tests:data-streamdown="image", the hover overlay div, the download-name regex.Verification / Tests
tsc -bandtsc -p tsconfig.test.json: 0 errors (exit 0, no output). Frontend suite on the rebased branch: 6881 pass / 0 fail.tests/studio/test_tauri_python_tool_images.py: 3 passed. The sandbox-roots backend suite shows pre-existing home-directory failures in this Windows sandbox — byte-identical counts (28F/241P/3S) on untouchedorigin/mainin a throwaway worktree, so they are environmental and not introduced here.markdown-sandbox-image.test.ts);%23round-trips while a raw#is a fragment delimiter → null; project scope beats threadId (search-images.test.ts).Follow-up (not blocking)
Upstream, this is one line: Streamdown shipping its own
imgswap point. If that lands, the wholesale restatement shrinks back to just the resolve-and-fetch step.