Repository navigation
feat(transport): opt-in abort of the active turn on client disconnect (#7) - #10
Merged
Merged
Conversation
…#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #7.
What
deps.abortOnDisconnect(default off) — when set, the messages route wires the turn'sAbortControllerto 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'sclosefires when the request body completes — hooking it never fires on disconnect (first attempt, test-caught).reply.raw'sclose+!writableEndedis the client-gone signal.activeTurns.get(id) === ac) keeps the normal post-response close a no-op.Tests
netsocket POST → destroyed mid-hang → session flips toerror(the abort landed through the transport catch).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.