Skip to content

Flatten typed properties in optimistic updateNode merge (closes #1695) - #1732

Merged
mstomar125 merged 1 commit into
mainfrom
worktree-issue-1695-optimistic-flatten
Jul 24, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
worktree-issue-1695-optimistic-flatten

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

Fixes an ai-chat UI lag: the optimistic (pre-round-trip) merge in SharedNodeStore.updateNode() shallow-spread changes, so a namespaced { properties: {...} } write (a) replaced node.properties wholesale and (b) never flattened properties.* into the top-level fields components read. As a result, selecting a model (textarea gated on top-level node.model) and sending a message (list reads top-level node.messages) both appeared to hang for one network/IPC round trip, until the backend's already-flattened response arrived.

The backend node_to_typed_value (nodespace-types/src/convert.rs) remains the single flattening authority; this adds a minimal, optimistic-only mirror so the pre-round-trip state reflects the same top-level fields the backend would promote. The backend response always overwrites these, so any drift degrades optimistic latency only — never correctness.

Changes

  • node-normalize.ts — new OPTIMISTIC_TYPED_FIELDS map (the exact per-type fields convert.rs promotes: ai-chat status/provider/model/messages, task status/priority/dueDate/assignee/startedAt/completedAt), plus deepMergeProperties (one-level merge + one level into the [nodeType] namespace) and promoteTypedFields (promotes a field only if present in this write — flat properties.x or nested properties.<type>.x — so an omitted field never clobbers a top-level value with undefined).
  • shared-node-store.svelte.ts — the optimistic merge deep-merges properties and spreads the promoted top-level fields into the new node.
  • update-protocol.ts — new UpdateOptions.replaceProperties (default deep-merge; true = use the incoming bag as-is).
  • reactive-node-service.svelte.ts — updateNodeProperties() passes replaceProperties: true (it already computes the full merged/replaced bag), preserving its merge: false = wholesale-replace contract.
  • schema-field-update.ts / schema-property-form.svelte — pass replaceProperties: true in their old-format migration paths (which deliberately drop flat keys and build the full bag), so the deep-merge default doesn't re-add the dropped keys to the optimistic node (surfaced by review).

Anti-divergence

The typed-field list is one tiny table colocated in node-normalize.ts with a doc comment pointing at convert.rs, and is always overwritten by the authoritative backend echo — so it can never cause a correctness divergence, only an optimistic-latency one.

Verification

  • New tests: node-normalize.test.ts (+8 — deep-merge sibling/namespace/missing-bag; promote present-only/nested/null/no-map/map-alignment) and shared-node-store.test.ts (+5 — flat ai-chat promotion, message-send preserves provider/model via the omitted-field guard, deep-merge keeps sibling keys, nested task promotion, non-typed node untouched). All green.
  • Caught + fixed a regression: updateNodeProperties(merge=false) expects wholesale replace; now flagged via replaceProperties: true.
  • Full frontend suite: 166 files, 4091 tests passing; svelte-check: 0 errors / 1768 files.
  • Independent adversarial review: CONFIRMED-GOOD. Key finding: the deep-merge changes only the local optimistic node — the persisted wire payload is still built from the raw changes.properties (shared-node-store.svelte.ts capture path), so the backend stays the flattening authority and no persistence/corruption path is introduced; the backend echo reconciles. All updateNode({ properties }) call sites audited; the two schema-migration sites above were the only ones needing replaceProperties. Content typing ({ content, nodeType }, no properties) short-circuits the new block entirely, so the real hot path is unaffected.

Closes #1695.

The optimistic (pre-round-trip) merge shallow-spread changes, so a namespaced
{ properties: {...} } write replaced properties wholesale and never flattened
properties.* into the top-level fields viewers read — so ai-chat's model
selection and sent messages appeared to hang for a full RPC round trip.

Adds a minimal optimistic-only mirror of the backend's node_to_typed_value
promotion (OPTIMISTIC_TYPED_FIELDS in node-normalize.ts, kept in sync with
convert.rs), plus deepMergeProperties/promoteTypedFields. The optimistic merge
now deep-merges properties and promotes typed fields immediately; the backend
echo still overwrites them, so drift affects latency only, never correctness.

Adds UpdateOptions.replaceProperties for callers that compute their own full
properties bag (updateNodeProperties, schema migration paths) so they aren't
re-merged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Independent adversarial review returned CONFIRMED-GOOD. The de-risking finding: the deep-merge changes only the local optimistic node — the persisted wire payload is still built from the raw changes.properties, so the backend remains the flattening authority and no persistence/corruption path is introduced; the backend echo reconciles. Every updateNode({ properties }) caller was audited: ai-chat handlers get the intended fix, full-bag builders are no-ops, and the only sites needing replaceProperties: true (updateNodeProperties + the two schema old-format migration branches that deliberately drop flat keys) now set it. Undefined-clobber guard, nested-vs-flat handling, array identity, hot-path short-circuit (content typing has no properties), and rollback all verified. Full frontend suite 4091/4091, svelte-check 0 errors.

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.

Optimistic updateNode merge doesn't flatten properties.* into top-level fields, causing ai-chat UI to lag behind RPC round-trip

1 participant