Skip to content

fix(ai-persistence): ignore empty TEXT_MESSAGE_START message ids so they are not stored - #1117

Open
kolaworld wants to merge 1 commit into
TanStack:mainfrom
kolaworld:fix/1087-empty-text-message-start-id
Open

fix(ai-persistence): ignore empty TEXT_MESSAGE_START message ids so they are not stored#1117
kolaworld wants to merge 1 commit into
TanStack:mainfrom
kolaworld:fix/1087-empty-text-message-start-id

Conversation

@kolaworld

@kolaworld kolaworld commented Aug 15, 2026

Copy link
Copy Markdown

🎯 Changes

  • Ignore empty TEXT_MESSAGE_START messageId values in persistence so they are not stored as the in-progress stream id.
  • That leaves streamingMessageId unset, so a later TOOL_CALL_START can still apply parentMessageId.
  • Regression: empty start id + parentMessageId: 'stream-assistant' + mid-stream crash with snapshotStreaming still persists id: 'stream-assistant'.

✅ 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 streaming persistence so empty text message IDs no longer overwrite the parent assistant message ID.
    • Preserved the correct assistant message association for tool calls and partial responses, including when a stream fails mid-response.
  • Tests

    • Added regression coverage for persistence during interrupted streaming responses.

An empty start id was stored and blocked the TOOL_CALL_START parentMessageId fallback.
@coderabbitai

coderabbitai Bot commented Aug 15, 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 Plus

Run ID: fdced981-bede-40ac-964e-a8f95ceacc71

📥 Commits

Reviewing files that changed from the base of the PR and between 9a4124d and 269bbe4.

📒 Files selected for processing (3)
  • .changeset/fix-empty-text-message-start-id.md
  • packages/ai-persistence/src/middleware.ts
  • packages/ai-persistence/tests/with-persistence.test.ts

📝 Walkthrough

Walkthrough

The persistence middleware now ignores empty TEXT_MESSAGE_START message IDs. A regression test verifies that streaming snapshots retain the existing assistant message ID after tool calls and mid-stream failures. A patch changeset documents the fix.

Changes

Streaming persistence

Layer / File(s) Summary
Preserve non-empty streaming message IDs
packages/ai-persistence/src/middleware.ts, packages/ai-persistence/tests/with-persistence.test.ts, .changeset/fix-empty-text-message-start-id.md
The middleware updates the streaming message ID only when chunk.messageId is non-empty. The regression test covers tool-call linkage, partial assistant output, and mid-stream failure. The changeset documents the patch release.

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

Merge Risk: ⚪ Minimal · up to 269bb

This change prevents empty streaming message IDs from being persisted, preserving subsequent parent-message handling without introducing a current-head merge-blocking risk.

Possibly related PRs

  • TanStack/ai#1066: Preserves message IDs in an AI message conversion or persistence path.
  • TanStack/ai#1101: Changes assistant stream message ID handling in middleware.ts.
  • TanStack/ai#1116: Preserves assistant message IDs during streaming snapshot persistence.

Suggested reviewers: mikemikimike, alemtuzlak

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main persistence fix: ignoring empty TEXT_MESSAGE_START message IDs.
Description check ✅ Passed The description includes the required changes, checklist, release impact, testing, and changeset information.
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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@github-actions github-actions Bot added the waiting-on: maintainer The ball is in the maintainers’ court label Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on: maintainer The ball is in the maintainers’ court

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant