transport: accept external abort signal in newTurn#38
Merged
mschristensen merged 3 commits intomainfrom Apr 14, 2026
Merged
Conversation
Collaborator
|
@JoaoDiasAbly I've simplified this a bit by using |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||
672ce66 to
c9bc35e
Compare
Contributor
Author
wasn't aware of |
Allow server-side route handlers to pass an external AbortSignal (e.g. req.signal) into newTurn via the new `signal` option. When the signal fires — due to client disconnect or serverless function timeout — the turn's internal AbortController is aborted through the same path as Ably cancel messages, stopping LLM generation and stream piping. The listener is cleaned up on both end() and close() to avoid leaks. Tests cover: signal abort, pre-aborted signal, in-flight stream cancellation, listener cleanup on end() and close(), and non-interference with Ably cancel routing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c9bc35e to
a97dd49
Compare
mschristensen
approved these changes
Apr 14, 2026
The external signal support added in 46744a4 manually managed an abort event listener and cleanup function to link req.signal to the internal controller. AbortSignal.any() does this in a single line and the platform handles lifetime — no listener, no cleanup, no cleanupExternalSignal field on RegisteredTurn. Removes two tests that asserted removeEventListener was called, since there is no manual listener to remove. The five behavioral tests (signal fires, already-aborted, start rejection, in-flight stream cancellation, Ably cancel independence) are unchanged.
Add documentation for the `signal` option on `newTurn()`, which lets the server pass `req.signal` to abort turns on request cancellation or serverless function timeout. Updates cancel feature page (new section), turns concept page (abort signal section), and server transport internals (newTurn description).
a97dd49 to
9aef9b2
Compare
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.
Allow server-side route handlers to pass an external AbortSignal (e.g. req.signal) into newTurn via the new
signaloption. When the signal fires — due to client disconnect or serverless function timeout — the turn's internal AbortController is aborted through the same path as Ably cancel messages, stopping LLM generation and stream piping.The listener is cleaned up on both end() and close() to avoid leaks.
Tests cover: signal abort, pre-aborted signal, in-flight stream cancellation, listener cleanup on end() and close(), and non-interference with Ably cancel routing.