service: persistent background server retains ~450 MB RSS after TUI exit
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- cli, linux, typescript
- Bereich
- backend, devtools, performance
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 230k
- Forks
- 31.3k
- Ø Merge
- 5 Std. 32 Min.
- Gemergte PRs (30 T.)
- 453
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus anomalyco/opencode
-
area/desktop platform/macos status/repro-plausible type/bug version/v2
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
anomalyco/opencode#67064 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 82/100
anomalyco/opencode#67009 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
area/web type/feature version/v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
anomalyco/opencode#67001 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
skills: a Claude-compatible SKILL.md that fails to parse is dropped without any logEvtl. vergeben @liwenjie200543 hat das vor 2 Tagen übernommen. Offenarea/plugins platform/linux reproduced type/bug version/v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
anomalyco/opencode#66970 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
tui: Mermaid renderer displays <b>/<strong> tags literally and ignores \n line breaksEvtl. vergeben @argszero hat das vor 2 Tagen übernommen. Offenarea/tui platform/wsl status/repro-simulated type/bug version/v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
anomalyco/opencode#66773 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in anomalyco/opencode
Ähnliche Issues
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
ci
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
ClickHouse/clickhouse-js#1248 ·
Maintainer antworten meist innerhalb von 1 Tag
-
E2E: Darlehen-Test wartet auf die gebuchte Auszahlung, bevor er zur Liquiditätsvorschau wechseltOffentechnik
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
SR5-FoundryVTT/SR5-FoundryVTT#2162 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
AhmedNAgy25/analysor#25 ·
Maintainer antworten meist innerhalb von 1 Tag