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

  1. Ensure host and sandbox use the same maxBodyBytes / envelope-limit configuration.
  2. Shrink the handler response body on the host side so the encoded envelope fits the limit.
  3. Clean the shared bridge directory of stale/foreign files and rerun.
  4. 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

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


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)