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

Abierto
#66,901 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cli, linux, typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
TypeScript
Estrellas
230k
Forks
31.3k
Merge medio
5 h 32 min
PR fusionados (30 d)
453

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de anomalyco/opencode

Todos los issues de anomalyco/opencode

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.