service: persistent background server retains ~450 MB RSS after TUI exit
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- cli, linux, typescript
- 领域
- backend, devtools, performance
调研方向
The report is a memory snapshot, not a located defect: start by reproducing the growth with repeated TUI exits while watching RSS and inotify watch counts in /proc/<pid>/status and /proc/<pid>/fdinfo for the serve --service process. Related threads #54631 and #64159 cover duplicated watchers and prior growth evidence and should be read first. Done would be a measured before/after trend and either a bounded footprint or a documented expected size, with maintainer agreement on which.
由索引模型根据 Issue 内容生成。
描述
Description
Summary
After exiting the TUI on Linux, a shared opencode serve --service process and its persistent-PTY child remain and hold a substantial amount of memory: about 443 MiB RSS / 409 MiB PSS for the service and 41 MiB RSS / 39 MiB PSS for the PTY daemon. I understand from the docs that the shared background server is intended to survive client exits; this report is about the large resident memory retained with no client open and whether it is bounded or can be reduced. If this is intended behavior, it would help to document the expected footprint or provide a supported low-memory mode that stops the service and PTY daemon when the last client exits.
Environment
- opencode version: 2.4.2 (
opencode --version) - Latest release: 2.4.2, so no update was pending
- Client: TUI, with the shared background service and persistent PTY daemon
- Model and provider: Not relevant
- OS: Linux 6.18.65_1_1 SMP PREEMPT_DYNAMIC x86_64 GNU/Linux
- Terminal: Ghostty (
TERM=xterm-256color,TERM_PROGRAM=ghostty,COLORTERM=truecolor) - Shell:
/bin/bash - Install/channel: Release binary at
~/.opencode/bin/opencode - Active plugins:
~/.config/opencode/plugins/opencode_mosp,@tarquinen/opencode-dcp@latest,[email protected]; the startup log reported 17 plugins in total, but the full list was not captured. Plugin status during a clean/no-plugin run was not determined.
Reproduction
-
Start
opencodein Ghostty and use at least one session. -
Exit the TUI normally.
-
Inspect the remaining processes:
opencode --version opencode service status opencode api get /api/info ps -o pid,ppid,rss,vsz,pmem,etime,args -C opencode -C opencode-pty -
For each remaining OpenCode PID, inspect memory:
grep -E '^(VmRSS|VmSize|VmSwap|Threads):' /proc//status
grep -E '^(Rss|Pss|Swap|Private_Clean|Private_Dirty):' /proc//smaps_rollup -
Observe that the shared service and PTY daemon remain after the TUI process is gone.
Expected Behavior
Exiting the TUI should release the client's memory. If the shared service is expected to remain running by design, its memory use should be bounded and minimized, or there should be a supported setting to stop the service and its PTY daemon when the last client exits.
Actual Behavior
Three OpenCode-related processes were present; only one was an active TUI client:
PID Process RSS PSS Swap Threads
4372 ~/.opencode/bin/opencode serve --service 453736 kB 418580 kB 38680 kB 22
23141 opencode-pty ... daemon --runtime-dir ~/.local/state/opencode/pty --name <redacted> 41584 kB 39887 kB 8888 kB 62
6791 opencode TUI 305124 kB 270420 kB 4032 kB 25
Combined resident memory was about 782 MiB RSS / 712 MiB PSS, with about 50 MiB swap used across those processes. The TUI was active at the time of measurement; the two persistent processes account for about 484 MiB RSS / 457 MiB PSS and about 46 MiB swap.
opencode service status reported http://127.0.0.1:49374.
opencode api get /api/info returned:
{"version":"2.4.2","pid":4372,"hostname":"","urls":["http://127.0.0.1:49374"],"paths":{"tmp":"/tmp/opencode"},"capabilities":{"persistentPty":true}}
The service process was detached with PPID 1 and had been running for about 5h 49m. The PTY daemon was its child and had been running for about 4h 46m. There was one listener on port 49374, no zombie processes, and no stale service registration observed.
Watcher evidence from the service process did not show duplicated watches in this snapshot:
cat /proc/4372/fdinfo/* | grep -c '^inotify wd:' # 27
cat /proc/4372/fdinfo/* | grep '^inotify wd:' | sort -u | wc -l # 27
ls -l /proc/4372/fd | grep -c inotify # 2
Relevant log lines from ~/.local/share/opencode/log/opencode.log:
timestamp=2026-11-27T18:02:43.211Z level=INFO run=a6e97402 message="background service starting" reason=missing previousVersion=undefined role=cli
timestamp=2026-11-27T19:30:14.703Z level=INFO run=a47a17a5 message="shutdown started" signal=SIGINT role=cli
The foreground opencode serve run shut down cleanly on SIGINT. The still-running TUI corresponded to run 4ce8ad2a, and earlier TUI client processes were gone.
System memory at the time:
total used free shared buff/cache available
Mem: 31Gi 22Gi 1.6Gi 197Mi 6.8Gi 8.3Gi
Swap: 31Gi 407Mi 31Gi
Additional Context
- Frequency: observed during normal use; this is a single snapshot, not yet a proven leak.
- Growth over time has not been measured, so the issue may need before/after RSS and watcher counts after repeated TUI exits,
/reload, and workspace switches. - The persistence of the shared service is documented behavior. This report is not claiming that the service PID itself must exit when a TUI exits.
- Documented mitigations, not yet tested here:
opencode service stop,opencode service set disabled true, oropencode --standalone. - Related issues:
- #54631 — open; duplicated location/file-search engines and inotify watches after location invalidation/reload.
- #64159 — closed;
serve --servicewatcher/memory accumulation; maintainers asked for growth-over-time evidence. - #51329 — background service preventing clean terminal exit.
- Service passwords, PTY tokens, auth headers, prompts, and workspace-specific data were redacted and are not included.
- 主要语言
- TypeScript
- 星标
- 230k
- 派生
- 31.3k
- 平均合并
- 5 小时 32 分钟
- 30 天内合并 PR
- 453
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
anomalyco/opencode 的其他 Issue
-
area/desktop platform/macos status/repro-plausible type/bug version/v2
难度 1/5 1-3 小时 新手友好度 88/100
anomalyco/opencode#67064 · 4 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 82/100
anomalyco/opencode#67009 · 2 条评论 ·
维护者通常 1 天内回复
-
area/web type/feature version/v2
难度 2/5 1-3 小时 新手友好度 78/100
anomalyco/opencode#67001 · 3 条评论 ·
维护者通常 1 天内回复
-
skills: a Claude-compatible SKILL.md that fails to parse is dropped without any log可能已有人在做 @liwenjie200543 于 2 天前认领。 未关闭area/plugins platform/linux reproduced type/bug version/v2
难度 2/5 1-3 小时 新手友好度 72/100
anomalyco/opencode#66970 · 4 条评论 ·
维护者通常 1 天内回复
-
tui: Mermaid renderer displays <b>/<strong> tags literally and ignores \n line breaks可能已有人在做 @argszero 于 2 天前认领。 未关闭area/tui platform/wsl status/repro-simulated type/bug version/v2
难度 2/5 1-3 小时 新手友好度 82/100
anomalyco/opencode#66773 · 4 条评论 ·
维护者通常 1 天内回复
查看 anomalyco/opencode 的全部 Issue
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
ci
难度 2/5 1-3 小时 新手友好度 78/100
ClickHouse/clickhouse-js#1248 ·
维护者通常 1 天内回复
-
E2E: Darlehen-Test wartet auf die gebuchte Auszahlung, bevor er zur Liquiditätsvorschau wechselt未关闭technik
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 67/100
SR5-FoundryVTT/SR5-FoundryVTT#2162 ·
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 84/100
AhmedNAgy25/analysor#25 ·
维护者通常 1 天内回复