Skip to content

Commit 3f9247c

Browse files
committed
fix(copilot): report the fetched size on an unavailable image
The bytes are in hand by the time preparation fails, so quoting record.size back recreated the contradictory placeholder the download-cap path already fixed: a client-declared figure printed beside the real reason. Same defect, one line below the one it was fixed in.
1 parent 9933aba commit 3f9247c

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

apps/sim/lib/copilot/vfs/file-reader.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ describe('readFileRecord', () => {
8080

8181
fetchWorkspaceFileBuffer.mockResolvedValue(bomb)
8282

83-
const result = await readFileRecord(imageRecord('bomb.png', bomb.length))
83+
// Recorded size deliberately disagrees with the real bytes: it is client-declared,
84+
// so the placeholder must report what was actually fetched.
85+
const result = await readFileRecord(imageRecord('bomb.png', 999_999))
8486

8587
expect(result?.attachment).toBeUndefined()
8688
expect(result?.content).toContain('It is too large to decode safely.')
87-
// The byte count must survive formatting — a sub-1KB bomb formatted without
89+
// The byte count must survive formatting too — a sub-1KB bomb formatted without
8890
// `includeBytes` collapses to "0 Bytes" next to the real reason.
8991
expect(result?.content).toContain(`(${bomb.length} Bytes)`)
9092
},

apps/sim/lib/copilot/vfs/file-reader.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,13 @@ export async function readFileRecord(record: WorkspaceFileRecord): Promise<FileR
481481
if (!prepared.ok) {
482482
span.setAttribute(TraceAttr.CopilotVfsReadOutcome, CopilotVfsReadOutcome.ImageTooLarge)
483483
return {
484-
content: readPlaceholder.imageUnavailable(record.name, record.size, prepared.reason),
484+
// The fetched buffer, not `record.size`: the bytes are in hand by now,
485+
// so there is no reason to quote the client-declared figure back.
486+
content: readPlaceholder.imageUnavailable(
487+
record.name,
488+
fetched.buffer.length,
489+
prepared.reason
490+
),
485491
totalLines: 1,
486492
}
487493
}

0 commit comments

Comments
 (0)