Skip to content

Add title to NodeData proto and wire client-side title preview - #2645

Merged
mstomar125 merged 6 commits into
mainfrom
issue-2547-title-proto
Sep 16, 2026
Merged

mstomar125 merged 6 commits into
mainfrom
issue-2547-title-proto

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #2547

Two independent, both-required fixes for title-templated nodes (e.g. person), per the issue's own root-cause analysis:

(A) Backend wire-protocol fix: NodeData (the daemon's gRPC wire type) had no title field at all, so node_to_proto silently dropped the server-computed title for every client (CLI, Tauri desktop app, MCP — which is CLI-backed) reading a node over gRPC, even though NodeService::compute_title computed and persisted it correctly to SQLite.

  • Added optional string title = 12; to NodeData (verified 12 is the next free field number; 4 and 10 are reserved) — optional because presence is meaningful: absent means this node type never gets a title (date/schema), present-but-empty (Some("")) is a legitimate value (a title_template whose fields are all still blank).
  • node_to_proto now maps node.title into it.
  • Fixed every client-side consumer that independently hardcoded title: None: the CLI's node_to_json/write_human_node (packages/cli/src/output.rs), the Tauri desktop app's proto_node_data_to_node (packages/desktop-app/src-tauri/src/commands/nodes.rs) and the separate node_from_proto used by semantic search (packages/desktop-app/src-tauri/src/commands/embeddings.rs), and a third independent conversion in the browser dev-mode HTTP proxy (packages/dev-tools/src/dev-proxy.ts's nodeDataToApiNode).
  • Two more paths in the same class turned up during review: upsert_node_with_parent (the transactional desktop-autosave upsert) built its NodeUpdate with title left None (leaving the DB title stale after an ordinary autosave content edit) — fixed the same way update_node_unchecked already does, by recomputing from the merged node state. UpdateNodesBatch looked similar but turned out not to have the bug (its title: None is never actually read — update_with_version_check_returning_node always recomputes its own title regardless); added a regression test proving that rather than "fixing" a non-bug.

(B) Client-side reactive computation (ADR-077): the editing client is supposed to compute its own title locally and instantly from in-progress field values, independent of any backend round trip. Wired evaluateTitleTemplate into:

  • person-schema-form.svelte: oninput handlers on first/last name track each field's live (not just last-blurred) value locally, since a user can tab from one name field to the other and keep typing before either blurs — pairing a fresh keystroke with a stale committed value for the other field would silently drop it from the preview.
  • generic-schema-form.svelte: for any schema with a titleTemplate (the general, non-person path a user-defined title-templated type actually renders through), updateField now also pushes a computed title alongside the field's own write. Passes schema.fields through so an enum field referenced by the template resolves to its label, matching compute_title()'s actual backend behavior (interpolate_title_template_with_schema) — without this, an enum-backed title_template would flash the raw stored value before the backend's round trip corrected it to the label.

Both push the computed title into sharedNodeStore via a shared pushComputedTitle() helper, gated on isComputedField: true (skips persistence/OCC entirely — a pure, synchronous, unpersisted UI echo), so it can't fight the field's own persisted write, and every reader of the store (header, tab, inline row) sees it in the same tick. Also fixed a pendingUpdates leak this new per-keystroke path exposed: isComputedField writes were still being tracked for rollback even though they never persist and are never eligible for it, so nothing ever cleared their entries.

Both

  • Corrected person-schema-form.test.ts's mock, which fabricated a title field (`${first_name} ${last_name}`.trim() || 'Untitled') the real backend never actually sent — the exact gap that let this bug ship. Added coverage that deliberately omits title from the mocked backend response and proves the preview still resolves correctly with the backend write left permanently unresolved.
  • Added a round-trip test crossing the actual gRPC serialization boundary: a node_to_proto unit test, plus full SetLocalPersonIdentity/CreateSchema+CreateNode/GetNode/UpdateNodesBatch round trips through the daemon's real NodeServiceImpl RPC handlers (not just the in-process NodeService layer the existing service-layer test used) — covering both person and a second, non-person title-templated schema (ticket, "{severity}: {subject}"), per the issue's explicit "not person-specific" requirement.
  • Re-verified PR Route person-schema-form saves through sharedNodeStore.updateNode #2552's earlier fix (routing person-schema-form.svelte's save through sharedNodeStore.updateNode) remains correct and necessary: it's untouched by this PR, and the new title-preview mechanism depends on the same store-routing being in place, so if anything it's more load-bearing now, not less.

Test plan

  • bun run quality:fix clean (frontend lint/typecheck, cargo fmt, cargo clippy --all-targets -D warnings)
  • bun run test:all (frontend + skill + full Rust workspace) — all green, run to completion multiple times as the diff evolved
  • cargo build --bin nodespaced — clean
  • bun run test:e2e (27/27, real daemon round trip) — all green
  • cargo test -p nodespace-app --test "*" (ADR-048 Tauri-seam integration tests, including node_crud_tauri_seam_test.rs and the real-socket grpc_round_trip.rs) — all green
  • Two full adversarial review rounds, findings addressed each time: round 1 caught the dev-proxy's title presence collapsing Some("") to null (fixed); round 2 caught the missing enum-label resolution in the client preview and the two additional backend paths noted above (fixed)

🤖 Generated with Claude Code

mstomar125 and others added 6 commits September 16, 2026 08:38
Backend: NodeData had no title field, so node_to_proto silently dropped
the server-computed title for every client (CLI, Tauri, MCP) reading a
node over gRPC, even though NodeService computed and persisted it
correctly. Add optional string title = 12 to NodeData, map node.title
into it in node_to_proto, and read it in every client-side deserializer
(CLI's node_to_json/write_human_node, the Tauri desktop app's
proto_node_data_to_node and node_from_proto).

Frontend: per ADR-077, wire evaluateTitleTemplate into
person-schema-form.svelte and generic-schema-form.svelte so a
title-templated node's title updates in sharedNodeStore instantly on
oninput, independent of the backend round trip. Pushed via a separate
isComputedField update (skips persistence/OCC) so it never fights the
field's own persisted write. person-schema-form.svelte tracks each
field's live value locally (not just the last blurred one) since a user
can tab between name fields and keep typing before either blurs.

Correct person-schema-form.test.ts's mock, which fabricated a title the
real backend never sent; add coverage crossing the actual gRPC
serialization boundary (node_to_proto unit tests plus a full
create/update/fetch round trip through the daemon's real RPC handlers)
for both person and a second, non-person title_template schema.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
packages/dev-tools/src/dev-proxy.ts's nodeDataToApiNode() is a third,
independent NodeData->JS conversion (hand-maintained ProtoNodeData
interface, used only by the browser dev-mode HTTP path) that had the
same gap as the two Rust conversions fixed in the prior commit — add
title to the interface and forward it, collapsing absent-or-empty to
null the same way this function already treats parentId/collectionId.

Also rewrites a few comments that cited the issue number inline
(caught by scripts/check-code-references.ts's ratchet) to describe the
behavior directly instead, per CLAUDE.md.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Adversarial review caught that nodeDataToApiNode() collapsed a
legitimately-empty title (title_template fields all still blank) to
null, the same as absent — contradicting the presence distinction the
daemon, CLI, and both Tauri conversions all correctly preserve. Only
true absence (undefined) now maps to null; an empty string passes
through unchanged, unlike parentId/collectionId (real relationship
references, where "" and absent genuinely are the same thing).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Second adversarial review round found that evaluateTitleTemplate did
plain token substitution, unlike interpolate_title_template_with_schema
(the Rust function compute_title() actually calls), which resolves an
enum field's stored value to its label. Any title_template referencing
an enum field would flash the raw value ("p1") in the instant client
preview, then correct to the label ("P1 - Critical") once the backend's
round trip landed.

evaluateTitleTemplate now takes an optional `fields` parameter and does
the same enum-label lookup (but not date reformatting, unlike the
separate evaluateSummaryTemplate, matching the backend's actual title
computation exactly). generic-schema-form.svelte passes schema.fields
through; person-schema-form.svelte omits it since neither of its two
hardcoded fields is an enum.

Also extracts the "compute template, diff against current title,
conditionally push via isComputedField" kernel both forms independently
implemented into a shared pushComputedTitle() helper, so a future change
to that mechanism has one call site to update, not two.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Second adversarial review round found two more paths in the same class
as the issue's root cause: upsert_node_with_parent (the transactional
autosave upsert) built its NodeUpdate with title left None, which the
store layer treats as "leave the DB column unchanged" — an ordinary
content edit through desktop autosave left the title stale. Fix it the
same way update_node_unchecked already does: merge the new content into
a clone of the existing node, call compute_title, and pass the result
through as Some(new_title) instead of leaving it None. The node is
always attached to a parent by the end of this call, so is_root is
always Some(false), matching create_node's parent_id.is_none() pattern.

UpdateNodesBatch (the daemon RPC behind CLI batch updates) does not
have the analogous bug: it also builds a NodeUpdate with title: None,
but that field is never read by NodeService::update_node's
update_with_version_check_returning_node, which always recomputes its
own title_update from the merged node state regardless of what the
caller passed. Added a regression test on each path since neither was
previously covered: one exercising update_nodes_batch through the real
gRPC handler, one exercising upsert_node_with_parent's update branch
directly.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
pushComputedTitle's title preview fires on every keystroke, and each call
went through updateNode()'s "track pending update for potential rollback"
path unconditionally. isComputedField implies skipPersistence, which makes
determinePersistenceBehavior short-circuit before the real persist block
that would otherwise remove that entry on success/failure — so every one
of these writes accumulated in pendingUpdates with nothing to ever clean
it up, unbounded by anything but keystrokes-per-edit-burst. Skip tracking
these writes at all: they never persist and are never eligible for the
rollback this bookkeeping exists for.

Also documents the known gap this doesn't fix (B1 from review): a failed
real persist has no path back to reset the speculative title, since the
two writes are independent updateNode() calls with no cross-reference.
Left as a follow-up rather than risking a same-PR fix in the write-failure
path, which already carries several carefully-reasoned race-condition
mitigations.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.

NodeData proto (daemon) never sends title field — dropped for every client and title-templated node type

1 participant