Repository navigation
Description
Description
opencode serve appears to retain/fragment a large amount of anonymous JS/Bun heap during long-running server-mode usage. On a Linux production host the process grew to a 26.8 GiB cgroup memory peak and left ~2.86 GiB in swap after ~1.5 days. A service restart immediately dropped the process back to ~250 MiB RSS and memory.swap.current=0.
This looks like the same class of long-running memory growth reported in multiple issues, but this report includes Linux cgroup + smaps_rollup data from the server mode process.
Related existing reports I found while searching before opening this:
- Memory Megathread #20695
- OOM kill: message history accumulation causes 8.5GB memory usage during task execution #29730
- Memory leak in server mode: unbounded EventTarget listeners added to Effect-ts internal emitter (QL) per session #29204
- Windows 11: long-running full TUI sessions accumulate large JS heap; reopening the session amplifies it via rehydration #24445
- [IMPORTANT]Excessive memory usage #22018
- 1.4.0 memory leak. Bun occupies more than 3g memory at most. #21430
- [Bug] Memory Leak: OpenCode Process Killed by 00M Killer During Extended Runtime #9743
- [Bug]: Massive memory leak (60GB+ OOM crash) on Server #17908
- [Critical] Memory leak causes kernel soft lockups (356s, 7/8 CPUs), OOM kills (111GB virt/21GB RSS), and total system death on Linux #13230
Environment
- OS: Ubuntu 22.04.5 LTS
- Kernel: 6.8.0-124-generic
- Architecture: x86_64
- RAM: ~125 GiB
- Swap: 50 GiB
/swapfile - opencode version:
1.17.9 - Install path:
~/.opencode/bin/opencode - Mode: long-running server
- Command:
/home/roomhacker/.opencode/bin/opencode serve --hostname 127.0.0.1 --port 4095systemd unit is a simple service with Restart=always; no memory limits were configured before this incident.
Observed behavior
After ~1 day 13 hours of uptime:
opencode.service active since Fri 2026-06-19 22:31:16 MSK
Main PID: 2733850
Tasks: 21
MemoryCurrent: ~3.35 GiB
memory.peak: 26867433472 bytes (~26.8 GiB)
memory.swap.current: 2925260800 bytes (~2.86 GiB)
memory.swap.peak: 3846123520 bytes (~3.85 GiB)
Process-level memory before restart:
PID=2733850
RSS≈1.13 GiB
Swap≈2.86 GiB
VSZ≈105 GiB
/proc/$PID/smaps_rollup:
Rss: 1133880 kB
Pss: 1131378 kB
Pss_Dirty: 1094860 kB
Pss_Anon: 1094860 kB
Private_Dirty: 1094860 kB
Anonymous: 1094860 kB
Swap: 2856700 kB
SwapPss: 2856700 kB
Top mappings by swap/RSS were anonymous JS/Bun/WebKit allocations:
[anon:WKFastMalloc]
[anon:JSJITCode]
[anon:JSStructureHeap]
Examples from /proc/$PID/smaps:
1 GiB anonymous arena: Swap≈511M
1 GiB anonymous arena: Swap≈435M
1 GiB anonymous arena: Swap≈313M
1 GiB anonymous arena: Swap≈150M
many [anon:WKFastMalloc] chunks: 20M-70M swapped each
The binary also showed as deleted from the running process:
/home/roomhacker/.opencode/bin/opencode (deleted)
So the service had likely been updated on disk while the old long-running process kept its heap alive.
Impact
The host had other workload too, but opencode.service alone held several GiB of anonymous heap/swap. During overall memory pressure, swap was nearly exhausted. Restarting only opencode.service freed ~3 GiB of swap immediately.
Before restart:
opencode MemoryCurrent≈3.3G
opencode swap≈2.9G
global swap used≈43G
After restart:
opencode MemoryCurrent≈257M
opencode memory.swap.current=0
global swap used≈40G
Expected behavior
Long-running opencode serve should either:
- release old session/request/tool-output state when work is done,
- provide a configurable retention/GC policy for server mode,
- expose memory diagnostics/heap snapshot hooks, or
- document recommended production limits/restart policy.
It should not require periodic restarts to prevent anonymous heap/swap buildup.
Reproduction notes
The server was used heavily through a web/frontend client connected to opencode serve. Workloads included long sessions with many tool calls and large command outputs, including package installation/build commands and repeated shell tool runs.
I do not have a minimal deterministic repro yet, but the symptom is measurable in production and matches other long-running memory reports:
systemctl show opencode.service -p MainPID -p MemoryCurrent -p TasksCurrent
cat /sys/fs/cgroup/system.slice/opencode.service/memory.peak
cat /sys/fs/cgroup/system.slice/opencode.service/memory.swap.current
cat /proc/$PID/smaps_rollupWorkaround used locally
I restarted the service and then added a soft cgroup pressure threshold, not a hard kill limit:
systemctl set-property opencode.service MemoryAccounting=yes MemoryHigh=10GAfter restart:
opencode.service: active/running
MemoryCurrent≈237M
MemoryHigh=10737418240
MemoryMax=infinity
memory.swap.current=0
oom=0
oom_kill=0
127.0.0.1:4095 LISTEN
Request
Please do not close this as a generic duplicate without tracking the actual server-mode leak/retention path. The useful next step would be either:
- guidance for collecting Bun/JSC heap snapshots from the bundled
opencodebinary, - a debug flag to expose heap stats in server mode,
- or a fix/retention policy for long-running sessions/tool output/state.
Activity
Necmttn commentedon Jun 21, 2026
For server mode, memory growth needs daemon-level telemetry rather than after-the-fact host forensics. Emit periodic process metrics: rss, heap used/total, external memory, swap, active sessions, open streams, tool calls served, and uptime. Pair that with a leak guard that snapshots the last N session/tool events before restart, so the next report can tie growth to a workload pattern.
Generated with ax.
megamen32 commentedon Jun 22, 2026
I have a more specific repro now. It is not perfect/minimal yet, but it is much more actionable than the original long-running report.
Trigger
From the macOS desktop client:
opencode serveinstance.During that operation the memory growth happens on the remote server-side
opencode serveprocess, not only in the local desktop client.Server setup for this run
Before the test I restarted
opencode.serviceto get a clean baseline and raised the cgroup soft limit from 10 GiB to 40 GiB so the test would not be throttled byMemoryHigh:The monitored process was:
Result from one short run
Capture duration: ~295 seconds.
Peaks during the run:
The clear burst was here:
Fastest observed step:
smaps evidence
After the run:
Largest mapping observed:
There was also a large anonymous arena:
Why this looks related
The repro correlates three things during the desktop remote project picker/folder expansion:
opencode serve,WKFastMallocallocations,:4095, especiallyCLOSE_WAIT.So this may not just be generic long-running session retention. It may be triggered by remote desktop project discovery / folder tree expansion and/or the server API/streaming path used by that UI.
I can try to reduce this further later, but this short run already reproduces several GiB of server-side anonymous heap growth in seconds.
megamen32 commentedon Jun 22, 2026
Update: reproduced again on a clean
1.17.9remote server, and this time it crashed the server process.Setup
I updated a second Linux remote server from
1.17.7to latest1.17.9and restarted the server cleanly before the test.Server:
Trigger
Same UI path as before:
I started the interaction around
01:32server local time.Result
The memory spike happened immediately during folder expansion/project browsing, then
opencode serveaborted and systemd restarted it.Window with the spike:
Fastest observed growth:
The large growth correlated with a burst of connections/file picker activity:
Crash log
Journal:
PID transition from the monitor:
After restart the service returned to ~400 MiB and stayed up.
Why this update matters
This is not only accumulated memory over a long-running session and it is not fixed in
1.17.9. A clean1.17.9server process can be crashed within about a minute by the desktop remote project picker / folder expansion path.The interesting signals are still the same:
VmSize,megamen32 commentedon Jun 22, 2026
https://youtu.be/8-D9uCZE7F8 Repro video for OpenCode remote server memory leak / crash on 1.17.9.
Trigger:
macOS desktop client (1.17.9) -> remote Linux opencode serve (1.17.9) -> Add project -> expand/browse folders in project picker.
The right-side dashboard shows live server-side cgroup/process metrics for
opencode serve: MemoryCurrent, RSS, Anonymous memory, VmSize, threads, FDs, TCP connections, PID history, restarts, and journal.Dashboard tool:
https://github.com/megamen32/service-crash-watch
In previous measured run on the same setup, a clean 1.17.9 server crashed:
MemoryCurrent peak 11.6 GiB, VmSize 95.8 GiB, +1507 MiB in 3 seconds, then
memory allocation failedandstatus=6/ABRT.aryansinghrajput3738-code commentedon Jun 27, 2026
http://localhost:3000 npm install
npm install
npm start
node server.js
github-actions commentedon Aug 27, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.