feat: AbortSignal support across session and core (closes #60)#61
Merged
feat: AbortSignal support across session and core (closes #60)#61
Conversation
…send/stream
Threads an optional AbortSignal from Session.send / Session.stream (and
MainSession variants) through to LLMAdapter.complete / LLMAdapter.stream.
Built-in OpenAI and Anthropic adapters forward the signal to their SDK
request options. Aborting cancels the in-flight LLM call with a standard
DOMException('aborted', 'AbortError') and skips L3 persistence entirely
(both user and assistant records are dropped — atomic with non-stream
behavior, no partial messages polluting context).
Bumps @stello-ai/session 0.6.0 → 0.7.0 (additive; existing callers
unaffected). Closes part A of #60.
… runtime
Adds signal threading across the entire turn lifecycle:
- TurnRunnerOptions.signal — tool loop checks throwIfAborted() at every
round boundary, before each tool call, and after each tool result is
collected (suppresses phantom onToolResult after cancel).
- TurnRunnerSession.send/stream and EngineRuntimeSession.send/stream
accept { signal? }; runStream short-circuits when the signal is already
aborted, otherwise forwards to session.stream and re-throws AbortError
from the iterator instead of silently closing.
- TurnRunnerToolExecutor.executeTool gains an options object carrying the
signal; ToolExecutionContext.signal lets individual tools opt-in to
honoring cancellation for long-running work (tools that ignore it still
work — the runner aborts at the next round boundary).
- SessionCompatible and adaptSessionToEngineRuntime forward the signal to
the underlying @stello-ai/session contract.
- Engine.turn / Engine.stream / Orchestrator / StelloAgent passthrough
preserves signal via TurnRunnerOptions spread; no field stripping.
Bumps @stello-ai/core 0.7.2 → 0.8.0 (additive). Closes part B of #60.
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.
Summary
Threads an optional
AbortSignalfrom host throughSession.send/streamandTurnRunnerall the way down to the LLM call, with checkpoints at every round boundary in the tool loop. Closes #60.LLMCompleteOptions.signal,SessionSendOptionsforSessionandMainSession. Built-in OpenAI / Anthropic adapters forward to SDK request options. Aborted calls reject withDOMException('aborted', 'AbortError')and write no L3 (both user and assistant records dropped — atomic with non-stream behavior).TurnRunnerOptions.signal,TurnRunnerSession.send/stream+EngineRuntimeSession.send/streamaccept{ signal? },TurnRunnerToolExecutor.executeToolgains options arg,ToolExecutionContext.signalfor tools to opt-in.run/finishFromStreamResultcallthrowIfAborted()between rounds, before each tool call, and after each tool result is collected (suppresses phantomonToolResult).runStreamshort-circuits on already-aborted signal and re-throwsAbortErrorfrom the iterator.SessionCompatibleandadaptSessionToEngineRuntimeforward through. Engine / Orchestrator / Agent passthrough preserves signal via existingTurnRunnerOptionsspread.All changes are additive — existing callers unaffected, no breaking changes.
Open-question decisions
send, noMessagemetadata bloat, host already received chunks via the iterator).onToolResultordering on abort: suppress callback if signal aborts after tool result is collected — host bookkeeping stays consistent.ctx.signal: runner waits for the in-flight tool to return, then throws on the next round boundary. Documented at the tool runtime contract.Test plan
@stello-ai/session— 6 new tests inabort.test.ts(send abort + reject, no L3; pre-aborted signal short-circuits; signal forwarded to adapter; stream mid-flight abort; pre-aborted stream rejects; signal forwarded to adapter.stream). Plus 1 added assertion inopenai-compatible.test.tsfor SDK signal forwarding. 134 passed.@stello-ai/core— 5 new tests inturn-runner-abort.test.ts(round-boundary abort, pre-aborted, signal threading; runStream mid-stream abort, pre-aborted runStream). 2 new tests insession-runtime.test.ts(signal forwarding through adapter for both send and stream). 1 new e2e test instello-agent.test.ts(agent.stream({ signal })aborts iterator + result). Existing assertions updated for new call signatures. 282 passed.pnpm -r test: 431 passed across session/core/devtools.pnpm -r build: green.Release
Stello uses manual git-tag releases (no Changesets / Version PR flow). Maintainer publishes manually after merge.