fix: stale port-holder cleanup#8
Open
paleo wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
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-holderutilities to detect port holders (PID/PGID/CWD) and sweep leaked processes. - Update
dev-serverstartup/stop flows to detect conflicts, clean up “ours” stale holders, and re-check port availability. - Split
tsconfiginto 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.