Repository navigation
Description
#19979 made the agent's remote graph apply restore widget values that arrive under positional _extra_N names. The document addresses a widget that way when the widget's real name only exists after a dynamic combo (a node input that swaps out its child widgets when the selection changes) has rebuilt its children.
A multi-model review of the release backport, #20561, raised ten findings against src/workbench/extensions/agent/crdt/liveGraphApplier.ts. That backport copies #19979 unchanged, so every finding describes code that is already on main. The full text of each one is in the review comments on #20561. This issue tracks the ones that look like real defects after reading the code. None of them blocks the backport.
Correctness
A partial frame loses values that only become addressable once the frame applies. syncWidgets filters a node's document widget map down to the changed keys, and changed() resolves an _extra_N alias against the live widget list as it stands before the frame. An alias whose target index does not exist yet resolves to nothing and gets filtered out. A frame carrying only mode therefore applies the new selection, rebuilds the children at the new option's defaults, and never reads back mode.a or _extra_2 even though the document still holds them. The retry loop in applyWidgets cannot recover them because it only ever retries entries that survived that filter. The same loss hits a value held back by holdsLocalWrite, since the later echo is skipped at follower entry.
On node creation, values are written at pre-configure indices and read back at post-configure indices. createNode computes positionalWidgetValues against the constructed widget list, then configure restores those values positionally over whatever list exists after the selection callback has run. A dynamic combo's option swap changes both child count and order, so a value can land on the wrong widget. The deferred mountedWidgetValues pass does not catch it: it excludes any name that was in the constructed list, and excludes an alias whose index is inside constructed.length. With constructed [mode, mode.x, mode.a] and a document of {mode: 'faithful', 'mode.a': 91, '_extra_2': 71}, 91 lands on a sibling of mode.a and neither entry is re-applied.
Retry rounds reuse the ordering computed before any selector ran. applyWidgets ranks entries once with ordinaryWidgetEntries, then sets pending = unresolved each round without re-ranking. Entries that are not yet mounted all rank MOUNTED_LAST, so they keep Y.Map insertion order for the whole loop. If an outer selector mounts both a nested selector and that selector's child in round one, round two can apply the child first and then the nested selector, whose setter rebuilds the child back to its default. Both resolved, so nothing retries. Ranks only become meaningful as widgets mount, which argues for re-ranking pending at the start of each round.
The alias identity check in positionalWidgetValues is always true, so an alias can be applied twice. Inside the map, overflowWidget(node, alias) and widget are both serializableWidgets(node)[index], so the condition reduces to supportsDynamicWidgetOverflow(node) && Object.hasOwn(widgets, alias) and never checks that _extra_<index> is not the real name of a different live widget. On a dynamic-combo node that owns a widget literally named _extra_1, one document entry is applied both to the widget at index 1 and to the widget actually named _extra_1, firing both callbacks. supersededOverflowAlias already guards exactly this with node.widgets?.some((w) => w.name === name). This one needs an unusual node class to trigger, but the asymmetry between the two functions is real.
A value that fails validation can silently suppress a valid alias. applyWidgets drops entries whose value fails isWidgetValue, but supersededOverflowAlias judges supersession against the raw document map. A frame carrying {'mode.b': <invalid>, '_extra_2': <valid>} applies neither and reports nothing, because mode.b is dropped by validation and _extra_2 is skipped as superseded by it. Either judge supersession against the filtered entries, or report when the named entry was discarded.
A throw in the deferred widget pass aborts node creation. The applyWidgets call at the end of createNode fires widget.callback on freshly mounted sub-widgets, and dynamicComboWidget's updateWidgets throws on a missing insertion point. The throw skips floorSizeToContent and propagates out of upsertNode into the per-node try, which means a recreated node never reaches the loop that reconnects its incident links. The failure is reported rather than silent, but the node is left disconnected. Isolating failures per entry, or wrapping just that pass, would keep one bad widget from costing the node its links.
Unresolved alias reports grow without bound. reportMissingWidgets reports unresolved aliases even when reportMissing is false, and the reported set is keyed widget:${nodeId}:${name} and never pruned for widget keys. A document whose catalog is skewed against the live widget list emits one report per alias per node in a single frame and grows the set forever. A per-node or per-frame cap would bound it.
inputSpecTree recurses with no depth limit, in src/schemas/nodeDef/inputSpecTree.ts. The doc comment rules out cycles but not unbounded depth, and /object_info content comes from third-party node packs. A deeply nested COMFY_DYNAMICCOMBO_V3 definition overflows the stack. Reached through the agent applier the RangeError is swallowed, so every node of that type silently fails to apply. This module has other callers, so a cap belongs in the module rather than at one call site.
Performance
The overflow gate runs before the cheap name test and is not cached. overflowWidget calls supportsDynamicWidgetOverflow(node) before testing name against OVERFLOW_WIDGET_NAME_RE, so every call re-walks the node's whole input-spec tree running safeParse per nested input. changed(), documentWidget() and positionalWidgetValues() each reach it once per document key per frame, so one remote edit on a node with many widget keys repeats that walk on the main thread during streaming. Swapping the two lines returns O(1) for a non-alias name, and the verdict is static per node type, so it can be memoized there.
widgetEntryRank allocates inside a sort comparator. It is the comparator for ordinaryWidgetEntries, so each of the O(N log N) comparisons builds two fresh serializableWidgets(node) arrays and scans them linearly. Hoisting the live list and building a name-to-index Map once before sorting removes it.
Task Decomposition
Ten independent remedies. Items 1 and 2 share a fix (replay named values from the document instead of inferring from indices), so they should land together. Everything else is independent and separately landable, which makes this a candidate for several small PRs rather than one.
| # | Sub-task | Tier | Depends on | Acceptance |
|---|---|---|---|---|
| 1 | Replay the node's whole document widget map when an applied entry mounts or rebuilds widgets, instead of the changed subset | analytical | — | A frame carrying only mode restores mode.a and _extra_2 from the document |
| 2 | On creation, match widgets by identity after configure rather than by pre-configure index |
analytical | 1 (shared remedy) | Constructed [mode, mode.x, mode.a] with document {mode: 'faithful', 'mode.a': 91, '_extra_2': 71} puts 91 on the widget the document names, not on a positional sibling |
| 3 | Re-rank pending at the start of each retry round |
routine | — | A nested selector is applied before the child it rebuilds, with the child's value surviving |
| 4 | Guard the creation path's alias resolution against a live widget whose real name is _extra_<index>, plus an arity check |
routine | — | A dynamic-combo node owning a widget named _extra_1 receives one write, not two |
| 5 | Judge supersession against the validated entries, or report when the named entry was discarded | routine | — | {'mode.b': <invalid>, '_extra_2': <valid>} either applies the alias or reports the discard |
| 6 | Isolate per-entry failures in the deferred widget pass in createNode |
routine | — | A throwing widget callback still leaves a recreated node's incident links reconnected |
| 7 | Cap unresolved-alias reports per node or per frame | trivial | — | Many skewed aliases on one node emit a bounded number of reports |
| 8 | Add a depth limit to inputSpecTree in src/schemas/nodeDef/inputSpecTree.ts |
routine | — | A definition nested past the cap returns a bounded walk and reports, instead of throwing RangeError |
| 9 | Test the _extra_N name pattern before the overflow gate, and memoize the gate per node type |
trivial | — | A non-alias name returns without walking the input-spec tree |
| 10 | Hoist the live widget list and build a name-to-index map before sorting | trivial | — | The sort comparator allocates nothing per comparison |
Item 8 is in a module with callers outside the agent, so it may belong to a different owner than items 1 to 7, 9 and 10.
Activity