Skip to content

fix(native-chat): show images in Codex structured chat - #18266

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/codex-chat-image-preview
Sep 3, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/codex-chat-image-preview

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​468 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​467
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​822 $\color{#cf222e}{\Huge{\mathbf{−}}}$​242 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​580

Summary

  • render typed image-ref blocks in Codex structured-session transcripts as accessible thumbnails
  • resolve image bytes through the owning local, folder, runtime, or SSH execution host, failing closed while ownership is unresolved
  • reuse bounded, lease-aware preview caching and the existing full-size dialog with textual fallback

Validation

  • focused transcript, runtime-owner, file-link, and local-image tests
  • pnpm tc:web
  • changed-code quality, React Doctor, formatting, and diff checks

This PR intentionally leaves legacy terminal transcript rows on their existing chip behavior; the terminal optimistic-echo lane is in the stacked follow-up PR.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/codex-chat-image-preview branch from 778c8a2 to be00c8b Compare September 2, 2026 23:40

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

One stability bug to fix before merge: the resolved image runtime context is recreated on every parent render, so every visible image is released and re-read during streaming.

Reviewed changes

  • Preview cache hardening — local-image-src-cache.ts extracts the existing preview blob cache into its own module and adds byte-budgeted, lease-versioned eviction with pinning and deferred blob revocation.
  • Structured transcript image thumbnails — NativeChatTranscriptChrome.tsx renders image-ref blocks as IntersectionObserver-gated thumbnails with a full-size dialog and textual fallback; legacy terminal chips keep their existing behavior.
  • Runtime ownership derivation — native-chat-image-runtime-context.ts resolves the owning local/folder/runtime/SSH execution host into a RuntimeFileOperationArgs, failing closed while unresolved, with a folder-workspace path fallback in native-chat-file-link.ts.
  • Typing indicator extraction — TypingIndicatorRow is moved to NativeChatTypingIndicatorRow.tsx.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 9972e301-ef8b-4bdf-bf8c-911d358b9928

📥 Commits

Reviewing files that changed from the base of the PR and between f136efb and 149c04f.

📒 Files selected for processing (7)
  • src/renderer/src/components/editor/local-image-src-cache.ts
  • src/renderer/src/components/editor/rich-markdown-extensions.ts
  • src/renderer/src/components/editor/rich-markdown-local-image.test.ts
  • src/renderer/src/components/editor/useLocalImageSrc.test.ts
  • src/renderer/src/components/editor/useLocalImageSrc.ts
  • src/renderer/src/components/native-chat/NativeChatTranscriptChrome.test.tsx
  • src/renderer/src/components/native-chat/NativeChatTranscriptChrome.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The change adds runtime-aware local image loading with a bounded blob URL cache, lease validation, invalidation, eviction, and URL cleanup. Native chat resolves image ownership from tab and workspace state, passes runtime context through message rendering, and displays lazy local image previews with dialog support. Folder workspace paths use a fallback resolver. Typing indicators use a shared component. Tests cover cache limits, release behavior, runtime context stability, visibility observation, and owner changes.

Merge Risk: ⚪ Minimal · up to 149c0

Native structured chat now renders locally resolved image references as accessible thumbnails with full-size dialog support while preserving chip fallbacks when resolution is unavailable. Cache and lifecycle regressions identified during development are covered by focused tests, and no current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes a useful summary and validation notes, but it does not follow the required template. It omits the ELI5, What Changed, Why, Linked Issue, Visual Proof, AI Disclosure, Review, b… Complete the required template sections. Add the issue reference after "Fixes #", provide visual proof or write "N/A" with a reason, document testing and platform coverage, complete the required checklist items, and include any applicable A…
Docstring Coverage ⚠️ Warning Docstring coverage is 10.64% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: showing images in Codex structured native chat.
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.
Full details: Description check

Explanation

The description includes a useful summary and validation notes, but it does not follow the required template. It omits the ELI5, What Changed, Why, Linked Issue, Visual Proof, AI Disclosure, Review, boundary, Notes, and Checklist sections.

Resolution

Complete the required template sections. Add the issue reference after "Fixes #", provide visual proof or write "N/A" with a reason, document testing and platform coverage, complete the required checklist items, and include any applicable AI disclosure and review notes.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 6f9c9b4d-eb01-417a-a6bd-18cfbe6dedf3

📥 Commits

Reviewing files that changed from the base of the PR and between 4b2d9b5 and 778c8a253892664685992467369f08666f92b6d9.

📒 Files selected for processing (13)
  • src/renderer/src/components/editor/local-image-src-cache.ts
  • src/renderer/src/components/editor/local-image-src-reader.ts
  • src/renderer/src/components/editor/useLocalImageSrc.test.ts
  • src/renderer/src/components/editor/useLocalImageSrc.ts
  • src/renderer/src/components/native-chat/NativeChatMessageList.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx
  • src/renderer/src/components/native-chat/NativeChatTranscriptChrome.test.tsx
  • src/renderer/src/components/native-chat/NativeChatTranscriptChrome.tsx
  • src/renderer/src/components/native-chat/NativeChatTypingIndicatorRow.tsx
  • src/renderer/src/components/native-chat/native-chat-file-link.test.ts
  • src/renderer/src/components/native-chat/native-chat-file-link.ts
  • src/renderer/src/components/native-chat/native-chat-image-runtime-context.test.ts
  • src/renderer/src/components/native-chat/native-chat-image-runtime-context.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Memoized image runtime owner — useNativeChatImageRuntimeContext now wraps resolveNativeChatImageRuntimeContext in useMemo keyed on the shallow-stable ownerState and tabId, so the derived RuntimeFileOperationArgs keeps referential identity across unrelated re-renders. This resolves the prior release/re-read churn finding and the corresponding test was updated to reflect the stabilized identity.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one test-quality suggestion inline. The production fix is correct.

Reviewed changes

  • Scoped image preview to the Codex lane — NativeChatStructuredSession now passes runtimeContext only when props.agent === 'codex', so legacy terminal sessions keep their chip rendering (enablePreview stays false).
  • Stabilized the observed element — TranscriptImagePreview drops the fragment wrapper and always returns a single div, so the IntersectionObserver target keeps DOM identity when the fallback swaps to the thumbnail.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment on lines +161 to +175
const observedElement = container.firstElementChild
expect(observedElement).not.toBeNull()
if (!observedElement || !callback) {
throw new Error('image preview did not register visibility observation')
}
const notifyVisibility = callback
await act(async () => {
notifyVisibility(
[{ target: observedElement, isIntersecting: true } as IntersectionObserverEntry],
{} as IntersectionObserver
)
await flushPromises()
})

expect(container.firstElementChild).toBe(observedElement)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

observedElement is NativeChatImageAttachments' outer mb-2 flex flex-wrap wrapper, but observeTranscriptVisibility registers the listener keyed on the inner TranscriptImagePreview ref div. Firing the callback with the wrapper as target never matches the visibilityListeners map, so setNear never fires, the preview never materializes, and the assertion is trivially true. This test would still pass with the fragment regression reintroduced.

Technical details
# Regression test doesn't exercise the observed-element fix

## Affected sites
- src/renderer/src/components/native-chat/NativeChatTranscriptChrome.test.tsx:161 — captures `container.firstElementChild` (the wrapper).
- src/renderer/src/components/native-chat/NativeChatTranscriptChrome.test.tsx:169 — fires the callback with that wrapper as `entry.target`.
- src/renderer/src/components/native-chat/NativeChatTranscriptChrome.tsx:37 — `visibilityListeners.set(element, listener)` where `element` is the inner ref div, not the wrapper.

## Required outcome
- The test must actually drive `setNear` on the observed element and assert the ref div's
  identity is preserved across materialization (e.g. assert a thumbnail `<img>` appears AND
  the ref div node is unchanged).

## Suggested approach (optional)
- Use the element the fake observer was asked to observe as the target, e.g.
  `const target = vi.mocked(FakeIntersectionObserver.observe).mock.calls[0]?.[0]`,
  or `observedElement.firstElementChild`, then fire `notifyVisibility` with that `target`
  and assert on the ref div identity rather than the wrapper.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ The runtime-owner fallback in this delta is correct and backed by a genuine regression test — no new issues in these commits. Approval is withheld only because the prior test-quality thread on the transcript visibility-observation test remains open and is untouched by this delta.

Reviewed changes

  • Resolved runtime-only image owners — resolveNativeChatImageRuntimeContext now derives the execution host from route.runtimeEnvironmentId via toRuntimeExecutionHostId when a route carries only a runtime owner (no executionHostId), so owner-only worktrees resolve an image read context during paired hydration instead of failing closed with null.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

brennanb2025 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Review complete at exact head f136efb.

Verdict: clean for the requested scope. PR1 remains limited to Codex structured-session image-ref previews and the shared runtime-owner/preview plumbing; terminal transcript rows are not upgraded, paired-web thumbnail behavior is preserved, and observer/cache cleanup plus runtime-only owner routing are covered.

Verification:

  • Native-chat suite and targeted runtime/image tests passed (including 969 native-chat tests in the final review)
  • pnpm tc:web passed
  • Changed-file oxlint/quality, oxfmt, and git diff --check passed
  • END readiness checklist: PASS WITH RISK, with no proven P0/P1/P2 findings

Residual validation gaps: no Electron/CDP visible-proof run was possible against these exact heads, and the full SSH/network/mobile matrix was not run (mobile-facing code is untouched). The stale attachment-cache/SSH-save owner-migration concern remains an adjacent pre-existing follow-up, not introduced by this PR.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Visual QA — structured Codex chat image preview

Exercised on an isolated Orca dev instance from this worktree (Orca: brennanb2025/codex-chat-image-preview, Dock Orca/ brennanb2025-codex-chat-image-preview). Flow: New tab → Codex structured chat → paste 64×64 teal/white PNG → composer thumbnail + full-size dialog → send “What color is the square in this image?” → transcript thumbnail + full-size dialog. Codex replied “The square is white.” Transcript <img> was a decoded 64×64 blob: URL.

1. Empty structured Codex Chat

01-codex-chat-empty.png

2. Composer pasted-image thumbnail

02-composer-pasted-thumbnail.png

3. Composer full-size preview dialog

03-composer-fullsize-dialog.png

4. Transcript thumbnail after send (PR change)

04-transcript-image-thumbnail.png

5. Transcript full-size preview dialog

06-transcript-fullsize-dialog.png

Gaps: legacy terminal transcript chips, SSH/folder/unresolved-owner fallbacks, and runtime-owner switches were not exercised. Screenshots are uncropped full-window captures; they are not committed to the branch.

@brennanb2025

brennanb2025 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Review complete at 149c04f0e9daf8b733852adbc2a588584224756e.

Verdict: land after fixes. The same-model adversarial review completed two passes, grounded the implementation against established attachment/ownership/lifecycle patterns, and fixed three proven regressions without expanding scope:

  • shared local-image cache entries could be revoked while rich-markdown node views still displayed them; node views now hold/release leases;
  • a mounted preview could miss a compatible in-flight prewarm read; pinning no longer invalidates that read;
  • thumbnail/dialog error state could remain stuck after cache refresh; failures are now tied to the failed URL.

Validation:

  • focused editor/native-chat suites passed (26 tests in final local rerun; reviewer’s broader focused suite passed 92 tests);
  • full native-chat suite passed 970/970;
  • pnpm tc:web, changed-code quality, formatting hooks, and git diff --check passed;
  • Grok exercised the real structured Codex chat flow in Electron, verified blob-backed 64x64 thumbnails and the full-size dialog, and attached uncropped screenshots here: fix(native-chat): show images in Codex structured chat #18266 (comment);
  • start and end readiness-checklist passes found no evidence-backed P0/P1/P2 findings.

Residual gaps: live SSH/paired-runtime and Windows variants were not exercised in this macOS run; the changed structured-chat path is gated away from those hosts, and routing/ownership tests cover the relevant branches. Legacy terminal-chip rendering remains intentionally unchanged in this PR.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No new issues in this cache-lease delta — the version-bump move from acquire to release is correct and backed by genuine regression tests. Approval remains withheld only because the prior test-quality thread on the transcript visibility-observation test is still open and untouched by these commits.

Reviewed changes

  • Retained image preview cache leases across surfaces — lease acquisition now pins without bumping the cache-key version, and release is what invalidates stale in-flight reads, so a mounted preview adopts an in-flight prewarm read and one surface's releaseLocalImageSrc no longer evicts a blob another surface still leases.

  • Extended lease acquisition to the rich-markdown image nodeView — the ProseMirror image node now holds a pin for its lifetime and releases it on destroy or reload.

  • Scoped thumbnail and dialog error state to the offending src — TranscriptImagePreview tracks the failed blob URL rather than a boolean, so a cache refresh produces a fresh URL and retries a previously failed thumbnail.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025
brennanb2025 merged commit 40d9927 into main Sep 3, 2026
28 checks passed
brennanb2025 added a commit that referenced this pull request Sep 5, 2026
…s Codex (#18743)

* fix(native-chat): render Claude structured chat through the same UI as Codex

Structured native chat is one shared, agent-agnostic component tree, but three
Codex-hardcoded terms on that path made a Claude session render differently.

- `showTurnStatus` was `agent === 'codex'`, which gated the whole structured
  presentation: the live tool-progress row, the completion check and activity
  grouping (`structuredActivityUi`), and the Thinking / Working for N /
  Worked for N status rows. Claude fell back to the legacy compact chrome.
- `runtimeContext` was likewise Codex-only, so a Claude transcript rendered
  images as filename chips instead of previews.
- The composer's structured slash menu always served the Codex catalog,
  ignoring `agent`. That disagreed with the dispatcher, which does branch per
  agent: Codex-only tokens offered to Claude missed the command guard and were
  sent to the model as literal prompt text, where Codex shows an error.

The first two gates landed Codex-first (#17597, #18266) before the Claude
structured lane existed; they were rollout scoping, not capability limits.
Neither `useNativeChatTurnStatus` nor `useNativeChatImageRuntimeContext` has
any agent-specific logic. The menu now reads `structuredSlashCommands(agent)`,
the function the dispatcher already used, so both read one list.

No new rendering logic: two gates removed and one existing shared function
reused. There are now zero `agent === 'codex' | 'claude'` branches in any
native-chat component.

* docs(native-chat): update structured turn status contract

---------

Co-authored-by: Merge Sim <sim@local>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(native-chat): render structured image refs from their runtime owner

* fix(native-chat): keep transcript image keys stable

* fix(native-chat): memoize the image runtime owner

* fix(native-chat): keep image preview observation scoped

* fix(native-chat): resolve runtime-only image owners

* fix(native-chat): retain image preview cache leases

---------

Co-authored-by: Merge Sim <sim@local>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…s Codex (stablyai#18743)

* fix(native-chat): render Claude structured chat through the same UI as Codex

Structured native chat is one shared, agent-agnostic component tree, but three
Codex-hardcoded terms on that path made a Claude session render differently.

- `showTurnStatus` was `agent === 'codex'`, which gated the whole structured
  presentation: the live tool-progress row, the completion check and activity
  grouping (`structuredActivityUi`), and the Thinking / Working for N /
  Worked for N status rows. Claude fell back to the legacy compact chrome.
- `runtimeContext` was likewise Codex-only, so a Claude transcript rendered
  images as filename chips instead of previews.
- The composer's structured slash menu always served the Codex catalog,
  ignoring `agent`. That disagreed with the dispatcher, which does branch per
  agent: Codex-only tokens offered to Claude missed the command guard and were
  sent to the model as literal prompt text, where Codex shows an error.

The first two gates landed Codex-first (stablyai#17597, stablyai#18266) before the Claude
structured lane existed; they were rollout scoping, not capability limits.
Neither `useNativeChatTurnStatus` nor `useNativeChatImageRuntimeContext` has
any agent-specific logic. The menu now reads `structuredSlashCommands(agent)`,
the function the dispatcher already used, so both read one list.

No new rendering logic: two gates removed and one existing shared function
reused. There are now zero `agent === 'codex' | 'claude'` branches in any
native-chat component.

* docs(native-chat): update structured turn status contract

---------

Co-authored-by: Merge Sim <sim@local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant