-
-
Notifications
You must be signed in to change notification settings - Fork 302
fix(ai): preserve server chat reasoning #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AlemTuzlak
merged 1 commit into
TanStack:main
from
kolaworld:fix/1145-server-chat-reasoning
Aug 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/ai': patch | ||
| --- | ||
|
|
||
| Preserve reasoning in server chat message history and interrupt snapshots. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
testing/e2e/fixtures/tools-test/client-tool-reasoning.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "fixtures": [ | ||
| { | ||
| "match": { | ||
| "userMessage": "[client-tool-reasoning] run test", | ||
| "sequenceIndex": 0 | ||
| }, | ||
| "response": { | ||
| "reasoning": "I should show a notification before confirming it was displayed.", | ||
| "toolCalls": [ | ||
| { | ||
| "name": "show_notification", | ||
| "arguments": "{\"message\":\"Reasoning notification\",\"type\":\"info\"}" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "match": { | ||
| "userMessage": "[client-tool-reasoning] run test", | ||
| "sequenceIndex": 1 | ||
| }, | ||
| "response": { | ||
| "content": "The notification has been shown after reasoning." | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/ai
Length of output: 50368
🏁 Script executed:
Repository: TanStack/ai
Length of output: 10100
🏁 Script executed:
Repository: TanStack/ai
Length of output: 50368
🏁 Script executed:
Repository: TanStack/ai
Length of output: 50368
🏁 Script executed:
Repository: TanStack/ai
Length of output: 50367
🏁 Script executed:
Repository: TanStack/ai
Length of output: 36764
🏁 Script executed:
Repository: TanStack/ai
Length of output: 262
🌐 Web query:
AG-UI protocol REASONING_MESSAGE_CONTENT STEP_FINISHED event ordering💡 Result:
In the AG-UI protocol, the interaction between reasoning events (
REASONING_MESSAGE_CONTENT) and legacy step events (STEP_FINISHED) has evolved toward a canonical event-based structure [1][2][3]. The AG-UI protocol defines dedicatedREASONING_*events to replace older, genericSTEP_*events for handling model chain-of-thought or "thinking" processes [1][4][3]. While some legacy implementations may still emitSTEP_STARTEDandSTEP_FINISHEDevents alongside or instead of these reasoning events, the modern standard and recommended approach is to use the dedicated reasoning sequence [2][3][5]. Standard Event Ordering for Reasoning: 1. REASONING_START: Marks the beginning of the reasoning/thinking phase [4][3]. 2. REASONING_MESSAGE_START: Initiates the streaming reasoning message [4][3]. 3. REASONING_MESSAGE_CONTENT: Delivers accumulated content chunks [4][3][6]. This event type is used to stream the "thinking" text incrementally [4][2]. 4. REASONING_MESSAGE_END: Completes the reasoning message [4][3]. 5. REASONING_END: Signals the completion of the entire reasoning phase [4][3]. Legacy Context: Older implementations often wrapped reasoning within genericSTEP_STARTEDandSTEP_FINISHEDevents [2][3]. In these cases, frontends had to reconcile these generic markers with the reasoning content [2][5]. Modern AG-UI protocol specifications (>= 0.1.15) treat theREASONING_*events as the primary, canonical way to represent this lifecycle [3]. Stream processors or adapters may still reconcile both types into a single interface (such as a ThinkingPart in a UI message) to ensure backward compatibility and deduplication of content, but new integrations should rely on the dedicated reasoning event flow [2][3]. Events should always be processed in the order they are received, and events sharing the same ID (e.g., messageId) belong to the same logical stream [1].Citations:
🏁 Script executed:
Repository: TanStack/ai
Length of output: 262
🏁 Script executed:
Repository: TanStack/ai
Length of output: 5451
Deduplicate reasoning content regardless of event order.
A
STEP_FINISHEDevent followed by matchingREASONING_MESSAGE_CONTENTcurrently produces duplicate thinking content. Deduplicate both event types and add a reversed-order regression test inpackages/ai/tests/stream-processor.test.ts.🤖 Prompt for AI Agents