Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-ollama): forward the caller's abort signal to the Ollama request #1708

MergedArVaViT(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/1708/headmerged by AlemTuzlak View on GitHub

Aborting a chat() run on the Ollama adapter now cancels the request to Ollama, for both streaming and structured output.

🎯 Changes

  • OllamaTextAdapter gives each call a client whose fetch carries the caller's abort signal (options.request.signal). It reuses the per-call client that wrapFetch already builds, and the wrapper still runs and sees the signal.
  • Tests in packages/ai-ollama/tests/abort-signal-wire.test.ts.
  • docs/adapters/ollama.md: an adapter with your own Ollama client ignores the abort signal, as it already ignores wrapFetch.
  • A patch changeset for @tanstack/ai-ollama.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

pnpm run test:pr was not run. The checks it covers for this change are listed under Testing.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Root cause

Issue. abortController.abort() on a chat() run with the Ollama adapter leaves the HTTP request open until Node's headers timeout (300 s). Ollama keeps generating, and the process cannot exit.

Cause. The engine passes the caller's signal to the adapter as request.signal, but the adapter called client.chat() without it. ollama 0.6 takes no per-call signal. Its own stream signal only backs AbortableAsyncIterator.abort() and client.abort(), which exist once the response headers arrive, and the non-streaming call has no signal at all.

Fix. The fetch of the per-call client sets the caller's signal on every request. That covers the wait for headers, the streamed body and the structured output call. On this private per-call client, nothing can reach ollama's own stream signal, so replacing it loses nothing. Without a signal or wrapFetch, the adapter uses its shared client as before.

Testing

  • abort-signal-wire.test.ts runs the real ollama client against a fetch that never answers: chat() streaming and chat({ outputSchema }) both end when the caller aborts, and wrapFetch still runs on a call with a signal. All three fail on main.
  • The issue's scenario against a local HTTP server that never answers: the socket now closes 4 ms (stream) and 1 ms (structured output) after the abort. On main it stays open.
  • @tanstack/ai-ollama: 67 tests pass, with tsc, oxlint --type-aware, publint --strict and knip. kiira check and scripts/verify-links.ts pass.

Linked issues

Closes #1644

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Aborting a chat now cancels in-flight Ollama requests for both streaming and structured output.
    • Request cancellation can be used alongside wrapFetch.
  • Documentation
    • Clarified that custom Ollama clients do not use wrapFetch or the request abort signal.
    1. 🦋 Changeset detected

      Latest commit: 8bea6d30661c52ba4a28aa80067ef9c1ee32ad49

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 1 package
      NameType
      @tanstack/ai-ollamaPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: TanStack/ai/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: dc887bc0-5c15-4de4-8d86-6c4d98cf3eab

      📥 Commits

      Reviewing files that changed from the base of the PR and between c97ae8c270836decf1c8c0ec15f7422a227db88d and 8bea6d30661c52ba4a28aa80067ef9c1ee32ad49.


      📒 Files selected for processing (5)
      • .changeset/ollama-forward-abort-signal.md
      • docs/adapters/ollama.md
      • docs/config.json
      • packages/ai-ollama/src/adapters/text.ts
      • packages/ai-ollama/tests/abort-signal-wire.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.



      📝 Walkthrough

      Walkthrough

      The Ollama adapter now forwards request abort signals to fetch for streaming and structured-output requests. It also applies wrapFetch when a request signal is supplied. Documentation describes the custom-client exception.

      Changes

      Ollama request cancellation

      Layer / File(s)Summary
      Forward request signals through Ollama fetch
      packages/ai-ollama/src/adapters/text.ts, packages/ai-ollama/tests/abort-signal-wire.test.ts, docs/adapters/ollama.md, .changeset/ollama-forward-abort-signal.md, docs/config.json
      clientFor accepts request options and creates a per-call client when client configuration exists and either wrapFetch or a signal is supplied. Streaming and structured-output requests pass their options to it. Tests cover cancellation on both paths and confirm wrapFetch is invoked with a signal. Documentation describes the custom-client exception, and a patch changeset and documentation date are updated.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~12 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: alemtuzlak


      Merge Risk: ⚪ Minimal · up to 8bea6

      No concrete issue has been identified that should block this change from merging after normal checks.

      Pre-merge checks | Passed 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: forwarding the caller's abort signal to Ollama requests.
      Description checkPassedThe description follows the required template, explains the root cause and fix, documents testing and release impact, links the issue, and includes the changeset and documentation updates. It clearly …
      Linked Issues checkPassedIssue [#1644] requires caller aborts to cancel Ollama HTTP requests for streaming and structured output. packages/ai-ollama/src/adapters/text.ts now creates a per-call Ollama client when adapter con…
      Out of Scope Changes checkPassedThe changes stay within issue [#1644]. The source change implements signal forwarding. The tests verify the required behavior and preserve wrapFetch. The Ollama documentation records the behavior fo…
      Docstring CoveragePassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share

      Comment `@coderabbitai help` to get the list of available commands.
    3. Thanks for the PR, @ArVaViT! 🙌 @AlemTuzlak will take a look.

      Automated pre-review checks

      • ✅ CI passing
      • ✅ No merge conflicts
      • ✅ Changeset present
      • ⚠️ No E2E test changes detected — behavior changes need coverage under testing/e2e/ (see CONTRIBUTING)
      Automated triage — a human review follows.
    4. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

    5. AlemTuzlak approved these changes

    6. View your CI Pipeline Execution ↗ for commit 8bea6d30661c52ba4a28aa80067ef9c1ee32ad49


      ☁️ Nx Cloud last updated this comment at 2026-10-12 06:18:46 UTC

    7. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 8bea6d30661c52ba4a28aa80067ef9c1ee32ad49

      CommandStatusDurationResult
      nx run-many --targets=build --exclude=examples/...✅ Succeeded6sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-10-12 06:18:56 UTC

    8. Open in StackBlitz

      @tanstack/ai

      npm i https://pkg.pr.new/@tanstack/ai@1708

      @tanstack/ai-acp

      npm i https://pkg.pr.new/@tanstack/ai-acp@1708

      @tanstack/ai-angular

      npm i https://pkg.pr.new/@tanstack/ai-angular@1708

      @tanstack/ai-anthropic

      npm i https://pkg.pr.new/@tanstack/ai-anthropic@1708

      @tanstack/ai-bedrock

      npm i https://pkg.pr.new/@tanstack/ai-bedrock@1708

      @tanstack/ai-byteplus

      npm i https://pkg.pr.new/@tanstack/ai-byteplus@1708

      @tanstack/ai-claude-code

      npm i https://pkg.pr.new/@tanstack/ai-claude-code@1708

      @tanstack/ai-client

      npm i https://pkg.pr.new/@tanstack/ai-client@1708

      @tanstack/ai-cloudflare

      npm i https://pkg.pr.new/@tanstack/ai-cloudflare@1708

      @tanstack/ai-code-mode

      npm i https://pkg.pr.new/@tanstack/ai-code-mode@1708

      @tanstack/ai-code-mode-snippets

      npm i https://pkg.pr.new/@tanstack/ai-code-mode-snippets@1708

      @tanstack/ai-codex

      npm i https://pkg.pr.new/@tanstack/ai-codex@1708

      @tanstack/ai-cohere

      npm i https://pkg.pr.new/@tanstack/ai-cohere@1708

      @tanstack/ai-compaction

      npm i https://pkg.pr.new/@tanstack/ai-compaction@1708

      @tanstack/ai-devtools-core

      npm i https://pkg.pr.new/@tanstack/ai-devtools-core@1708

      @tanstack/ai-durable-stream

      npm i https://pkg.pr.new/@tanstack/ai-durable-stream@1708

      @tanstack/ai-elevenlabs

      npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@1708

      @tanstack/ai-event-client

      npm i https://pkg.pr.new/@tanstack/ai-event-client@1708

      @tanstack/ai-fal

      npm i https://pkg.pr.new/@tanstack/ai-fal@1708

      @tanstack/ai-gemini

      npm i https://pkg.pr.new/@tanstack/ai-gemini@1708

      @tanstack/ai-grok

      npm i https://pkg.pr.new/@tanstack/ai-grok@1708

      @tanstack/ai-grok-build

      npm i https://pkg.pr.new/@tanstack/ai-grok-build@1708

      @tanstack/ai-groq

      npm i https://pkg.pr.new/@tanstack/ai-groq@1708

      @tanstack/ai-isolate-cloudflare

      npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@1708

      @tanstack/ai-isolate-daytona

      npm i https://pkg.pr.new/@tanstack/ai-isolate-daytona@1708

      @tanstack/ai-isolate-e2b

      npm i https://pkg.pr.new/@tanstack/ai-isolate-e2b@1708

      @tanstack/ai-isolate-node

      npm i https://pkg.pr.new/@tanstack/ai-isolate-node@1708

      @tanstack/ai-isolate-quickjs

      npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@1708

      @tanstack/ai-isolate-quickjs-bun

      npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs-bun@1708

      @tanstack/ai-llmgateway

      npm i https://pkg.pr.new/@tanstack/ai-llmgateway@1708

      @tanstack/ai-lovable

      npm i https://pkg.pr.new/@tanstack/ai-lovable@1708

      @tanstack/ai-mcp

      npm i https://pkg.pr.new/@tanstack/ai-mcp@1708

      @tanstack/ai-memory

      npm i https://pkg.pr.new/@tanstack/ai-memory@1708

      @tanstack/ai-mistral

      npm i https://pkg.pr.new/@tanstack/ai-mistral@1708

      @tanstack/ai-octane

      npm i https://pkg.pr.new/@tanstack/ai-octane@1708

      @tanstack/ai-ollama

      npm i https://pkg.pr.new/@tanstack/ai-ollama@1708

      @tanstack/ai-ollaya

      npm i https://pkg.pr.new/@tanstack/ai-ollaya@1708

      @tanstack/ai-openai

      npm i https://pkg.pr.new/@tanstack/ai-openai@1708

      @tanstack/ai-opencode

      npm i https://pkg.pr.new/@tanstack/ai-opencode@1708

      @tanstack/ai-openrouter

      npm i https://pkg.pr.new/@tanstack/ai-openrouter@1708

      @tanstack/ai-perplexity

      npm i https://pkg.pr.new/@tanstack/ai-perplexity@1708

      @tanstack/ai-persistence

      npm i https://pkg.pr.new/@tanstack/ai-persistence@1708

      @tanstack/ai-preact

      npm i https://pkg.pr.new/@tanstack/ai-preact@1708

      @tanstack/ai-react

      npm i https://pkg.pr.new/@tanstack/ai-react@1708

      @tanstack/ai-react-ui

      npm i https://pkg.pr.new/@tanstack/ai-react-ui@1708

      @tanstack/ai-reactor

      npm i https://pkg.pr.new/@tanstack/ai-reactor@1708

      @tanstack/ai-remix

      npm i https://pkg.pr.new/@tanstack/ai-remix@1708

      @tanstack/ai-sandbox

      npm i https://pkg.pr.new/@tanstack/ai-sandbox@1708

      @tanstack/ai-sandbox-blaxel

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-blaxel@1708

      @tanstack/ai-sandbox-boxd

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-boxd@1708

      @tanstack/ai-sandbox-cloudflare

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-cloudflare@1708

      @tanstack/ai-sandbox-daytona

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-daytona@1708

      @tanstack/ai-sandbox-docker

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-docker@1708

      @tanstack/ai-sandbox-e2b

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-e2b@1708

      @tanstack/ai-sandbox-local-process

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-local-process@1708

      @tanstack/ai-sandbox-railway

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-railway@1708

      @tanstack/ai-sandbox-sprites

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-sprites@1708

      @tanstack/ai-sandbox-upstash-box

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-upstash-box@1708

      @tanstack/ai-sandbox-vercel

      npm i https://pkg.pr.new/@tanstack/ai-sandbox-vercel@1708

      @tanstack/ai-skills

      npm i https://pkg.pr.new/@tanstack/ai-skills@1708

      @tanstack/ai-solid

      npm i https://pkg.pr.new/@tanstack/ai-solid@1708

      @tanstack/ai-solid-ui

      npm i https://pkg.pr.new/@tanstack/ai-solid-ui@1708

      @tanstack/ai-svelte

      npm i https://pkg.pr.new/@tanstack/ai-svelte@1708

      @tanstack/ai-typesafe

      npm i https://pkg.pr.new/@tanstack/ai-typesafe@1708

      @tanstack/ai-utils

      npm i https://pkg.pr.new/@tanstack/ai-utils@1708

      @tanstack/ai-vercel-gateway

      npm i https://pkg.pr.new/@tanstack/ai-vercel-gateway@1708

      @tanstack/ai-vertex

      npm i https://pkg.pr.new/@tanstack/ai-vertex@1708

      @tanstack/ai-vue

      npm i https://pkg.pr.new/@tanstack/ai-vue@1708

      @tanstack/ai-vue-ui

      npm i https://pkg.pr.new/@tanstack/ai-vue-ui@1708

      @tanstack/ai-worldlabs

      npm i https://pkg.pr.new/@tanstack/ai-worldlabs@1708

      @tanstack/openai-base

      npm i https://pkg.pr.new/@tanstack/openai-base@1708

      @tanstack/preact-ai-devtools

      npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@1708

      @tanstack/react-ai-devtools

      npm i https://pkg.pr.new/@tanstack/react-ai-devtools@1708

      @tanstack/solid-ai-devtools

      npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@1708

      @tanstack/svelte-ai-devtools

      npm i https://pkg.pr.new/@tanstack/svelte-ai-devtools@1708

      commit: 8bea6d3

    9. AlemTuzlak merged this501bbad

    10. AlemTuzlak closed this

Sign in to join this conversation.