Skip to content

Give the create path a child's rootness instead of deriving it - #2857

Merged
malibio merged 1 commit into
mainfrom
issue-2849-child-title-rootness
Sep 22, 2026
Merged

malibio merged 1 commit into
mainfrom
issue-2849-child-title-rootness

Conversation

@malibio

@malibio malibio commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #2849

Problem

insert_node_in_tx_no_invariant_dispatch recomputed a missing title via compute_title(&node, None), which resolves rootness by looking up the parent edge. Inside create_node_with_parent's transaction the node row is written before the edge, so every child read as a root and was titled with its own body text — overwriting the correct None the prepare step had already computed. Body sentences leaked into node_title_fts, title_match_nodes, the ADR-040 title boost and mention autocomplete.

Fix (option 1 from the issue)

create_node_in_tx and insert_node_in_tx_no_invariant_dispatch take is_root: bool from the caller:

  • create_node_with_parent → false
  • create_node_with_parent_in_tx → parent.is_none()
  • create_node and invariant-action creates → true (neither has a parent at insert time)

With rootness known, the recompute reproduces the prepare step's answer and can no longer overwrite a deliberate None.

Tests

  • entity_resolution_test: the pinning test is inverted to a_body_node_mentioning_the_name_is_not_an_entity — asserts the stored title is None and hits.is_empty().
  • New test_create_node_with_parent_titles_only_roots: roots titled, children NULL, through both the standalone and _in_tx entry points.
  • Both fail with the fix reverted (verified).
  • Full nodespace-core suite passes; no existing title-dependent tests (mention autocomplete, title_match_nodes) needed changes. Pre-push gate passed.

🤖 Generated with Claude Code

…#2849)

insert_node_in_tx_no_invariant_dispatch recomputed a missing title with
rootness unknown, which made compute_title look up the parent edge. Inside
create_node_with_parent's transaction the node row is written before that
edge, so every child read as a root and was titled with its own body text,
overwriting the correct None the prepare step had computed.

create_node_in_tx and insert_node_in_tx_no_invariant_dispatch now take
is_root from their callers: false for a parented create, true for
create_node and invariant-action creates (neither ever has a parent at
insert time).

The entity-resolution test that pinned the bug is inverted, and a unit test
asserts roots are titled and children are not through both the standalone
and _in_tx entry points. Both fail with the fix reverted.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio

malibio commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #2857

Review Type: Initial review (the PR had no reviews or comments yet)

Requirements Check (issue #2849)

  • ✅ A node created through create_node_with_parent with a parent_id has a NULL title after commit. Both the standalone path (create_node_in_tx(.., false)) and the _in_tx path (parent.is_none()) now pass rootness in. test_create_node_with_parent_titles_only_roots checks both entry points.
  • ✅ The recompute in create_node_in_tx can no longer overwrite a deliberate None. The recompute still runs when the title is None, but it now uses Some(is_root) and skips the store lookup. It therefore returns the same None that prepare_create_node_with_parent computed.
  • ✅ entity_resolution_test::a_body_node_mentioning_the_name_is_not_an_entity is inverted. It now asserts both stored.title == None and hits.is_empty(). Checking the title as well is a stronger test than checking the hits alone.
  • ✅ Existing title-dependent tests still pass (mention autocomplete, title_match_nodes). The main agent's full nodespace-core run and the pre-push gate both passed.
  • ✅ Tests and quality. test:all passed in the pre-push gate. quality:fix and clippy are clean. The main agent confirmed that both the new test and the inverted test fail when the fix is reverted.

Code Review Findings

Correctness of the hardcoded true for create_node and the invariant action (checked, no issue)

  • 📁 packages/core/src/services/node_service/crud.rs:137 and packages/core/src/playbook/actions.rs:1874. Before this change, both paths called compute_title(.., None). That looked up the parent edge of a node that had just been inserted, which always found nothing, so is_root was always true. Hardcoding true keeps their behavior exactly the same and removes one query. The invariant CreateNode action has no parent_id param (it reads only content and properties). create_node_with_parent sends its no-parent branch to create_node, so true is correct there too.

🟢 Pre-existing, out of scope: "create first, attach a parent later" paths still title the child

  • 📁 Any caller that runs NodeService::create_node(n) and then adds a has_child edge in a later operation (for example a later AddRelationship action, or a later move) still gets a content-derived title on a node that ends up as a child. The same applies in reverse: moving a titled root under a parent does not clear its title.
  • I found no production path in core, daemon or node_ops that does this today. node_ops::create_node goes through create_node_with_parent. methodology/install.rs creates root-level nodes. The upsert path around crud.rs:2190 writes directly to the store with title: None and then calls move_node, so its children are already untitled.
  • This matches the previous behavior and is not a regression. It is still worth knowing that "title ⇔ root" is enforced only at creation time, not across reparenting. Principle: an invariant should be maintained where the state changes. If the entity index is going to rely on "every titled row is an entity", the move path should eventually recompute the title too. That work is better filed as its own issue than folded into this PR.

🟢 API shape: a bare bool parameter

  • 📁 crud.rs:199-204 (create_node_in_tx) and crud.rs:253-258 (insert_node_in_tx_no_invariant_dispatch). A positional bool is hard to read at call sites (create_node_in_tx(tx, node, false)). A two-variant enum (Rootness::Root / Rootness::Child) or a named local (let is_root = false;) would make each call site explain itself. Both methods are pub(crate) and have five call sites, so the cost of the bool is small and this is not blocking. Principle: readable call sites / avoid boolean parameters (Clean Code).
  • The doc comments are good. They explain why rootness can't be derived at insert time (the edge is written later in the same transaction), which is the non-obvious part.

🟢 Nit: redundant compute_title for content-typed children

  • 📁 crud.rs:575 then crud.rs:283. For a child of a content-titled type, prepare_create_node_with_parent computes None, and insert_node_in_tx_no_invariant_dispatch sees None and runs compute_title again, which repeats the get_schema_node lookup. The result is now the same both times, so this only costs performance, and it predates this PR. The problem is that Option<String> cannot tell "already computed as None" apart from "not yet computed". It could be fixed later if create throughput matters. Principle: DRY / do the work once.

🟢 Test quality

  • 📁 packages/core/src/services/node_service/mod.rs:4501-4555. The test creates the in-transaction child before the in-transaction root in the same transaction. That ordering exercises the "edge not yet written" window, and it asserts both directions (roots titled, children untitled), so it guards against a fix that goes too far as well as one that goes nowhere. Good.
  • 📁 mod.rs:4590. The ADR-069 S2 regression test was updated to pass false, which matches its intent (a child whose edge write fails).

Project rules

  • No backward-compatibility code, no deprecation, and no lint suppression. Comments describe behavior without issue numbers, and the stale crud.rs:NNN line references in the old test doc comment were removed.
  • FYI: origin/main has one commit that is not on this branch (6bc23eb, eval fixture in scripts/eval/fixtures/decisions.ts). It touches no file in this diff, so a squash merge won't conflict.

Recommendation: APPROVE

This is a small, well-scoped fix for a real correctness bug. The change is minimal: rootness is now passed in instead of looked up while the edge doesn't exist yet. The tests are targeted and confirmed to fail without the fix. All findings are optional 🟢 follow-ups or nits.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review summary

The review verdict was APPROVE, with three 🟢 suggestions. None of them changed the code:

  • ⏭️ Title isn't recomputed when a node is moved under or out of a parent. Skipped as out of scope. This PR fixes how titles are chosen at creation time. Keeping titles right after moves is a separate problem. Today it isn't reached in production, because every parented create goes through create_node_with_parent. If the entity index is going to rely on "every titled row is an entity", that needs its own issue.
  • ⏭️ Use an enum instead of the bool parameter. Skipped. Both methods are pub(crate) and have five call sites between them. The doc comments on both explain what is_root means and why it can't be looked up. Adding a new type for that is more than the change needs. Worth revisiting if a second flag like this shows up on the same methods.
  • ⏭️ A child's title is computed twice (once in prepare, once in insert). Skipped. This was already true before this PR, and both computations now return the same answer. Fixing it means telling "computed as None" apart from "not computed yet", which is the more invasive option 2 in the issue.

No commits added. No re-review needed.

@malibio
malibio merged commit dc9fbeb into main Sep 22, 2026
@malibio
malibio deleted the issue-2849-child-title-rootness branch September 22, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant