microsoft / microsoft/vscode

A pasted image renders as a broken thumbnail when its attachment has no contentType

Open
#331,568 0 comments 0 reactions 1 assignee Claimed by @justschen View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

A pasted image in an agent session renders as a broken thumbnail. The bytes are fine and the model receives the image; only the workbench fails to display it.

### Cause

The attachment is persisted without a `contentType`. Taken from a real session database:

```json
{"type":"embeddedResource","label":"Pasted Image","displayKind":"image","data":"iVBORw0KGgo…"}
```

There is no `contentType` key anywhere in that database. The restore path reads it unguarded:

```ts
if (attachment.type === MessageAttachmentKind.EmbeddedResource) {
if (!attachment.contentType.startsWith('image/')) {
```

so restoring the attachment throws and it never renders. Evaluated in the running workbench against that exact record:

```
(s) => s.contentType.startsWith("image/")
→ TypeError: Cannot read properties of undefined (reading 'startsWith')
```

`MessageEmbeddedResourceAttachment.contentType` is declared as a required `string`, so nothing in the type system anticipated the value the wire actually carries.

### Scope

`contentType` is dereferenced without a guard in four places: `stateToProgressAdapter` (the one users see), `codexPromptResolver` (twice) and `copilotAgentSession`.

Every current producer defaults the field, so newly pasted images are unaffected. This is about attachments already on disk, which stay broken for the life of the session.

### Reproduction

Any session whose stored attachment lacks `contentType` renders that attachment as a broken image. I have not identified which producer wrote one without it, and I would rather report that honestly than guess: the record predates the build I could inspect.

*AI disclosure: this issue and the related code were written with the assistance of AI.*

### Public patches and patcher scripts

[Public patch catalog and patcher scripts](https://github.com/RyanEwen/vscode-patches/blob/main/CATALOG.md) · [Source patch index](https://github.com/RyanEwen/vscode-patches/blob/main/SOURCE-PATCHES.md). The [public collection](https://github.com/RyanEwen/vscode-patches) includes the maintained patchers, rollback instructions, regression scripts, and historical snapshots. Build restrictions and exact installer coverage are documented there.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.