Skip to content

desk-hub stand-in: a client's reset mid-upgrade no longer ends the local hub (provision.test flake) - #291

Merged
SSFSKIM merged 2 commits into
masterfrom
p5-o14-provision-flake
Oct 28, 2026
Merged

SSFSKIM merged 2 commits into
masterfrom
p5-o14-provision-flake

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Fixes the test/endpoint/provision.test.ts flake on the Linux pool (the 2026-10-28 P5 O14 row of docs/tech-debt-tracker.md; runs 40669200856 and 40690529203, unit 4 of 4, on branches that do not touch it).

Cause

The local hub did not die on its own: apps/desk-hub/local/run.ts threw. Node's HTTP server takes its own error listener off a socket before it emits upgrade, and the stand-in's proxy (apps/desk-hub/local/proxy.ts) added one only once the hub had upgraded. A client that reset its connection before then, or at any point on a refusal, raised an unhandled 'error' event (read ECONNRESET, or write EPIPE) and ended the whole process. Every later request then met ECONNREFUSED.

The suite does this in one place. In retire › reconciles a DELETE the hub completed whose answer was lost, the restarted endpoint still holds a service token that the hub has already deleted. Its hub link's upgrade is refused 401, and the retire's unenroll calls HubLink.stop() while that refusal can still sit unread, which resets the socket. The suite always dies at the same point: that case passes, and the next one (is refused on an attended enrollment) fails on its first request with ECONNRESET, followed by six ECONNREFUSED failures. That is the signature of both pool runs.

Evidence:

  • Reproduced locally with the hub's own output. I added temporary instrumentation that logs each upgrade and reports the runner's exit. The suite failed with the same 7 cases. A 401-refused /machine/socket upgrade was the last one in flight, and the runner died with Unhandled 'error' event … Error: read ECONNRESET at TCP.onStreamRead.
  • The unfixed tree, uninstrumented, under load: 1 of 20 runs failed (4 concurrent copies beside 6 busy-loop processes), with the same 7 cases and the same exit. 10 runs alone all passed, which is why it shows up as a rare flake.
  • The mechanism on its own: a ws client, the endpoint's socket library, closed while its upgrade is being refused kills the runner. So does a raw client's reset. The same check, run outside vitest in a node:22-slim container on Linux and on macOS, gave the same result on both:
    • Old proxy: 5 of 5 resets after the refusal and 5 of 5 resets before the answer were uncaught, and a reset before the hub upgraded left the hub's side open.
    • New proxy: no uncaught errors, and the hub's side closed.

Fix

  • apps/desk-hub/local/proxy.ts: the upgrade handler owns the socket's errors from the start. The socket's close now ends the hub's side whether or not the hub has upgraded, so a client gone mid-handshake leaves no upgrade open behind it. If the client is already gone after admission, the upgrade is not forwarded at all. Deployed Access drops the connection here and nothing more; the stand-in now does the same.
  • apps/desk-hub/test/proxy.test.ts (new): tests the proxy in front of a hub double. A client that resets once refused, one that resets before it is answered, and one that resets before or after the hub upgraded. Against the old handler it reports 11 uncaught errors and a hub side left open.
  • test/endpoint/local-hub.ts: an unasked exit of the local hub now prints its tail of output, so a death mid-suite says why. Both pool failures had only ECONNREFUSED to show.

The fix is not a retry, and the test's cases and assertions are unchanged. The endpoint's behaviour, aborting an in-flight handshake on stop, is legitimate client behaviour and stays as it is.

Verification

  • Gate: ci-gate --gates static,unit,probes --runner macos --class1a pool, run 40694837226, green (static, unit 1–4/4, probes). provision.test.ts and proxy.test.ts both ran in unit 4/4 on the pool. No hosted e2e groups: the change touches none of src/endpoint, apps/desk-hub/src or desk-web.
  • 20 consecutive local runs under the shard's load: provision.test.ts passed in all 20, and the local hub never died. Each run took the gate's unit 4/4 file set, all 499 files together, at --maxWorkers=8 as the pool runs them. The same harness on the unfixed tree had already failed once in 20 loaded runs, as described above. Separately, src/main/files/service.test.ts > cuts a listing at the cap with truncated hit its 5 s timeout in 8 of the 20 local runs. That is this Mac's load and unrelated to this change: the file is untouched here and passed in the gate's unit 4/4.
  • Review: doperpowers:reviewer-medium, no material findings.

The tracker row's exit ("the cause is found and fixed") is met; the row can go when this lands.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)

…cal hub

Node's HTTP server takes its own error listener off a socket before it
emits 'upgrade'; the stand-in's proxy added one only once the hub had
upgraded. A client that reset its connection before then (and on a
refusal, at any point) threw an unhandled 'error' event and ended
local/run.ts, so every later request met ECONNREFUSED. In
test/endpoint/provision.test.ts the retire case that reconciles a lost
DELETE does exactly this: the restarted endpoint's hub link is refused
401 under the dead service token, and the retire's unenroll stops the
link while that refusal can still sit unread, which resets the socket.
That is the death seen on the pool (runs 40669200856, 40690529203) and
reproduced locally with the hub's own output: "Unhandled 'error' event,
read ECONNRESET".

The upgrade handler now owns the socket's errors from the start, and the
socket's close ends the hub's side whether or not the hub has upgraded,
so a client gone mid-handshake leaves no upgrade open behind it.
apps/desk-hub/test/proxy.test.ts holds the proxy to it (11 uncaught
errors against the old handler). The endpoint suites' local hub now
reports an unasked exit with its output, so a death mid-suite says why.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T13:28:50.161830Z 2753c92 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
@SSFSKIM
SSFSKIM merged commit 258b136 into master Oct 28, 2026
SSFSKIM added a commit that referenced this pull request Oct 28, 2026
…291); its tracker row closes

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
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