Skip to content

C4: Deduplicate the sync-boundary normalizeNodeData (one shared normalizer for both sync paths) #1266

Closed

Description

@malibio

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-67
  • packages/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

  1. Extract the duplicated normalizeNodeData into a single shared function — the natural home is alongside the C2-era unified sync helper services/hierarchy-sync.ts, or a small services/node-normalize.ts. Both tauri-sync-listener.ts and browser-sync-service.ts import and call it at their fetchAndUpdateNode / setNode sites.
  2. 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.
  3. Do not touch the chat message shapes (chat/types.ts, DisplayMessage, the protocol/persisted converters) or nodeToTaskNode itself — 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.ts and browser-sync-service.ts call it.
  • The two local normalizeNodeData copies are deleted.
  • A type-specific normalization (the existing task branch, and a hypothetical future SchemaNode branch) 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 any introduced beyond the existing as unknown as Node cast (which moves, not multiplies); bun run check clean; createLogger only.

Testing

  • Parity test: feed the same task node 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.ts and browser-sync-service.test.ts still green after the extraction (bun run test, never bun test).
  • bun run test:all before PR.

Coordination

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

  1. self-assigned this
    on May 30, 2026
  2. added a commit that references this issue on May 30, 2026
    11a65e5
  3. added a commit that references this issue on Jun 22, 2026
    f7acdf1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions