Skip to content

feat(ai-ollama): enhance error handling in chatStream to emit RUN_ERROR events#862

Open
harshlocham wants to merge 2 commits into
TanStack:mainfrom
harshlocham:fix/ollama-prestream-run-error
Open

feat(ai-ollama): enhance error handling in chatStream to emit RUN_ERROR events#862
harshlocham wants to merge 2 commits into
TanStack:mainfrom
harshlocham:fix/ollama-prestream-run-error

Conversation

@harshlocham

@harshlocham harshlocham commented Jun 28, 2026

Copy link
Copy Markdown
Contributor
  • Added error handling in the OllamaTextAdapter's chatStream method to yield RUN_ERROR events instead of throwing errors directly.
  • Introduced utility functions to format error payloads and raw events for better error reporting.
  • Added a new test suite to verify the correct emission of RUN_ERROR events on chat stream rejections.

🎯 Changes

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved Ollama chat streaming behavior: pre-stream failures now emit a structured stream error event instead of throwing.
    • Error output includes clear details (message, code, and any available raw event data) for more consistent handling.
  • Tests
    • Added coverage to verify that when the chat request rejects before streaming starts, the adapter emits exactly one error event and does not raise an exception.

…OR events

- Added error handling in the OllamaTextAdapter's chatStream method to yield RUN_ERROR events instead of throwing errors directly.
- Introduced utility functions to format error payloads and raw events for better error reporting.
- Added a new test suite to verify the correct emission of RUN_ERROR events on chat stream rejections.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6e032a6a-43fc-470d-876a-f614678eb6dc

📥 Commits

Reviewing files that changed from the base of the PR and between 7f530ef and c494bd9.

📒 Files selected for processing (1)
  • .changeset/ollama-prestream-run-error.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/ollama-prestream-run-error.md

📝 Walkthrough

Walkthrough

OllamaTextAdapter.chatStream now emits a structured RUN_ERROR chunk instead of rethrowing pre-stream failures. The adapter uses shared run-error helpers, a test covers the rejection path, and the changeset documents the behavior change.

Changes

Structured error emission in chatStream

Layer / File(s) Summary
chatStream error handling and test
packages/ai-ollama/src/adapters/text.ts, packages/ai-ollama/tests/text-adapter.test.ts, .changeset/ollama-prestream-run-error.md
Adds run-error helper imports, changes the catch path to yield a RUN_ERROR chunk with message, code, optional rawEvent, and error, verifies the pre-stream rejection case emits one RUN_ERROR chunk, and updates the changeset notes.

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

Possibly related PRs

  • TanStack/ai#673: Shares the toRunErrorRawEvent / RUN_ERROR error-shaping pattern used by this Ollama adapter change.

Suggested reviewers: AlemTuzlak

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing substantive content under Changes and does not complete the required Release Impact selection. Fill in the Changes section with a brief summary and motivation, and mark the correct Release Impact option for the included changeset.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly names the ai-ollama chatStream error-handling change and the emitted RUN_ERROR events.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@nx-cloud

nx-cloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit c494bd9

Command Status Duration Result
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-01 11:16:47 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

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

@tanstack/ai-acp

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

@tanstack/ai-angular

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

@tanstack/ai-anthropic

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

@tanstack/ai-bedrock

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

@tanstack/ai-claude-code

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

@tanstack/ai-client

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

@tanstack/ai-code-mode

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

@tanstack/ai-code-mode-skills

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

@tanstack/ai-codex

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

@tanstack/ai-devtools-core

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

@tanstack/ai-elevenlabs

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

@tanstack/ai-event-client

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

@tanstack/ai-fal

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

@tanstack/ai-gemini

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

@tanstack/ai-grok

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

@tanstack/ai-grok-build

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

@tanstack/ai-groq

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

@tanstack/ai-isolate-cloudflare

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

@tanstack/ai-isolate-node

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

@tanstack/ai-isolate-quickjs

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

@tanstack/ai-mcp

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

@tanstack/ai-mistral

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

@tanstack/ai-ollama

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

@tanstack/ai-openai

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

@tanstack/ai-opencode

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

@tanstack/ai-openrouter

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

@tanstack/ai-preact

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

@tanstack/ai-react

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

@tanstack/ai-react-ui

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

@tanstack/ai-sandbox

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

@tanstack/ai-sandbox-cloudflare

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

@tanstack/ai-sandbox-daytona

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

@tanstack/ai-sandbox-docker

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

@tanstack/ai-sandbox-local-process

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

@tanstack/ai-sandbox-sprites

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

@tanstack/ai-sandbox-vercel

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

@tanstack/ai-solid

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

@tanstack/ai-solid-ui

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

@tanstack/ai-svelte

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

@tanstack/ai-utils

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

@tanstack/ai-vue

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

@tanstack/ai-vue-ui

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

@tanstack/openai-base

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

@tanstack/preact-ai-devtools

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

@tanstack/react-ai-devtools

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

@tanstack/solid-ai-devtools

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

commit: c494bd9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants