Skip to content

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

Merged
w01fb0ss merged 2 commits into
w01fb0ss:mainfrom
rajnishmanitiwari:fix/windows-listener-state-tolerance
Nov 26, 2026
Merged

w01fb0ss merged 2 commits into
w01fb0ss:mainfrom
rajnishmanitiwari:fix/windows-listener-state-tolerance

Conversation

@rajnishmanitiwari

Copy link
Copy Markdown
Contributor

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.

The owner check now rejects a listener row owned by any process other
than the background process, except the System Idle/System process
(0 or 4): a second listener on the same loopback port would otherwise
receive the token the client sends as its first message, and the
pre-connect owner check is what stops that. A TIME_WAIT leftover from
a dead predecessor is reported under PID 0 or 4, so tolerating those
is enough. Addresses the review on w01fb0ss#26.

Tests: new tests pin the foreign-row rejection and the System-process
tolerance; 3 of 7 fail with the fix reverted. Full apps/desktop suite
110/110 pass; package typecheck and Biome clean.

Signed-off-by: Rajnish Mani Tiwari <76885104+rajnishmanitiwari@users.noreply.github.com>
@w01fb0ss

Copy link
Copy Markdown
Owner

Thanks for the quick update — rejecting rows owned by other processes is exactly what we needed, and tolerating PID 0/4 for TIME_WAIT leftovers makes sense. Could you update the PR description (it still says rows owned by anyone else are tolerated)? Merging once CI is green; this will ship in v0.0.4.

@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.

Approved: the listener check no longer depends on the TCP state column and still rejects other processes' rows.

@w01fb0ss
w01fb0ss merged commit 5cf8a36 into w01fb0ss:main Nov 26, 2026
6 of 7 checks passed
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