Skip to content

fix: content chunk issue fix#272

Merged
AlemTuzlak merged 1 commit intomainfrom
chore/fix-content-chunk
Feb 7, 2026
Merged

fix: content chunk issue fix#272
AlemTuzlak merged 1 commit intomainfrom
chore/fix-content-chunk

Conversation

@AlemTuzlak
Copy link
Contributor

@AlemTuzlak AlemTuzlak commented Feb 7, 2026

🎯 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
    • Fixed an issue with delta handling in message streaming to properly manage undefined values and prevent concatenation errors.
    • Made the delta property optional in text message content events, allowing full content to be provided without incremental delta updates.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

This PR addresses a delta handling issue in the chat stream processor by making the delta property optional in the TextMessageContentEvent interface, adding defensive checks to guard against undefined/empty values during content concatenation, and introducing comprehensive test coverage for various delta/content scenarios.

Changes

Cohort / File(s) Summary
Changeset
.changeset/fifty-dingos-mate.md
Patch release changelog entry documenting the fix for delta handling.
Type Definitions
packages/typescript/ai/src/types.ts
Made delta property optional in TextMessageContentEvent interface and updated documentation to reflect that delta may be undefined when only content is provided.
Stream Processing Logic
packages/typescript/ai/src/activities/chat/stream/processor.ts
Added guards to check delta and content for undefined/empty values before concatenation, preventing potential undefined-string issues and clarifying precedence when delta is absent.
Test Suite
packages/typescript/ai/tests/stream-processor.test.ts
Added comprehensive test cases for StreamProcessor handling of TEXT_MESSAGE_CONTENT chunks under multiple scenarios: delta accumulation, undefined delta handling, content fallback, content-only chunks, and absence of text content.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • harry-whorlow

Poem

🐰 Streams of deltas, flowing free,
Now undefined won't trouble thee!
With guards in place and tests so bright,
Content concatenates just right!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks substantive content in the 'Changes' section and does not explain the motivation or implementation details for the fix. Fill in the Changes section with a clear explanation of what issue was fixed, why it occurred, and how the fix addresses it. Mention the key changes to types, processor logic, and new tests.
Title check ❓ Inconclusive The title 'fix: content chunk issue fix' is vague and redundant, using generic phrasing like 'issue fix' without clearly describing the specific technical change being made. Revise the title to be more specific and descriptive, such as 'fix: handle undefined delta in TEXT_MESSAGE_CONTENT chunks' or 'fix: make delta property optional in streaming messages'.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/fix-content-chunk

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 and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Feb 7, 2026

View your CI Pipeline Execution ↗ for commit a95bb2b

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 58s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 1m 14s View ↗

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 7, 2026

Open in StackBlitz

@tanstack/ai

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

@tanstack/ai-anthropic

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

@tanstack/ai-client

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

@tanstack/ai-devtools-core

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

@tanstack/ai-gemini

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

@tanstack/ai-grok

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

@tanstack/ai-ollama

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

@tanstack/ai-openai

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

@tanstack/ai-openrouter

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

@tanstack/ai-preact

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

@tanstack/ai-react

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

@tanstack/ai-react-ui

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

@tanstack/ai-solid

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

@tanstack/ai-solid-ui

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

@tanstack/ai-svelte

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

@tanstack/ai-vue

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

@tanstack/ai-vue-ui

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

@tanstack/preact-ai-devtools

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

@tanstack/react-ai-devtools

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

@tanstack/solid-ai-devtools

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

commit: a95bb2b

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/typescript/ai/src/activities/chat/stream/processor.ts (1)

763-763: ⚠️ Potential issue | 🟡 Minor

Stale comment: delta is no longer "always defined".

Line 763 says "delta is always defined but may be empty string", which is no longer accurate now that delta is optional on TextMessageContentEvent.

Suggested fix
-    // Check if content is present (delta is always defined but may be empty string)
+    // Check if content is present (delta may be undefined or empty string)
🧹 Nitpick comments (1)
packages/typescript/ai/tests/stream-processor.test.ts (1)

5-167: Consider calling finalizeStream() after manual processChunk() calls.

These tests use processChunk() directly rather than process(), which means finalizeStream() is never called. This works with the default ImmediateStrategy since text is emitted on every chunk, but wouldn't catch issues with batching strategies where the final flush happens in finalizeStream(). Consider adding processor.finalizeStream() after the last processChunk() call to mirror production behavior more closely.

@AlemTuzlak AlemTuzlak merged commit 6f886e9 into main Feb 7, 2026
6 checks passed
@AlemTuzlak AlemTuzlak deleted the chore/fix-content-chunk branch February 7, 2026 16:42
@github-actions github-actions bot mentioned this pull request Feb 7, 2026
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.

1 participant