mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-20 19:06:22 +00:00
Wire the AI SDK's abortSignal into the tool fiber via runPromiseExit's signal option so interruption is first-class, and move the "finalize on cancel" path into an Effect.onInterrupt finalizer that re-awaits the still-running native Promise uninterruptibly, builds the output, and posts it through completeToolCall. Replaces the imperative `if (options.abortSignal?.aborted)` tail check with structural interruption handling. When the fiber is interrupted, the finalizer captures the truncated bash output (or MCP tool result) and the .then on runPromiseExit resolves the SDK's Promise with the captured value instead of propagating the interrupt cause as a rejection, so the tool is reported as successfully completed rather than as a tool-error. InstanceRef is provided on the tool fiber so InstanceState.context resolves through ServiceMap rather than falling through to the AsyncLocalStorage, which the onInterrupt finalizer runs outside of.