fix: tool screenshots show as images, not base64 text #16199
main fromrefs/pull/16199/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubProblem#
When an agent takes a device screenshot (or a preview snapshot with an image), expanding the tool row shows a wall of base64 JSON instead of the image.
Screenshots are 300 to 630 KB. The detail read for an expanded tool row caps output at 256 KB, so the server cut the output into a JSON string and clients printed it as text. Under the cap, clients only showed [image].
Change#
Image bytes no longer go over the WebSocket. Clients load each image over HTTP, through the same signed /api/assets URLs that attachments use.
- Detail read (
WireProjection.ts): replaces each image's bytes with{ type: "image", mimeType }and keeps its position. On real rows the expanded output went from about 600 KB to under 1 KB. If the remaining text is still too large, the truncated text keeps the image markers. - New asset resource
tool-output-image { threadId, itemId, index }: the server reads the stored item, decodes the image, and serves the bytes withnosniffand a private cache. When it signs the URL, it also returns the pixel size, so clients reserve the right box before the image loads. - Parser (
shared/toolOutput.ts): reads the MCP{ data, mimeType }shape and the{ source: { media_type, data } }shape that Claude stores. Only PNG, JPEG, GIF, and WebP are served, so an agent cannot get SVG or HTML served inline. At most 8 images per tool call, and an image larger than a provider turn accepts (10 MB) is not decoded. - Web and desktop: the image shows in the tool inspector. Click it to open the full-size view.
- Mobile: the image shows in the expanded work-log row. Tap it to open the preview.
Not changed:
- Claude
Readimage rows already show the file from its path. - Codex: the adapter keeps only
structuredContentfor MCP results, so Codex threads store no screenshot bytes and show no image. Codex rows still show structured JSON, not base64. Storing screenshot bytes for Codex is a separate storage decision (see #11295).
Scope and approval#
Maintainer request. Theo reported this from a real thread.
Verification#
- Web, isolated dev server seeded from real data: expanding "Took a screenshot of the device" in the reported thread shows the 920x2000 PNG. Clicking it opens the full-size view. The asset returns 200
image/png(447 KB) withnosniffand a private cache. A tampered token returns 404. - iOS (iPhone 17 Pro Max simulator), same backend: the expanded row shows the screenshot, and tapping it opens the full-size preview.
- Tests: parser shapes and type allowlist, 8-image cap, detail read without bytes, markers kept for oversized output, asset sign and serve with pixel size, size cap before decoding, client text and image helpers.
- Checks: typecheck passes in contracts, shared, client-runtime, server, web, and mobile.
| Before (web) | After (web) |
|---|---|
![]() | ![]() |
Full-size view on web:

| iOS inline | iOS preview |
|---|---|
![]() | ![]() |
On iOS the work group keeps its existing 256 pt height cap and scrolls inside, so a tall screenshot shows partly until you scroll the group or tap it. This is the same as the viewed-image rows.
Reviewed with sol-loop: 4 rounds with GPT-6.1-Sol on high.
Created with Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code
- 1
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/assets/AssetAccess.ts line 715Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -672,3 +704,5 @@672704 }673705 break;674706 }707+ case "tool-output-image": {708+ const image = yield* readToolOutputImage(input.resource).pipe(
🟠 High
assets/AssetAccess.ts:708assetsCreateUrldecodes the entire unboundeddatastring for atool-output-imagebefore issuing the URL, so a stored tool result containing a sufficiently large allowed-type image can exhaust the server process instead of being rejected.toolOutputImageslimits only the number of entries, not each image's base64 or decoded byte length; enforce a size limit before decoding and apply the same limit when serving the image.🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/server/src/assets/AssetAccess.ts around line 708: `assetsCreateUrl` decodes the entire unbounded `data` string for a `tool-output-image` before issuing the URL, so a stored tool result containing a sufficiently large allowed-type image can exhaust the server process instead of being rejected. `toolOutputImages` limits only the number of entries, not each image's base64 or decoded byte length; enforce a size limit before decoding and apply the same limit when serving the image.Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Fixed in 766602e54e.
readToolOutputImagenow skips an image before it decodes anything when its base64 is longer than a provider turn accepts (PROVIDER_SEND_TURN_MAX_IMAGE_BYTES, 10 MB decoded). Mint (issueAssetUrl) and serve (resolveAsset) both use it, so mint fails withAssetWorkspaceAssetNotFoundErrorand serve returns 404. Covered by a 14 MB base64 case inAssetAccess.test.ts.Context:
getTurnItemalready parses the whole stored item into memory, the same as the existing detail read. So the cap limits the extra decode work, not the stored size. Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This change adds a cross-platform production path that extracts tool screenshots, serves decoded bytes through signed asset URLs, and renders them in web and mobile work logs. An unresolved High-severity finding also reports that base64 whitespace can cause valid images within the size limit to be rejected.
Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 4.9 KiB −23 B (−0.5%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB −23 B (−1.9%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.8 KiB −41 B (−0.2%) 29.3 KiB ✅ Codex Live turn messages 2 1 −1 (−50.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB −31 B (−0.6%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB −31 B (−2.5%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB −41 B (−0.2%) 29.3 KiB ✅ Claude Live turn messages 2 1 −1 (−50.0%) 8 ✅ Baseline:
24238fe· PR result:766602e· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
- apps/server/src/assets/AssetAccess.ts lines 219 to 237Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -199,2 +217,21 @@199217 );200218219+// The largest image a provider turn accepts, as base64 (4 characters per 3 bytes).220+const MAX_TOOL_OUTPUT_IMAGE_BASE64_LENGTH = Math.ceil(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES / 3) * 4;221+222+/**223+ * Decodes one image a tool returned inline; null when the stored item has no224+ * such image, or it is larger than a provider turn accepts.225+ */226+const readToolOutputImage = Effect.fn("AssetAccess.readToolOutputImage")(function* (input: {227+ readonly threadId: ThreadId;228+ readonly itemId: TurnItemId;229+ readonly index: number;230+}) {231+ const orchestrator = yield* Orchestrator.OrchestratorV2;232+ const item = yield* orchestrator.getTurnItem(input);233+ const image =234+ item?.type === "dynamic_tool" ? toolOutputImages(item.output)[input.index] : undefined;235+ return image?.data === undefined || image.data.length > MAX_TOOL_OUTPUT_IMAGE_BASE64_LENGTH236+ ? null237+ : { mimeType: image.mimeType, bytes: Buffer.from(image.data, "base64") };
🟠 High
assets/AssetAccess.ts:219readToolOutputImagereturnsnullfor MIME-wrapped base64 representing an image within the 10 MB byte limit, so the signed asset is reported as not found and the screenshot is not displayed. The length check runs before decoding, while Node's base64 decoder ignores whitespace; decode first and comparebytes.lengthwithPROVIDER_SEND_TURN_MAX_IMAGE_BYTES.-// The largest image a provider turn accepts, as base64 (4 characters per 3 bytes). -const MAX_TOOL_OUTPUT_IMAGE_BASE64_LENGTH = Math.ceil(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES / 3) * 4; - /** * Decodes one image a tool returned inline; null when the stored item has no * such image, or it is larger than a provider turn accepts. @@ const item = yield* orchestrator.getTurnItem(input); const image = item?.type === "dynamic_tool" ? toolOutputImages(item.output)[input.index] : undefined; - return image?.data === undefined || image.data.length > MAX_TOOL_OUTPUT_IMAGE_BASE64_LENGTH - ? null - : { mimeType: image.mimeType, bytes: Buffer.from(image.data, "base64") }; + if (image?.data === undefined) return null; + const bytes = Buffer.from(image.data, "base64"); + return bytes.length > PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + ? null + : { mimeType: image.mimeType, bytes }; });🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/server/src/assets/AssetAccess.ts around lines 219-237: `readToolOutputImage` returns `null` for MIME-wrapped base64 representing an image within the 10 MB byte limit, so the signed asset is reported as not found and the screenshot is not displayed. The length check runs before decoding, while Node's base64 decoder ignores whitespace; decode first and compare `bytes.length` with `PROVIDER_SEND_TURN_MAX_IMAGE_BYTES`.Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Not changing this. Decoding first and then comparing
bytes.lengthbrings back the unbounded decode from the previous finding on this line. The length check exists to reject an oversized image before any decode work.The case it misses is narrow: base64 with MIME line breaks whose decoded size is within about 1.3% of the 10 MB cap. MCP image blocks and the Anthropic
source.datathat Claude stores are plain base64 without line wrapping. In that rare case the row shows its existing "image unavailable" state, with no error and no crash. Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
- Review profile: CHILL
- Plan: Team
- Run ID:
099c3644-8b82-4ec8-9814-3e6757556bfc
📥 Commits
Reviewing files that changed from the base of the PR and between 24238fee321e2c6bc711832b8cf3698b1f6b30ca and 766602e54e3ed375fafc3bfca8dc41748ce020f4.
📒 Files selected for processing (17)
apps/mobile/src/features/threads/ThreadFeed.tsxapps/mobile/src/features/threads/ThreadMarkdownImage.tsxapps/mobile/src/features/threads/thread-work-log.tsxapps/server/src/assets/AssetAccess.test.tsapps/server/src/assets/AssetAccess.tsapps/server/src/http.tsapps/server/src/orchestration-v2/WireProjection.test.tsapps/server/src/orchestration-v2/WireProjection.tsapps/server/src/ws.tsapps/web/src/components/ChatMarkdown.tsxapps/web/src/components/chat/MessagesTimeline.tsxapps/web/src/components/chat/V2ItemInspector.tsxpackages/client-runtime/src/work-log/itemDetail.test.tspackages/client-runtime/src/work-log/itemDetail.tspackages/contracts/src/assets.tspackages/shared/src/toolOutput.test.tspackages/shared/src/toolOutput.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough#
Dynamic-tool output can include supported inline images. The change extracts images into indexed asset resources, serves them through signed asset URLs, and renders them in web and mobile tool-output views with preview handling.
Changes#
Tool-output image handling
Layer / File(s) Summary Image contracts and extraction
packages/contracts/src/assets.ts,packages/shared/src/toolOutput.ts,packages/shared/src/toolOutput.test.ts,packages/client-runtime/src/work-log/itemDetail.ts,packages/client-runtime/src/work-log/itemDetail.test.tsThe asset contract adds indexed tool-output-imageresources. Shared helpers extract supported MCP and Anthropic base64 images, cap results at eight, and omit image bytes. Item-detail helpers expose indexed assets and exclude readable images from extracted text.Tool-output wire projection
apps/server/src/orchestration-v2/WireProjection.ts,apps/server/src/orchestration-v2/WireProjection.test.tsDynamic-tool detail projection omits image bytes, retains image markers in order, and bounds output. Tests cover oversized text and image counts. Signed image asset delivery
apps/server/src/assets/AssetAccess.ts,apps/server/src/assets/AssetAccess.test.ts,apps/server/src/ws.ts,apps/server/src/http.tsThe server issues and resolves signed URLs for indexed tool-output images. The HTTP route returns image bytes with their MIME type, a private cache policy, and nosniff. Tests cover dimensions, bytes, missing indexes, and oversized images.Web and mobile image rendering
apps/web/src/components/ChatMarkdown.tsx,apps/web/src/components/chat/*,apps/mobile/src/features/threads/*Web and mobile tool-output views render extracted images. The timeline and work-log paths pass image expansion or preview callbacks to the image components. Priority: ⬇️ Low
Estimated code review effort: 4 (Complex) | ~40 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant WireProjection participant V2ItemInspector participant assetsCreateUrl participant AssetAccess participant Orchestrator participant HTTPAssetRoute WireProjection->>V2ItemInspector: bounded output with image markers V2ItemInspector->>assetsCreateUrl: indexed tool-output-image resource assetsCreateUrl->>AssetAccess: issue asset URL AssetAccess->>Orchestrator: getTurnItem(threadId, itemId) Orchestrator-->>AssetAccess: stored turn item AssetAccess-->>V2ItemInspector: signed asset URL V2ItemInspector->>HTTPAssetRoute: request image asset HTTPAssetRoute->>AssetAccess: resolve signed claims AssetAccess-->>HTTPAssetRoute: image bytes and MIME type HTTPAssetRoute-->>V2ItemInspector: image responseSuggested reviewers:
juliusmarminge,maria-rcksMerge Risk: ⚪ Minimal · up to
76660No identified issue blocks merging the tool-output image change after normal checks.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Title check ✅ Passed The title clearly summarizes the main change: tool screenshots now display as images instead of base64 text. Description check ✅ Passed The description covers the problem, change, scope, and verification. It also includes before-and-after screenshots and platform-specific results. The scope section says this was a maintainer request b… - Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.




macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed