Skip to content

fix(desktop): tolerate a broken TCP state column in the Windows listener check - #26

Open
rajnishmanitiwari wants to merge 1 commit into
w01fb0ss:mainfrom
rajnishmanitiwari:fix/windows-listener-state-tolerance
Open

rajnishmanitiwari wants to merge 1 commit into
w01fb0ss:mainfrom
rajnishmanitiwari:fix/windows-listener-state-tolerance

Conversation

@rajnishmanitiwari

Copy link
Copy Markdown

Fixes #15. On some Windows builds the OS reports a listening socket with a wrong or empty TCP state (0, 1, 6, or unmapped), so the owner check's State = 2 predicate matched 0 rows even though the socket was listening and accepting connections. Startup then failed every time with listener_missing and the GUI blamed machine load. The listener query no longer filters on State: a row for the port owned by the process proves the bound socket, and rows owned by anyone else are tolerated as long as one row is ours. The token-authenticated handshake in connectBackground remains the identity proof, and a query returning no rows at all still reports listener_missing. Note: the GUI still shows the generic load message for a launch timeout; surfacing the check code to the user is a separate follow-up, not in this PR. Tests: new windows-background-security.test.ts pins the query and the row-matching order; 3 of its 5 tests fail against the old script. Full apps/desktop suite 108/108 pass; package typecheck and Biome clean.

…ner check

On some Windows builds the OS reports a listening socket with a wrong or
empty TCP state (0, 1, 6, or unmapped), so the owner check's State = 2
predicate matched 0 rows even though the socket was listening and accepting
connections. Startup then failed every time with listener_missing and the
GUI blamed machine load. The listener query no longer filters on State: a
row for the port owned by the process proves the bound socket, and rows
owned by anyone else are tolerated as long as one row is ours. The
token-authenticated handshake in connectBackground remains the identity
proof, and a query returning no rows at all still reports
listener_missing.

Fixes w01fb0ss#15.

Tests: new windows-background-security.test.ts pins the query and the
row-matching order; 3 of its 5 tests fail against the old script.
Full apps/desktop suite 108/108 pass; package typecheck and Biome clean.

Signed-off-by: Rajnish Mani Tiwari <76885104+rajnishmanitiwari@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 02:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@w01fb0ss w01fb0ss left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks — this is a real startup blocker on Windows 26300 (#15), and dropping the State = 2 filter is the right fix: the state column isn't identity evidence.

One change before merging: please keep rejecting rows owned by other processes. The client sends its token as the first message, so the pre-connect owner check is what stops a second listener on the same loopback port from receiving it. A TIME_WAIT leftover from a dead predecessor is reported as owned by the System Idle/System process (0 or 4), so tolerating those is enough:

$foreign = @($listener | Where-Object { $p = [int]$_['OwningProcess']; $p -ne $processId -and $p -ne 0 -and $p -ne 4 })
if ($foreign.Count -gt 0) { throw 'listener_identity_changed' }
if (@($listener | Where-Object { [int]$_['OwningProcess'] -eq $processId }).Count -eq 0) { throw 'listener_identity_changed' }

plus a test for "another process owns a row → rejected". I'll approve the CI run now.

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.

[Windows 11 26300] 0.0.3 startup check fails with listener_missing — OS misreports TCP listener state, check should not be fatal

3 participants