Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
fix(server): release a refused download's body before reporting it (#732)
ANIRUDDHA ADAKd152152bf62f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2a0e59a4..3d6b414e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,10 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+- A file download refused because the computer's response carried no usable byte length now releases+ the connection before reporting the refusal. The unread body could be as large as the whole+ download budget, so a computer reached through a proxy that re-chunks left a transfer running and a+ connection checked out of the pool on every attempt.### A Bot's turn in a group is no longer offered coordination tools it cannot callA Bot answering another Bot in a group conversation was offered `ask_person`, and `message_bot`diff --git a/server/src/computer/client.ts b/server/src/computer/client.tsindex 3fb61ec4..74171d43 100644--- a/server/src/computer/client.ts+++ b/server/src/computer/client.ts@@ -293,6 +293,10 @@ export function createComputerTransport(const bytes =length !== null && /^\d+$/.test(length) ? Number(length) : Number.NaN;if (!response.body || !Number.isSafeInteger(bytes) || bytes < 0) {+ // Nothing else will ever read this body, so release it here rather than+ // leaving the whole download budget checked out of the pool. A cancel that+ // fails must not replace the refusal the caller is told about.+ await response.body?.cancel().catch(() => undefined);throw new ComputerUnavailableError("The assistant's computer returned an invalid file download.",);diff --git a/server/tests/computer-client.test.ts b/server/tests/computer-client.test.tsindex 5e57f461..7cb4fa2c 100644--- a/server/tests/computer-client.test.ts+++ b/server/tests/computer-client.test.ts@@ -73,6 +73,40 @@ describe("computer client", () => {);});+ test("releases the connection it refuses to hand back", async () => {+ let cancelled = false;+ const body = new ReadableStream<Uint8Array>({+ start(controller) {+ controller.enqueue(Uint8Array.from([1, 2, 3]));+ },+ cancel() {+ cancelled = true;+ },+ });+ const client = clientWith(() => new Response(body));++ await expect(client.download("x")).rejects.toThrow(+ ComputerUnavailableError,+ );+ expect(cancelled).toBe(true);+ });++ test("still names the invalid download when releasing it fails", async () => {+ const body = new ReadableStream<Uint8Array>({+ start(controller) {+ controller.enqueue(Uint8Array.from([1, 2, 3]));+ },+ cancel() {+ throw new Error("socket already gone");+ },+ });+ const client = clientWith(() => new Response(body));++ await expect(client.download("x")).rejects.toThrow(+ ComputerUnavailableError,+ );+ });+test.each([[404, WorkspaceNotFoundError],[413, WorkspaceTooLargeError],