Fix hydrated image attachment previews#327300
Merged
Merged
Conversation
Fixes #327299 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7f569181-94f9-4602-b654-95c75286953e
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes hydrated image previews by rejecting URI objects as inline bytes, enabling the carousel’s existing file-resource fallback.
Changes:
- Strictly validate legacy numeric byte maps.
- Add regression coverage for URI-backed attachments.
Show a summary per file
| File | Description |
|---|---|
chatImageExtraction.ts |
Validates inline image byte representations. |
chatImageExtraction.test.ts |
Covers URI rejection and legacy byte maps. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Medium
justschen
approved these changes
Jul 24, 2026
justschen
approved these changes
Jul 24, 2026
ulugbekna
added a commit
that referenced
this pull request
Jul 24, 2026
Hydrated (reload/resume/reconnect) image attachments arrive as uri-only variable entries whose `value` is a URI, with the real file reference in `references[0]` and no inline bytes. Since #327300, `coerceImageBuffer` correctly returns undefined for such values instead of a bogus buffer, so `ImageAttachmentWidget` no longer renders garbage - but it still falls back to a generic file-media icon because nothing loads the real bytes. Make `ImageAttachmentWidget` lazily read the bytes via `IFileService` when inline bytes are absent but a resource is available (and the image is not fully omitted / over the image limit), then re-render the preview with the actual image. The icon fallback is kept if the read fails (e.g. the file no longer exists). Works for `file:` and remote `vscode-agent-host:` resources. Adds regression tests for the widget lazy byte-load (a hydrated uri-only image triggers a resource read; an inline-bytes image does not). Fixes #327329 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e04660de-4e7b-4432-99dd-24e0ffc35d1a
ulugbekna
added a commit
that referenced
this pull request
Jul 24, 2026
Hydrated (reload/resume/reconnect) image attachments arrive as uri-only variable entries whose `value` is a URI, with the real file reference in `references[0]` and no inline bytes. Since #327300, `coerceImageBuffer` correctly returns undefined for such values instead of a bogus buffer, so `ImageAttachmentWidget` no longer renders garbage - but it still falls back to a generic file-media icon because nothing loads the real bytes. Make `ImageAttachmentWidget` lazily read the bytes via `IFileService` when inline bytes are absent but a resource is available (and the image is not fully omitted / over the image limit), then re-render the preview with the actual image. The icon fallback is kept if the read fails (e.g. the file no longer exists). Works for `file:` and remote `vscode-agent-host:` resources. Adds regression tests for the widget lazy byte-load (a hydrated uri-only image triggers a resource read; an inline-bytes image does not). Fixes #327329 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e04660de-4e7b-4432-99dd-24e0ffc35d1a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #327299
Summary
Why this is correct
Before send, pasted images carry inline
Uint8Arraydata. Agent Host intentionally snapshots that data to disk, and history hydration restores the attachment as an image entry whosevalueis aURIand whosereferencespoint to the persisted file.coerceImageBufferis only responsible for recognizing inline bytes. Its previous object fallback accepted every object, so the seven enumerable fields of aURIbecame seven zero bytes. Because that result was truthy, Images Preview preferred the corrupt inline data and skipped its valid file-resource fallback.The new validation accepts only the exact legacy serialized-
Uint8Arrayshape: contiguous numeric keys starting at0, each containing an integer byte from0through255. ExistingUint8ArrayandArrayBufferpaths are unchanged. URI and other structured objects now returnundefined, which deliberately lets the existing resource path read the persisted image.The regression test uses the hydrated shape (
value: URIplus its resource reference), while the existing numeric-map tests ensure backward compatibility, including reordered numeric keys.Validation
npm run typecheck-clientnpm run valid-layers-check./scripts/test.sh --run src/vs/workbench/contrib/chat/test/common/chatImageExtraction.test.ts