Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Summary / Root Cause
Introduced in #44774 (3f63afc1f80f, first shipped in v0.1.14-nightly.20261130.5479 and still present in v0.1.14-nightly.20261130.5492 / 801da69aafe4):
-
ThreadHandoff.start_()replays the entire event log from sequence0on every startup while buffering all live events in an unbounded PubSub:apps/server/src/peer/handoff/ThreadHandoff.ts:947-962subscribes tothreads.streamStoredEvents(already after lines 936–946 handled pending/departing shells fromgetShellSnapshot()).apps/server/src/orchestration-v2/Orchestrator.ts:18262definesstreamStoredEventsaseventSink.stream()— with noafterSequence, noeventType, and nobounded: true(comparestreamDomainEventsright below it, which starts atafterSequence: latest).apps/server/src/orchestration-v2/EventSink.ts:1034-1078defaultsafterSequenceto0, subscribes to the unboundedliveEventsPubSub (line 1069), and returnsStream.concat(replay(highWater), live)(line 1075).- While
replay(highWater)scans every historical event inorchestration_eventsfrom sequence1tohighWater,liveis never pulled, so all live events from active sessions accumulate in the unbounded PubSub subscription.
-
ThreadHandoff.settle()loads full threadrunsandusermessagesbefore checking whether the thread has ahandoff:apps/server/src/peer/handoff/ThreadHandoff.ts:880-886:const records = yield* threads.getThreadRecords(threadId, ["runs", "messages"], { messageRoles: ["user"], }); const handoff = records.thread.handoff; if (handoff === undefined) return;
- For every historical terminal
run.updatedevent replayed since sequence0,settle()runsProjectionStore.readCanonicalProjectionforruns+usermessages even when0threads in the database have ahandofffield.
-
Result: infinite ~19–20 minute
SIGABRTcrash loop in Electron's shared 4 GiB V8 pointer-compression cage.- On a mature
statev2.sqlite(15.7Mrows inorchestration_events, including long-running threads with thousands of runs/messages), the replay cannot finish before the main thread + SQLite readerworker_threadsexhaust Electron's process-wide 4 GiB V8 pointer-compression cage. - Once the shared 4 GiB cage fills, even a freshly spawned worker thread with only
2–3 MBof live heap hitsFATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory→node::OOMErrorHandler→abort()(SIGABRT). - The desktop process automatically restarts the backend 500 ms later (
desktop.backendInstance.scheduleRestartFiber), which starts replaying from sequence0all over again, killing all active agent sessions every ~19–20 minutes.
- On a mature
Steps to reproduce
- Run T3 Code desktop
v0.1.14-nightly.20261130.5479orv0.1.14-nightly.20261130.5492against an existingstatev2.sqlitewith a largeorchestration_eventshistory (millions of events) and long-running threads (thousands of runs/messages), with active provider sessions running. - Observe
server.trace.ndjsonimmediately after startup:OrchestrationEventStore.readAgentEventsandThreadHandoff.settle→ProjectionStore.readCanonicalProjectionrun continuously (~8.5 calls/s) even though zero threads havehandoffset. - Watch backend child RSS /
/proc/<pid>/smaps: the 4 GiB V8 pointer-compression cage climbs steadily to4096 MiBand aborts withSIGABRT(~19 minutes in my environment), then restarts and loops indefinitely.
Expected behavior
ThreadHandoff.start_()should only watch newrun.updatedevents after startup (e.g. starting fromlatestSequence()/ usingstreamDomainEventsorstreamStoredEventsFrom({ afterSequence: latest, eventType: "run.updated" })), since lines 936–946 already reconcile anypending/departingshells on startup.ThreadHandoff.settle()should checkthread.handoffvia a lightweight lookup (e.g.getThreadShellorgetThreadRecords(threadId, [])) before loadingrunsandmessages.
Actual behavior
Backend child process (apps/server/dist/bin.mjs) enters an infinite ~19–20 minute SIGABRT OOM crash loop (4 crashes in 60 minutes, tearing down active agent sessions each time).
Impact
Blocks work completely
Version or commit
0.1.14-nightly.20261130.5492 (801da69aafe4); regression introduced in 0.1.14-nightly.20261130.5479 via #44774 (3f63afc1f80f).
Environment
- Arch Linux (x86_64, 93 GiB RAM with ~39 GiB available, no kernel OOM kills)
- T3 Code Desktop (
t3code-nightly-binAUR) statev2.sqlite: 46.2 GiB,orchestration_eventssequence1..15,724,989, 19,892 threads (0 threads withhandoff); largest thread has 4,686 runs / 12,166 messages / 46,822 turn items
Logs or stack traces
# 4 consecutive identical SIGABRT crashes every ~19-20 min after upgrading to 5492:
Mon 2026-11-30 19:16:40 CET 3081909 1000 1000 SIGABRT present /opt/t3code-nightly-bin/t3code 841.7M
Mon 2026-11-30 19:36:58 CET 3641391 1000 1000 SIGABRT present /opt/t3code-nightly-bin/t3code 843.3M
Mon 2026-11-30 19:56:28 CET 3873332 1000 1000 SIGABRT present /opt/t3code-nightly-bin/t3code 839.3M
Mon 2026-11-30 20:15:13 CET 4180684 1000 1000 SIGABRT present /opt/t3code-nightly-bin/t3code 822.7M
# /proc/4180684/smaps aggregated by 4 GiB address bucket, 42 seconds before crash:
0x1eeb_00000000: RSS=3942.9 MiB, VSZ=4096.0 MiB, regions=1276 <-- shared 4 GiB V8 pointer cage 96.3% full
# Top heap-growth spans in a single ~2-minute server.trace.ndjson rotation:
sql.transaction: count=648, sum=24837.9 MiB, max=225.7 MiB
ProjectionStore.readCanonicalProjection: count=472, sum=22972.2 MiB, max=223.0 MiB
OrchestratorV2.getThreadRecords: count=462, sum=22042.6 MiB, max=165.9 MiB
ThreadManagementService.getThreadRecords: count=456, sum=21727.2 MiB, max=165.9 MiB
ThreadHandoff.settle: count=455, sum=21704.2 MiB, max=165.9 MiB
OrchestrationEventStore.readAgentEvents: count=662 (in fresh post-restart trace)
# server-child.log immediately before SIGABRT (PID 3873332):
OrchestratorProjectionError: Failed to load orchestration projection for thread <redacted>.
at ProjectionStore.readCanonicalProjection (...)
at OrchestratorV2.getThreadRecords (...)
at ThreadManagementService.getThreadRecords (...)
at ThreadHandoff.settle (...) {
[cause]: ProjectionStoreReadError: ... {
[cause]: effect/sql/SqlError: Failed to execute statement {
[cause]: Error: Database reader failed: Worker terminated due to reaching memory limit: JS heap out of memory
}
}
}
<--- Last few GCs --->
[3873332:0x127007634000] 503 ms: Mark-Compact (reduce) 3.7 (37.2) -> 2.3 (5.2) MB, pooled: 0.0 MB, 4.06 / 0.00 ms last resort; GC in old space requested
[3873332:0x127007634000] 505 ms: Mark-Compact (reduce) 2.3 (5.2) -> 2.2 (3.5) MB, pooled: 0.0 MB, 1.55 / 0.00 ms last resort; GC in old space requested
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
# systemd-coredump stack trace of crashing worker thread (PID 3873332, TID 4178898):
#0 abort (libc.so.6)
#2 node::OOMErrorHandler(char const*, v8::OOMDetails const&) (t3code)
#15 v8::ValueDeserializer::ReadValue(v8::Local<v8::Context>) (t3code)
#16 node::worker::Message::Deserialize(...) (t3code)
#17 node::worker::MessagePort::ReceiveMessage(...) (t3code)
#18 node::worker::MessagePort::OnMessage(...) (t3code)
#23 node::worker::Worker::Run() (t3code)
# Crash 4 (PID 4180684, TID 4181535) hit the same OOM handler inside sqlite row extraction:
#0 abort (libc.so.6)
#2 node::OOMErrorHandler(char const*, v8::OOMDetails const&) (t3code)
#20 v8::String::NewFromUtf8(...) (t3code)
#21 node::sqlite::ExtractRowValues(...) (t3code)
#22 node::sqlite::StatementSyncIterator::Next(...) (t3code)
Workaround
Downgrading to 0.1.14-nightly.20261129.5452 (the last nightly before #44774; no DB migrations were added in 5479/5492) immediately stopped the crash loop and kept backend RSS flat at ~847 MiB with zero OrchestrationEventStore.readAgentEvents replay storm.
Activity
alexskatell commentedon Nov 30, 2026
Confirming the exact same regression on macOS arm64 (Apple Silicon) — 6 JS heap OOM crashes in 5.5 hours (every 46–68 min) starting immediately after upgrading to
v0.1.14-nightly.20261130.5479and continuing onv0.1.14-nightly.20261130.5492(0 crashes prior to.5479).Environment & observations
machine.pressureallnone)statev2.sqlitewith long-lived threads (~26k runs) and 0 active thread handoffsserver.trace.ndjson):ThreadHandoff.settleran 5,042 times (~315/min,961.3scumulative wall time,259.8 GBcumulative positive heap growth, up to397.7 MB/call).ThreadHandoff.settleran 6,936 times (~365/min,390.9 GBcumulative positive heap growth, up to404.5 MB/call), pushing RSS past3.9 GBwithin ~25 min.Both crash modes & compound collision with
#45047Across the 6
.ipscrash reports:FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memoryat2,604–3,045 MBheap insideMessagePort::OnMessage -> v8::ValueDeserializer::ReadValue(Mark-Compact (reduce)reclaiming<1 MB).WorkerThread): OOM at only19.8–21.9 MBheap (0.4s–4.0sworker uptime) insideMessagePort::OnMessage -> AsyncWrap::MakeCallback, consistent with the shared 4 GiB V8 pointer-compression cage being exhausted.#45047(getTurnStartContext): In 3 of the 6 crashes,provider-turn.startloggedDatabase reader failed: Worker terminated due to reaching memory limit: JS heap out of memoryright before abort. In Crash feat: Cloud Agents #6's trace, an unfinishedgetTurnStartContext(projection_run_attempts+299.3 MB,~435 MBacross 4 tables) and an unfinishedThreadHandoff.settle(projection_messages+164.5 MB) were deserializing concurrently on the exact second of the abort.Notes for the fix & workaround
ThreadHandoff.start_(), capturinglatestSequencebefore callingprojections.getShellSnapshot()and subscribing from{ afterSequence: latest }avoids missing arun.updatedevent between snapshot and subscription while eliminating the replay-from-0 storm and unboundedliveEventsbuffering. InThreadHandoff.settle(), a lightweight thread/shell check (handling missing/deleted threads cleanly) beforegetThreadRecords(threadId, ["runs", "messages"], ...)prevents full-history loads on non-handoff threads.v0.1.14-nightly.20261130.5465(published 9 min before#44774merged, with zero persistence/SQLite migrations added between.5465and.5492) is the latest pre-regression nightly.alexskatell commentedon Nov 30, 2026
Thanks for the quick fix in #46293! One quick note: #46293 switches
ThreadHandoff.start_()tostreamDomainEvents(which stops the startup replay-from-0 storm), butThreadHandoff.settle()(ThreadHandoff.ts:882) still loads allrunsandusermessagesbefore checkingrecords.thread.handoff === undefined. On large threads (~26k runs), every live turn completion still triggers a ~165–400 MB heap spike alongside #45047. Opened a focused follow-up issue to track that remaining half: #46314