Skip to content

Match search's keyword half on root titles; one title rule on every write path (#2867, #2858) - #2875

Merged
malibio merged 10 commits into
mainfrom
issue-2867-title-keyword-search
Sep 23, 2026
Merged

malibio merged 10 commits into
mainfrom
issue-2867-title-keyword-search

Conversation

@malibio

@malibio malibio commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

General search's keyword half now matches root titles (node_title_fts) instead of running full-text search over node.content at every depth. A child line can no longer come back from search as if it were a document.

What changed

  • Keyword half is title-only. bm25_search_roots (content FTS + ancestor CTE) is replaced by bm25_search_titles, which runs bm25 over node_title_fts and returns (id, bm25) in rank order. Tier 3 (keyword-only) results are now ordered by bm25 rank, not node_id.
  • Only tree roots are embedding roots. get_embedding_root_id (and its spawned-task twin) used to stop below a non-embeddable parent, so every line on a date page or under a task got its own vector and could be returned bare by the vector half. They now walk to the tree root; a date page or task is not embeddable, so nothing under it is vectorized. This matches data-layer.md ("Only root nodes … get embedded"; "Not embeddable: … child nodes"), which the code had drifted from.
  • Titles and embeddings follow rootness on every edge write. Moving a node never re-derived its title, so an indented root stayed in the title index (and an outdented child had no title). New NodeService::refresh_for_rootness (+ _in_tx, title only) re-derives the title, drops a new child's own embeddings and queues its tree root. It is best-effort after the edge commit (logs, never fails the move). It is called from move_node, move_node_unchecked, create_parent_edge, bulk_create_has_child_edges, and has_child create/delete in create_relationship, create_relationship_in_tx, delete_relationship, remove_relationship_in_tx, and merge_nodes. The title write goes through a new title-only SqliteStore::set_title that bumps neither version nor modified_at (title is a derived index column) and is guarded by the version read.
  • Every search-returnable root is titled. schema and date roots now carry their content as their title (derive_title, and SchemaNode::into_node for seeded core schemas).
  • One title rule on every write path (Decide whether date and schema nodes get titles, and unify the title rule across write paths #2858). NodeService::derive_title is the single definition: template if the type has one; else content for a root and for task/collection at any depth; else none. compute_title wraps it. Bulk hierarchy inserts now derive titles through it too (with_titles, one schema lookup per type) and pass them to the store as BulkNodeRow's 7th field. SqliteStore::compute_title_for_bulk_insert is deleted. It had its own list (date/schema/checkbox) and ignored templates, so a bulk-inserted person got a content title.
  • Per-surface opt-outs (Decide whether date and schema nodes get titles, and unify the title rule across write paths #2858). Entity resolution excludes schema (a type isn't an entity: "…to the list" resolved to the Ordered List schema) and date (ISO titles tokenize to bare numbers). @mention autocomplete excludes schema and keeps date, since a date link is a real mention. General search's keyword half and TITLE_BOOST skip schema (a type name is a common word; "project roadmap" ranked the Project schema over the user's roadmap).
  • project and person are not embedded. Both now return None for their own and parent contribution, like task. (project embedded its content; person embedded a display name via compute_display_name, which had no other use and is deleted.) Titledness and embeddability stay independent.
  • person allows children (backend behavior + frontend plugin): child nodes are notes about the person. They get no title and no embedding of their own.
  • Default Knowledge scope widened, as an allow-list. KNOWLEDGE_CORE_TYPES = text, header, code-block, schema, table, task, date, project, person, plus every user-defined (non-core schema) type, read from the schema list at search time. agent-guidance, skill, tool, play, database-settings, ai-chat stay out.
  • Deleted: NON_EMBEDDABLE_CONTAINER_TYPES and its parity test; the node_fts table, its three triggers, its bootstrap DDL and its rebuild/backfill; the unused semantic_search_scoped.
  • Guidance: SKILL.md and references/cli.md no longer claim a name search never returns tasks or typed records. node query --title-contains stays the recommended name→ID lookup (it's exact; search mixes in meaning-similar documents), and the reason is now stated correctly.

node_fts consumers

None remained. node query --content-contains, the content contains filter, the skill updater's lookup and the desktop search box's include_title_matches path all use LOWER(content) LIKE on node, not the FTS index.

Probe anomalies

  • schema untitled → fixed (titled + indexed).
  • person "titled but unindexed" did not reproduce: on a current database every titled person root is indexed (the triggers cover every write path).
  • database-settings is a system singleton outside the default scope, so it needs no title.

Database reset required

Existing databases keep old embeddings on date-page/task children and have no titles on schemas/dates. Per the no-migration rule there is no backfill — reset the database.

Docs

Companion edits in nodespace-docs (committed to main): data-layer.md drops the content-FTS exception, states the title-only keyword rule, and records the #2858 title decisions (one rule, per-surface opt-outs); ADR-029 gets a revision note on the widened Knowledge scope and title-only keyword matching, plus project/person rows in its per-type table; creating-node-types.md's person example allows children; product-features.md describes the BM25 leg and chat titles correctly.

Tests

  • test_bm25_search_titles_never_matches_child_lines — a word only in child lines under a text root, a task, a date page and an agent-guidance root matches nothing.
  • test_bm25_search_titles_finds_task_date_and_record_titles, test_core_schemas_are_titled_but_not_keyword_hits, test_user_defined_record_is_found_by_title, test_indented_root_drops_its_embedding, test_bm25_search_titles_ordered_by_rank.
  • test_embedding_root_is_tree_root_under_non_embeddable_roots.
  • test_move_rederives_title_from_rootness, test_has_child_edge_rederives_title_from_rootness — both (and the child-line test) fail with the refresh helper stubbed out.
  • title_rule_agrees_across_write_paths_for_every_core_type: single-node and bulk titles agree for every core type, root and child, and match the decided values.
  • schemas_and_dates_are_not_resolved (fails with the date exclusion removed), mention_autocomplete_offers_dates_but_not_schemas.
  • test_title_matches_respect_default_knowledge_scope now asserts a task is returned and agent-guidance is not; test_knowledge_scope_admits_user_knowledge_and_excludes_system_types pins the allow-list.

Closes #2867
Closes #2858

🤖 Generated with Claude Code

malibio and others added 3 commits September 23, 2026 08:19
closes #2867)

General search's keyword half ran FTS over node.content at every depth and
walked hits up to a root, stopping below a hardcoded container list — so a
child line came back as if it were a document. It now runs bm25 over
node_title_fts, which holds only titled roots, and Tier 3 is ordered by bm25
rank.

- Embedding roots are always tree roots: children of a date page or task no
  longer get their own vectors; those roots are found by title.
- Titles follow rootness on every has_child edge write (move, parent edge,
  relationship create/delete, tx variants, bulk attach), via a title-only
  store write that bumps neither version nor modified_at.
- schema and date roots carry their content as their title; entity
  resolution excludes schemas (a type is not an entity).
- Knowledge scope is an allow-list of user-knowledge core types plus every
  user-defined type; system types stay out.
- Delete NON_EMBEDDABLE_CONTAINER_TYPES + parity test, node_fts + triggers +
  rebuild, and the unused semantic_search_scoped.
- Skill guidance no longer claims search never returns tasks/records.

Requires a database reset (no backfill, per the no-migration rule).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…loses #2858)

- NodeService::derive_title is the single title definition: template if the
  type has one; else content for a root and for task/collection at any depth;
  else none. compute_title wraps it; bulk hierarchy inserts derive titles
  through it (with_titles, one schema lookup per type) and pass them to the
  store as BulkNodeRow's title. compute_title_for_bulk_insert, which had its
  own date/schema/checkbox list and ignored templates, is deleted.
- Entity resolution excludes schema (a type is not an entity) and date (ISO
  titles tokenize to bare numbers). @mention autocomplete excludes schema and
  keeps date (a date link is a real mention).
- Parity test over every core type, root and child.

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

malibio commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #2875

Review Type: Initial Review (no prior reviews or comments on the PR)

Summary

This is a clear improvement to the codebase. It removes a whole class of bug: bare child lines coming back from search. The fix goes to the root cause (content FTS at every depth plus a hand-kept container list) and doesn't patch the symptom. It also deletes a lot of machinery: node_fts, its three triggers and backfill, NON_EMBEDDABLE_CONTAINER_TYPES and its parity test, the ancestor CTE, semantic_search_scoped, and compute_title_for_bulk_insert. derive_title is now the single title rule, bulk callers pass the title in, and the store has no rule of its own. That fixes the checkbox and person disagreement structurally, not by syncing two lists. The rootness-refresh wiring covers every production has_child write path I could find. No lint suppression, no dead_code allows, no backward-compat code, and no issue numbers in code comments.

The findings below are ranking and embedding side effects plus a few test gaps. None of them blocks the merge.


Requirements Check

#2867

# Criterion Status Notes
1 Keyword half queries node_title_fts; no path uses FTS over content ✅ bm25_search_titles replaces bm25_search_roots. node_fts is gone.
2 Search can't return a non-root; test on a seeded tree (task, date, agent-guidance) ✅ (keyword half) / ⚠️ (vector half, see finding 2) test_bm25_search_titles_never_matches_child_lines covers text, task, date and agent-guidance. The embedding root is now the tree root (test_embedding_root_is_tree_root_under_non_embeddable_roots). One gap remains: an indented former root keeps its own vector.
3 search "<task title>" and search "<user-defined record title>" return the root ⚠️ The task title is tested. No test covers a user-defined record such as a company named "Northwind Trading", through either bm25_search_titles or search_semantic with the dynamic user_types set. The test docstring says "a user-defined record", but the body tests only a task and a date (finding 4).
4 Fresh seeded DB returns no agent-guidance, skill or tool content in default scope ✅ The allow-list scope excludes them. Their children have no title and no longer get an embedding. test_title_matches_respect_default_knowledge_scope covers agent-guidance.
5 Keyword-only results ordered by bm25 rank ✅ Tier 3 keeps bm25 order (take(remaining) over ranked hits). test_bm25_search_titles_ordered_by_rank creates the weaker match first, so insertion order can't pass for rank order.
6 NON_EMBEDDABLE_CONTAINER_TYPES and its parity test deleted ✅
7 node_fts and triggers deleted, or remaining consumer named ✅ DDL, triggers, backfill and its test are deleted. The PR body confirms no consumer remains.
8 Every search-returnable root is titled and indexed (schema, person, database-settings) ✅ Schema is titled via derive_title and SchemaNode::into_node (test_core_schemas_are_titled_and_indexed). The person anomaly didn't reproduce. database-settings is outside scope. Both are explained in the PR body.
9 SKILL.md and cli.md updated; --title-contains recommendation revisited ✅ Both drop the false "never returns tasks/typed records" claim and now give the correct reason to prefer --title-contains (exact match, not a mix of meaning-similar results).
10 Companion docs: data-layer.md drops the content-FTS exception; ADR-029 Knowledge updated ✅ Verified in nodespace-docs dfc328c: data-layer.md L277–294 and the ADR-029 revision note at L117.
11 test:all and quality:fix pass ✅* Not re-run here. The branch was pushed through the pre-push gate.

#2858

# Criterion Status Notes
1 Decision on Q1–4 recorded in nodespace-docs with reasoning ✅ data-layer.md records the date and schema titles, checkbox under the general rule, and per-surface opt-outs with reasons.
2 One shared rule for single-node and bulk paths ✅ NodeService::derive_title. The store rule is deleted, and BulkNodeRow carries the caller-derived title.
3 Test: both paths agree for every core type, root and child ✅ title_rule_agrees_across_write_paths_for_every_core_type iterates behaviors plus core schemas and also pins the expected values.
4 If date/schema are titled: tests cover their title value and each affected surface ⚠️ Partial Covered: title values, entity resolution (schemas_and_dates_are_not_resolved) and @mention (mention_autocomplete_offers_dates_but_not_schemas). Not covered: title_contains/title_match_nodes and ADR-040 TITLE_BOOST. TITLE_BOOST is where the new schema titles change ranking (finding 1).
5 (If untitled) exclusion comment — N/A — The titled branch was chosen, and the stale TODO is gone.
6 Tests and quality pass ✅* Same caveat as above.

Code Review Findings

🟡 Important

1. Core schemas now get ranking boosts for any query that contains a type name
📁 packages/core/src/services/embedding_service.rs:718-750, packages/core/src/models/schema_node.rs:224-238
Schemas are embeddable and in the Knowledge scope, and they now carry their type name as a title. That changes ranking in two ways the PR doesn't discuss:

  • TITLE_BOOST is a substring contains on the lowercased title. Any query containing "task", "text", "list", "person", "project", "header" and so on now boosts the matching core schema.
  • The same query makes the schema a bm25 title hit. If the schema also clears the KNN threshold, it is promoted to Tier 1, above the user's own documents that only matched semantically.

Example: "project roadmap for Q3" can now rank the Project schema above the user's roadmap note. The decision that schemas are titled and in scope is settled. This ranking consequence is a separate question, and it has no test (see #2858 AC4).
Recommendation: Run a quick check with nodespace-semantic-bench, or a targeted test such as "query project roadmap with a text root titled Q3 roadmap; the root outranks the Project schema". If the check shows a regression, the smallest fix is to drop is_core schemas from the keyword half or from TITLE_BOOST, and keep them findable by vector.
Principle: when you change inputs, check the downstream invariants. A new title feeds three ranking signals, not only the index.

2. The vector half can still return a non-root: a stale embedding survives an indent
📁 packages/core/src/services/node_service/crud.rs:2854-2897 (refresh_title_for_rootness), packages/core/src/db/sqlite_store/embeddings.rs:463-467
The PR makes the title follow rootness on every edge write, but it doesn't do the same for embeddings. Two cases:

  • A root with its own embedding that is indented (under a text root, a date page or a task) keeps its embedding rows. search_embeddings has no root filter, so the vector half can still return that node bare. This is the failure Search's keyword half should match root titles, not node content at every depth #2867 set out to remove, now reachable through the other half.
  • A child outdented to root gains a title but is never queued for embedding. Moves don't call queue_root_for_embedding.

Both gaps predate this PR. It is still the natural place to close them, because refresh_title_for_rootness is now the single hook every rootness change passes through.
Recommendation: In refresh_title_for_rootness (and the _in_tx twin, deferred to after commit), delete the node's own embeddings when is_root == false, and queue the node (or its new root) when rootness flips. Otherwise, file a follow-up and scope the claim in AC2 to "the keyword half".
Principle: the invariant is "only roots are search results". It should be enforced at the same boundary for both derived indexes (DRY across title and vector).

3. The non-tx refresh is a separate, unguarded read-modify-write after the edge write
📁 packages/core/src/services/node_service/crud.rs:2854-2897; call sites in hierarchy.rs:377,508,871,960 and relationship.rs:764,803,1317
In the non-tx paths, store.move_node / append_child_edge commits first. refresh_title_for_rootness then runs get_node, computes the title, and calls set_title as a second write with no version check. Two consequences:

  • A crash between the two writes leaves a wrong title. That self-heals only on the node's next content update or move.
  • A concurrent update_node that changes content between the refresh's get_node and set_title can have its fresh title overwritten with one derived from the old content. set_title is unconditional.

The window is small and the damage limited to a derived column, so this doesn't block the merge.
Recommendation (cheap): Make set_title a single statement that re-derives nothing but guards on the content it read, e.g. UPDATE node SET title=?1 WHERE id=?2 AND content=?3. Alternatively, where the store method already opens a transaction (move_node), run the refresh inside it.
Principle: atomicity of derived state. A derived column written outside the transaction that invalidated it can drift.

4. User-defined record title search is untested (#2867 AC3)
📁 packages/core/tests/embedding_service_test.rs (test_bm25_search_titles_finds_task_date_and_record_titles)
The docstring promises "a user-defined record", but the body checks only a task and a date. The dynamic user_types path in search_ops::search_semantic (get_all_schemas → !is_core) is covered only by a unit test of matches_scope with a hand-built set. Nothing covers the get_all_schemas → filter wiring.
Recommendation: Create a company schema and a "Northwind Trading" instance. Assert that bm25_search_titles finds it and that search_semantic with default scope returns it. The second assertion fails if the user_types wiring breaks.
Principle: test the integration seam, not only the pure function.

🟢 Suggestion

5. merge_nodes_in_tx re-points has_child edges without a title refresh
📁 packages/core/src/db/sqlite_store/conflicts.rs:~400-460
When a loser that was a child is merged into a survivor that was a root, the survivor gains a parent edge and keeps its root title. Duplicate merges are almost always root-to-root, so this is rare, but it's the one edge-rewriting path outside the refresh net. Either refresh the survivor after the merge or add a one-line comment saying why it's exempt.

6. The per-edge refresh in bulk_create_has_child_edges costs N × (get_node + schema lookup)
📁 packages/core/src/services/node_service/hierarchy.rs:959-961
On the sync cold-sweep, every attached child costs two extra reads. Most of them are no-ops, because a node that was just attached usually already has no title. Consider one batched UPDATE node SET title = NULL WHERE id IN (…) AND node_type NOT IN ('task','collection') AND <no title_template>, or at least cache the schema lookup per type as with_titles does.

7. search_semantic loads every schema on every default-scope search
📁 packages/core/src/ops/search_ops.rs:691-706
This is two queries (schema nodes plus declarations), and relationship declarations are hydrated only to be discarded. It's cheap today. If it shows up in profiles, a store method that reads only SELECT id FROM node WHERE node_type='schema' AND NOT is_core would do. Not needed now (YAGNI).

8. Not emitting an event from set_title is fine, for a reason worth writing down
📁 packages/core/src/db/sqlite_store/nodes.rs:406-432
I checked the frontend. It reads node.title only for title-template types (node-row.svelte:131), plus a title || content fallback. Rootness never changes a templated or task/collection title, so no UI cache can go stale from this write. A sentence saying so in the set_title doc comment would stop a future reader from "fixing" it by bumping the version, which would trigger OCC conflicts on every move.

Nitpicks

  • Nit: packages/core/src/services/node_service/bulk.rs:22-37: with_titles builds a full throwaway Node (two Utc::now() calls, empty vecs) only to call derive_title. If derive_title took (node_type, content, properties, is_root, schema), both call sites would be simpler.
  • Nit: packages/core/src/services/node_service/bulk.rs:8-17: the 6-tuple input type is spelled out inline, while its 7-tuple output has a BulkNodeRow alias. A named struct for both would remove the positional .6 in the parity test.
  • Nit: packages/core/src/services/node_service/crud.rs: refresh_title_for_rootness and _in_tx differ only in how they read and write. This matches the existing _in_tx twin convention, so leave it unless a third variant appears.
  • Nit: packages/core/src/services/embedding_service.rs:796-799: the comment "With tokenized OR search, results are already ranked… fewer candidates are needed (top roots bubble up)" still describes root resolution. It could now say simply that title hits are already roots, so 2× is headroom for scope filtering.

Recommendation

APPROVE

The change is correct and deletes a lot of code. The title-rule unification is structural, not cosmetic, and the rootness refresh covers every production has_child write path I traced. The one path it misses is the edge-case merge in finding 5. Before merge I'd recommend the two cheap test additions (findings 1 and 4), which close the partially met acceptance criteria. Finding 2 (stale vectors on indent) can go in this PR through the new refresh hook or be filed as a follow-up.

@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 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.

…es, keep schemas out of keyword ranking

- refresh_for_rootness (renamed from refresh_title_for_rootness) now also
  drops a node's own embeddings when it becomes a child and queues its tree
  root, so the vector half can't return an indented root bare.
- set_title is guarded by the version read, so it loses to a concurrent
  content update instead of overwriting it; doc states why it emits no event.
- merge_nodes re-derives the survivor's title after re-pointing edges.
- bm25_search_titles and TITLE_BOOST skip schemas: a type name is a common
  word ("project roadmap" ranked the Project schema over the user's roadmap).
- Tests: user-defined record found by title (store + search_semantic),
  schemas titled but not keyword hits, indented root drops its embedding.

Skipped: batching the per-edge refresh in bulk_create_has_child_edges (sync
cold-sweep only), narrowing get_all_schemas per search (unmeasured), and the
BulkNodeRow struct / derive_title-signature nits.

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

malibio commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (ca42bd7)

✅ Addressed

  • 🟡 1 — Schemas ranked by type-name queries. bm25_search_titles now leaves out schema, and TITLE_BOOST skips it. A type name is a common word, so "project roadmap" ranked the Project schema above the user's roadmap. Schemas are still found by meaning through their embedding. Test: test_core_schemas_are_titled_but_not_keyword_hits asserts that exactly the user's document comes back. Recorded in data-layer.md.
  • 🟡 2 — The vector half could still return a non-root. The helper is now refresh_for_rootness. When a node becomes a child, it drops that node's own embeddings. In both directions it queues the tree root, so a new root gets its first embedding and a tree that gained a child gets its aggregate rebuilt. Test: test_indented_root_drops_its_embedding. The _in_tx twin still handles only the title. The tx paths (invariant-rule actions, merge) rarely change rootness and the embedding store has no tx-scoped writers; the doc comment says so.
  • 🟡 3 — Racy title write. set_title now carries a WHERE version = ? guard using the version it read. If a content update lands concurrently, the guarded write loses, and that update's own current title stands.
  • 🟡 4 — User-defined record untested. test_user_defined_record_is_found_by_title creates a Company schema through handle_create_schema plus a "Northwind Trading" record. It asserts the record comes back from both bm25_search_titles and search_semantic in the default scope, which exercises the get_all_schemas/!is_core wiring.
  • 🟢 5 — Merge re-pointing. merge_nodes now re-derives the survivor's title inside the merge transaction after edges are re-pointed.
  • 🟢 8 — Why set_title emits no event. Now in the doc comment: rootness never changes a title the UI renders, and bumping the version would turn every move into an OCC conflict.
  • Nit — the bm25_limit comment no longer mentions root resolution.

⏭️ Skipped

  • 🟢 6 — Batching the refresh in bulk_create_has_child_edges. Only the sync cold sweep hits it, where N × (get_node + a cached-ish schema lookup) is negligible next to the sweep itself. Worth revisiting if the cold sweep shows up in a profile.
  • 🟢 7 — Narrowing get_all_schemas per search. It's cheap at current schema counts and not measured. Same condition for revisiting.
  • Nits — derive_title taking fields instead of a Node, a BulkNodeRow struct, merging the _in_tx twin. Each is a style choice that matches existing conventions and has no correctness effect.

Tests

The full core suite passes (38 binaries), and the push went through the pre-push gate (test:all, daemon build, e2e).

@malibio

malibio commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #2875 (Re-Review of ca42bd7)

Review Type: Re-Review

Previous Review Summary

  • Findings in the previous review: 12 (4 🟡, 4 🟢, 4 Nits)
  • Addressed: 7. Findings 1, 2, 3, 4, 5 and 8, plus the bm25_limit comment nit. All 7 are verified fixed.
  • Not addressed (skipped with reasons): 5. Findings 6 and 7 and three nits. The reasons are sound; one caveat on 6 is below.
  • New issues: 1 🟡 (a pre-existing failure-mode ordering that this commit makes more likely) and 2 🟢.

Requirements Check (delta)

#2867

# Criterion Status Notes
2 Search can't return a non-root ✅ (was ⚠️) The vector half now enforces it on the non-tx edge paths: refresh_for_rootness drops a node's own embedding when it becomes a child. test_indented_root_drops_its_embedding pins this. The tx paths still update the title only, and the doc comment says so.
3 Task and user-defined record found by title ✅ (was ⚠️) test_user_defined_record_is_found_by_title creates a schema through handle_create_schema and a "Northwind Trading" record. It asserts on both bm25_search_titles and search_semantic in the default scope, so it covers the get_all_schemas → !is_core wiring end to end.

All other #2867 criteria are unchanged ✅.

#2858

# Criterion Status Notes
4 Titled date/schema: each affected surface covered ✅ (was ⚠️) TITLE_BOOST and the keyword half now skip schema. test_core_schemas_are_titled_but_not_keyword_hits asserts that "project roadmap" returns exactly the user's roadmap. The decision is recorded in nodespace-docs 667b65f (data-layer.md L292). The title_contains path has no new schema behaviour to test beyond its scope.

All other #2858 criteria are unchanged ✅.


Verification of Addressed Findings

  • 1. Schemas and keyword ranking: ✅ fixed. bm25_search_titles joins node and filters n.node_type != 'schema' before LIMIT, so schemas don't use up candidate slots. This is the same join-with-bm25 pattern resolve_entities_by_title already uses. TITLE_BOOST skips schemas. Both are documented, and the test is exact-match (== vec![roadmap.id]), so it isn't vacuous.
  • 2. Stale vector on indent: ✅ fixed on the non-tx paths. delete_embeddings runs when !is_root, and the tree root is queued in both directions. The test seeds a real embedding row and asserts it's gone after move_node_unchecked. On the tx paths, only the title is refreshed, and that is documented. That's acceptable given how rarely those paths change rootness. See new finding N2 for the remaining source-tree staleness.
  • 3. Racy title write: ✅ fixed. set_title now guards on version = ?. Does the guard skip a write it should make? I traced every non-tx caller:
    • Checked move_node (hierarchy.rs:~505). store.move_node does not bump node.version; it touches only relationship. So the refresh reads version == expected_version and the guarded write matches. update_node_with_version_bump(node_id, expected_version) runs after the refresh, so the ordering is refresh then bump, and neither blocks the other. ✅
    • move_node_unchecked, create_parent_edge, bulk_create_has_child_edges, create_relationship, delete_relationship. Nothing bumps the node's version between the refresh's get_node and set_title, so the guard only fails when another writer genuinely intervened. ✅
    • Residual window (acceptable). Suppose a concurrent update_node computed its title from rootness it read before the move, and commits inside the refresh's read→write window. The refresh's write then loses and that update's stale-rootness title stands. This needs three interleavings within milliseconds on a derived column, and the next edit or move self-heals it. Not worth more machinery.
  • 4. User-defined record test: ✅ fixed. See above.
  • 5. Merge re-pointing: ✅ fixed correctly. Rootness is read with get_parent_id_in_tx against the tx connection, after merge_nodes_in_tx has re-pointed edges, so it sees the uncommitted post-merge state. refresh_for_rootness_in_tx then reads the node through get_node_in_tx and writes through set_title_in_tx, which is unguarded but correct inside the tx because it is serialized. compute_title's schema lookup goes through a pooled reader, which is fine because the schema isn't mutated by the merge. Capturing self.clone() into the 'static closure matches how other with_transaction callers carry the service.
  • 8. set_title event rationale: ✅ documented. The comment states the invariant (rootness never changes a UI-rendered title) and warns against the OCC regression.
  • bm25_limit comment nit: ✅ fixed.

Skip Reasons

  • 6. Per-edge refresh cost in bulk_create_has_child_edges: 🟡 reason mostly sound, with a caveat. When I raised it, the per-edge cost was two reads. After this commit, each edge also runs a delete_embeddings write transaction plus queue_root_for_embedding: a root walk, a type probe, has_embeddings, and a stale-marker write. Those root writes are repeated N times for children of the same parent. That is still bounded and runs only in the sync cold-sweep, so deferring is fine, but "negligible" now understates it. Recommendation: leave it, and if the cold sweep shows up in a profile, dedupe the queued roots per batch. (Not blocking.)
  • 7. get_all_schemas per search: ✅ sound. It is unmeasured and cheap at current schema counts (YAGNI).
  • Nits (Node-taking derive_title, BulkNodeRow struct, _in_tx twin): ✅ sound. These are style choices consistent with existing conventions.

New Findings

🟡 Important

N1. A derived-index refresh failure now aborts the move after it committed, which skips the OCC bump and the sync events
📁 packages/core/src/services/node_service/hierarchy.rs:~505-512 (checked move_node), also :377, :871, :960; relationship.rs:764,803,1316
refresh_for_rootness(...).await? sits between the committed store.move_node and update_node_with_version_bump plus the RelationshipUpdated/RelationshipDeleted emission. If any step of the refresh errors, the move is durable but three things go wrong:

  • the version is not bumped, so concurrent movers aren't OCC-fenced (the exact hazard the ADR-069 §2 comment right below describes);
  • no relationship event is emitted, so other devices and clients never learn about the move;
  • the caller is told the move failed, and it may retry.

The steps that can fail are get_node, the schema read, set_title, and now also the delete_embeddings transaction. The title-only refresh from the first commit already had this shape. This commit adds a multi-statement write transaction to it, which widens the failure surface under write contention.
Recommendation: Title and embeddings are both derived indexes, so neither should be able to fail a structural write. Do one of these:

  • (a) Make refresh_for_rootness best-effort: log a warn and return (). This mirrors queue_root_for_embedding, which already swallows its errors.
  • (b) Move the call after the version bump and event emission.

(a) is the smaller change and covers all seven call sites.
Principle: failure isolation. A secondary or derived write must not abort, or partially abort, the primary operation after it committed.

🟢 Suggestion

N2. The tree a node leaves keeps its content in its aggregate embedding
📁 packages/core/src/services/node_service/crud.rs (refresh_for_rootness)
The refresh queues the moved node's new tree root, but nothing queues the old one. After you outdent a subtree, or move it into a different tree, the old root's embedding still includes the moved text until that tree is next edited. Vector search can then return the old document for content it no longer contains. Unlike the bug this PR fixes, this is a relevance issue, not a "bare child line" issue, and it predates the PR. The callers already capture the old parent (old_parent_id in the checked move). Recommendation: queue the old parent's root there too, or file a follow-up.

N3. Move-time cost per keystroke
📁 same function
Every indent or outdent now does get_node, a schema read, possibly set_title, a delete_embeddings transaction (a no-op when no rows exist, but still a BEGIN/COMMIT on the write connection), and a root-queue walk. That's fine for interactive single moves. Recommendation (cheap): skip delete_embeddings unless has_embeddings(node_id) is true, which avoids a write-lock round-trip on the common path of moving a child that never had an embedding.


Recommendation

APPROVE

All four 🟡 findings from the first review are fixed correctly and pinned by non-vacuous tests. The version guard never blocks the legitimate move path, because store.move_node doesn't bump the version and the refresh runs before the OCC bump. The merge refresh reads and writes consistently through the tx connection. The new 🟡 (N1) is a failure-mode ordering issue: it only matters when the derived-index write errors after a committed move. It predates this commit in weaker form. It's a small change (make the refresh non-fatal), and I'd recommend it before merge, but it doesn't block the merge.

@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 (re-review of ca42bd7): APPROVE (posted as a comment — GitHub blocks self-approval). All four prior 🟡 findings verified fixed; one new 🟡 (make refresh_for_rootness non-fatal so a derived-index error can't skip the OCC bump/events after a committed move) recommended but non-blocking. Full findings in the comment above.

- refresh_for_rootness now logs and returns () instead of failing: it runs
  after the edge write has committed, so an error there must not report a
  committed move as failed and skip the caller's version bump and events.
  The _in_tx twin stays fallible (a failure rolls back the whole tx).
- Only delete embeddings when the node has any, so an ordinary indent doesn't
  take the write lock for nothing.

Skipped: re-queueing the tree a node left (its aggregate keeps the moved
content until next edit) — predates this PR, relevance-only.

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

malibio commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed (6ef3863)

✅ Addressed

  • 🟡 N1 — A failed refresh aborted a committed move. refresh_for_rootness is now best-effort: it logs a warn and returns (). It runs after the edge write has committed, so a derived-index failure can no longer report the move as failed and skip the version bump and events. The _in_tx twin stays fallible on purpose, because a failure there rolls back the whole transaction and stays atomic.
  • 🟢 N3 — Pointless write lock on an ordinary indent. Embeddings are deleted only when has_embeddings says the node has any.

⏭️ Skipped

  • 🟢 N2 — Re-queue the tree a node left. That tree's aggregate keeps the moved content until its next edit. The behavior predates this PR and affects relevance only, not correctness. It can be a follow-up issue.
  • Skip-6 caveat (N× refresh in the cold sweep, same root queued N times): still sync cold-sweep only. Dedupe the queued roots if it shows up in a profile.

Tests

The full core suite passes (38 binaries), and the push went through the pre-push gate.

Re-Review Decision

NO RE-REVIEW NEEDED. Both changes are small and low-risk. N1 turns an error into a log at the call sites; the logic is unchanged. N3 adds one guard. The reviewer already approved and named exactly these fixes.

malibio and others added 3 commits September 23, 2026 09:21
A project is a named record found by its title, like a task: its content is
only its name, so a vector for it adds nothing the keyword half doesn't
already match. ProjectNodeBehavior now returns None for both its own and its
parent contribution, matching TaskNodeBehavior.

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

- Being titled and being embeddable are independent: drop the title-based
  justification from ProjectNodeBehavior and get_embedding_root_id.
- A chat is a root, so its title column follows its content ("Untitled",
  then the generated name); AiChatNode::into_node's None is overwritten by
  compute_title on write.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- PersonNodeBehavior::can_have_children and the frontend person plugin's
  canHaveChildren are now true: child nodes are notes about the person.
- person is no longer embedded (get_embeddable_content returns None, like
  task and project), so neither the person nor its notes get vectors.
  compute_display_name existed only to build that embedding and is deleted
  with its tests.

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

malibio commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #2875 (Re-Review of ca42bd7..4d3f19a)

Review Type: Re-Review

Scope:

  • 6ef3863f: best-effort refresh (N1) and embedding delete guarded by has_embeddings (N3)
  • cc183e28: project no longer embedded
  • 5dd30c00: comment corrections
  • 4d3f19a0: person can have children and is no longer embedded; compute_display_name deleted

The project, person and title/embeddability decisions are the user's and are treated as settled. This review checks only that they are implemented correctly and completely.

Previous Review Summary

  • Findings in the previous re-review: 3 new (N1 🟡, N2 🟢, N3 🟢), plus the finding-6 caveat
  • Addressed: 2 (N1, N3). Both are verified fixed.
  • Not addressed: 1 (N2, source-tree aggregate staleness). Skipped with a reason. It predates this PR, is a relevance issue and not a correctness one, and is acceptable as deferred.
  • New issues: 0 🔴, 0 🟡, 3 🟢 (test-pinning gaps and one manual check)

Requirements Check (delta)

No acceptance criterion of #2867 or #2858 changes status. All stay ✅, as in the previous re-review. The new commits sit outside both issues' acceptance criteria, and they are consistent with them:

  • KNOWLEDGE_CORE_TYPES still admits project and person.
  • Both types are titled roots, so the title-only keyword half finds them.
  • Titledness and embeddability are now documented as independent (ADR-029 revision, data-layer.md L182).

Verification of Addressed Findings

  • N1: refresh failure aborted a committed move. ✅ Fixed correctly.
    • refresh_for_rootness now returns (). It wraps try_refresh_for_rootness and logs with tracing::warn! on failure.
    • All seven non-tx call sites changed from .await? to .await: hierarchy.rs 377, 508, 871 and 960, and relationship.rs 764, 803 and 1316.
    • So in the checked move_node, update_node_with_version_bump and the relationship events now always run once the edge write commits.
    • queue_root_for_embedding sits outside the fallible block. A failed title or embedding step still queues the tree root, which is right: the aggregate needs rebuilding regardless.
    • The _in_tx twin still returns Result and propagates with ?. That's correct there: inside a transaction, a failure should roll back the whole unit, including the edge write.
  • N3: needless write transaction on every move. ✅ Fixed. delete_embeddings now runs only when !is_root && has_embeddings(node_id). The common case, moving a node that never had a vector, costs one read and no write-lock round-trip.
  • N2: skipped. ✅ The skip reason holds (see the summary above).

Completeness of the project and person changes

I checked backend behaviors, core tests, the frontend plugins and tests, the daemon, agent prompts, skill text and nodespace-docs.

Surface Result
ProjectNodeBehavior: get_embeddable_content / get_parent_contribution → None ✅ test_project_node_behavior_is_not_embedded; the old "projects are embeddable" assertion was removed
PersonNodeBehavior: can_have_children → true, embeddable and parent contribution → None ✅ person_can_have_children, person_is_not_embedded
compute_display_name deletion ✅ It had no remaining callers. The stale cross-reference in the core_schemas.rs person-schema comment is fixed. title_template is now the single rule for composing a name.
Frontend core-plugins.ts person canHaveChildren: true ✅ Matches the Rust change
person-node.svelte ✅ Already passes {children} through to BaseNode. It has no leaf-specific handling (no hasRingEffect or leaf branch keyed on person).
Other frontend canHaveChildren consumers ✅ They are generic (pluginRegistry.canHaveChildren). Nothing hardcodes person as a leaf.
Backend container validation (prepare_create_node_with_parent, move_children_to_parent non-container guard) ✅ Driven by the behavior's can_have_children, so it follows automatically
Agent (packages/agent) prompts and skill text (packages/skill) ✅ Nothing says a person is a leaf or that person/project are embedded (grepped for person/project with child, leaf, note or embed)
Daemon ✅ No person or project embeddability or leaf assumptions (person appears only in unique-field and identity tests)
behavior_is_embeddable probe / KNOWLEDGE_CORE_TYPES ✅ Behavior-driven; project and person stay in the Knowledge scope and are found by title
nodespace-docs ✅ 7249618, e4fb734, 844f75e: ADR-029 per-type table has project and person rows (the person row says its child notes aren't embedded either); data-layer.md L182 lists project and person as not embeddable and says non-embeddable roots may still have unembedded children; creating-node-types.md's person example matches core-plugins.ts
Comment-only 5dd30c00 ✅ The ai_chat_node.rs and ai_chat_title.rs comments now describe it correctly: the title column is derived from content on write, and titledness is separate from embeddability

New Findings

🟢 Suggestion

S1. The frontend/Rust canHaveChildren parity test doesn't list person
📁 packages/desktop-app/src/tests/plugins/core-plugins.test.ts:597-613 (RUST_CAN_HAVE_CHILDREN)
The parity table exists to lock the frontend and backend copies together, but person isn't in it. The flip from false to true therefore isn't pinned on the frontend side. A future edit to either copy alone would pass CI. Recommendation: add person: true to the table. It's one line.
Principle: a parity test protects only what it lists.

S2. The behavior-driven non-embeddable integration test doesn't cover project or person
📁 packages/core/tests/embedding_service_test.rs:202-215 (test_behavior_driven_non_embeddable_types, list ["task", "date", "collection", "query", "horizontal-line"])
The unit tests in behaviors/mod.rs pin the behavior methods. This integration test goes through NodeService's embeddability probe (behavior_is_embeddable), which is what the embedding queue actually consults. Recommendation: add "project" and "person" to the list.

S3. Manually check person child creation in the UI
📁 packages/desktop-app/src/lib/design/components/person-node.svelte
The person node renders readonly, and making children possible is a real UX change. The backend and plugin flags are correct, but nothing tests the editor path: Enter on a person, Tab-indenting a note under it, and a person page showing its notes. Recommendation: try it once in the running app with the run-app skill before merge. If it works, no code change is needed.


Recommendation

APPROVE

N1 and N3 are fixed correctly. N1's fix is placed right: failures are swallowed only after commit, the queue step still runs, and the in-transaction twin still propagates errors. The project and person changes are consistent across backend, frontend, agent, skill text and docs, and I found no leftover leaf or embeddability assumptions. The remaining items are two one-line test additions and a manual smoke test, none of which block the merge.

@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 (re-review of ca42bd7..4d3f19a): APPROVE (posted as a comment — GitHub blocks self-approval). N1 and N3 verified fixed; project/person changes consistent across backend, frontend, agent, skill and docs. Three 🟢 non-blocking suggestions (add person to the canHaveChildren parity table, add project/person to the non-embeddable integration test, smoke-test person child notes in the UI). Full findings in the comment above.

…e tables

- core-plugins.test.ts: RUST_CAN_HAVE_CHILDREN lists person: true, so the
  frontend side of the flip is pinned.
- embedding_service_test.rs: the non-embeddable type list includes project
  and person.

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

malibio commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed (c68da72)

✅ Addressed

  • 🟢 S1: RUST_CAN_HAVE_CHILDREN in core-plugins.test.ts lists person: true, which pins the frontend side of the flip.
  • 🟢 S2: test_behavior_driven_non_embeddable_types now lists project and person.

⏭️ Deferred to the user

  • 🟢 S3: a manual smoke test of person child notes in the running app (Enter on a person, Tab-indent a note, open the person page). This is a verification step with no code change, so it's offered to the user rather than run automatically.

Tests

Both updated tests pass. The push went through the full pre-push gate. One retry was needed: architecture-benchmarks measured 52ms against its 40ms budget while other sessions' gates were running, and it passes in isolation.

Re-Review Decision

NO RE-REVIEW NEEDED. The changes are two test-table additions with no production code changes, and the reviewer already approved.

Conflict in resolve_entities_by_title: main extracted token selection into
select_entity_tokens; took main's version and kept this branch's
schema/date exclusion. Updated the stale bm25_search_roots reference in
select_entity_tokens' doc and a frontend comment pointing at the deleted
compute_display_name.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CbMVLf7z8mBEgn2xPsNLcB
@malibio
malibio merged commit bc17eb4 into main Sep 23, 2026
@malibio
malibio deleted the issue-2867-title-keyword-search branch September 23, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant