Repository navigation
Description
Summary
The worker daemon (dist/daemon/main.js, supervised by com.callstack.simlock.worker) aborted twice on a V8 out-of-memory error, even with NODE_OPTIONS=--max-old-space-size=12288. Each restart ended every lease on the worker at once (#1103), so every e2e test running through the gateway failed together. The callers saw the worker holding this device is not connected to the gateway, followed by Daemon RPC request failed and HTTP 500s while the worker was coming back.
Environment
- Worker: Mac Studio, Apple silicon, 14 cores, 36 GiB RAM, macOS 15.7.4, Xcode 26.3 (17C519), Node 22.23.4 (Homebrew
node@22). - simlock: upstream
mainat0aa6a58plus fix(agent-device): an allocate's device mode reaches the lease request (#1223) #1225 cherry-picked (package version 0.5.0). One gateway on the same host, reached through a Cloudflare tunnel. - agent-device 0.21.36 with the
agent-devicecapability enabled. Most leases came through/v1/agent-device/rpc: tester-army e2e suites that take screenshots and record video on every test. - Capacity at the time:
fixed, iOS 11 running / 11 devices, Android 2 / 2, warm pool 8 slim iPhone 17 Pro.
The two crashes
| Process launched | Crashed | Uptime |
|---|---|---|
| 2026-11-03 07:03:25 +01:00 | 2026-11-03 14:42:55 +01:00 | 7.6 h |
| 2026-11-04 15:38:52 +01:00 | 2026-11-05 22:11:47 +01:00 | 30.5 h |
Both are EXC_CRASH (SIGABRT), abort() called from node::OOMErrorHandler, in the launchd worker process (parent pid 1).
Crash on Nov 3, while JSON.parse allocated a string:
node::OOMErrorHandler
v8::internal::V8::FatalProcessOutOfMemory
v8::internal::Heap::FatalProcessOutOfMemory
v8::internal::Heap::CollectGarbage
v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath
v8::internal::FactoryBase<Factory>::NewRawStringWithMap<SeqOneByteString>
v8::internal::JsonParser<unsigned char>::MakeString
v8::internal::JsonParser<unsigned char>::Parse
v8::internal::Builtin_JsonParse
Crash on Nov 5, under external memory pressure while a typed array's buffer was being set up:
node::OOMErrorHandler
v8::internal::V8::FatalProcessOutOfMemory
v8::internal::Heap::FatalProcessOutOfMemory
v8::internal::Heap::CollectGarbage
v8::internal::Heap::ReportExternalMemoryPressure
v8::Isolate::AdjustAmountOfExternalAllocatedMemory
v8::internal::JSArrayBuffer::Setup
v8::internal::JSTypedArray::GetBuffer
v8::internal::Builtin_TypedArrayPrototypeBuffer
The JavaScript frames are not symbolicated in the .ips files. The worker log had rotated by the time we looked, so there is no log context from the minutes before either crash.
What we saw on the host
At 31 h after the second restart, with the farm at full load:
- The worker's RSS was 1.75 GiB, and the agent-device simulator daemon it spawns was at 1.9 GiB. RSS swung by about 1 GiB between samples 20 s apart, so the host was swapping them.
- Swap was 9.4 GiB, more than its 8 GiB starting size, macOS pressure was
warn, andvm_statcounted 35 M pageouts. The booted simulators took far more RAM than the host has. simlock status --jsonlisted 351 devices in statedeleted(247 iOS, 104 Android), next to 13 live ones. The worker keeps every deleted device in memory and in the status reply.~/.simlock/history.dbwas 480 MB, and~/.simlock/agent-device/sessionsheld 12,556 session folders (4.9 GiB). They are never pruned.
The memory starvation clearly made things worse. Still, an Apple-silicon worker should not run out of a 12 GiB V8 heap: its live state is about 13 devices and a few leases. Something keeps growing over the daemon's lifetime, or one reply is buffered whole. Both stacks fit the second case: a large JSON body parsed into one string, and a large ArrayBuffer, such as a relayed screenshot, recording or exec output.
Questions / suggestions
- Does the worker or the relay buffer a whole response body (agent-device RPC replies, screenshots, recordings,
device.execoutput, lease files) before forwarding it? If so, could it stream instead and cap the size? - Does anything keep growing for the life of the process: per-lease or per-request maps, device rows in state
deleted, the event buffer, history writes or relay connections? - A
--heapsnapshot-near-heap-limit(ornode --heap-prof) recipe in the worker docs would let operators capture the next one. We have added nothing like that yet. - Together with agent-device: a worker restart ends every lease whose device is still running #1103, a worker restart is a farm-wide outage for the agent-device front. Re-attaching running devices to their leases after a restart would turn an OOM into a blip.
Mitigation on our side
We now run upstream main 0ebd818 with the memory-pressure admission work (#1398–#1403), and we cut capacity to iOS 7 / Android 2 (9 total) with iosSlimBytesPerDevice at 3 GiB. Swap dropped to 1.1 GiB and pressure is normal. We will add RSS samples here if the worker keeps growing on this build.
Activity
V3RON commentedon Nov 7, 2026
Not reproduced on
main. Both crashes ran a build without the fix for #1242, and nothing else found on the worker matches the stacks.What the crashes match
node-2026-11-03-144256.ips, 13:42:56Z): execstdinof tens of MB parsed as one JSON string. fix(contract): device.exec refuses a stdin over 8 MiB with BAD_REQUEST #1318 fixed it with an 8 MiB cap (EXEC_STDIN_MAX_LENGTH,src/contract/operations.ts:479).0aa6a58+ fix(agent-device): an allocate's device mode reaches the lease request (#1223) #1225. fix(contract): device.exec refuses a stdin over 8 MiB with BAD_REQUEST #1318 is not in it, but it is in0ebd818:Paths checked on the worker (question 1)
src/agent-device/shared/rpc.ts:3) and a download at 2 GB without buffering it (src/agent-device/host/host.ts:52).@agent-device/proxy0.21.35 passesupstreamResponse.bodythrough.src/daemon/relay.ts:413).src/agent-device/host/lease-end.ts:32,:59). Both are small.Things that keep growing (question 2)
Neither explains a 12 GiB heap. Each is filed on its own:
deleteddevice rows, kept in memory and instatus.get.history.dbis capped ateventLog.maxBytes(256 MiB of events by default,src/core/config.ts:1021), plus metrics.What would let me reproduce it on
0ebd818stdin, and whether any exec now fails withBAD_REQUEST.NODE_OPTIONS="--max-old-space-size=12288 --heapsnapshot-near-heap-limit=1 --diagnostic-dir=<dir>"set in the service, and the.heapsnapshotit writes.simlock status --json | wc -cat the start and the end.Written by an agent.
vitalyiegorov commentedon Nov 9, 2026
Data point (no OOM this time), simlock 0.6.0 worker on macOS 15.7.4, 36 GiB, capacity iOS 10 / Android 3:
node-*.ipssince 2026-11-05. Pressure normal, no daemon.log errors.status --jsonkeeps hundreds ofstate: deleteddevice records (about 830 at the last count). They are our main suspect for the retained memory.vitalyiegorov commentedon Nov 11, 2026
Another data point for the slow worker RSS growth (no OOM this time). Host: macstudio (macOS 15.7.4 arm64, simlock 0.6.0, Node 22.23.4), a 10 iOS / 3 Android worker.
After each restart RSS goes back to about 0.15 GiB. The normal working range is 0.3–2.1 GiB, so the growth looks like a leak and not load. This time there were 0 leases, no new
node-*.ips(the last one is from 2026-11-05), memory pressure was normal and swap was 1.1 GiB. I drained the worker, restarted it withlaunchctl kickstart -k, then undrained it.V3RON commentedon Nov 11, 2026
Reproduction
Reproduced on
main84c85b11, which corrects the earlier note. The worker keeps about 17 KiB of heap for every call the gateway relays to it, so the growth follows agent-device traffic, not leases. Test onbug/1409-repro:src/daemon/relay.test.ts, "lets every Request it handed a target be collected once the relay has answered, a GET with no body and a PUT with one".A scratch probe (gateway and worker in one process, fake agent-device, heap after a full GC):
Root cause
Defect.
src/daemon/relay.ts:297stores the target's Request inactive.request, and thefinallyat:157never clears it. The Request carriessignal: active.controller.signal(:336), so Node's fetch registers the Request's own AbortController in itsrequestFinalizerwith that signal as the held value. The abort listener at:153closes overactive, so the held value reaches the registry's own target, which is therefore never collected. Every relay keeps its Request,LinkChannel, headers and streams for the life of the process.Simplest fix
Add
active.request = undefined;to#admitted'sfinallyinsrc/daemon/relay.ts:157, afterthis.#active.delete(input.relayId);.Alternatives rejected
:153listener at the end: any other closure overactiveon that signal rebuilds the cycle.:56needs it alive while a target holds only its signal.Risk
active.requestafter#admittedreturns; a two-way relay's pipe ends before it does.setFlagsFromString("--expose-gc"), new in this repo.AbortSignalandTimeoutpairs. They look like pending timeouts that free themselves when they fire; not proven.Fast track
Written by an agent.
V3RON commentedon Nov 11, 2026
Handoff
Done: PR #1533 clears
active.requestin the relay'sfinally(src/daemon/relay.ts), with the triage test. Audit probed 1/1. Review round 1 passed (0 blocking, 1 note), the ledger is posted, the PR is ready, and the fast-track exit check passes.Not done: merge.
Findings: CI failed twice, on runs 43053157583 (Console, Console 1/2 and 2/2) and 43053158033 (Real proxy), both in Playwright's browser install step:
Temporary failure resolving 'azure.archive.ubuntu.com', apt exit 100. That is the runner's network, before any test runs. No test failed.Blocked on: GitHub runner DNS. Once the Ubuntu mirror resolves, rerun with
gh run rerun <id> --failedand run.agents/scripts/merge-pr.sh 1533, or re-rundeliver 1409.Written by an agent.
V3RON commentedon Nov 11, 2026
Delivery run
Merged: none
Parked: #1409 — CI red twice in Playwright's browser install (runner DNS could not resolve the Ubuntu mirror); PR #1533 passed review and is ready
Waiting: none
Decided: none
Asleep: 20 min
Written by an agent.
fix(daemon): a relay lets go of its target Request once it answers (c…