Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions apps/sim/lib/copilot/chat/payload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,46 @@ describe('buildCopilotRequestPayload', () => {
])
})

it('fails the request when an authorized attachment cannot be prepared', async () => {
it('isolates a failed attachment and still prepares valid siblings', async () => {
const cause = new Error('provenance sidecar unavailable')
mockTrackChatUpload.mockRejectedValueOnce(cause)

await expect(
buildCopilotRequestPayload(
{ ...attachmentParams, userPermission: 'write' },
{ selectedModel: 'claude-opus-4-8' }
)
).rejects.toMatchObject({
message: 'Failed to prepare attached file "payroll.xlsx" for Copilot. Please try again.',
cause,
})
mockTrackChatUpload
.mockRejectedValueOnce(cause)
.mockResolvedValueOnce({ displayName: 'photo.png' })

const payload = await buildCopilotRequestPayload(
{
...attachmentParams,
userPermission: 'write',
fileAttachments: [
...attachmentParams.fileAttachments,
{
id: 'a2',
key: 'workspace/ws-1/1731000000001-ab12cd35-photo.png',
filename: 'photo.png',
media_type: 'image/png',
size: 10,
},
],
},
{ selectedModel: 'claude-opus-4-8' }
)

expect(mockTrackChatUpload).toHaveBeenCalledTimes(2)
expect(payload.context).toEqual([
{
type: 'uploaded_file',
content:
'File "payroll.xlsx" could not be prepared for Copilot and was omitted. Other attached files remain available.',
},
{
type: 'uploaded_file',
content: [
'File "photo.png" (image/png, 10 bytes) uploaded.',
'Read with: read("uploads/photo.png")',
'To save permanently: materialize_file(fileName: "photo.png")',
].join('\n'),
},
])
})
})

Expand Down
12 changes: 8 additions & 4 deletions apps/sim/lib/copilot/chat/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,14 @@ export async function buildCopilotRequestPayload(
chatId,
error: cause.message,
})
throw new Error(
`Failed to prepare attached file "${filename}" for Copilot. Please try again.`,
{ cause }
)
// Isolate failures by entry. Aborting here discarded every valid
// sibling attachment in the request, even ones already tracked. Give
// the model a local marker for this file and continue preparing the
// rest of the batch.
uploadContexts.push({
type: 'uploaded_file',
content: `File "${filename}" could not be prepared for Copilot and was omitted. Other attached files remain available.`,
Comment thread
Sg312 marked this conversation as resolved.
})
}
}
}
Expand Down
1 change: 0 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading