Skip to content

fix(ports): report a Stop as succeeded when the listener already exited - #15888

Merged
nwparker merged 2 commits into
mainfrom
nwparker/windows-port-tree-kill
Aug 22, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/windows-port-tree-kill

Conversation

@nwparker

@nwparker nwparker commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​58 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7

Rewritten. This PR originally escalated the Windows Stop to a taskkill /T /F tree kill, adopting the mechanism proposed in #10346. That mechanism is wrong — I checked it before merging and it does not survive contact with the scanner. What remains is the one defect I can actually prove.

What #10346 claimed, and why it is not right

the listener is a child of the npm run dev wrapper the scan attributed the port to, so terminating the wrapper orphans the child that holds the socket

The scan does not attribute the port to a wrapper. scanWindowsNetstatPorts reads netstat -ano and takes the PID column (local-workspace-port-scanner.ts:245-263), and that column is the process owning the TCP endpoint — the listener itself. The POSIX path takes the same field from lsof. So process.kill(pid, 'SIGTERM') already targets the right process, and a tree kill would only add descendants nobody asked to stop.

#10150 is also not this code path. It reports a dev server surviving project close / terminal exit, not the Resource Manager Stop button. That is PTY teardown, and it is what the job objects in #15755 / #15886 address.

The real defect

process.kill(pid, 'SIGTERM')
return { ok: true }
} catch (error) {
  return { ok: false, reason: message }   // `kill ESRCH` shown as a Stop failure
}

The authorizing re-scan runs first, then the signal. If the listener exits in between — common for a dev server the user just Ctrl-C'd elsewhere — process.kill throws ESRCH and the UI reports failure for a port that is now free, which is exactly the outcome Stop asked for.

ESRCH is now success. Every other error still fails, with its message.

Tests

Drive-by

src/main/ports/port-scan-command-execution.test.ts blocks the calling thread for the full watchdog budget plus margin (5.2s) and asserts against vitest's 5s default. It has been failing deterministically since #12217; given a real budget it passes.

Risk

None identified. One error code changes classification; no process that was not already being signalled is signalled now.

Credit to @innocarpe (#10346) for surfacing the Stop path, with the correction above.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@nwparker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3fb953f5-787f-4200-8ec2-0204d52a84ea

📥 Commits

Reviewing files that changed from the base of the PR and between 1354ff5 and 323404d.

📒 Files selected for processing (3)
  • src/main/ports/port-scan-command-execution.test.ts
  • src/main/ports/workspace-port-ownership.test.ts
  • src/main/ports/workspace-port-ownership.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

`killWorkspacePort` surfaced the raw `kill ESRCH` when the pid exited between
the authorizing re-scan and the signal. The port is free at that point -- which
is exactly what Stop was asked for -- so the UI reported a failure for work that
had already completed.

Also pins the pid we signal: `netstat -ano` and `lsof` report the process that
owns the socket, so the scanned pid is the listener itself, not a supervising
wrapper. Escalating this to a tree kill would reach descendants nobody asked to
stop without freeing anything extra.
It blocks the calling thread for the full watchdog budget plus margin (5.2s) and
then asserts against vitest's 5s default, so it has been failing deterministically
since #12217.
@nwparker
nwparker force-pushed the nwparker/windows-port-tree-kill branch from 87638b1 to 323404d Compare August 22, 2026 06:41
@nwparker nwparker changed the title fix(windows): stop a workspace port by killing the tree, not just the wrapper fix(ports): report a Stop as succeeded when the listener already exited Aug 22, 2026
@nwparker
nwparker merged commit 84659e2 into main Aug 22, 2026
47 checks passed
@nwparker
nwparker deleted the nwparker/windows-port-tree-kill branch August 22, 2026 07:19
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 23, 2026
…ed (stablyai#15888)

* fix(ports): report a Stop as succeeded when the listener already exited

`killWorkspacePort` surfaced the raw `kill ESRCH` when the pid exited between
the authorizing re-scan and the signal. The port is free at that point -- which
is exactly what Stop was asked for -- so the UI reported a failure for work that
had already completed.

Also pins the pid we signal: `netstat -ano` and `lsof` report the process that
owns the socket, so the scanned pid is the listener itself, not a supervising
wrapper. Escalating this to a tree kill would reach descendants nobody asked to
stop without freeing anything extra.

* test(ports): give the spawn-stall test a budget longer than the stall

It blocks the calling thread for the full watchdog budget plus margin (5.2s) and
then asserts against vitest's 5s default, so it has been failing deterministically
since stablyai#12217.

(cherry picked from commit 84659e2)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…ed (stablyai#15888)

* fix(ports): report a Stop as succeeded when the listener already exited

`killWorkspacePort` surfaced the raw `kill ESRCH` when the pid exited between
the authorizing re-scan and the signal. The port is free at that point -- which
is exactly what Stop was asked for -- so the UI reported a failure for work that
had already completed.

Also pins the pid we signal: `netstat -ano` and `lsof` report the process that
owns the socket, so the scanned pid is the listener itself, not a supervising
wrapper. Escalating this to a tree kill would reach descendants nobody asked to
stop without freeing anything extra.

* test(ports): give the spawn-stall test a budget longer than the stall

It blocks the calling thread for the full watchdog budget plus margin (5.2s) and
then asserts against vitest's 5s default, so it has been failing deterministically
since stablyai#12217.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ed (stablyai#15888)

* fix(ports): report a Stop as succeeded when the listener already exited

`killWorkspacePort` surfaced the raw `kill ESRCH` when the pid exited between
the authorizing re-scan and the signal. The port is free at that point -- which
is exactly what Stop was asked for -- so the UI reported a failure for work that
had already completed.

Also pins the pid we signal: `netstat -ano` and `lsof` report the process that
owns the socket, so the scanned pid is the listener itself, not a supervising
wrapper. Escalating this to a tree kill would reach descendants nobody asked to
stop without freeing anything extra.

* test(ports): give the spawn-stall test a budget longer than the stall

It blocks the calling thread for the full watchdog budget plus margin (5.2s) and
then asserts against vitest's 5s default, so it has been failing deterministically
since stablyai#12217.
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