{"record":{"id":"0fcb977493d6b3a2","repo":"paperclipai/paperclip","slug":"bridge-response-envelope-exceeded-the-configured-size-limit","errorCode":null,"errorMessage":"Bridge response envelope exceeded the configured size limit.","messagePattern":"Bridge response envelope exceeded the configured size limit\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/adapter-utils/src/sandbox-callback-bridge.ts","lineNumber":2419,"sourceCode":"      const stats = await fs.stat(filePath).catch(() => null);\n      if (stats && stats.mtimeMs < staleBefore) {\n        await fs.rm(filePath, { force: true }).catch(() => undefined);\n      }\n    }\n  }\n\n  async function waitForResponse(requestId, reserveResponse) {\n    const responsePath = path.posix.join(responsesDir, \\`\\${requestId}.json\\`);\n    const deadline = Date.now() + responseTimeoutMs;\n    while (Date.now() < deadline) {\n      const handle = await fs.open(responsePath, \"r\").catch(error => {\n        if (error.code === \"ENOENT\") return null;\n        throw error;\n      });\n      if (handle) {\n        try {\n          const stat = await handle.stat();\n          if (stat.size > sandboxBridgeEnvelopeLimit(maxBodyBytes)) throw new Error(\"Bridge response envelope exceeded the configured size limit.\");\n          reserveResponse(6 * stat.size + 1);\n          const bytes = Buffer.alloc(stat.size + 1);\n          let length = 0;\n          while (length < bytes.length) {\n            const read = await handle.read(bytes, length, bytes.length - length, length);\n            if (!read.bytesRead) break;\n            length += read.bytesRead;\n          }\n          if (length !== stat.size) throw new Error(\"Bridge response envelope changed while reading.\");\n          return JSON.parse(bytes.subarray(0, length).toString(\"utf8\"));\n        } finally {\n          await handle.close();\n          await fs.rm(responsePath, { force: true }).catch(() => undefined);\n        }\n      }\n      await sleep(pollIntervalMs);\n    }\n    throw new Error(\"Timed out waiting for host bridge response.\");","sourceCodeStart":2401,"sourceCodeEnd":2437,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/packages/adapter-utils/src/sandbox-callback-bridge.ts#L2401-L2437","documentation":"The sandbox-side waiter polls the responses directory and, when it finds a response file, stats it and rejects any file larger than sandboxBridgeEnvelopeLimit(maxBodyBytes). This guards against reading a corrupt, foreign, or misbehaving-host envelope into memory. The bridge treats the whole response as invalid and the pending request will surface an error to the caller.","triggerScenarios":"fs.stat on <responsesDir>/<requestId>.json returns stat.size greater than sandboxBridgeEnvelopeLimit(maxBodyBytes) while waiting for a bridge response.","commonSituations":"A buggy or older host writing unbounded response bodies into the shared directory; tampered or leftover files in the responses dir from a crashed process with different limits; mismatched maxBodyBytes between host and sandbox sides.","solutions":["Ensure host and sandbox use the same maxBodyBytes / envelope-limit configuration.","Shrink the handler response body on the host side so the encoded envelope fits the limit.","Clean the shared bridge directory of stale/foreign files and rerun.","Upgrade both sides to matching package versions so the envelope limit logic agrees."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const stat = await fs.stat(responsePath).catch(() => null);\nif (stat && stat.size > SANDBOX_BRIDGE_ENVELOPE_LIMIT) throw new Error(\"response envelope too large before read\");","typeGuard":null,"tryCatchPattern":"try { return await waitForResponse(id); } catch (e) {\n  if (e.message.includes(\"envelope exceeded\")) { await cleanResponsesDir(); return waitForResponse(id); }\n  throw e;\n}","preventionTips":["Keep host and sandbox maxBodyBytes/envelope limits identical","Pin both sides to the same package version","Periodically sweep stale files from the shared responses directory","Treat any foreign file in the responses dir as suspicious and remove it"],"tags":["sandbox","size-limit","envelope","ipc"],"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-22T11:17:16.035Z"}