Skip to content

fix: stale port-holder cleanup#8

Open
paleo wants to merge 3 commits into
mainfrom
fix/cleanup
Open

fix: stale port-holder cleanup#8
paleo wants to merge 3 commits into
mainfrom
fix/cleanup

Conversation

@paleo
Copy link
Copy Markdown
Owner

@paleo paleo commented May 15, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 15, 2026 11:09
Copy link
Copy Markdown

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 adds proactive cleanup for stale dev-server processes that still hold configured ports, and restructures TypeScript configs so tests are typechecked without affecting build output.

Changes:

  • Add port-holder utilities to detect port holders (PID/PGID/CWD) and sweep leaked processes.
  • Update dev-server startup/stop flows to detect conflicts, clean up “ours” stale holders, and re-check port availability.
  • Split tsconfig into build vs. no-emit typecheck configs and update build scripts; add Vitest coverage for the new port-holder logic.

Reviewed changes

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

Show a summary per file
File Description
packages/worktree-env/tsconfig.json Switch to extending build tsconfig; enable no-emit typechecking for src + test.
packages/worktree-env/tsconfig.build.json New build-only tsconfig used by npm run build.
packages/worktree-env/test/port-holder.test.ts New tests for cwd canonicalization, port conflict detection, and waiting for port release.
packages/worktree-env/src/port-holder.ts New implementation for port-holder detection + stale port sweeping.
packages/worktree-env/src/dev-server.ts Integrate conflict detection/cleanup into start and stop flows; remove old isPortBusy.
packages/worktree-env/package.json Bump version and point build to tsconfig.build.json.
packages/docmap/tsconfig.json Same tsconfig split pattern (no-emit typechecking including tests).
packages/docmap/tsconfig.build.json New build-only tsconfig used by npm run build.
packages/docmap/package.json Point build to tsconfig.build.json.

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

Comment on lines +47 to +57
socket.setTimeout(500);
socket.once("connect", () => {
socket.destroy();
resolve(true);
});
socket.once("timeout", () => {
socket.destroy();
resolve(false);
});
socket.once("error", () => {
resolve(false);
Comment on lines +127 to +135
function listenerPid(port: number): number | undefined {
const out = tryExec(`lsof -nP -iTCP:${port} -sTCP:LISTEN -t`);
if (out === undefined) return;
const trimmed = out.trim();
if (trimmed === "") return;
const pid = Number(trimmed.split(/\s+/)[0]);
return Number.isFinite(pid) ? pid : undefined;
}

Comment on lines +51 to +55
it("resolves holder symlink before comparing", () => {
const real = mkdtempSync(join(tmpdir(), "wt-real-"));
const link = `${real}-link`;
symlinkSync(real, link);
try {
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