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

オープン
#170 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
36/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
nodejs, typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
TypeScript
スター
21
フォーク
6
平均マージ
8時間 31分
マージ済み PR(30日)
55

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PostHog/coherence のほかの issue

PostHog/coherence の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。