Repository navigation
Description
Found by the daily slow-request review (#108). The 38 slow requests on 2026-10-26 at 18:05–18:06 local were all clients reconnecting right after the desktop's backend crashed and restarted at 18:04.
Evidence
The desktop journal reports backend exited unexpectedly … reason: killed by SIGILL four times since 2026-10-23. In ~/.t3/userdata/logs/server-child.log, each crash comes 80–90 s after ForkHeapSnapshot logs Heap near limit; writing heap snapshot.:
| Snapshot started (UTC) | Heap used | Crash (UTC) | Snapshot file |
|---|---|---|---|
| 2026-10-23 18:30:34 | 2.80 GB | 18:31:35 | 0 bytes |
| 2026-10-24 06:57:54 | 2.67 GB | 06:59:36 | 0 bytes |
| 2026-10-27 00:02:42 | 2.81 GB | 00:04:07 | 0 bytes |
| 2026-10-27 09:21:47 | 2.69 GB | 09:23:01 | 0 bytes |
The heap limit is 4.40 GB, and the snapshot runs at 60% of it. Uptime before the snapshot was about 9.3 h (10-27 00:04 → 09:21) and 12.4 h (10-23 18:31 → 10-24 06:57).
Two problems:
- The diagnostic causes the crash and captures nothing.
NodeV8.writeHeapSnapshot(apps/server/src/observability/ForkHeapSnapshot.ts:53, called fromEventLoopMonitor.ts:174) runs synchronously. It freezes the event loop for the 80–90 s it runs, and Node's docs say a snapshot needs about twice the heap's size in memory. At 2.7 GB used it crosses V8's limit, and Electron's Node aborts with SIGILL before the file gets any data. The system-memory guard (MemAvailable ≥ 1.5 × heap) doesn't help: the limit hit is V8's heap limit, not system memory. Unverified: inferred from the timing and the empty files; the V8 fatal message isn't in the log. - The heap leak from Server crashes when its JavaScript heap reaches 4 GB after hours of uptime #120 is still there. Server crashes when its JavaScript heap reaches 4 GB after hours of uptime #120 was closed on 2026-10-22, but the heap still reaches 2.7 GB within 9–12 h.
Each crash drops every client connection and the agents' T3 tool sessions. During the restart, readers waited on the writer for about 10 s (IssueInbox.list ×26, getThreadProcesses ×4, IssueLinks.enrich ×4). dispatchCommand waited up to 32 s in serverRuntimeStartup.enqueueCommand for command readiness.
Suggested direction (unverified)
- Replace the in-process
writeHeapSnapshotwith V8's sampling heap profiler. Usenode:inspectorHeapProfiler.startSamplingearly, then writestopSampling's profile at the 60% threshold. It costs little, the file is small, and it gives allocation stacks for the retained memory. That's enough to find what grows. - Then fix the growing structure that profile names, as Server crashes when its JavaScript heap reaches 4 GB after hours of uptime #120 asked.
Sample records (slow-requests.ndjson)
2026-10-27T00:05:17Z ws.rpc.issues.inbox.list 10.2 s — IssueInbox.list → sql.transaction lockWait 10.1 s2026-10-27T00:05:13Z ws.rpc.server.getThreadProcesses 11.8 s — orchestration.readRunningThreadWork → sql.transaction lockWait 8.2 s2026-10-27T00:06:25Z ws.rpc.orchestration.dispatchCommand 32.1 s — serverRuntimeStartup.enqueueCommand
Activity
tannerpolley commentedon Oct 27, 2026
T3 Code status: Unavailable
Issue: #186 2026-10-27 Server crashes every 9–12 h: the near-limit heap snapshot kills it, and the heap still grows to 2.7 GB
Thread: thread:delegated-task:command%3Amcp%3Aa45c4156-6756-45dc-bd27-1ea406cde16f%3Adelegate-task%3Aissue-186-part3-20261029
Model: gpt-6.1-sol
Branch: issue-186-2026-10-27-server-crashes-every-9-12-h
Updated: 2026-11-13T05:11:10.365Z
tannerpolley commentedon Oct 27, 2026
T3 Code closeout: done
Issue: #186 2026-10-27 Server crashes every 9–12 h: the near-limit heap snapshot kills it, and the heap still grows to 2.7 GB
Thread: thread:delegated-task:command%3Amcp%3Aaa92b214-6639-4e71-b9ca-340b044b2103%3Adelegate-task%3A0fc992a5-4944-4184-8f78-ccf622964f7f
Model: gpt-6.1-terra
Branch: issue-186-2026-10-27-server-crashes-every-9-12-h
Completed: 2026-10-27T17:48:53.446Z
Implemented part 1 of issue #186 and committed it locally as
176ab20c57. Sampling starts with the event-loop monitor, and the first reading at or above 60% of the heap limit writes a Chrome DevTools.heapprofilewhen sufficient disk space is available.Changed files:
ForkHeapSnapshot.ts.Verification from
apps/server:PATH=$HOME/.local/share/vite-plus/fallback-bin:$PATH nice -n 10 vp test run src/observability/HeapSamplingProfile.test.ts— 2 tests passed.PATH=$HOME/.local/share/vite-plus/fallback-bin:$PATH nice -n 10 vp run typecheck— passed, with unrelated existing suggestions.profiles=1 extension=.heapprofile head=object samples=true.The issue did not specify a sampling interval or disk reserve. I chose 512 KiB between samples to limit continuous profiling overhead and retained a 1 GiB disk reserve for the profile and ordinary logs.
The leak investigation remains part 2; this change does not establish what is growing. No push, PR, or merge was made.
tannerpolley commentedon Oct 28, 2026
Daily slow-request review (#108), 2026-10-28.
Before the fix: v2.12.66 crashed three more times the same way, at 2026-10-27 17:42Z, 22:47Z and 02:08Z. Each crash came 80–90 s after
Heap near limit; writing heap snapshotat about 2.7 GB used, and each snapshot file is 0 bytes.Since v2.12.72 was installed (2026-10-28 02:40Z, with fix(server): stop the near-limit heap snapshot from crashing the server #188's sampling profiler): no crash after 14 h 20 min, and the server's RSS is 0.90 GB. The old version had passed 2.7 GB of heap within 8–12 h. No
.heapprofilehas been written yet, because heap use hasn't reached 60% of the limit, and the log shows no profiler start failure.Slow requests in the last 24 h: 59 of 61 records came in the two bursts after the 17:42Z and 02:08Z restarts:
issues.inbox.list×31, waiting on the writer, median 10.5 s;issues.list→IssueLinks.enrich×7, up to 28.8 s;dispatchCommandwaiting for startup ×9, up to 33.2 s;getThreadProcesses×6,pullRequests.*×4 andvcs.refreshStatus×2, up to 33.0 s.There have been no slow records since v2.12.72 started.
Still open: whether the heap still grows on v2.12.72. The upstream sync in v2.12.72 may have changed the growth. If a profile appears, it names the growing allocations; if none appears after a few days of uptime, part 2 may be moot.
tannerpolley commentedon Oct 29, 2026
Daily slow-request review (#108), 2026-10-29.
backend exitedorSIGILL.~/.t3/userdata/logs/heap-2026-10-29T07-32-24.885Z.heapprofile(508 KB). Heap use reached 60 % of the limit about 14 h after v2.12.76 started at 2026-10-28 23:20Z, so the heap still grows. That profile is the input for part 2; it hasn't been analysed yet.tannerpolley commentedon Oct 29, 2026
T3 Code closeout: done
Issue: #186 2026-10-27 Server crashes every 9–12 h: the near-limit heap snapshot kills it, and the heap still grows to 2.7 GB
Thread: thread:delegated-task:command%3Amcp%3Aa45c4156-6756-45dc-bd27-1ea406cde16f%3Adelegate-task%3Aissue-186-part2-2026-10-29
Model: gpt-6.1-sol
Branch: issue-186-2026-10-27-server-crashes-every-9-12-h
Completed: 2026-10-29T17:58:37.787Z
The profile does not establish a single cause of the growing heap. I stopped without code changes, as requested. It identifies large allocations, but it contains no retaining-object graph or comparison over time that would prove which structure keeps growing.
I read #186 and its comments, copied the profile to
/tmp/t3-186-heap/input.heapprofile, and analyzed only that copy. The script aggregated 1,585,339,800 bytes (1.48 GiB) of sampled self size across 1,976 allocation-tree nodes. Source mappings came from the exact matching production bundle,binCli-Cb7S2lMm.mjs.HttpApiBuilder.js:629,JSON.stringify(e)compactEventStoreSchemaGetter.js:938,JSON.parsedecodeRecordsThe largest individual stacks, with Effect scheduler frames abbreviated, were:
processImmediate → Effect evaluation → HTTP JSON encoder: 695.24 MiB.worker message → Effect evaluation → compactEventStore: 253.56 MiB. Including descendant allocations, this compaction subtree totals 310.12 MiB, including 54.01 MiB inMap.get/Map.setframes.processImmediate → Effect evaluation → JSON.parse: 155.40 MiB.worker message → Effect evaluation → JSON.parse: 73.14 MiB.The HTTP encoder is upstream Effect code, but its stack does not identify the response route or retaining owner. Compaction is the strongest application-specific candidate: its map tracks distinct event entities during a scan, but that map belongs to one invocation. This capture cannot distinguish a large active scan from memory retained after completion. I also verified that the matching production bundle already contains the prior tracing fix that removes successful result payloads from span status.
Evidence is preserved in:
The checkout is clean. No commit, push, or PR was created. Tests and
check:changedwere not run because no code changed; the production heap-growth cause remains unresolved.tannerpolley commentedon Oct 29, 2026
Part 2 analysis of
heap-2026-10-29T07-32-24.885Z.heapprofile(GPT-6.1 Sol worker, 2026-10-29). No code changed.The sampled live allocations total 1.48 GiB, mapped to source through the matching production bundle:
HttpApiBuilder.js:629,JSON.stringify)compactEventStore(apps/server/src/orchestration-v2/ProjectionMaintenance.ts:235), 310 MiB with its childrenSchemaGetter.js:938,JSON.parse)decodeRecords(apps/server/src/usage/usageScanCache.ts:142,:193)Lead: about 714 MiB of serialized HTTP response strings were still alive at capture. Either something keeps HTTP API responses after they are sent, or very large responses are being built. The stack doesn't name the route. Likely suspects are the bounded thread-history and snapshot HTTP endpoints, which came in with upstream pingdotgg#26240 on 2026-10-28.
Why no fix: a sampling profile has no retainer graph, and one capture can't tell a large in-flight response or compaction scan from memory kept after it finishes.
Next step: find the route. For example, log the HTTP route and response size for responses over a few MB, or capture a second profile later in the same uptime and compare. The worker's scripts and full results are in
/tmp/t3-186-heap/; they're temporary and will be lost on reboot.tannerpolley commentedon Oct 29, 2026
Status and part 3 scope (root orchestrator, 2026-10-29).
HttpApiBuilder.js:629, used by every HttpApi route). The profile names neither the route nor what retains them. Next largest:compactEventStoreat 254 MiB (ProjectionMaintenance.ts:235), which Database grows ~1 GB/day and never shrinks: trim old tool output and turn on automatic shrinking #238 may also touch.Part 3 done means:
Out of scope: #238's database trimming, and attaching to or copying the live server's database.
tannerpolley commentedon Oct 29, 2026
T3 Code closeout: done
Issue: #186 2026-10-27 Server crashes every 9–12 h: the near-limit heap snapshot kills it, and the heap still grows to 2.7 GB
Thread: thread:delegated-task:command%3Amcp%3Aa45c4156-6756-45dc-bd27-1ea406cde16f%3Adelegate-task%3Aissue-186-part3-20261029
Model: gpt-6.1-sol
Branch: issue-186-2026-10-27-server-crashes-every-9-12-h
Completed: 2026-10-29T22:34:38.088Z
Committed a reproducible HTTP-response retention fix locally as
6c2f15957f2f8d986063ae94dabd6d160cd467f7. The working tree is clean. No push, PR, or merge.Route and retainer: In an isolated test,
GET /api/orchestration/shellreturned three completed HTTP 200 responses of 2,098,720 characters each. The heap snapshot showed a response retained through:prepared-statement cache → lookup fiber → lazy caller stack → HTTP request → Node response close listener → completed request fiber → encoded response bodyThe reproduction used synthetic data, in-memory stores, the Node HTTP adapter, local tracing, and compression. After the fix, the same probe returned identical responses and its heap snapshot contained no serialized shell response strings. The evidence transcript records the setup, paths, and limits.
Fix: The SQLite statement cache now materializes caller stack text before caching a lookup fiber, releasing the closure that retained the request. Cache hits skip this work. I moved the existing
detachStackFramehelper into the shared package and updated its two existing callers.Failing test:
cached statements keep stack text without retaining the caller framefailed before the fix because the cached stack still read from the caller’s mutable closure. It passes afterward and also checks that a cache hit neither prepares the statement again nor rematerializes the stack.Verification:
vp run typecheckinpackages/sharedandapps/server: passed; server emitted existing suggestions only.vp linton changed files andgit diff --check: passed.Production attribution remains incomplete. This proves retention on the shell route when the main SQLite connection fills its statement cache. Production normally uses a reader worker for reads; the supplied sampling profile cannot establish which production routes filled that cache or whether this explains all 714 MiB. I did not access the live database, attach to the live server, or change compaction.