aft icon indicating copy to clipboard operation
aft copied to clipboard

aft_inspect starts one TypeScript language server per project root with no limit

Open iceteaSA opened this issue 3 weeks ago • 2 comments

Problem

One aft_inspect call with diagnostics can start many TypeScript language servers at the same time. When its files are in a folder with many small TypeScript projects, it starts one server for each project root that it touches. There is no limit on the number of language servers for one call, for one project root, or for the process. No setting gives a limit.

What I measured (aft 0.64.0, Linux, one module process)

  • One aft_inspect call took 7.1 s. Its files were in a folder that held copies of small TypeScript plugin packages, each with its own tsconfig.json.
  • In about 1 s, aft started 23 TypeScript language servers, one for each package root. With their tsserver.js and typings-installer children, that was 92 processes and about 13.1 GiB resident memory.
  • The memory of the module's cgroup increased from 6.3 GiB to 21.7 GiB in about 10 s. The page cache of the host decreased by 5.6 GiB, and 325 MiB went to swap.
  • We stopped the 92 processes manually after 6 minutes (the log shows 23 exited TypeScript … (SIGTERM) lines). Without that, the per-server idle stop from #1170 stops them after lsp.idle_minutes. With the default of 60 minutes, the memory stays in use for one hour.

Source (v0.64.0)

  • crates/aft/src/lsp/manager.rs:175-185: the server key is the server type plus the workspace root of the file. Thus each nested package root gets its own server.
  • ensure_server_for_file (manager.rs:2542) starts a server for each new key. I found no count limit in crates/aft/src/lsp/. The constants there limit paths, backlogs, records and retries, not servers. RUST_ANALYZER_WORKER_PROCESS_CAP applies to rust-analyzer worker processes only.
  • docs/config.md documents lsp.idle_minutes, lsp.disabled and lsp.servers, but no limit.

Request

A limit on language servers that run at the same time. For example:

  • lsp.max_servers for the process, and
  • a fan-out limit for one aft_inspect call: files after the limit get a PARTIAL diagnostics result, not a new server.

At the limit, aft can stop the idle server with the oldest last use before it starts a new one.

Workarounds today

  • lsp.idle_minutes at its minimum (5) makes the high memory use shorter, but does not prevent it.
  • lsp.disabled: ["typescript"] or inspect.categories.diagnostics: false prevents it, but removes TypeScript diagnostics for all projects.

iceteaSA avatar Nov 12 '26 18:11 iceteaSA

Thanks for the detailed report and the source pointers. The diagnosis is right. In 0.64.0, AFT keys each TypeScript language server by the nearest project root of the file, so every package with its own tsconfig.json gets its own server. Nothing limits how many servers run, for one aft_inspect call or for the process.

We're measuring two fixes on a folder like yours:

  • One TypeScript server shared by the packages of a repository that use the same TypeScript install. Each package's tsconfig.json still decides its own files.
  • A limit on running servers. Files past the limit would come back as a named gap in a PARTIAL result instead of starting another server.

We'll post here when we've chosen.

Until then, lsp.idle_minutes: 5 shortens how long the servers stay up. lsp.disabled: ["typescript"] prevents them, but it removes TypeScript diagnostics for every project.

aft-alfonso[bot] avatar Nov 12 '26 19:11 aft-alfonso[bot]

Fixed in v0.65.0, released today: TypeScript packages in one repository now share one language server per TypeScript version, and lsp.max_servers (default 8) caps how many run at once. Thanks for the report. If you still see it after updating, reply here and we'll reopen.

aft-alfonso[bot] avatar Nov 14 '26 10:11 aft-alfonso[bot]