Skip to content

transport: accept external abort signal in newTurn#38

Merged
mschristensen merged 3 commits intomainfrom
fix/AIT-663
Apr 14, 2026
Merged

transport: accept external abort signal in newTurn#38
mschristensen merged 3 commits intomainfrom
fix/AIT-663

Conversation

@JoaoDiasAbly
Copy link
Copy Markdown
Contributor

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.

@JoaoDiasAbly JoaoDiasAbly requested review from a team and ttypic and removed request for a team April 13, 2026 10:04
@mschristensen mschristensen self-requested a review April 14, 2026 15:46
@mschristensen
Copy link
Copy Markdown
Collaborator

@JoaoDiasAbly I've simplified this a bit by using AbortSignal.any(). LMK what you think and I'll approve and merge 672ce66

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 14, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 92.89% 2015 / 2169
🔵 Statements 91.09% 2158 / 2369
🔵 Functions 93.83% 365 / 389
🔵 Branches 78.33% 911 / 1163
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/core/transport/server-transport.ts 93.67% 70.93% 90.47% 94.03% 92-99, 181, 218-236
src/core/transport/types.ts 0% 0% 0% 0%
Generated in workflow #118 for commit 9aef9b2 by the Vitest Coverage Report Action

@github-actions github-actions bot temporarily deployed to staging/pull/38/typedoc April 14, 2026 15:52 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/38/typedoc April 14, 2026 16:02 Inactive
@JoaoDiasAbly
Copy link
Copy Markdown
Contributor Author

@JoaoDiasAbly I've simplified this a bit by using AbortSignal.any(). LMK what you think and I'll approve and merge 672ce66

wasn't aware of AbortSignal.any - definitely cleaner! It's a ✅ from me

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>
@mschristensen mschristensen enabled auto-merge (rebase) April 14, 2026 20:29
@github-actions github-actions bot temporarily deployed to staging/pull/38/typedoc April 14, 2026 20:30 Inactive
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).
@mschristensen mschristensen merged commit 173e87b into main Apr 14, 2026
12 checks passed
@mschristensen mschristensen deleted the fix/AIT-663 branch April 14, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants