addSibling throws unnecessarily when target is the root message
Author: nuthalapativarunCreated Jun 26, 2026Updated Jun 26, 2026
Bug
addSibling in src/lib/utils/tree/addSibling.ts throws an error when the caller tries to add a sibling to the conversation root message:
The sibling message is the root message, therefore we can't add a siblingThis restriction is unnecessary. A sibling of the root message is simply another top-level message with ancestors = []. The existing guard if (nearestAncestor) already handles the no-parent case correctly — it skips the children-update step, which is exactly right when there is no parent node to update.
Affected files
src/lib/utils/tree/addSibling.ts— lines 18-20, the premature throwsrc/lib/utils/tree/addSibling.spec.ts— line 50 carries a TODO noting this should be fixed
Expected behavior
addSibling(conv, newMessage, conv.rootMessageId) should succeed and return a new message ID. The new message should be added to conv.messages with ancestors = [] and children = []. No parent node exists, so no children array needs updating.
Steps to reproduce
const siblingId = addSibling(conv, newMessage, conv.rootMessageId);
// throws: "The sibling message is the root message, therefore we can't add a sibling"
// expected: returns new message ID; conv.messages grows by 1; new message has ancestors = []Source: huggingface/chat-ui