Skip to content

create_node_in_tx recomputes a child node's title as if it were a root, titling body nodes with their own text #2849

Closed

Description

@malibio

Overview

NodeService::create_node_in_tx recomputes a node's title with rootness unknown, at a point in the transaction where the parent edge does not exist yet. Every child node created through create_node_with_parent is therefore misclassified as a root and titled with its own body text, when it should have no title at all.

Found while building the entity-resolution tier (#2841), which indexes node.title on the premise that a non-null title marks a nameable thing.

The mechanism

prepare_create_node_with_parent gets this right. It computes the title passing rootness explicitly (crud.rs:558):

// is_root = parent_id.is_none() — avoids a DB lookup at create time
self.compute_title(&temp_node, Some(params.parent_id.is_none())).await?

For a child that yields None, which is correct — compute_title returns None for a non-root node of a content-titled type (crud.rs:2793-2807).

But create_node_in_tx then sees a None title and recomputes it (crud.rs:266-267):

if node.title.is_none() {
    node.title = self.compute_title(&node, None).await?;
}

Passing None for is_root makes compute_title resolve rootness itself, via store.get_parent_id(&node.id). Inside create_node_with_parent's transaction the node is inserted before create_parent_edge_in_tx runs (crud.rs:345-360), so that lookup finds no parent, returns is_root = true, and the node is titled strip_markdown(content).

The correct None from the prepare step is indistinguishable from "not computed yet", so the recompute overwrites a right answer with a wrong one.

Reproduction

packages/core/tests/entity_resolution_test.rs::a_body_node_mentioning_the_name_is_not_an_entity pins the current behaviour:

CHILD TITLE = Some("we should call Northwind Trading about the renewal")

Expected: None.

Impact

node.title is read by several surfaces, all of which treat it as a display identity:

Nothing is visibly broken, which is presumably why it has gone unnoticed; the cost is diffuse noise in every title-keyed surface.

Fix options

  1. Thread rootness through. Give create_node_in_tx the caller's known is_root rather than letting it re-derive. Most direct; touches the signature and its call sites.
  2. Distinguish "no title" from "not computed". The recompute exists for callers that never computed one; an explicit marker would let it skip nodes whose title was deliberately resolved to None.
  3. Recompute after the edge write. Moves the lookup to where it would get the right answer, at the cost of a second write.

(1) looks cleanest. Whichever is chosen, the invariant worth asserting is that a node created with a parent_id has a NULL title on commit.

Acceptance criteria

  • A node created via create_node_with_parent with a parent_id has a NULL title after commit
  • The recompute in create_node_in_tx cannot overwrite a deliberately-None title
  • entity_resolution_test::a_body_node_mentioning_the_name_is_not_an_entity is inverted to assert hits.is_empty() (it currently pins the buggy behaviour, with a doc comment saying so)
  • Existing title-dependent tests still pass — check mention autocomplete and title_match_nodes in particular, since some may have been written against the current wrong behaviour
  • Tests pass (bun run test:all), code passes bun run quality:fix

Reference files

  • packages/core/src/services/node_service/crud.rs:266-267 — the recompute
  • packages/core/src/services/node_service/crud.rs:558 — the correct computation it overwrites
  • packages/core/src/services/node_service/crud.rs:2790-2810 — compute_title's rootness branch
  • packages/core/src/services/node_service/crud.rs:345-360 — insert-before-edge ordering
  • packages/core/tests/entity_resolution_test.rs — the pinning test

Activity

  1. added
    bug
    on Sep 22, 2026
  2. malibio commented on Sep 22, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 5264 passed (262 files)

  3. self-assigned this
    on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions