paperclipai/paperclip · error
Bridge response envelope exceeded the configured size limit.
Error message
Bridge response envelope exceeded the configured size limit.
What it means
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.
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.
Defensive patterns
Strategy: validation
Validate before calling
const stat = await fs.stat(responsePath).catch(() => null);
if (stat && stat.size > SANDBOX_BRIDGE_ENVELOPE_LIMIT) throw new Error("response envelope too large before read"); Try / catch
try { return await waitForResponse(id); } catch (e) {
if (e.message.includes("envelope exceeded")) { await cleanResponsesDir(); return waitForResponse(id); }
throw e;
} Prevention
- 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
When it happens
Trigger: fs.stat on <responsesDir>/<requestId>.json returns stat.size greater than sandboxBridgeEnvelopeLimit(maxBodyBytes) while waiting for a bridge response.
Common situations: 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.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- Bridge envelope exceeded the configured size limit.
- Bridge envelope too large
- Bridge response body exceeded the configured size limit.
- Bridge response envelope changed while reading.
- A sandbox command is required.
AI-assisted analysis of paperclipai/paperclip@3f1d897a7c (2026-09-18).
Data as JSON: /api/errors/0fcb977493d6b3a2.
Report an issue: GitHub.
Appendix: source
Thrown at packages/adapter-utils/src/sandbox-callback-bridge.ts:2419
const stats = await fs.stat(filePath).catch(() => null);
if (stats && stats.mtimeMs < staleBefore) {
await fs.rm(filePath, { force: true }).catch(() => undefined);
}
}
}
async function waitForResponse(requestId, reserveResponse) {
const responsePath = path.posix.join(responsesDir, \`\${requestId}.json\`);
const deadline = Date.now() + responseTimeoutMs;
while (Date.now() < deadline) {
const handle = await fs.open(responsePath, "r").catch(error => {
if (error.code === "ENOENT") return null;
throw error;
});
if (handle) {
try {
const stat = await handle.stat();
if (stat.size > sandboxBridgeEnvelopeLimit(maxBodyBytes)) throw new Error("Bridge response envelope exceeded the configured size limit.");
reserveResponse(6 * stat.size + 1);
const bytes = Buffer.alloc(stat.size + 1);
let length = 0;
while (length < bytes.length) {
const read = await handle.read(bytes, length, bytes.length - length, length);
if (!read.bytesRead) break;
length += read.bytesRead;
}
if (length !== stat.size) throw new Error("Bridge response envelope changed while reading.");
return JSON.parse(bytes.subarray(0, length).toString("utf8"));
} finally {
await handle.close();
await fs.rm(responsePath, { force: true }).catch(() => undefined);
}
}
await sleep(pollIntervalMs);
}
throw new Error("Timed out waiting for host bridge response.");View on GitHub (pinned to 3f1d897a7c)