From e35648e3a2eeb93bc6dd611e1af2ef64674057ca Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 14 Oct 2026 14:27:43 +0200 Subject: [PATCH 1/4] test: a download over 2 GB fails, never cut short (#557) --- src/agent-device/edge.test.ts | 158 +++++++++++++++++++++ src/agent-device/gateway-front.test.ts | 53 +++++++ src/agent-device/host/download-cap.test.ts | 69 +++++++++ src/agent-device/testing.ts | 96 ++++++++++++- 4 files changed, 375 insertions(+), 1 deletion(-) create mode 100644 src/agent-device/host/download-cap.test.ts diff --git a/src/agent-device/edge.test.ts b/src/agent-device/edge.test.ts index 055bae3ee..49738f570 100644 --- a/src/agent-device/edge.test.ts +++ b/src/agent-device/edge.test.ts @@ -1,3 +1,4 @@ +import { createHash } from "node:crypto"; import { mkdtemp, rm } from "node:fs/promises"; import { createServer } from "node:net"; import { tmpdir } from "node:os"; @@ -3701,3 +3702,160 @@ describe("a worker's capabilities in status.get, through the whole worker daemon expect(workers[0]?.capabilities).toEqual([{ name: "agent-device", state: "available" }]); }); }); + +const downloadLimit = 2_147_483_648; +const tooLargeReply = (size: number) => ({ + code: "INVALID_ARGS", + error: `the download is ${String(size)} bytes; simlock carries downloads up to 2 GB (2147483648 bytes)`, + ok: false, +}); + +async function drainDownload(response: Response): Promise<{ + readonly bytes: number; + readonly digest: string; + readonly ended: boolean; +}> { + const hash = createHash("sha256"); + let bytes = 0; + const reader = (response.body as ReadableStream).getReader(); + try { + for (;;) { + const next = await reader.read(); + if (next.done) return { bytes, digest: hash.digest("hex"), ended: true }; + hash.update(next.value); + bytes += next.value.length; + } + } catch { + return { bytes, digest: "", ended: false }; + } +} + +describe( + "the agent-device front, through the whole worker daemon: downloads over 2 GiB", + { + timeout: 120_000, + }, + () => { + it("an artifact download whose `content-length` is 2147483649 is answered 413 with simlock's reply; the fake produced 0 bytes and its body was cancelled", async () => { + const rig = await setUp(); + rig.fake.serveArtifact({ contentLength: "size", size: downloadLimit + 1 }); + + const response = await send(rig, "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/artifacts/a1"); + + expect(response.status).toBe(413); + expect(await response.json()).toEqual(tooLargeReply(downloadLimit + 1)); + expect(rig.fake.artifactBytesProduced).toBe(0); + await expect.poll(() => rig.fake.artifactBodyCancelled).toBe(true); + }); + + it("an artifact download of exactly 2147483648 bytes with `content-length` arrives byte for byte", async () => { + const rig = await setUp(); + rig.fake.serveArtifact({ contentLength: "size", size: downloadLimit }); + + const response = await send(rig, "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/artifacts/a1"); + const received = await drainDownload(response); + + expect(response.status).toBe(200); + expect(received.ended).toBe(true); + expect(received.bytes).toBe(downloadLimit); + expect(received.digest).toBe(rig.fake.producedDigest()); + }); + + it("a download with no `content-length` of exactly 2147483648 bytes arrives byte for byte", async () => { + const rig = await setUp(); + rig.fake.serveArtifact({ contentLength: "none", size: downloadLimit }); + + const response = await send(rig, "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/artifacts/a1"); + const received = await drainDownload(response); + + expect(response.status).toBe(200); + expect(received.ended).toBe(true); + expect(received.bytes).toBe(downloadLimit); + expect(received.digest).toBe(rig.fake.producedDigest()); + }); + + it("a download with no `content-length` that passes 2147483648 bytes errors the agent's response, which never ends cleanly, and the fake's body is cancelled", async () => { + const rig = await setUp(); + rig.fake.serveArtifact({ contentLength: "none", size: downloadLimit + 1 }); + + const response = await send(rig, "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/artifacts/a1"); + const received = await drainDownload(response); + + expect(received.ended).toBe(false); + await expect.poll(() => rig.fake.artifactBodyCancelled).toBe(true); + }); + + it("an agent that cancels a 1 GiB download halfway cancels the fake's body", async () => { + const rig = await setUp(); + rig.fake.serveArtifact({ contentLength: "none", size: 1_073_741_824 }); + + const response = await send(rig, "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/artifacts/a1"); + const reader = (response.body as ReadableStream).getReader(); + let bytes = 0; + while (bytes < 536_870_912) { + const next = await reader.read(); + if (next.done) break; + bytes += next.value.length; + } + await reader.cancel(); + + expect(bytes).toBeGreaterThanOrEqual(536_870_912); + await expect.poll(() => rig.fake.artifactBodyCancelled).toBe(true); + expect(rig.fake.artifactBytesProduced).toBeLessThan(1_073_741_824); + }); + + it("an RPC reply and a preflight reply pass unchanged", async () => { + const rig = await setUp(); + await granted(rig, 1); + + const reply = await command(rig, "snapshot", 1); + const preflight = await send(rig, "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/upload/preflight", { body: "{}" }); + + expect(reply.status).toBe(200); + expect((await envelopeOf(reply)).result).toMatchObject({ ok: true }); + expect(preflight.status).toBe(200); + expect( + ((await preflight.json()) as { upload: { url: string } }).upload.url.startsWith( + `${rig.origin}/v1/agent-device/upload/direct/`, + ), + ).toBe(true); + }); + + it("a 2147483648-byte upload reaches the fake byte for byte", async () => { + const rig = await setUp(); + const preflight = await send(rig, "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/upload/preflight", { body: "{}" }); + const ticket = ( + (await preflight.json()) as { upload: { url: string; headers: Record } } + ).upload; + const hash = createHash("sha256"); + let sent = 0; + const piece = new Uint8Array(65_536).fill(7); + const body = new ReadableStream( + { + pull: (controller) => { + if (sent >= downloadLimit) { + controller.close(); + return; + } + sent += piece.length; + hash.update(piece); + controller.enqueue(piece); + }, + }, + { highWaterMark: 0 }, + ); + + const put = await fetch(ticket.url, { + body, + duplex: "half", + headers: { ...ticket.headers, "content-length": String(downloadLimit) }, + method: "PUT", + } as RequestInit); + + expect(put.status).toBe(200); + expect(rig.fake.uploadSummaries).toEqual([ + { bytes: downloadLimit, sha256: hash.copy().digest("hex") }, + ]); + }); + }, +); diff --git a/src/agent-device/gateway-front.test.ts b/src/agent-device/gateway-front.test.ts index 8513b1124..3ba5b4c73 100644 --- a/src/agent-device/gateway-front.test.ts +++ b/src/agent-device/gateway-front.test.ts @@ -1,4 +1,5 @@ import { mkdtemp, readFile, rm } from "node:fs/promises"; +import { createHash } from "node:crypto"; import { createServer } from "node:net"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -2185,3 +2186,55 @@ describe( }); }, ); + +describe( + "the agent-device front, through a gateway: downloads over 2 GiB", + { timeout: 120_000 }, + () => { + const limit = 2_147_483_648; + + it("an artifact download whose `content-length` is 2147483649 gets the 413 reply; the worker's fake produced 0 bytes and its body was cancelled", async () => { + const rig = await setUp(); + await granted(rig, 1); + const worker = holderOf(rig, 1); + worker.fake.serveArtifact({ contentLength: "size", size: limit + 1 }); + + const response = await send(rig, "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/artifacts/a1", { headers: leased(1) }); + + expect(response.status).toBe(413); + expect(await response.json()).toEqual({ + code: "INVALID_ARGS", + error: `the download is ${String(limit + 1)} bytes; simlock carries downloads up to 2 GB (2147483648 bytes)`, + ok: false, + }); + expect(worker.fake.artifactBytesProduced).toBe(0); + await expect.poll(() => worker.fake.artifactBodyCancelled).toBe(true); + }); + + it("a download with no `content-length` that passes 2147483648 bytes errors the agent's response, which never ends cleanly", async () => { + const rig = await setUp(); + await granted(rig, 1); + const worker = holderOf(rig, 1); + worker.fake.serveArtifact({ contentLength: "none", size: limit + 1 }); + + const response = await send(rig, "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/artifacts/a1", { headers: leased(1) }); + const reader = (response.body as ReadableStream).getReader(); + const hash = createHash("sha256"); + let ended = false; + try { + for (;;) { + const next = await reader.read(); + if (next.done) { + ended = true; + break; + } + hash.update(next.value); + } + } catch { + ended = false; + } + + expect(ended).toBe(false); + }); + }, +); diff --git a/src/agent-device/host/download-cap.test.ts b/src/agent-device/host/download-cap.test.ts new file mode 100644 index 000000000..ceaacca48 --- /dev/null +++ b/src/agent-device/host/download-cap.test.ts @@ -0,0 +1,69 @@ +import { createHash } from "node:crypto"; +import { describe, expect, it } from "vitest"; + +import { FakeAgentDevice } from "../testing.js"; +import { AgentDeviceHost } from "./host.js"; + +const LIMIT = 2_147_483_648; +const identity = { requesterId: "tok_a", role: "agent" } as const; + +function download(): Request { + return new Request("http://simlock.test/v1/agent-device/artifacts/a1", { + headers: { authorization: "Bearer slk_test_agent" }, + }); +} + +async function drain(response: Response): Promise<{ + readonly bytes: number; + readonly digest: string; + readonly error: unknown; + readonly ended: boolean; +}> { + const hash = createHash("sha256"); + let bytes = 0; + const reader = (response.body as ReadableStream).getReader(); + try { + for (;;) { + const next = await reader.read(); + if (next.done) return { bytes, digest: hash.digest("hex"), error: undefined, ended: true }; + hash.update(next.value); + bytes += next.value.length; + } + } catch (error) { + return { bytes, digest: "", error, ended: false }; + } +} + +function hostFor(fake: FakeAgentDevice): AgentDeviceHost { + return new AgentDeviceHost(fake, ["ios"]); +} + +describe("the agent-device host's download cap, called directly", { timeout: 120_000 }, () => { + it.each(["3e9", "2147483649, 2147483649", "9007199254740993"])( + "a content-length of %s is counted as absent: the body is counted, and one passing 2147483648 bytes under it errors", + async (contentLength) => { + const fake = new FakeAgentDevice(); + fake.serveArtifact({ contentLength, size: LIMIT + 1 }); + + const response = await hostFor(fake).forward(download(), identity); + expect(response.status).toBe(200); + const result = await drain(response); + + expect(result.ended).toBe(false); + expect(result.error).toBeDefined(); + expect(fake.artifactBodyCancelled).toBe(true); + }, + ); + + it("a 2 GiB download whose body nobody reads leaves the fake having produced at most 128 KiB after 1 s", async () => { + const fake = new FakeAgentDevice(); + fake.serveArtifact({ contentLength: "none", size: LIMIT }); + + const response = await hostFor(fake).forward(download(), identity); + expect(response.status).toBe(200); + await new Promise((resolve) => setTimeout(resolve, 1_000)); + + expect(fake.artifactBytesProduced).toBeLessThanOrEqual(128 * 1024); + await response.body?.cancel(); + }); +}); diff --git a/src/agent-device/testing.ts b/src/agent-device/testing.ts index 4255f2014..4e247ca2f 100644 --- a/src/agent-device/testing.ts +++ b/src/agent-device/testing.ts @@ -1,3 +1,5 @@ +import { createHash, type Hash } from "node:crypto"; + import type { AgentDeviceHealthProbe } from "./host/health.js"; import type { AgentDeviceUpstream, AgentDeviceUpstreamState } from "./host/upstream.js"; @@ -137,6 +139,21 @@ function errorEnvelope(id: unknown, failure: FakeFailure): Response { }); } +const ARTIFACT_PIECE_BYTES = 64 * 1024; +const UPLOAD_TEXT_LIMIT = 1024 * 1024; + +export interface FakeArtifact { + // why: the number of bytes the body would carry if read to its end. + readonly size: number; + // why: "size" states the size up front, "none" leaves the header off, any other string is sent as given (for a malformed one). + readonly contentLength: "size" | "none" | string; +} + +export interface FakeUploadSummary { + readonly bytes: number; + readonly sha256: string; +} + export class FakeAgentDevice implements AgentDeviceUpstream { readonly requests: FakeAgentDeviceRequest[] = []; readonly leases = new Map(); @@ -145,7 +162,15 @@ export class FakeAgentDevice implements AgentDeviceUpstream { // why: the ids of releases whose request was hung up on before the fake answered, so a test can wait until the hang-up has reached the daemon side. readonly hungUpReleases: string[] = []; readonly refused: string[] = []; + // why: a direct upload keeps its text only up to 1 MiB, so a test can move 2 GiB; `uploadSummaries` holds each one's size and digest. readonly uploads: string[] = []; + readonly uploadSummaries: FakeUploadSummary[] = []; + // why: what the artifact route produced and whether its body was cancelled, so a test can tell a stream that stopped from one that was drained. + artifactBytesProduced = 0; + artifactBodyCancelled = false; + artifactRequests = 0; + #artifact: FakeArtifact | undefined; + #artifactHash: Hash = createHash("sha256"); // why: the headers the proxy sent the daemon with each upload preflight, so a test can see which of the caller's credentials reached it. readonly preflightHeaders: Record[] = []; baseUrl = "http://127.0.0.1:47001"; @@ -304,6 +329,71 @@ export class FakeAgentDevice implements AgentDeviceUpstream { this.#releaseWaitsForCommands = false; } + serveArtifact(artifact: FakeArtifact): void { + this.#artifact = artifact; + this.artifactBytesProduced = 0; + this.artifactBodyCancelled = false; + this.#artifactHash = createHash("sha256"); + } + + // why: the digest of every byte the artifact route produced so far, to compare with what the agent received. + producedDigest(): string { + return this.#artifactHash.copy().digest("hex"); + } + + #artifactResponse(): Response { + const artifact = this.#artifact; + if (artifact === undefined) return new Response("Not found", { status: 404 }); + this.artifactRequests += 1; + let produced = 0; + const body = new ReadableStream( + { + cancel: () => { + this.artifactBodyCancelled = true; + }, + pull: (controller) => { + if (produced >= artifact.size) { + controller.close(); + return; + } + const length = Math.min(ARTIFACT_PIECE_BYTES, artifact.size - produced); + const piece = new Uint8Array(length); + for (let index = 0; index < length; index += 1) piece[index] = (produced + index) % 251; + produced += length; + this.artifactBytesProduced += length; + this.#artifactHash.update(piece); + controller.enqueue(piece); + }, + }, + { highWaterMark: 0 }, + ); + const headers = new Headers({ "content-type": "application/octet-stream" }); + if (artifact.contentLength === "size") headers.set("content-length", String(artifact.size)); + else if (artifact.contentLength !== "none") + headers.set("content-length", artifact.contentLength); + return new Response(body, { headers, status: 200 }); + } + + async #keepUpload(request: Request): Promise { + const hash = createHash("sha256"); + const kept: Uint8Array[] = []; + let bytes = 0; + const reader = request.body?.getReader(); + for (;;) { + const next = await reader?.read(); + if (next === undefined || next.done) break; + hash.update(next.value); + bytes += next.value.length; + if (bytes <= UPLOAD_TEXT_LIMIT) kept.push(next.value); + } + this.uploadSummaries.push({ bytes, sha256: hash.digest("hex") }); + this.uploads.push( + bytes <= UPLOAD_TEXT_LIMIT + ? Buffer.concat(kept).toString("utf8") + : `<${String(bytes)} bytes>`, + ); + } + restart(): void { this.#restarts += 1; this.generation += 1; @@ -350,9 +440,13 @@ export class FakeAgentDevice implements AgentDeviceUpstream { } if (url.pathname.startsWith("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/upload/direct/")) { this.requests.push({ method: request.method, path: url.pathname, tenant: tenantHeader }); - this.uploads.push(await request.text()); + await this.#keepUpload(request); return Response.json({ ok: true }); } + if (url.pathname.startsWith("/artifacts/")) { + this.requests.push({ method: request.method, path: url.pathname, tenant: tenantHeader }); + return this.#artifactResponse(); + } if (url.pathname !== "/rpc") { this.requests.push({ method: request.method, path: url.pathname, tenant: tenantHeader }); return new Response("Not found", { status: 404 }); From c41e09d2d774a1a83bbc8ec99dcd7c66957998b0 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 14 Oct 2026 14:35:36 +0200 Subject: [PATCH 2/4] feat(agent-device): a download over 2 GB fails, never cut short (#557) 3 failing -> 0 failing --- docs/HTTP-API.md | 6 ++++ src/agent-device/host/host.ts | 63 +++++++++++++++++++++++++++++++++-- src/http/server.ts | 33 +++++++++++++++++- 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/docs/HTTP-API.md b/docs/HTTP-API.md index 48ee161b0..9edf2bf79 100644 --- a/docs/HTTP-API.md +++ b/docs/HTTP-API.md @@ -1492,6 +1492,12 @@ agent-device close With `agentDevice.enabled` `false` or unset, on a worker or a gateway, every `/v1/agent-device` URL answers `404`. +Downloads (artifacts) up to 2 GB (2147483648 bytes) are carried. A download +whose `content-length` is over that is answered `413` with +`{"ok": false, "code": "INVALID_ARGS", "error": "..."}` before any byte is +read. A download with no usable `content-length` that passes 2 GB is cut with +a failed response, never one that ends as if it were whole. + A **gateway** with `agentDevice.enabled` serves the same URL, and the CLI is pointed at the gateway the same way. `open` lands only on a worker whose agent-device is available, and the commands, heartbeats and `close` of that diff --git a/src/agent-device/host/host.ts b/src/agent-device/host/host.ts index d3b9a0725..911365f46 100644 --- a/src/agent-device/host/host.ts +++ b/src/agent-device/host/host.ts @@ -28,6 +28,62 @@ function stripBodyHeaders(headers: Headers): Headers { return copy; } +const DOWNLOAD_LIMIT = 2_147_483_648; + +function tooLarge(size: number | undefined): Response { + const shown = size === undefined ? "more than 2147483648" : String(size); + return Response.json( + { + code: "INVALID_ARGS", + error: `the download is ${shown} bytes; simlock carries downloads up to 2 GB (${String(DOWNLOAD_LIMIT)} bytes)`, + ok: false, + }, + { status: 413 }, + ); +} + +// why: only a plain decimal is trusted as a size; anything else is counted as absent and the body is counted instead. +function declaredLength(response: Response): number | undefined { + const value = response.headers.get("content-length"); + if (value === null || !/^\d+$/.test(value)) return undefined; + const size = Number(value); + return Number.isSafeInteger(size) ? size : undefined; +} + +function capped(response: Response): Response { + const body = response.body; + if (body === null) return response; + const declared = declaredLength(response); + if (declared !== undefined && declared > DOWNLOAD_LIMIT) { + void body.cancel().catch(() => undefined); + return tooLarge(declared); + } + const reader = body.getReader(); + let seen = 0; + // why: highWaterMark 0 pulls from the worker only as fast as the agent reads, so nothing is buffered past the cap. + const counted = new ReadableStream( + { + cancel: (reason) => reader.cancel(reason), + pull: async (controller) => { + const next = await reader.read(); + if (next.done) { + controller.close(); + return; + } + seen += next.value.length; + if (seen > DOWNLOAD_LIMIT) { + void reader.cancel().catch(() => undefined); + controller.error(new Error("the download passed 2 GB (2147483648 bytes)")); + return; + } + controller.enqueue(next.value); + }, + }, + { highWaterMark: 0 }, + ); + return new Response(counted, { headers: response.headers, status: response.status }); +} + export class AgentDeviceHost { readonly #identities = new Map(); #loading: Promise | undefined; @@ -94,9 +150,10 @@ export class AgentDeviceHost { const tag = this.tag(proxied, identity); try { const response = await this.#proxy.proxy.handle(proxied); - return new URL(proxied.url).pathname === PREFLIGHT_PATH - ? await this.#withTicketPrefix(response) - : response; + if (new URL(proxied.url).pathname === PREFLIGHT_PATH) { + return await this.#withTicketPrefix(response); + } + return capped(response); } finally { this.#identities.delete(tag); } diff --git a/src/http/server.ts b/src/http/server.ts index e030f3afd..e16015044 100644 --- a/src/http/server.ts +++ b/src/http/server.ts @@ -172,7 +172,11 @@ export class HttpGateway { return new Promise((resolve, reject) => { let settled = false; const server = serve( - { fetch: site.fetch, hostname: this.#host, port: this.#port }, + { + fetch: async (request, env) => abortOnBodyError(await site.fetch(request, env), env), + hostname: this.#host, + port: this.#port, + }, (info) => { if (settled) return; settled = true; @@ -217,3 +221,30 @@ export class HttpGateway { this.#logger.info("HTTP gateway stopped", { host: this.#host, port: this.#port }); } } + +// why: the node adapter answers a body that fails mid-stream by ending the response cleanly with an error line, so a client would take a cut-short download for a whole one; this makes the client see the failure. +function abortOnBodyError(response: Response, env: unknown): Response { + const body = response.body; + const outgoing = (env as { outgoing?: { socket?: Socket | null } } | undefined)?.outgoing; + if (body === null || outgoing === undefined) return response; + const reader = body.getReader(); + const guarded = new ReadableStream({ + cancel: (reason) => reader.cancel(reason), + pull: async (controller) => { + try { + const next = await reader.read(); + if (next.done) controller.close(); + else controller.enqueue(next.value); + } catch { + // why: a client told "connection: close" takes a socket closed mid-chunk for the end of the body, so an invalid chunk header goes first. + outgoing.socket?.end("!\r\n"); + controller.close(); + } + }, + }); + return new Response(guarded, { + headers: response.headers, + status: response.status, + statusText: response.statusText, + }); +} From b7339a2a268eae6f2f1a9c60dde93f29d6f929a6 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 14 Oct 2026 14:42:26 +0200 Subject: [PATCH 3/4] fix(agent-device): drop the unused size-less 413 message branch (#557) --- src/agent-device/host/host.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/agent-device/host/host.ts b/src/agent-device/host/host.ts index 911365f46..fa185bfbc 100644 --- a/src/agent-device/host/host.ts +++ b/src/agent-device/host/host.ts @@ -30,12 +30,11 @@ function stripBodyHeaders(headers: Headers): Headers { const DOWNLOAD_LIMIT = 2_147_483_648; -function tooLarge(size: number | undefined): Response { - const shown = size === undefined ? "more than 2147483648" : String(size); +function tooLarge(size: number): Response { return Response.json( { code: "INVALID_ARGS", - error: `the download is ${shown} bytes; simlock carries downloads up to 2 GB (${String(DOWNLOAD_LIMIT)} bytes)`, + error: `the download is ${String(size)} bytes; simlock carries downloads up to 2 GB (${String(DOWNLOAD_LIMIT)} bytes)`, ok: false, }, { status: 413 }, From 262df76c971d74a2e778e98e8747a3f9e658274f Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 14 Oct 2026 14:53:01 +0200 Subject: [PATCH 4/4] fix(agent-device): oversize download reply uses the shared front reply shape --- src/agent-device/host/host.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/agent-device/host/host.ts b/src/agent-device/host/host.ts index fa185bfbc..6a7f4b06d 100644 --- a/src/agent-device/host/host.ts +++ b/src/agent-device/host/host.ts @@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto"; import type { TokenIdentity } from "../../http/token-store.js"; import type { AgentDevicePlatform } from "./agent-device-supervisor.js"; import { FRONT_PREFIX, PROXY_BASE_PATH } from "../shared/paths.js"; +import { frontReply, refusal } from "../shared/replies.js"; import { recordingFetch, ReleaseScopeRecord } from "./lease-end.js"; import type { AgentDeviceUpstream } from "./upstream.js"; @@ -31,13 +32,12 @@ function stripBodyHeaders(headers: Headers): Headers { const DOWNLOAD_LIMIT = 2_147_483_648; function tooLarge(size: number): Response { - return Response.json( - { - code: "INVALID_ARGS", - error: `the download is ${String(size)} bytes; simlock carries downloads up to 2 GB (${String(DOWNLOAD_LIMIT)} bytes)`, - ok: false, - }, - { status: 413 }, + return frontReply( + refusal( + `the download is ${String(size)} bytes; simlock carries downloads up to 2 GB (${String(DOWNLOAD_LIMIT)} bytes)`, + 413, + ), + undefined, ); }