Skip to content

feat(transport): opt-in abort of the active turn on client disconnect (#7) - #10

Merged
thatswiftdev merged 1 commit into
mainfrom
wt/disconnect-abort
Oct 20, 2026
Merged

thatswiftdev merged 1 commit into
mainfrom
wt/disconnect-abort

Conversation

@thatswiftdev

Copy link
Copy Markdown
Contributor

Implements #7.

What

deps.abortOnDisconnect (default off) — when set, the messages route wires the turn's AbortController to the response stream: if the client vanishes before the answer is flushed (tab close, network drop), the turn aborts cleanly through the existing ABORTED path instead of running to its full wall budget. Proxied long-poll hosts stay safe on the default.

The seam (worth the comment)

  • req.raw's close fires when the request body completes — hooking it never fires on disconnect (first attempt, test-caught).
  • reply.raw's close + !writableEnded is the client-gone signal.
  • Map-identity guard (activeTurns.get(id) === ac) keeps the normal post-response close a no-op.

Tests

  • raw net socket POST → destroyed mid-hang → session flips to error (the abort landed through the transport catch).
  • flag off (control): the turn outlives the destroyed socket.

Gates: tsc 0 · 35 files / 200 passed / 5 skipped.

Composes with #9 (abort classification): a disconnect-aborted claude-cli turn will read ABORTED, not empty-answer-failed, once both merge.

…#7)

A client that vanishes mid-turn (tab close, network drop) previously
left the turn running to its full wall budget; only the explicit
/abort route ended it early. Now the messages route wires the turn's
AbortController to the RESPONSE stream: reply.raw 'close' while the
response is still unwritten (client gone before the answer flushed)
aborts the turn.

Seam notes (the first attempt taught the difference):
- req.raw 'close' fires when the REQUEST BODY completes — not socket
  death; hooking it never fired on disconnect.
- reply.raw 'close' + !writableEnded is the client-gone signal.
- A map-identity guard (activeTurns.get(id) === ac) makes the normal
  post-response close a no-op.

Opt-in: deps.abortOnDisconnect (default OFF) — proxied long-poll
deployments where socket close is routine must not trip it. Hosts
that serve browsers directly (Lionidas) turn it on.

Tests: raw net socket POST → destroy mid-hang → session flips to
error (abort landed); flag off → the turn outlives the destroyed
socket (control), cleaned up via /abort.

Gates: tsc 0; 35 files / 200 passed / 5 skipped.
@thatswiftdev
thatswiftdev merged commit 685090e into main Oct 20, 2026
1 check passed
@thatswiftdev
thatswiftdev deleted the wt/disconnect-abort branch October 20, 2026 05:13
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