From fcb3977f5a53e709063b3869dda3666d0a99799d Mon Sep 17 00:00:00 2001 From: "agent-think[bot]" Date: Thu, 13 Aug 2026 11:47:13 +0000 Subject: [PATCH] computer: Embed capability limit in errors Generate the capability size error as a quoted literal so the configured limit is fixed in the Dynamic Worker module. Cover the generated source to keep the user-facing value visible. --- .changeset/bright-lions-report.md | 5 +++ .../worker-javascript/module-graph.ts | 3 +- .../worker-javascript.test.ts | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .changeset/bright-lions-report.md diff --git a/.changeset/bright-lions-report.md b/.changeset/bright-lions-report.md new file mode 100644 index 00000000..da4638ce --- /dev/null +++ b/.changeset/bright-lions-report.md @@ -0,0 +1,5 @@ +--- +"@cloudflare/computer": patch +--- + +Embed the configured byte limit directly in Worker JavaScript capability size errors. diff --git a/packages/computer/src/backends/worker-javascript/module-graph.ts b/packages/computer/src/backends/worker-javascript/module-graph.ts index 3f5a3fcb..8280e7b5 100644 --- a/packages/computer/src/backends/worker-javascript/module-graph.ts +++ b/packages/computer/src/backends/worker-javascript/module-graph.ts @@ -237,6 +237,7 @@ function isInternalModuleName(name: string) { } function capabilitiesModule(maxCapabilityBytes: number) { + const requestTooLargeMessage = `Workspace capability request exceeds ${maxCapabilityBytes} bytes.`; return ` let host; const callKey = Symbol.for("cloudflare.workspace.runtime.call"); @@ -258,7 +259,7 @@ function capabilitiesModule(maxCapabilityBytes: number) { if (!host) throw new Error("Workspace capabilities are not installed"); const request = JSON.stringify(args.map(encode)); if (new TextEncoder().encode(request).byteLength > ${maxCapabilityBytes}) { - throw new Error("Workspace capability request exceeds ${maxCapabilityBytes} bytes."); + throw new Error(${JSON.stringify(requestTooLargeMessage)}); } const raw = await host.call(namespace + "." + method, request); const payload = JSON.parse(String(raw)); diff --git a/packages/computer/src/backends/worker-javascript/worker-javascript.test.ts b/packages/computer/src/backends/worker-javascript/worker-javascript.test.ts index 46c22076..f75ef9bc 100644 --- a/packages/computer/src/backends/worker-javascript/worker-javascript.test.ts +++ b/packages/computer/src/backends/worker-javascript/worker-javascript.test.ts @@ -157,6 +157,39 @@ describe("WorkerJavaScriptBackend", () => { ).toThrow(/positive finite/); }); + it("includes the configured capability byte limit in generated errors", async () => { + const load = vi.fn(() => ({ + getEntrypoint() { + return { + evaluate: ( + _input: unknown, + host: { + assertResult(value: unknown): Promise; + attachOutput(readable: ReadableStream): Promise; + }, + ) => evaluateResult(host, null), + }; + }, + })); + const workspace = new Workspace({ + storage: new SQLiteTestStorage(), + backends: [ + new WorkerJavaScriptBackend({ + loader: { load }, + maxCapabilityBytes: 256, + }), + ], + }); + await workspace.fs.mkdir("/workspace", { recursive: true }); + + await (await workspace.runtime.exec("export default null")).result(); + + const capabilities = load.mock.calls[0]?.[0].modules["workspace-capabilities.js"]; + expect(capabilities).toEqual(expect.any(String)); + expect(capabilities).toContain("exceeds 256 bytes"); + expect(capabilities).not.toContain("maxCapabilityBytes"); + }); + it("disposes Loader resources when evaluate throws synchronously", async () => { let entrypointDisposals = 0; let workerDisposals = 0;