Skip to content

addSibling throws unnecessarily when target is the root message #2387

Description

@nuthalapativarun

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 = []

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions