Repository navigation
Add title to NodeData proto and wire client-side title preview - #2645
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 notitlefield at all, sonode_to_protosilently dropped the server-computed title for every client (CLI, Tauri desktop app, MCP — which is CLI-backed) reading a node over gRPC, even thoughNodeService::compute_titlecomputed and persisted it correctly to SQLite.optional string title = 12;toNodeData(verified 12 is the next free field number; 4 and 10 are reserved) —optionalbecause 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_protonow mapsnode.titleinto it.title: None: the CLI'snode_to_json/write_human_node(packages/cli/src/output.rs), the Tauri desktop app'sproto_node_data_to_node(packages/desktop-app/src-tauri/src/commands/nodes.rs) and the separatenode_from_protoused 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'snodeDataToApiNode).upsert_node_with_parent(the transactional desktop-autosave upsert) built itsNodeUpdatewithtitleleftNone(leaving the DB title stale after an ordinary autosave content edit) — fixed the same wayupdate_node_uncheckedalready does, by recomputing from the merged node state.UpdateNodesBatchlooked similar but turned out not to have the bug (itstitle: Noneis never actually read —update_with_version_check_returning_nodealways 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
evaluateTitleTemplateinto:person-schema-form.svelte:oninputhandlers 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 atitleTemplate(the general, non-person path a user-defined title-templated type actually renders through),updateFieldnow also pushes a computed title alongside the field's own write. Passesschema.fieldsthrough so an enum field referenced by the template resolves to its label, matchingcompute_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
sharedNodeStorevia a sharedpushComputedTitle()helper, gated onisComputedField: 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 apendingUpdatesleak this new per-keystroke path exposed:isComputedFieldwrites were still being tracked for rollback even though they never persist and are never eligible for it, so nothing ever cleared their entries.Both
person-schema-form.test.ts's mock, which fabricated atitlefield (`${first_name} ${last_name}`.trim() || 'Untitled') the real backend never actually sent — the exact gap that let this bug ship. Added coverage that deliberately omitstitlefrom the mocked backend response and proves the preview still resolves correctly with the backend write left permanently unresolved.node_to_protounit test, plus fullSetLocalPersonIdentity/CreateSchema+CreateNode/GetNode/UpdateNodesBatchround trips through the daemon's realNodeServiceImplRPC handlers (not just the in-processNodeServicelayer the existing service-layer test used) — covering bothpersonand a second, non-person title-templated schema (ticket,"{severity}: {subject}"), per the issue's explicit "not person-specific" requirement.person-schema-form.svelte's save throughsharedNodeStore.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:fixclean (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 evolvedcargo build --bin nodespaced— cleanbun run test:e2e(27/27, real daemon round trip) — all greencargo test -p nodespace-app --test "*"(ADR-048 Tauri-seam integration tests, includingnode_crud_tauri_seam_test.rsand the real-socketgrpc_round_trip.rs) — all greenSome("")tonull(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