Warm server runs one tsserver per worktree, pushing parallel-agent hosts into swap

Abierto
#170 0 comentarios 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
36/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
nodejs, typescript

Línea de trabajo

Start with the repro script in the issue, which creates worktrees and prints per-process RSS. The spawn decision is in dist/enforcement/server.js near line 874, the idle timeout is DEFAULT_IDLE_MS near line 61, and the tsserver options are in dist/adapters/typescript.js near line 264. Done means the RSS total stays bounded as worktrees grow, for example via a maxTsServerMemory setting or a machine-wide cap. The cap design is still open, so confirm the approach with maintainers before coding.

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

Descripción

Each git worktree gets its own warm server (serve -> typescript-language-server -> tsserver), with no machine-wide cap, no memory check before spawning, and no tsserver heap limit. Parallel agent sessions in separate worktrees of one repo therefore run N copies of the same project load. On a 16 GB host, 4 sessions pushed it into swap.

Environment

  • @posthog/coherence 1.8.0
  • tsserver from coherence's bundled typescript 5.9.3, via typescript-language-server 5.3.0
  • Node v22.23.2, Debian 12, 8 cores, 15.8 GB RAM
  • Project: 916 .ts files, 160k lines

Measurements

Fresh worktree, 30 s after coherence warm: serve 71 MB + LSP 58 MB + tsserver 485 MB = 614 MB per tree. Grows linearly with the worktree count.

Live, 4 agent sessions in 4 worktrees:

tree RSS tsserver RSS
928 MB 1,094 MB (peak 1,405 MB)
887 MB 949 MB
838 MB 697 MB
540 MB 547 MB
  • About 3.2 GB in total. tsserver grows from 485 MB to 0.7 to 1.4 GB with use.
  • Host state: swap 976/976 MB full, /proc/pressure/memory full avg300=22.58, load 46 on 8 cores.
  • In that state, two coherence CLI calls that normally take about 170 ms took about 12 s, and git status timed out at 10 s.
  • Idle exit (DEFAULT_IDLE_MS = 5 min) followed by a respawn on the next hook adds repeated cold project loads while the host is already swapping. Observed tsserver ages: 15 s and 4 min inside sessions 25+ min old.

Repro

repro.sh <ts-repo-with-coherence> <count> creates <count> worktrees, runs coherence warm in each, prints RSS per process after 30 s, then cleans up.

#!/usr/bin/env bash
set -euo pipefail
repo=$(realpath "$1"); count=${2:-4}
base=$(mktemp -d /tmp/coherence-warm-repro.XXXXXX)
export COHERENCE_NO_UPDATE_CHECK=1
cli=$(readlink -f "$repo/node_modules/@posthog/coherence/dist/cli.js")
rss_mb() { local kb; kb=$(ps -o rss= -p "$1" 2>/dev/null || true); echo $(( ${kb:-0} / 1024 )); }
cleanup() {
  for root in "$base"/wt-*; do
    [ -d "$root" ] || continue
    serve=$(pgrep -f "[c]li.js serve --root $root\$" || true)
    [ -n "$serve" ] && kill $serve && sleep 1
    rm -f "$root/node_modules"; rm -r "$root/.coherence/run" 2>/dev/null || true
    git -C "$repo" worktree remove "$root" || true
  done
  rmdir "$base" 2>/dev/null || true
}
trap cleanup EXIT
for i in $(seq 1 "$count"); do
  root="$base/wt-$i"
  git -C "$repo" worktree add --detach --quiet "$root" HEAD
  ln -s "$repo/node_modules" "$root/node_modules"
  (cd "$root" && node "$cli" warm)
done
sleep 30
for root in "$base"/wt-*; do
  serve=$(pgrep -f "cli.js serve --root $root\$"); lsp=$(pgrep -P "$serve" | head -1); tsserver=$(pgrep -P "$lsp" | head -1)
  echo "$(basename "$root"): serve $(rss_mb "$serve") MB, lsp $(rss_mb "$lsp") MB, tsserver $(rss_mb "$tsserver") MB"
done

Output with count 2:

wt-1: serve 71 MB, lsp 58 MB, tsserver 485 MB
wt-2: serve 72 MB, lsp 58 MB, tsserver 485 MB

Code

  • dist/enforcement/server.js:874: the client spawns serve --root <root> whenever nothing listens, with no count or memory check
  • dist/adapters/typescript.js:264: no maxTsServerMemory in initializationOptions.tsserver
  • dist/enforcement/server.js:61: DEFAULT_IDLE_MS = 5 * 60 * 1000
  • dist/lifecycle/hook.js:890: WARM_UP fires on SessionStart, UserPromptSubmit, and project entry

Possible fixes

  • Machine-wide cap on warm servers with LRU eviction, or skip warming and answer cold when MemAvailable is low
  • Set maxTsServerMemory
  • Make the idle timeout configurable
Lenguaje dominante
TypeScript
Estrellas
21
Forks
6
Merge medio
8 h 31 min
PR fusionados (30 d)
55

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 PostHog/coherence

Todos los issues de PostHog/coherence

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.