You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Think: expose the turn's AbortSignal to beforeTurn #2309
Think.beforeTurn(ctx) may await I/O or a model call before streamText starts. If the user stops the turn during that wait, the hook has no way to observe the cancellation: TurnContext does not expose an AbortSignal. The turn can therefore remain in preparation until the awaited work finishes or times out.
Optional matches TurnInput.signal? and preserves callers without a signal. A subclass can pass it to abortable I/O, stop waiting promptly, and return from beforeTurn at a safe boundary. Some preparation writes should finish atomically, so exposing the signal is more useful than automatically racing and abandoning the entire hook. This request is for the in-process subclass hook; it does not require sending an AbortSignal through extension RPC snapshots.
Use case
We currently carry this one-field patch on @cloudflare/think@0.17.0. Our beforeTurn may wait for image-history previews (up to 8 seconds) or a history-summary model call (up to 30 seconds). Before the patch, Stop could not interrupt those waits. With the signal threaded through the waits, a local full-stack test using the real WebSocket cancel frame ended the two stopped turns in 7 ms and 29 ms, and both conversations handled a subsequent turn normally.
Related: #2240 also requests a field on TurnContext, but for request correlation rather than cancellation.
I implemented this as a small patch on my fork: compare the branch against main (commit). It exposes input.signal as optional TurnContext.abortSignal, documents its use in beforeTurn, and adds a Workers regression test that cancels during the hook and verifies a later turn still succeeds.
Validation passed: Think build, all 229 tests in think-session.test.ts, Think typecheck, repository formatting, and lint. The full pnpm run check stops at check:exports because my filtered install has no build outputs for three unrelated packages.
I tried to open a PR, but GitHub says this repository limits PR creation to collaborators. If a maintainer can open a PR from this branch or enable PR creation for my account, I'm happy to follow through with review.
Activity
banchichen commentedon Sep 21, 2026
I implemented this as a small patch on my fork: compare the branch against
main(commit). It exposesinput.signalas optionalTurnContext.abortSignal, documents its use inbeforeTurn, and adds a Workers regression test that cancels during the hook and verifies a later turn still succeeds.Validation passed: Think build, all 229 tests in
think-session.test.ts, Think typecheck, repository formatting, and lint. The fullpnpm run checkstops atcheck:exportsbecause my filtered install has no build outputs for three unrelated packages.I tried to open a PR, but GitHub says this repository limits PR creation to collaborators. If a maintainer can open a PR from this branch or enable PR creation for my account, I'm happy to follow through with review.
feat(think): expose the running turn's identity to hooks and tools (#…