Skip to content

Improve message reconciliation - #231

Merged
renal128 merged 3 commits into
nextfrom
message-reconciliation
Aug 25, 2026
Merged

Improve message reconciliation#231
renal128 merged 3 commits into
nextfrom
message-reconciliation

Conversation

@renal128

@renal128 renal128 commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Turns out that event_id is not a unique ID - there can be multiple agent responses with the same event_id (e.g. if theres agent utterance, tool call and another agent utterance in the same turn). So we didn't have a good way to match streamed events. Recently we added responseId in the backend as unique identifiers of agent utterances, so we can match them properly, which is the focus of this PR:

  • Reconcile agent streams, full responses, and corrections by response_id (one turn can produce several agent messages).
  • Replace messages with chatHistory: a mixed, stable list of messages and tool calls, that can be extended with other types of entries in the future.

Test plan

  • unit tests
  • manual tests

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 22791f0. Configure here.

@renal128
renal128 force-pushed the message-reconciliation branch 2 times, most recently from a86df21 to ae071f1 Compare August 22, 2026 15:40
@renal128 renal128 changed the title Replace messages with a response_id-keyed chatHistory Chat History reliability Aug 22, 2026
@renal128 renal128 changed the title Chat History reliability Improve message reconciliation Aug 23, 2026
@renal128
renal128 requested a review from jacksonh August 25, 2026 11:59
Base automatically changed from swift6 to next August 25, 2026 17:23
renal128 and others added 3 commits August 25, 2026 18:23
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@renal128
renal128 force-pushed the message-reconciliation branch from 51f7119 to 2334e71 Compare August 25, 2026 17:23
@cursor

cursor Bot commented Aug 25, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Breaking public API (messageschatHistory) and stricter protocol parsing (response_id required) affect all transcript UIs; core reconciliation logic changed but is covered by new unit tests.

Overview
Replaces the public messages array with chatHistory — a single ordered list of ChatHistoryItem entries (messages plus ConversationToolCall records). Conversation, ConversationClient, docs, and the chat widget now observe $chatHistory and derive transcript bubbles via compactMap(\.message).

Incoming agent events (streaming parts, full responses, corrections) are merged through a new ChatHistoryReconciler, keyed by server response_id so multiple agent utterances in one turn (e.g. before/after a tool) no longer collide on event_id. EventParser and public event types now require response_id for those agent payloads. Message gains isFinal and stable ids (agent messages use response_id); tentative user transcripts update history instead of being ignored.

The widget shows a typing cursor on non-final bubbles; ChatWidgetController.messages() becomes chatHistory().

Reviewed by Cursor Bugbot for commit 2334e71. Bugbot is set up for automated code reviews on this repo. Configure here.

@renal128
renal128 merged commit fa97eca into next Aug 25, 2026
4 checks passed
@renal128
renal128 deleted the message-reconciliation branch August 25, 2026 17:35
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