[AIT-681] Compute fork metadata for edits via useChat#37
Draft
lawrence-forooghian wants to merge 1 commit intomainfrom
Draft
[AIT-681] Compute fork metadata for edits via useChat#37lawrence-forooghian wants to merge 1 commit intomainfrom
useChat#37lawrence-forooghian wants to merge 1 commit intomainfrom
Conversation
useChat
useChatuseChat
22b9a6e to
ac1b309
Compare
Our SDK has two forking operations: edit (replace a user message) and regenerate (re-run an assistant message). The AI SDK's useChat exposes the same two: sendMessage with a messageId (edit) [1] and regenerate(). We already made our regenerate compatible with useChat's — ChatTransport computes forkOf/parent from the conversation tree when trigger is 'regenerate-message'. It turns out we missed the edit case. Without fork metadata, edits via useChat were treated as new messages rather than forks in the conversation tree. The fix is by analogy with regeneration: widen the condition from `trigger === 'regenerate-message' && messageId` to just `messageId`. The tree lookup logic (resolve the node's wire msg-id as forkOf, its parentId as parent) is identical for both cases. [1] https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#send-message [AIT-681] Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ac1b309 to
2dadf28
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Our SDK has two forking operations: edit (replace a user message) and regenerate (re-run an assistant message). The AI SDK's
useChatexposes the same two:sendMessagewith amessageId(edit) andregenerate(). We already made our regenerate compatible withuseChat's —ChatTransportcomputesforkOf/parentfrom the conversation tree when trigger isregenerate-message.It turns out we missed the edit case. Without fork metadata, edits via
useChatwere treated as new messages rather than forks in the conversation tree.The fix is by analogy with regeneration: widen the condition from
trigger === 'regenerate-message' && messageIdto justmessageId. The tree lookup logic (resolve the node's wire msg-id asforkOf, itsparentIdasparent) is identical for both cases.Demo
The demo app used for the videos below is on a separate branch:
AIT-681-edit-demo(demo/vercel/react/edit-demo/).Normal
useChatedit (plain Vercel, no Ably transport)2026-04-10.16-56-51.mov
useChatedit with our transport — before fix (broken)2026-04-10.17-00-19.mov
useChatedit with our transport — after fix (working)2026-04-10.17-06-03.mov
AIT-681
🤖 Generated with Claude Code