service: persistent background server retains ~450 MB RSS after TUI exit

Aperta
#66,901 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cli, linux, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/service platform/linux type/feature version/v2
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

  1. Start opencode in Ghostty and use at least one session.

  2. Exit the TUI normally.

  3. 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
    
  4. 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

  5. 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, or opencode --standalone.
  • Related issues:
  • #54631 — open; duplicated location/file-search engines and inotify watches after location invalidation/reload.
  • #64159 — closed; serve --service watcher/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.
Lingua principale
TypeScript
Stelle
230k
Fork
31.3k
Merge medio
5h 32m
PR unite (30g)
453

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anomalyco/opencode

Tutte le issue di anomalyco/opencode

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.