Repository navigation
Description
Spun off from architectural-audit tracking issue #1228, finding C4 (message/entity shapes converted at multiple boundaries). Reframed after verification — the audit's premise is partly won't-do; the real, scopeable win is narrower. See below.
Background — and an important correction
The audit said: "Three message/entity shapes converted at multiple boundaries; normalize once at the sync boundary; reduce per-viewer converters." Two distinct things are bundled there, and they should be treated differently:
NOT in scope — the 3 chat message shapes are deliberately distinct
packages/desktop-app/src/lib/components/chat/types.ts documents (and the project's frontend-type-layering decision affirms) that the three chat message shapes — protocol/wire (ChatMessage in $lib/types/agent-types), view-model (DisplayMessage), and the ADR-028 persisted JSON shape on ai-chat node properties — deliberately do NOT converge; converters bridge them at the viewer boundary on purpose. Collapsing them would erase an intentional layering boundary. Leave these as-is. (The nodeToTaskNode converter at task-node.ts:268 is similarly a legitimate type-specific view conversion, not redundancy.)
IN scope — the duplicated sync-boundary normalizer
The genuinely-redundant part: there are two byte-identical normalizeNodeData implementations, one per sync path:
packages/desktop-app/src/lib/services/tauri-sync-listener.ts:61-67packages/desktop-app/src/lib/services/browser-sync-service.ts:205-211
Both are exactly:
function normalizeNodeData(nodeData: Node): Node {
if (nodeData.nodeType === 'task') {
return nodeToTaskNode(nodeData) as unknown as Node;
}
// Add other type-specific conversions here as needed (e.g., SchemaNode)
return nodeData;
}This is the "normalize once at the sync boundary" the audit wanted: a single node-normalization function both sync paths call, instead of two hand-synced copies that will drift the moment someone adds a SchemaNode branch to one and forgets the other. (Same class of bug C2/#1250 fixed for the dual hierarchy caches — two sync paths, one rule, hand-synced.)
The task
- Extract the duplicated
normalizeNodeDatainto a single shared function — the natural home is alongside the C2-era unified sync helperservices/hierarchy-sync.ts, or a smallservices/node-normalize.ts. Bothtauri-sync-listener.tsandbrowser-sync-service.tsimport and call it at theirfetchAndUpdateNode/setNodesites. - Delete both local copies. After this, adding a future type branch (e.g.
SchemaNode) is a one-place change applied uniformly to both runtime modes. - Do not touch the chat message shapes (
chat/types.ts,DisplayMessage, the protocol/persisted converters) ornodeToTaskNodeitself — those are deliberate layering, out of scope (document this in the PR so a reviewer doesn't expect them changed).
Acceptance criteria
- One shared node-normalization function exists; both
tauri-sync-listener.tsandbrowser-sync-service.tscall it. - The two local
normalizeNodeDatacopies are deleted. - A type-specific normalization (the existing
taskbranch, and a hypothetical futureSchemaNodebranch) is defined in exactly one place and applied identically in Tauri and browser modes. - No change to the chat message shapes or
nodeToTaskNode(deliberate layering preserved). - No
anyintroduced beyond the existingas unknown as Nodecast (which moves, not multiplies);bun run checkclean;createLoggeronly.
Testing
- Parity test: feed the same
tasknode through both the Tauri sync path and the browser sync path; assert both produce identical normalized output via the shared function (anti-drift guard — the whole point). - Existing
tauri-sync-listener.test.tsandbrowser-sync-service.test.tsstill green after the extraction (bun run test, neverbun test). -
bun run test:allbefore PR.
Coordination
- Small, frontend-only, parallel-safe. Touches the two sync-listener files + a new shared helper. No overlap with C3a (C3a: Delete frontend outdent ordering math — trust the daemon's authoritative order via relationship events #1259, ordering) / C3b (C3b: Enforce container rule (canHaveChildren) in the daemon; source the frontend UI gate from schema #1260, container rules) beyond living near
hierarchy-sync.ts— coordinate the import if both are in flight, but the functions are disjoint. - Builds on C2 (C2: Make structureTree single source of truth — unify dual sync paths + invariant check #1250) which established the unified-sync-helper pattern these normalizers should follow.
Standard NodeSpace startup / PR sequence
EnterWorktree({name: "issue-<N>-c4-shared-node-normalize"}), bun install, bun run test baseline, gh:*. createLogger not console; bun run test not bun test. Before PR: bun run test:all + bun run check (no new failures), bun run quality:fix + commit (revert unrelated reformats), bun run gh:pr <N>, /pragmatic-code-review, then ExitWorktree + gh pr merge --squash --delete-branch.
Spun off from #1228 (architectural audit), finding C4 (reframed: the genuinely-redundant duplicated sync normalizer; the 3 chat message shapes are deliberate layering and out of scope).
Activity
C4: Deduplicate the sync-boundary normalizeNodeData (one shared norma…
C4: Deduplicate the sync-boundary normalizeNodeData (one shared norma…