Skip to content

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 #186

Closed

Description

@tannerpolley

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:

  1. The diagnostic causes the crash and captures nothing. NodeV8.writeHeapSnapshot (apps/server/src/observability/ForkHeapSnapshot.ts:53, called from EventLoopMonitor.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.
  2. 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 writeHeapSnapshot with V8's sampling heap profiler. Use node:inspector HeapProfiler.startSampling early, then write stopSampling'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 s
  • 2026-10-27T00:05:13Z ws.rpc.server.getThreadProcesses 11.8 s — orchestration.readRunningThreadWork → sql.transaction lockWait 8.2 s
  • 2026-10-27T00:06:25Z ws.rpc.orchestration.dispatchCommand 32.1 s — serverRuntimeStartup.enqueueCommand

Activity

  1. tannerpolley commented on Oct 27, 2026

    @tannerpolley
    OwnerAuthor

    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

  2. tannerpolley commented on Oct 27, 2026

    @tannerpolley
    OwnerAuthor

    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 .heapprofile when sufficient disk space is available.

    Changed files:

    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.
    • An isolated Node process captured and parsed a real profile: 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.

  3. tannerpolley commented on Oct 28, 2026

    @tannerpolley
    OwnerAuthor

    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 snapshot at 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 .heapprofile has 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;
      • dispatchCommand waiting for startup ×9, up to 33.2 s;
      • getThreadProcesses ×6, pullRequests.* ×4 and vcs.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.

  4. tannerpolley commented on Oct 29, 2026

    @tannerpolley
    OwnerAuthor

    Daily slow-request review (#108), 2026-10-29.

  5. tannerpolley commented on Oct 29, 2026

    @tannerpolley
    OwnerAuthor

    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.

    Allocation function Sampled self size Share Source
    HTTP API JSON response encoder 713.76 MiB 47.2% Effect 4.0.5 HttpApiBuilder.js:629, JSON.stringify(e)
    compactEventStore 253.56 MiB 16.8% ProjectionMaintenance.ts:235
    JSON parser 251.05 MiB 16.6% Effect SchemaGetter.js:938, JSON.parse
    Usage-cache writer 29.18 MiB 1.9% usageScanCache.ts:142
    Usage-cache decodeRecords 26.00 MiB 1.7% usageScanCache.ts:193

    The 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 in Map.get/Map.set frames.
    • 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:changed were not run because no code changed; the production heap-growth cause remains unresolved.

  6. tannerpolley commented on Oct 29, 2026

    @tannerpolley
    OwnerAuthor

    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:

    Allocation site Live size Share
    HTTP API JSON response encoder (Effect HttpApiBuilder.js:629, JSON.stringify) 713.8 MiB 47 %
    compactEventStore (apps/server/src/orchestration-v2/ProjectionMaintenance.ts:235), 310 MiB with its children 253.6 MiB 17 %
    JSON parser (Effect SchemaGetter.js:938, JSON.parse) 251.1 MiB 17 %
    Usage scan cache writer and decodeRecords (apps/server/src/usage/usageScanCache.ts:142, :193) 55.2 MiB 4 %

    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.

  7. tannerpolley commented on Oct 29, 2026

    @tannerpolley
    OwnerAuthor

    Status and part 3 scope (root orchestrator, 2026-10-29).

    • Part 1 (crash) is done. The sampling profiler replaced the in-process heap snapshot, and there has been no backend crash since v2.12.72. The systemd-oomd kills at 2026-10-29 12:31 local hit agent job scopes, not T3.
    • Still growing: the installed backend was at 1.29 GB RSS after 5 h 33 min.
    • Part 2 lead: 714 MiB of live strings from Effect's generic JSON response encoder (HttpApiBuilder.js:629, used by every HttpApi route). The profile names neither the route nor what retains them. Next largest: compactEventStore at 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:

    1. Name the route or routes whose responses stay alive, and what keeps them alive after they are sent: a tracer or span attribute, a recorder, a cache, a client loop, or a single huge response. Back it with reproducible evidence, not inference.
    2. Fix the retention at its source. If the problem is response size rather than retention, bound or page that response.
    3. Add a focused test that fails before the fix.

    Out of scope: #238's database trimming, and attaching to or copying the live server's database.

  8. tannerpolley commented on Oct 29, 2026

    @tannerpolley
    OwnerAuthor

    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/shell returned 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 body

    The 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 detachStackFrame helper into the shared package and updated its two existing callers.

    Failing test: cached statements keep stack text without retaining the caller frame failed 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:

    • SQLite-client tests: 18 passed, including the final cache-hit optimization.
    • Combined SQLite, orchestration HTTP, and PR-cache tests: 28 passed before that optimization.
    • vp run typecheck in packages/shared and apps/server: passed; server emitted existing suggestions only.
    • vp lint on changed files and git 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions