Repository navigation
fix(native-chat): show pasted images while they save, and make them previewable - #18118
Conversation
…reviewable Pasting an image into the native chat composer showed nothing until the clipboard image finished being written to disk, and the resulting chip could never render the image at all. Preview was blocked by path authorization, not by rendering. Clipboard pastes are written to the OS temp dir, which sits outside every allowed root, so the composer's own `fs:readFile` of the file Orca had just written was denied. `saveClipboardImageBufferAsTempFile` now authorizes the path it writes, the same way other Orca-produced external files are handled. The delay is the macOS paste route: Cmd+V is intercepted in main and delivered through the app-menu paste channel, which has no clipboard blob in hand, so the composer only learned an image existed after the save round-trip. A new `clipboard:readImageThumbnail` probe reads the clipboard in memory and returns a downscaled preview; it runs alongside the save rather than before it, so text paste gains no latency. The DOM-paste route needs no probe — it mints a blob URL from the clipboard file on the same tick. Attachments now carry `pending` and `previewUrl`: the chip appears immediately with the real image dimmed under a spinner, then settles in place on the saved path. Send is blocked while anything is pending, because a pending chip has no agent-readable path yet. Pending chips are kept out of the pane attachment cache so a mid-save unmount cannot strand one, and blob previews are revoked on remove/clear. SSH pastes now carry their connectionId onto the chip so remote previews read over SFTP. Verified in a real Codex native chat under an isolated dev instance: the chip appears in 42-61ms with a spinner, settles at ~141ms, three rapid pastes produce three independent chips with Send disabled throughout, and the lightbox opens the full 5120x2880 image read from disk. Ablation confirms the authorization fix: the written path reads back, an unauthorized sibling in the same temp dir does not. Claude-Session: https://claude.ai/code/session_01NnEfY8NpfFtVnboLKnmgdW
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change adds shared clipboard image thumbnail contracts and native and web clipboard APIs. Local temporary clipboard image paths are authorized after saving. Native chat paste now shows pending previews while saves complete, preserves SSH connection metadata, and removes failed or stale attachments. Pending attachments disable sending and are excluded from the cache. Structured sending moves into a dedicated hook. Tests cover thumbnail generation, file authorization, paste settlement, attachment cleanup, pending previews, and send guards. Merge Risk: 🟡 Moderate · up to Pasted images now appear immediately and sending is blocked until saving finishes, but concurrent pastes can still show the wrong image preview, confusing attachment selection. Temporary clipboard images may also remain after an attachment is abandoned. Merge should wait for explicit owner acceptance or fixes for these bounded correctness and cleanup risks. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, implementation, and validation, but it does not follow several required template sections. It omits the required Linked Issue value, Visual Proof section, Testing checklist, Review section, Agent skill upstream boundary checklist, Notes, and final Checklist. Resolution Add all required template sections. Provide a valid issue reference after “Fixes #”. Add before and after visual proof, or write exactly “N/A” with a reason if applicable. Complete the Testing, Review, Agent skill upstream boundary, Notes, and Checklist sections. State AI usage details unless the contributor is exempt under the template.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 39efba8d-24ef-4946-8e97-d10dfda57ddc
📒 Files selected for processing (24)
src/main/window/clipboard-image-temp-file.test.tssrc/main/window/clipboard-image-temp-file.tssrc/main/window/clipboard-image-thumbnail.test.tssrc/main/window/clipboard-image-thumbnail.tssrc/main/window/clipboard-ipc-handlers.test.tssrc/main/window/clipboard-ipc-handlers.tssrc/preload/api/ui-bridge-clipboard-and-window-controls.tssrc/preload/api/ui-window-api.tssrc/renderer/src/components/native-chat/NativeChatComposer.test.tsxsrc/renderer/src/components/native-chat/NativeChatComposer.tsxsrc/renderer/src/components/native-chat/NativeChatComposerField.tsxsrc/renderer/src/components/native-chat/NativeChatImageAttachmentPreview.test.tsxsrc/renderer/src/components/native-chat/NativeChatImageAttachmentPreview.tsxsrc/renderer/src/components/native-chat/native-chat-image-paste.test.tssrc/renderer/src/components/native-chat/native-chat-image-paste.tssrc/renderer/src/components/native-chat/use-native-chat-composer-attachments.test.tsxsrc/renderer/src/components/native-chat/use-native-chat-composer-attachments.tssrc/renderer/src/components/native-chat/use-native-chat-composer-paste.test.tsxsrc/renderer/src/components/native-chat/use-native-chat-composer-paste.tssrc/renderer/src/components/native-chat/use-native-chat-structured-composer-send.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/web/preload-api/web-clipboard-api.tssrc/renderer/src/web/preload-api/web-ui-api.tssrc/shared/clipboard-image.ts
💤 Files with no reviewable changes (1)
- src/renderer/src/components/native-chat/native-chat-image-paste.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
|
|
||
| const resolvePendingImageAttachment = useCallback( | ||
| (id: string, path: string, connectionId?: string | null) => { | ||
| updateImageAttachments((prev) => |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Revalidate the target before settling a pending attachment.
beginPendingImageAttachment validates only the target that existed when the paste started. If the pane changes to a remote target, or loses its target, before the save finishes, this update settles a local path anyway. The send guard then permits a path that the current target cannot read.
When attachmentTargetBlocked() is true, remove the pending attachment, revoke its preview, and show the unsupported-attachment notice instead of resolving it.
| URL.revokeObjectURL(previewUrl) | ||
| } | ||
| void (async () => { | ||
| const saved = await saveClipboardImageForOwner(owner) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
printf '%s\n' '--- applicable repository guidance ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -type f -name '*.md' -maxdepth 3 -print
printf '%s\n' '--- target file outline ---'
ast-grep outline src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts
printf '%s\n' '--- target implementation and nearby callers ---'
sed -n '130,255p' src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts
printf '%s\n' '--- clipboard symbols ---'
rg -n -C 3 'saveClipboardImageForOwner|readClipboardImageThumbnail|saveClipboardImageAsTempFile' srcRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
printf '%s\n' '--- repository conventions ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/repo-wide.md
printf '%s\n' '--- native-chat learnings ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src-renderer-src-components-native-chat.md
printf '%s\n' '--- composer implementation ---'
sed -n '1,135p' src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts
printf '%s\n' '--- remaining menu-paste flow ---'
sed -n '220,285p' src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts
printf '%s\n' '--- clipboard IPC handlers and implementations ---'
rg -n -C 8 "clipboard:readImageThumbnail|clipboard:saveImageAsTempFile|saveClipboardImageAsTempFile|readClipboardImageThumbnail" src/main src/preload src/renderer/src/webRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
printf '%s\n' '--- main-process clipboard read/save sequence ---'
sed -n '100,190p' src/main/window/clipboard-ipc-handlers.ts
printf '%s\n' '--- thumbnail construction ---'
rg -n -C 10 'function buildClipboardImageThumbnail|const buildClipboardImageThumbnail|buildClipboardImageThumbnail' src/main src/shared
printf '%s\n' '--- web clipboard source reads ---'
sed -n '1,115p' src/renderer/src/web/preload-api/web-clipboard-api.ts
printf '%s\n' '--- relevant composer tests ---'
sed -n '235,365p' src/renderer/src/components/native-chat/use-native-chat-composer-paste.test.tsxRepository: stablyai/orca
Length of output: 22631
Use one clipboard snapshot for the preview and saved attachment.
handlePaste previews the ClipboardEvent image, but saveClipboardImageForOwner calls clipboard:saveImageAsTempFile, which reads the clipboard again. pasteFromClipboard also uses separate thumbnail and save reads. If the clipboard changes, the chip can show image A while the saved attachment contains image B. Pass one captured image to both operations or expose one IPC operation that returns both values. Add a test for a successful save after the clipboard changes.
Electron UI validation (isolated CDP instance)Isolated Real Codex Chat composer, distinctive 1600×900 PNG on the macOS clipboard, pasted with Cmd+V (CDP Pending (DOM, too fast to screenshot): chip at 21ms with Settled chip (uncropped): Lightbox — real 1600×900 image, not a 320px thumbnail, not “Preview unavailable”: Composer before paste: Authorization ablation in the same renderer: the clipboard temp file Orca wrote → Gaps: pending spinner not screenshotted (~25ms); this run hit the DOM-paste blob path, not the app-menu ≤320px thumbnail IPC; SSH paste not exercised. |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This PR makes pasted clipboard images appear immediately in the native-chat composer and fixes their preview/lightbox rendering. It authorizes the temp file Orca writes (so the composer's own fs:readFile is no longer denied), adds an in-memory clipboard:readImageThumbnail probe that runs alongside the save, and threads an optimistic pending/previewUrl attachment lifecycle with send-blocking and blob-URL revocation through the composer hooks.
- Path authorization —
saveClipboardImageBufferAsTempFilenow callsauthorizeExternalPathon the local temp file it writes; SSH saves skip it. - Thumbnail probe — new
clipboard:readImageThumbnailIPC (and a web counterpart) returns a ≤320px data URL, computed in memory with no filesystem/network work. - Pending-chip lifecycle —
beginPendingImageAttachment/resolvePendingImageAttachment/dropPendingImageAttachmentshow an immediate dimmed thumbnail under a spinner, keep pending chips out of the pane cache, and revokeblob:previews on remove/clear. - Send gating —
hasPendingAttachmentdisables Send and early-returns insend, so no message ships without its image. - SSH connectionId — settled chips now carry
connectionId, so remote previews read over SFTP. - Module split —
useNativeChatStructuredComposerSendandbuildClipboardImageThumbnailextracted;resolveImagePaste(dead) removed.
ℹ️ Nitpicks
NativeChatImageAttachmentPreviewrenders theisPending"Saving pasted image…" branch in the lightbox only whenfullSizeSrcis falsy, but a pending chip always carries apreviewUrl, sofullSizeSrc(localSrc ?? previewUrl) is never falsy while pending. The dialog spinner branch is currently unreachable; it's harmless as a defensive fallback, but worth knowing it won't render for the pending case.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — one test-coverage gap worth closing.
Reviewed changes
This delta (e4b9965) hardens the pending-chip lifecycle against two edge cases found in the prior pass: it strips previewUrl from the scope cache so a settled attachment never pins its transient clipboard Blob for the cache's lifetime, and it re-validates the attachment owner before settling a save that outlived a worktree/connection switch.
- Cache strips
previewUrl—writeNativeChatAttachmentCachenow dropspreviewUrlfrom settled attachments before caching, so a remount reloads the thumbnail from the authorized path (local or SFTP via the retainedconnectionId) instead of pinning the blob/data URL. - Owner re-validation —
attachmentOwnerStillMatchescompares the paste-time owner against the current one;settleImagePastedrops the pending chip (revoking its blob URL) and shows the worktree-not-ready notice when the backing host changed mid-save. - Tests — new coverage for the owner-change drop, plus an assertion on the cache's stripped
previewUrl.
ℹ️ Nitpicks
- The owner-mismatch path reuses the "Worktree not ready — try again in a moment." notice, which is a slightly off label for "the workspace changed while your image was saving." Harmless, but a dedicated wording would read more accurately.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| const cached = readNativeChatAttachmentCache('pty-1') | ||
| expect(cached.some((attachment) => attachment.id === pendingId)).toBe(false) | ||
| expect(cached).toMatchObject([{ path: '/tmp/settled.png' }]) | ||
| expect(cached[0]?.previewUrl).toBeUndefined() |
There was a problem hiding this comment.
This assertion is a no-op for the behavior it claims to pin. The settled chip here comes from attachResolvedPaths(['/tmp/settled.png']), which builds an attachment with no previewUrl, so previewUrl is undefined regardless of the new cache-strip — the test would still pass if the .map(({ previewUrl, ...rest }) => rest) were removed. To actually cover the strip, resolve a pending chip instead (its previewUrl is retained by resolvePendingImageAttachment's ...attachment spread) and assert the cached copy drops it.
…reviewable (stablyai#18118) * fix(native-chat): show pasted images while they save, and make them previewable Pasting an image into the native chat composer showed nothing until the clipboard image finished being written to disk, and the resulting chip could never render the image at all. Preview was blocked by path authorization, not by rendering. Clipboard pastes are written to the OS temp dir, which sits outside every allowed root, so the composer's own `fs:readFile` of the file Orca had just written was denied. `saveClipboardImageBufferAsTempFile` now authorizes the path it writes, the same way other Orca-produced external files are handled. The delay is the macOS paste route: Cmd+V is intercepted in main and delivered through the app-menu paste channel, which has no clipboard blob in hand, so the composer only learned an image existed after the save round-trip. A new `clipboard:readImageThumbnail` probe reads the clipboard in memory and returns a downscaled preview; it runs alongside the save rather than before it, so text paste gains no latency. The DOM-paste route needs no probe — it mints a blob URL from the clipboard file on the same tick. Attachments now carry `pending` and `previewUrl`: the chip appears immediately with the real image dimmed under a spinner, then settles in place on the saved path. Send is blocked while anything is pending, because a pending chip has no agent-readable path yet. Pending chips are kept out of the pane attachment cache so a mid-save unmount cannot strand one, and blob previews are revoked on remove/clear. SSH pastes now carry their connectionId onto the chip so remote previews read over SFTP. Verified in a real Codex native chat under an isolated dev instance: the chip appears in 42-61ms with a spinner, settles at ~141ms, three rapid pastes produce three independent chips with Send disabled throughout, and the lightbox opens the full 5120x2880 image read from disk. Ablation confirms the authorization fix: the written path reads back, an unauthorized sibling in the same temp dir does not. Claude-Session: https://claude.ai/code/session_01NnEfY8NpfFtVnboLKnmgdW * fix(native-chat): avoid stale image attachments and preview cache growth --------- Co-authored-by: Merge Sim <sim@local>




Pasting an image into the native chat composer showed nothing until the clipboard image finished saving, and the resulting chip could never render the image at all. Reported against restructured Codex chat; both problems affect every native chat agent.
What was broken
Preview never worked — path authorization, not rendering. Clipboard pastes are written to the OS temp dir (
app.getPath('temp')), which sits outside every allowed root, so the composer's ownfs:readFileof the file Orca had just written was denied.loadLocalImageAbsolutePathswallows the throw, so the thumbnail silently fell back to a generic icon and the lightbox showed "Preview unavailable".The delay is the macOS paste route. Cmd+V is intercepted in main (
before-input-event→ui:appMenuPaste) and delivered through the app-menu paste channel, which has no clipboard blob in hand. The composer only learned an image existed after the save round-trip returned, so nothing appeared in the meantime — which reads as a dropped paste and invites repeat pasting.Changes
saveClipboardImageBufferAsTempFileauthorizes the path it writes, the same way other Orca-produced external files are handled. This is the preview fix.clipboard:readImageThumbnailIPC — an in-memory clipboard probe returning a ≤320px data URL. It runs alongside the save rather than before it, so text paste gains no latency. The DOM-paste route needs no probe: it mints a blob URL from the clipboard file on the same tick.pendingandpreviewUrl. The chip appears immediately with the real image dimmed under a spinner, then settles in place on the saved path.connectionIdonto the chip, so remote previews read over SFTP. They previously did not.useNativeChatStructuredComposerSendandbuildClipboardImageThumbnailinto their own modules to stay under the max-lines caps; droppedresolveImagePaste, which became dead.Validation
Isolated dev instance (own user-data dir, private renderer port, CDP port-owner and
/@fs200/403 ownership proof), real Codex Chat tab, real 5120×2880 image on the macOS clipboard, driven through the actual macOS Cmd+V route:aria-busy=true, spinner present, label "Saving pasted image…"Ablation confirming the authorization fix, run live in the app:
ok:image/pngAccess denied: path resolves outside allowed directoriespnpm tcclean, oxlint clean, 1390 tests pass acrossnative-chatandmain/window.The pending spinner itself is not screenshotted — the pending window is under 100 ms on this machine, so that state is covered by DOM probes in the live run plus unit tests rather than an image.
https://claude.ai/code/session_01NnEfY8NpfFtVnboLKnmgdW