anomalyco / anomalyco/opencode

[BUG] CLI test fixtures leaking processes on Windows

Open
#42,989 0 comments 0 reactions 1 assignee View on GitHub

@Hona is already working on this.

Since Aug 17, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

CLI subprocess tests leave OpenCode processes running on Windows after the suite finishes. I currently have 35 of them alive, oldest 46 hours, ~32 GB of private commit between them, still holding loopback ports and file locks on checkouts.

The cause is in packages/opencode/test/lib/cli-process.ts. It spawns children with Bun.spawn(["bun", ...]). When the suite is launched through bun x (bunx), PATH resolves "bun" to the small node_modules\.bin\bun.exe shim, which starts the real bun as a separate process and waits on it. The fixture only ever holds the shim. So kill() + await exited completes as soon as the shim dies, while the real OpenCode process keeps running with no parent.

Two helpers leak: serve() and startRun(). acp() happens to be safe because stdin EOF exits the child first, and the generic spawn() is safe because it goes through CrossSpawnSpawner, which tree-kills on Windows.

The two tests meant to catch this can't:

  • test/cli/serve/serve-process.test.ts asserts typeof code === "number" || code === null, which is true for every possible value.
  • test/cli/run/run-process.test.ts has a test named "SIGINT interrupts an active non-interactive run without leaking the process" that leaks one every run.

I have a fix ready and will open a PR against this issue.

Plugins

custom

OpenCode version

1.17.11

Steps to reproduce
  1. On Windows, from packages/opencode, run the suite through bunx so the shim is on PATH:
    bun x bun@1.3.14 test test/cli/serve/serve-process.test.ts -t "kills the subprocess on scope close"
  2. The test passes.
  3. List bun processes:
    Get-CimInstance Win32_Process -Filter "Name='bun.exe'" | Select-Object ProcessId, ParentProcessId, CommandLine
  4. There is a leftover ... src\index.ts serve --port 0 process whose parent no longer exists. It still answers HTTP on its port.
Screenshot and/or share link

No response

Operating System

Windows 10

Terminal

Windows Terminal (PowerShell)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.