Skip to content

Commit 092ac94

Browse files
committed
fix(providers): report attachment limits in the unit vendors publish
The size ceilings are decimal MB — that is how OpenAI, AWS and Fireworks all write them — but the error messages divided by 1024², so OpenAI's 50 MB cap was reported to the user as "48MB". Someone shrinking a 49 MB file to get under it was chasing a limit that does not exist. One formatter, used by all three messages, so the file size and the ceiling in the same sentence are always in the same unit.
1 parent ade82d4 commit 092ac94

4 files changed

Lines changed: 34 additions & 7 deletions

File tree

apps/sim/executor/handlers/agent/agent-handler.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ import { buildAPIUrl, buildAuthHeaders } from '@/executor/utils/http'
5252
import { stringifyJSON } from '@/executor/utils/json'
5353
import { resolveVertexCredential } from '@/executor/utils/vertex-credential'
5454
import { executeProviderRequest } from '@/providers'
55-
import { shouldUseLargeFilePath, supportsFileAttachments } from '@/providers/attachments'
55+
import {
56+
formatAttachmentBytes,
57+
shouldUseLargeFilePath,
58+
supportsFileAttachments,
59+
} from '@/providers/attachments'
5660
import {
5761
canUseProviderLargeFilePath,
5862
getInlineHydrationMaxBytes,
@@ -974,11 +978,11 @@ export class AgentBlockHandler implements BlockHandler {
974978
!(canUseProviderLargeFilePath(providerId) && shouldUseLargeFilePath(file, providerId))
975979
)
976980
if (missingFile) {
977-
const inlineMB = (inlineMaxBytes / (1024 * 1024)).toFixed(0)
981+
const inlineMB = formatAttachmentBytes(inlineMaxBytes)
978982
const oversized = Number.isFinite(missingFile.size) && missingFile.size > inlineMaxBytes
979983
throw new Error(
980984
oversized
981-
? `File "${missingFile.name}" (${(missingFile.size / (1024 * 1024)).toFixed(2)}MB) exceeds the ${inlineMB}MB inline attachment limit, and provider "${providerId}" has no large-file upload path for it.`
985+
? `File "${missingFile.name}" (${formatAttachmentBytes(missingFile.size)}MB) exceeds the ${inlineMB}MB inline attachment limit, and provider "${providerId}" has no large-file upload path for it.`
982986
: `File "${missingFile.name}" could not be read for provider "${providerId}". The file may no longer be accessible.`
983987
)
984988
}

apps/sim/providers/attachments.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
buildOpenAICompatibleChatContent,
1212
buildOpenAIMessageContent,
1313
buildOpenRouterMessageContent,
14+
formatAttachmentBytes,
1415
formatMessagesForProvider,
1516
getProviderAttachmentMaxBytes,
1617
getProviderFileStrategy,
@@ -287,6 +288,15 @@ describe('provider attachments', () => {
287288
})
288289
})
289290

291+
describe('attachment limit formatting', () => {
292+
/** Guards the report of OpenAI's decimal 50 MB ceiling as "48MB" when divided by 1024². */
293+
it('reports a decimal-MB ceiling as the vendor publishes it', () => {
294+
expect(formatAttachmentBytes(50_000_000)).toBe('50')
295+
expect(formatAttachmentBytes(10 * 1024 * 1024)).toBe('10')
296+
expect(formatAttachmentBytes(9_591_617)).toBe('9.59')
297+
})
298+
})
299+
290300
describe('provider large-file capability', () => {
291301
/**
292302
* Guards the regression where every 6-10 MB attachment died with "Execution memory limit

apps/sim/providers/attachments.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,18 @@ export function getProviderAttachmentMaxBytes(providerId: ProviderId | string):
213213
return getProviderFileAttachment(providerId).maxBytes
214214
}
215215

216+
/**
217+
* Renders a byte count for a user-facing limit message.
218+
*
219+
* Decimal MB, because that is the unit the vendors publish and therefore the number a user is
220+
* comparing against. Dividing by 1024² instead reported OpenAI's 50 MB ceiling as "48MB", so a
221+
* user shrinking a 49 MB file to get under it was chasing a limit that did not exist.
222+
*/
223+
export function formatAttachmentBytes(bytes: number): string {
224+
const megabytes = bytes / 1_000_000
225+
return megabytes < 10 ? megabytes.toFixed(2).replace(/\.?0+$/, '') : megabytes.toFixed(0)
226+
}
227+
216228
export function inferAttachmentMimeType(file: UserFile): string {
217229
const explicitType = file.type?.trim().toLowerCase()
218230
return resolveFileType({
@@ -400,8 +412,8 @@ export function prepareProviderAttachments(
400412

401413
const maxBytes = getProviderAttachmentMaxBytes(providerId)
402414
if (Number.isFinite(file.size) && file.size > maxBytes) {
403-
const sizeMB = (file.size / (1024 * 1024)).toFixed(2)
404-
const maxMB = (maxBytes / (1024 * 1024)).toFixed(0)
415+
const sizeMB = formatAttachmentBytes(file.size)
416+
const maxMB = formatAttachmentBytes(maxBytes)
405417
throw new Error(
406418
`File "${file.name}" (${sizeMB}MB) exceeds the ${maxMB}MB agent attachment limit for provider "${providerId}"`
407419
)

apps/sim/providers/file-attachments.server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { downloadServableFileFromStorage } from '@/lib/uploads/utils/file-utils.
88
import { verifyFileAccess } from '@/app/api/files/authorization'
99
import type { UserFile } from '@/executor/types'
1010
import {
11+
formatAttachmentBytes,
1112
getProviderAttachmentMaxBytes,
1213
getProviderFileStrategy,
1314
INLINE_ATTACHMENT_THRESHOLD_BYTES,
@@ -88,8 +89,8 @@ export async function attachLargeFileRemoteUrls(
8889
if (!file.key || !shouldUseLargeFilePath(file, providerId)) continue
8990

9091
if (Number.isFinite(file.size) && file.size > maxBytes) {
91-
const sizeMB = (file.size / (1024 * 1024)).toFixed(2)
92-
const maxMB = (maxBytes / (1024 * 1024)).toFixed(0)
92+
const sizeMB = formatAttachmentBytes(file.size)
93+
const maxMB = formatAttachmentBytes(maxBytes)
9394
throw new Error(
9495
`File "${file.name}" (${sizeMB}MB) exceeds the ${maxMB}MB agent attachment limit for provider "${providerId}"`
9596
)

0 commit comments

Comments
 (0)