You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Worker aborts with V8 OOM in JSON.parse when several exec requests carry large stdin payloads; all leases lost #1242
A simlock 0.5.0 worker (Node 22.23.4, macOS, gateway mode) aborts with a V8 out-of-memory error while parsing an incoming message with JSON.parse. This happens when several POST /v1/leases/<id>/exec requests carrying a large stdin (base64 payloads of tens of MB) are in flight at once. Every lease on that worker is lost: in-flight execs return 503 after about 105 s, and later calls get 404 UNKNOWN_LEASE.
Worker log: the next start at 13:42:56Z logs Recovered stale daemon socket / Daemon started and re-establishes the gateway uplink. launchctl reports the last exit as -6.
Gateway log for one lease: device.exec → POST …/exec 503 after 105,242 ms → the client releases → POST …/exec 404 UNKNOWN_LEASE.
Workload: a tester-army e2e suite with 10 workers. Each worker uploads an ~89 MB fixture archive (deflated, base64 in stdin) through exec (simctl spawn <helper> untar) at the same moment. The host's load average was about 70.
The same burst also produced Cloudflare 524s and connection resets on other runs, because each exec holds a single long request.
Root cause
The worker (or its gateway uplink) materialises each exec request, stdin included, as one JSON string and parses it on the heap. Concurrent large stdin payloads exceed the V8 heap limit, and the process aborts instead of rejecting the request.
Suggested fix
Bound the accepted execstdin size per request, and the total in flight per worker. Reject an over-limit request with a typed error (413/PAYLOAD_TOO_LARGE) instead of crashing.
Stream stdin through the uplink and into the child process instead of parsing it as a single JSON string, or offer a separate upload endpoint, so large file transfers don't sit on the JSON path.
Optionally, keep lease state across a worker restart (the leases were lost even though the devices survived).
On the client side, we are capping concurrent large uploads (consumer issue linked below), but a worker should not be crashable by request size.
Another suite hitting the same limits: budgie's e2e port (budgie-at/budgie#1867) sends fixtures as base64 raw-deflate on exec stdin (a tar of the app's Documents/, via a helper simulator app), and limits app uploads to 3 at a time because 10 parallel uploads through the Cloudflare tunnel ended in 524 errors.
Gap: nothing bounds device.exec's stdin. The 8 MiB limit and BAD_REQUEST in the test are a proposal.
src/gateway/dispatcher.test.ts, "refuses a device.exec whose stdin is longer than 8,388,608 characters with BAD_REQUEST and forwards nothing to the worker, and forwards one at 8,388,608" (branch bug/1242-repro).
pnpm exec vitest run --project unit src/gateway/dispatcher.test.ts -t "longer than 8,388,608"
AssertionError: promise resolved "{ exitCode: +0 }" instead of rejecting
❯ src/gateway/dispatcher.test.ts:2532:48
await expect(exec("A".repeat(8_388_609))).rejects.toMatchObject({ code: "BAD_REQUEST" });
Root cause
src/contract/operations.ts:471 declares stdin: z.string().optional() with no bound, which breaks safety rule 10 ("never store one unbounded"). The gateway forwards any size (src/gateway/fleet-coordinator.ts:602) as a single uplink text message. The worker's socket client takes up to 100 MiB per message (the ws default, src/ports/uplink-websocket.ts:295). DaemonServer then buffers the line with no cap (src/daemon/server.ts:778) and JSON.parses it (:816), the frame in the crash stack. The string lives until the command exits; ten ~100 MB uploads fill the ~4 GB heap. The reporter's point 3 needs a correction: leases are rows in state.db and survive a restart. In the gateway log, the 404 UNKNOWN_LEASE comes after the client's own release.
Simplest fix
stdin: z.string().max(8_388_608).optional() in the contract. No protocol bump (maintainer, 2026-11-05): the wire shape stays a string, so the fix commit carries the trailer "Protocol-bump: none (stdin size cap; wire shape unchanged)" for protocol-bump-check.mjs. The gateway's and the worker's runDispatch then refuse an oversized stdin before forwarding or spawning. Large file transfer (stream stdin, or device.upload from ADR 0005 §19b′) is a feature: it needs a spec session.
Alternatives rejected
New PAYLOAD_TOO_LARGE/413 code: BAD_REQUEST already refuses bounds, like requesterId's 256.
Limit execs in flight per worker: more state, and not needed once each request is bounded.
Risk
Breaking for anyone uploading more than 8 MiB today, including the tester-army and budgie suites. Release notes needed.
The HTTP route still reads and parses the whole body before the refusal (src/http/lease-declarations.ts:138). A body limit on that route would avoid it.
DaemonServer#read still has no line cap for local socket clients.
Activity
V3RON commentedon Nov 5, 2026
Another suite hitting the same limits: budgie's e2e port (budgie-at/budgie#1867) sends fixtures as base64 raw-deflate on exec
stdin(a tar of the app'sDocuments/, via a helper simulator app), and limits app uploads to 3 at a time because 10 parallel uploads through the Cloudflare tunnel ended in 524 errors.Written by an agent.
V3RON commentedon Nov 5, 2026
Written by an agent.
V3RON commentedon Nov 5, 2026
Reproduction
Gap: nothing bounds
device.exec'sstdin. The 8 MiB limit andBAD_REQUESTin the test are a proposal.src/gateway/dispatcher.test.ts, "refuses a device.exec whose stdin is longer than 8,388,608 characters with BAD_REQUEST and forwards nothing to the worker, and forwards one at 8,388,608" (branchbug/1242-repro).Root cause
src/contract/operations.ts:471declaresstdin: z.string().optional()with no bound, which breaks safety rule 10 ("never store one unbounded"). The gateway forwards any size (src/gateway/fleet-coordinator.ts:602) as a single uplink text message. The worker's socket client takes up to 100 MiB per message (thewsdefault,src/ports/uplink-websocket.ts:295).DaemonServerthen buffers the line with no cap (src/daemon/server.ts:778) andJSON.parses it (:816), the frame in the crash stack. The string lives until the command exits; ten ~100 MB uploads fill the ~4 GB heap. The reporter's point 3 needs a correction: leases are rows instate.dband survive a restart. In the gateway log, the404 UNKNOWN_LEASEcomes after the client's own release.Simplest fix
stdin: z.string().max(8_388_608).optional()in the contract. No protocol bump (maintainer, 2026-11-05): the wire shape stays a string, so the fix commit carries the trailer "Protocol-bump: none (stdin size cap; wire shape unchanged)" for protocol-bump-check.mjs. The gateway's and the worker'srunDispatchthen refuse an oversized stdin before forwarding or spawning. Large file transfer (streamstdin, ordevice.uploadfrom ADR 0005 §19b′) is a feature: it needs a spec session.Alternatives rejected
PAYLOAD_TOO_LARGE/413 code:BAD_REQUESTalready refuses bounds, likerequesterId's 256.Risk
src/http/lease-declarations.ts:138). A body limit on that route would avoid it.DaemonServer#readstill has no line cap for local socket clients.Written by an agent.
fix(http): the exec route body and the docs state the 8 MiB stdin cap (…
docs(website): an oversize run_on_device stdin fails the tool's input…
test: raise two shrink-only line limits for the stdin cap tests (#1242)
V3RON commentedon Nov 5, 2026
Delivery run
Merged: #1318 (#1242)
Parked: none
Waiting: none
Decided: none
Written by an agent.
fix(contract): device.exec refuses a stdin over 8 MiB with BAD_REQUEST (