{"record":{"id":"2622765ae655045d","repo":"paperclipai/paperclip","slug":"attachment-exceeds-the-configured-size-limit","errorCode":null,"errorMessage":"Attachment exceeds the configured size limit","messagePattern":"Attachment exceeds the configured size limit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/photon/adapter.ts","lineNumber":446,"sourceCode":"        {\n          chatGuid: chat.guid,\n          text: parts[index],\n          replyTo: options.replyTo,\n          replaceMessageId: options.replaceMessageId,\n        },\n        undefined,\n        options,\n      );\n      messageIds.push(lastId);\n    }\n    for (let index = 0; index < files.length; index++) {\n      const file = files[index];\n      const bytes =\n        file.data instanceof Blob\n          ? Buffer.from(await file.data.arrayBuffer())\n          : Buffer.from(file.data as ArrayBuffer);\n      if (bytes.length > MAX_ATTACHMENT_BYTES)\n        throw new Error(\"Attachment exceeds the configured size limit\");\n      lastId = await this.sendPart(\n        publicationId,\n        `file-${index}`,\n        {\n          chatGuid: chat.guid,\n          filename: file.filename,\n          sha256: createHash(\"sha256\").update(bytes).digest(\"hex\"),\n          replyTo: options.replyTo,\n        },\n        { ...file, data: bytes },\n        options,\n      );\n      messageIds.push(lastId);\n    }\n    if (!lastId) throw new Error(\"Photon publication is empty\");\n    await this.endTyping(id);\n    return { id: lastId, messageIds };\n  }","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/server/src/services/photon/adapter.ts#L428-L464","documentation":"Thrown in PhotonAdapter.publish when an attachment's byte size (Buffer length after normalizing Blob/ArrayBuffer data) exceeds MAX_ATTACHMENT_BYTES, the configured ceiling. The adapter checks locally before uploading so oversized payloads never hit the Photon API.","triggerScenarios":"publish() with message.files[i] whose data (Blob or ArrayBuffer) converts to a Buffer longer than MAX_ATTACHMENT_BYTES; checked in the per-file loop before sendPart is called for that file.","commonSituations":"Attaching large screenshots, logs, or generated PDFs; uploading video recordings (.mp4) from agent runs; MAX_ATTACHMENT_BYTES configured lower than the source data (e.g. iMessage's ~100MB practical ceiling vs a stricter instance config).","solutions":["Shrink or re-encode the attachment (compress images, trim logs, lower bitrate on media) until it fits the limit","Check bytes.length (or file.data.size for Blob) before calling publish and refuse the file earlier in your own code","Raise MAX_ATTACHMENT_BYTES in configuration if the Photon server actually accepts larger payloads","Link the artifact instead of attaching it (upload elsewhere and send a URL as text)"],"exampleFix":"// before\nawait adapter.publish(id, pubId, { text: 'report', files: [bigFile] }, opts);\n// after\nconst bytes = bigFile.data instanceof Blob ? await bigFile.arrayBuffer() : bigFile.data;\nif (bytes.byteLength > MAX_ATTACHMENT_BYTES) {\n  bigFile = await compressAttachment(bigFile);\n}\nawait adapter.publish(id, pubId, { text: 'report', files: [bigFile] }, opts);","handlingStrategy":"validation","validationCode":"const MAX = MAX_ATTACHMENT_BYTES;\nfor (const f of message.files ?? []) {\n  const size = f.data instanceof Blob ? f.data.size : f.data.byteLength;\n  if (size > MAX) throw new Error(`Attachment ${f.filename} is ${size} bytes, limit ${MAX}`);\n}","typeGuard":"function withinLimit(file, max = MAX_ATTACHMENT_BYTES) {\n  const size = file.data instanceof Blob ? file.data.size : file.data.byteLength;\n  return size <= max;\n}","tryCatchPattern":"try {\n  await adapter.publish(id, pubId, msg, opts);\n} catch (e) {\n  if (e.message === 'Attachment exceeds the configured size limit') {\n    return publishAsLink(id, pubId, msg, opts); // attach URL instead\n  }\n  throw e;\n}","preventionTips":["Check attachment sizes at ingest time, before queueing a publication","Compress images/media automatically when over the limit","Keep MAX_ATTACHMENT_BYTES config in sync with iMessage's practical limits","Prefer linking large artifacts over attaching them"],"tags":["attachment","file-size-limit","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"3f1d897a7c018d76563a21c6e39c3c9b03933622","analyzedAt":"2026-09-18T08:03:59.046Z","contentChangedAt":"2026-09-18T08:03:59.046Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}