Skip to content

[AIT-681] Compute fork metadata for edits via useChat#37

Draft
lawrence-forooghian wants to merge 1 commit intomainfrom
AIT-681-passing-messageId-to-send
Draft

[AIT-681] Compute fork metadata for edits via useChat#37
lawrence-forooghian wants to merge 1 commit intomainfrom
AIT-681-passing-messageId-to-send

Conversation

@lawrence-forooghian
Copy link
Copy Markdown

@lawrence-forooghian lawrence-forooghian commented Apr 10, 2026

Summary

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) 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.

Demo

The demo app used for the videos below is on a separate branch: AIT-681-edit-demo (demo/vercel/react/edit-demo/).

Normal useChat edit (plain Vercel, no Ably transport)

2026-04-10.16-56-51.mov

useChat edit with our transport — before fix (broken)

2026-04-10.17-00-19.mov

useChat edit with our transport — after fix (working)

2026-04-10.17-06-03.mov

AIT-681

🤖 Generated with Claude Code

@lawrence-forooghian lawrence-forooghian changed the title Compute fork metadata for edits via useChat Compute fork metadata for edits via useChat Apr 10, 2026
@lawrence-forooghian lawrence-forooghian changed the title Compute fork metadata for edits via useChat [AIT-681] Compute fork metadata for edits via useChat Apr 10, 2026
@lawrence-forooghian lawrence-forooghian force-pushed the AIT-681-passing-messageId-to-send branch 2 times, most recently from 22b9a6e to ac1b309 Compare April 10, 2026 19:28
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>
@lawrence-forooghian lawrence-forooghian force-pushed the AIT-681-passing-messageId-to-send branch from ac1b309 to 2dadf28 Compare April 10, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant