Summary#
ChatClient.dispose() does not abort pending client-tool work or invalidate pending continuations. If a deferred .client() tool resolves after a Solid 2 chat is unmounted or its thread is replaced, it can trigger another request on the disposed client and old thread.
Update the shared client teardown in packages/ai-client/src/chat-client.ts to abort client-tool work and invalidate continuations. Review the Solid 2 cleanup in packages/ai-solid2/src/use-chat.ts as needed. Do not use stop() as a disposal substitute: it can cancel durable server runs.
Acceptance criteria#
- Disposing a
ChatClient aborts the signal passed to pending client tools and prevents late tool results from starting a continuation or another request.
- Regression tests cover deferred client-tool completion after Solid 2 unmount and thread replacement. They verify the tool signal and the absence of a request on the disposed client.
- Shared-client regression tests cover disposal with pending client-tool work, including a tool that resolves after abort.
- Disposal preserves durable server runs and does not invoke server-run cancellation.
Requested by @coolRoger.
Pull request: https://github.com/TanStack/ai/pull/2143
Review comment: https://github.com/TanStack/ai/pull/2143#discussion_r4547143811