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 sibling
This 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 throw
src/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 = []
Bug
addSiblinginsrc/lib/utils/tree/addSibling.tsthrows an error when the caller tries to add a sibling to the conversation root message:This restriction is unnecessary. A sibling of the root message is simply another top-level message with
ancestors = []. The existing guardif (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 fixedExpected behavior
addSibling(conv, newMessage, conv.rootMessageId)should succeed and return a new message ID. The new message should be added toconv.messageswithancestors = []andchildren = []. No parent node exists, so nochildrenarray needs updating.Steps to reproduce