Skip to content

CLI: Simplify and optimize process existence check for temp dir cleanup#3395

Merged
brandonpayton merged 4 commits intotrunkfrom
replace-ps-man
Mar 15, 2026
Merged

CLI: Simplify and optimize process existence check for temp dir cleanup#3395
brandonpayton merged 4 commits intotrunkfrom
replace-ps-man

Conversation

@brandonpayton
Copy link
Copy Markdown
Member

@brandonpayton brandonpayton commented Mar 15, 2026

Summary

  • Replaces the ps-man npm package with Node.js built-in process.kill(pid, 0) for checking whether a process is still running
  • process.kill(pid, 0) sends signal 0 (no actual signal) which tests process existence without side effects
  • Removes a dependency that spawned a shell process on every check, which was especially slow on Windows

Test plan

  • CI

brandonpayton and others added 2 commits March 15, 2026 00:56
The stale temp directory cleanup was using ps-man, which spawns
`tasklist /v /FO CSV` on Windows to check if a process is still
running. Each call takes ~1-4 seconds on Windows, and they run
sequentially — one per stale temp directory. With a few stale dirs,
this added 5-7+ seconds to every CLI boot.

Replace with process.kill(pid, 0), which is a standard Node.js/POSIX
idiom that checks process existence without sending a signal. It
completes in ~0.02ms per call (85,000x faster than tasklist).

Error handling: only treat ESRCH (no such process) as confirmation
that the process is gone. For EPERM (no permission) or any other
error, conservatively assume the process still exists to avoid
accidentally deleting a temp dir that may still be in use.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@brandonpayton brandonpayton changed the title CLI: replace ps-man with process.kill for process checks CLI: Simplify and optimize process existence check for temp dir cleanup Mar 15, 2026
@brandonpayton brandonpayton marked this pull request as ready for review March 15, 2026 05:31
@brandonpayton brandonpayton requested review from a team, Copilot and mho22 March 15, 2026 05:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the ps-man dependency and switches the Playground CLI’s temp-dir “stale lock” detection to Node’s built-in process.kill(pid, 0) existence check, improving performance (notably on Windows) and simplifying process checks.

Changes:

  • Replaced ps-man process listing with process.kill(pid, 0) for process existence checks.
  • Converted doesProcessExist from async to sync and updated callers accordingly.
  • Removed ps-man from root dependencies.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/playground/cli/src/temp-dir.ts Reworks process-existence logic to use process.kill(pid, 0) and adjusts stale temp-dir detection accordingly.
package.json Drops ps-man dependency now that it’s no longer used.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@brandonpayton
Copy link
Copy Markdown
Member Author

This is simple and low-risk and has tests. Let's go ahead and merge.

@brandonpayton brandonpayton merged commit ecfb5ee into trunk Mar 15, 2026
46 checks passed
@brandonpayton brandonpayton deleted the replace-ps-man branch March 15, 2026 21:03
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.

2 participants