Skip to content

fix(windows): stop the idle PowerShell bridge after 10 minutes - #490

Open
AmrDab wants to merge 2 commits into
mainfrom
fix/idle-bridge-stop
Open

AmrDab wants to merge 2 commits into
mainfrom
fix/idle-bridge-stop

Conversation

@AmrDab

@AmrDab AmrDab commented Nov 29, 2026

Copy link
Copy Markdown
Owner

What

On Windows, an idle clawdcursor server stops its PowerShell UIA bridge after 10 minutes with no command, and the next call starts it again (about 1 s for PowerShell plus the UIA assemblies).

Why

Every MCP server keeps one bridge for the whole session, from the warm-up at start until the host closes the session. Measured on one Windows PC with 11 open Claude sessions: 22 servers, 22 bridges, 777 MB working set held by the bridges alone (35–137 MB each), while the servers were idle (16 ms CPU in 30 s across all of them). An open but unused session now drops to the node process alone after 10 minutes.

How

PSRunner (src/platform/ps-runner.ts):

  • Arming: an idle timer is armed when the bridge signals ready and after each reply that leaves nothing current or queued.
  • Clearing: it is cleared when a command is queued or sent, and by stop(). It is unref()'d.
  • On expiry: it sends EXIT, kills after 500 ms, and detaches the process. The existing this.proc !== proc guard ignores its exit.
  • Next call: run() starts a fresh bridge, without the "Restarting crashed bridge" log.
  • State lost: only lazy caches (app names, the OCR engine), which rebuild on use.

Tests

src/__tests__/ps-runner-timeout.test.ts, three new cases with fake timers:

  1. Idle → EXIT + kill, then the next run() spawns a new bridge and resolves. This fails on main.
  2. A command in flight at the 10-minute mark is not cut, and the bridge stops 10 minutes after it ends. This fails on main.
  3. stop() leaves no timer behind.

typecheck, typecheck:tests, lint (0 errors, the 3 warnings as on main), npm run test:ci: 4300 passed, 80 skipped, 0 failed.

No release: for the 2.4 train.

🤖 Generated with Claude Code

AmrDab and others added 2 commits November 28, 2026 20:24
PSRunner kept its persistent PowerShell bridge alive until the server
exited, so every open but unused session held 35-140 MB. The bridge now
stops after 10 minutes with no command (EXIT, then kill after 500 ms)
and the next run() starts it again silently. The timer is armed when the
bridge is ready and after a command leaves nothing current or queued,
cleared on queue/send and in stop(), and unref'd. The idle length is a
constructor argument so tests can use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…or the benchmark

The benchmark's leftovers check needs to see the idle bridge stop within seconds, not 10 minutes. Unset, zero or not a
number: 10 minutes, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant