[react-ag-ui] Editing a message deletes the original instead of creating a branch

Author: sjmattaCreated Sep 25, 2026Updated Sep 25, 2026
Labelsbug

Checklist

  • I have searched existing issues and this is not a duplicate
  • This is a reproducible bug, not a usage question

Environment info

Packages:
  @assistant-ui/react          0.15.22
  @assistant-ui/react-ag-ui    0.0.62
  @ag-ui/client                0.0.59
Also reproduced on main at 877d3da94.

Affected area(s)

Runtime / Core

Runtime adapter in use

useAgUiRuntime

Steps to reproduce

  1. Send a user message. The agent answers a1.
  2. Edit that user message and send it (ActionBarPrimitive.Edit + EditComposer, which calls edit with sourceId set to the original message).
  3. Look at the branch picker on the edited message, or at the message repository.
typescript
let n = 0;
const core = new AgUiThreadRuntimeCore({
  agent: {
    runAgent: vi.fn(async (_input, s) => {
      n += 1;
      say(s, `a${n}`, `answer ${n}`);
      s.onRunFinishedEvent?.({ event: { type: "RUN_FINISHED", threadId: "t", runId: "r" } });
      s.onRunFinalized?.({});
    }),
  } as unknown as HttpAgent,
  logger: makeLogger(),
  showThinking: true,
  notifyUpdate: () => {},
});
await core.append(userMessage("first"));
const original = core.getMessages()[0]!;
await core.edit({ ...userMessage("edited", original.id), parentId: null });
const repo = core.getMessageRepository();

Expected vs actual behavior

Expected: the edit creates a sibling branch. The original user message and a1 stay reachable as branch 1/2.

Actual: the original user message is deleted. a1 stays in the repository with parentId: null, and the branch picker shows no earlier version.

repo messages (id, role, parentId):
[["a1", "assistant", null], ["<new id>", "user", null], ["a2", "assistant", "<new id>"]]
original still present: false

Code snippet or error log

AgUiThreadRuntimeCore.appendEntry:

typescript
private appendEntry(message: AppendMessage): string {
  if (message.sourceId) this.session.tryDeleteMessage(message.sourceId);

MessageRepository.deleteMessage moves the deleted message's children to its parent, which is why a1 ends up at the root.

Additional context

Regenerate does branch in the same runtime (BranchPickerPrimitive shows 1/2 after a reload); only edit loses the earlier version. #8347 and #8327 are about deletes in the same repository layer but describe different paths.

Track in Rupic

Source: assistant-ui/assistant-ui