Repository navigation
Flatten typed properties in optimistic updateNode merge (closes #1695) - #1732
Conversation
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]>
|
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 |
Summary
Fixes an ai-chat UI lag: the optimistic (pre-round-trip) merge in
SharedNodeStore.updateNode()shallow-spreadchanges, so a namespaced{ properties: {...} }write (a) replacednode.propertieswholesale and (b) never flattenedproperties.*into the top-level fields components read. As a result, selecting a model (textarea gated on top-levelnode.model) and sending a message (list reads top-levelnode.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— newOPTIMISTIC_TYPED_FIELDSmap (the exact per-type fields convert.rs promotes: ai-chatstatus/provider/model/messages, taskstatus/priority/dueDate/assignee/startedAt/completedAt), plusdeepMergeProperties(one-level merge + one level into the[nodeType]namespace) andpromoteTypedFields(promotes a field only if present in this write — flatproperties.xor nestedproperties.<type>.x— so an omitted field never clobbers a top-level value withundefined).shared-node-store.svelte.ts— the optimistic merge deep-mergespropertiesand spreads the promoted top-level fields into the new node.update-protocol.ts— newUpdateOptions.replaceProperties(default deep-merge;true= use the incoming bag as-is).reactive-node-service.svelte.ts—updateNodeProperties()passesreplaceProperties: true(it already computes the full merged/replaced bag), preserving itsmerge: false= wholesale-replace contract.schema-field-update.ts/schema-property-form.svelte— passreplaceProperties: truein 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.tswith a doc comment pointing atconvert.rs, and is always overwritten by the authoritative backend echo — so it can never cause a correctness divergence, only an optimistic-latency one.Verification
node-normalize.test.ts(+8 — deep-merge sibling/namespace/missing-bag; promote present-only/nested/null/no-map/map-alignment) andshared-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.updateNodeProperties(merge=false)expects wholesale replace; now flagged viareplaceProperties: true.svelte-check: 0 errors / 1768 files.changes.properties(shared-node-store.svelte.tscapture path), so the backend stays the flattening authority and no persistence/corruption path is introduced; the backend echo reconciles. AllupdateNode({ properties })call sites audited; the two schema-migration sites above were the only ones needingreplaceProperties. Content typing ({ content, nodeType }, noproperties) short-circuits the new block entirely, so the real hot path is unaffected.Closes #1695.