From 4f650f9e5c39264af9bd8c0ffb9ca89705264c94 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 18 Oct 2026 05:31:40 +0000 Subject: [PATCH 1/6] test(agent): reproduce undo restore refused over a pack's display-only DOM widget (PM-2165) --- .../extensions/agent/crdt/docOpMinter.test.ts | 64 ++++++++++++++++- .../agent/crdt/restoreOpMinter.test.ts | 69 +++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts index f717482e149..28e26e23d98 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts @@ -102,6 +102,37 @@ class TestPrompt extends LGraphNode { } } +/** + * Mirrors a custom node pack's video loader (VHS_LoadVideo): a catalog value + * widget plus a display-only DOM preview the pack registers with + * `serialize: false` in its OPTIONS. Litegraph still persists that preview + * into the workflow (widget-level `serialize` is unset), but it is not a + * prompt input, so the catalog's `widget_order` never names it. + */ +class TestVideoLoader extends LGraphNode { + constructor() { + super('Test Video Loader') + this.addWidget('combo', 'video', 'clip.mp4', () => {}, { + values: ['clip.mp4'] + }) + this.addWidget('button', 'choose video to upload', 'image', () => {}) + let preview: Record = { hidden: false, params: {} } + this.addDOMWidget( + 'videopreview', + 'preview', + document.createElement('div'), + { + serialize: false, + getValue: () => preview, + setValue: (value: Record) => { + preview = value + } + } + ) + this.serialize_widgets = true + } +} + class TestDynamicGroup extends LGraphNode { constructor() { super('Test Dynamic Group') @@ -142,7 +173,8 @@ const CATALOG: WidgetCatalog = { TestSource: { widget_order: ['steps'] }, TestSink: { widget_order: [] }, TestAutogrowSink: { widget_order: [] }, - TestPrompt: { widget_order: ['text'] } + TestPrompt: { widget_order: ['text'] }, + TestVideoLoader: { widget_order: ['video'] } } } @@ -198,6 +230,7 @@ beforeEach(() => { LiteGraph.registerNodeType('TestAutogrowSink', TestAutogrowSink) LiteGraph.registerNodeType('TestNote', TestNote) LiteGraph.registerNodeType('TestPrompt', TestPrompt) + LiteGraph.registerNodeType('TestVideoLoader', TestVideoLoader) LiteGraph.registerNodeType('TestDynamicGroup', TestDynamicGroup) LiteGraph.registerNodeType('TestEmptyComboGroup', TestEmptyComboGroup) }) @@ -583,6 +616,35 @@ describe('attachDocOpMinter', () => { doc.destroy() }) + // PM-2165: undoing an agent's deletion re-adds each node as a human + // add_node. A pack's display-only DOM preview (VHS `videopreview`) rode + // along as a named value, the applier refused it as `unknown_widget`, and + // the rest of the restore batch was aborted, so Ctrl+Z could not bring the + // workflow back. + it('leaves a display-only DOM widget out of a catalogued add_node, and the applier takes it', async () => { + const loader = new TestVideoLoader() + graph.add(loader) + await afterFlush() + + expect(minted).toEqual([ + expect.objectContaining({ + op: 'add_node', + class_type: 'TestVideoLoader', + node: expect.objectContaining({ + widgets_values: { video: 'clip.mp4' } + }) + }) + ]) + const doc = mint({ nodes: [], links: [] }, CATALOG) + const { outcomes } = applyOps( + doc, + mintWireOps(minted, { actor: 'human:user:tab', baseVersion: 1 }), + CATALOG + ) + expect(outcomes).toEqual([expect.objectContaining({ outcome: 'applied' })]) + doc.destroy() + }) + describe("link ops address the document's own input order", () => { /** A sink whose live input order (`mask`, `image`) is the reverse of the document's. */ function seedReorderedSink() { diff --git a/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts b/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts index 2f0cfd1f9da..375a919590b 100644 --- a/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts +++ b/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts @@ -1,8 +1,11 @@ +import { applyOps, mint } from '@comfyorg/comfy-multi-player' +import type { WidgetCatalog, WorkflowJSON } from '@comfyorg/comfy-multi-player' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' import type { GraphOperation } from './graphOperations' +import { mintWireOps } from './opEnvelope' import { attachRestoreOpMinter, notifyRestoreMintersAfterGraphConfigure, @@ -20,6 +23,29 @@ class TestSource extends LGraphNode { } } +/** A pack node whose display-only DOM preview is persisted but not a catalog widget (VHS). */ +class TestPreviewSource extends LGraphNode { + constructor() { + super('Test Preview Source') + this.addWidget('text', 'image', 'a.png', () => {}) + let preview: Record = { hidden: false } + this.addDOMWidget( + 'videopreview', + 'preview', + document.createElement('div'), + { + serialize: false, + getValue: () => preview, + setValue: (value: Record) => { + preview = value + } + } + ) + this.addOutput('image', 'IMAGE') + this.serialize_widgets = true + } +} + class TestSink extends LGraphNode { constructor() { super('Test Sink') @@ -30,6 +56,7 @@ class TestSink extends LGraphNode { beforeEach(() => { LiteGraph.registerNodeType('TestSource', TestSource) LiteGraph.registerNodeType('TestSink', TestSink) + LiteGraph.registerNodeType('TestPreviewSource', TestPreviewSource) }) /** @@ -120,6 +147,48 @@ describe('attachRestoreOpMinter', () => { ]) }) + // PM-2165: undoing an agent's deletion of a custom-pack node minted its + // display-only preview as a named widget value; the doc host refused the + // add_node as unknown_widget and aborted the rest of the restore batch. + it('restores a deleted node with a display-only DOM widget in a batch the applier takes whole', () => { + const catalog: WidgetCatalog = { + types: { + TestSource: { widget_order: ['image'] }, + TestSink: { widget_order: [] }, + TestPreviewSource: { widget_order: ['image'] } + } + } + const preview = new TestPreviewSource() + graph.add(preview) + graph.remove(preview) + // The document as the host holds it after the agent's deletion. + const doc = mint(graph.serialize() as unknown as WorkflowJSON, catalog) + const restored = new TestPreviewSource() + restored.id = preview.id + + restoreThrough(() => { + graph.add(restored) + restored.connect(0, sink, 0) + }) + + expect(minted[0]).toMatchObject({ + op: 'add_node', + node: { widgets_values: { image: 'a.png' } } + }) + expect( + (minted[0] as { node: { widgets_values: object } }).node.widgets_values + ).not.toHaveProperty('videopreview') + const { outcomes } = applyOps( + doc, + mintWireOps(minted, { actor: 'human:user:tab', baseVersion: 1 }), + catalog + ) + expect(outcomes.map((outcome) => outcome.outcome)).toEqual( + minted.map(() => 'applied') + ) + doc.destroy() + }) + it('maps a restored link target from live slot order to document order', () => { sink.addInput('prompt', 'STRING') docInputs = ['prompt', 'image'] From dab602e62a4174b069bd6bbd2f9fdaebacb2f77d Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 18 Oct 2026 05:32:05 +0000 Subject: [PATCH 2/6] fix(agent): keep display-only DOM widgets out of human add_node values (PM-2165) A custom pack's DOM preview registered with options.serialize false (VHS videopreview) is still persisted by litegraph, so wireNodeSnapshot sent it as a named widget value. The catalog never names it, the doc host refused the add_node as unknown_widget, and an undo of the agent's deletion lost the whole restore batch. --- .../extensions/agent/crdt/docOpMinter.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.ts b/src/workbench/extensions/agent/crdt/docOpMinter.ts index 0da2954731d..bcb580259d0 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.ts @@ -30,6 +30,7 @@ import type { ISerialisedNode } from '@/lib/litegraph/src/types/serialisation' import { isWidgetValue } from '@/lib/litegraph/src/types/widgets' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { reportError } from '@/platform/telemetry/reportError' +import { isComponentWidget, isDOMWidget } from '@/scripts/domWidget' import { useWidgetValueStore } from '@/stores/widgetValueStore' import type { RootGraphId } from '@/types/graphScopeId' import type { NodeId } from '@/types/nodeId' @@ -166,7 +167,24 @@ function isValueWidget( // One construct for both fields, so the two halves of the guard cannot // drift apart again. const { type = stored?.type, serialize = stored?.serialize } = widget ?? {} - return type !== 'button' && serialize !== false + if (type === 'button' || serialize === false) return false + return !(widget && isDisplayOnlyDomWidget(widget)) +} + +/** + * A DOM or component widget kept out of the prompt (`options.serialize: false`) + * is display state, not a node input: the catalog's `widget_order` comes from + * the node's prompt inputs, so it never names one. Litegraph still persists it + * in the workflow because its widget-level `serialize` is unset — a custom + * pack's video preview (VHS `videopreview`) is the case seen in prod. Sent as a + * named value it makes the applier refuse the whole `add_node` as + * `unknown_widget`, which aborted an undo's restore batch (PM-2165). + */ +function isDisplayOnlyDomWidget(widget: IBaseWidget): boolean { + return ( + (isDOMWidget(widget) || isComponentWidget(widget)) && + widget.options.serialize === false + ) } function nodeKey(graphId: string, nodeId: NodeId): string { From 72b00c050b8557292039f488c84de2968d7804b1 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 18 Oct 2026 06:37:58 +0000 Subject: [PATCH 3/6] fix(agent): keep a definition-declared DOM widget as a value even when kept out of the prompt (PM-2165) A custom widget type registered for one of the definition's inputs (core CAMERA_ANGLE_VIEW is one) can carry options.serialize false and still be a catalog widget. Only an undeclared display widget is dropped. --- .../extensions/agent/crdt/docOpMinter.test.ts | 34 +++++++++++++++++++ .../extensions/agent/crdt/docOpMinter.ts | 23 +++++++------ 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts index 28e26e23d98..b18d6f6b934 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts @@ -24,6 +24,7 @@ import { import { reportError } from '@/platform/telemetry/reportError' import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration' import { useLitegraphService } from '@/services/litegraphService' +import { useNodeDefStore } from '@/stores/nodeDefStore' import { useWidgetValueStore } from '@/stores/widgetValueStore' import { toRootGraphId } from '@/types/graphScopeId' import type { RootGraphId } from '@/types/graphScopeId' @@ -645,6 +646,39 @@ describe('attachDocOpMinter', () => { doc.destroy() }) + it('keeps a DOM widget out of the prompt as a value when its definition declares it', async () => { + useNodeDefStore().addNodeDef({ + name: 'TestVideoLoader', + display_name: 'Test Video Loader', + category: 'test', + python_module: 'test', + description: '', + output_node: false, + input: { + required: { video: [['clip.mp4'], {}] }, + optional: { videopreview: ['VIDEO_PREVIEW', {}] } + }, + output: [], + output_is_list: [], + output_name: [] + }) + const loader = new TestVideoLoader() + // A directly constructed test node carries no type; a created one does. + loader.type = 'TestVideoLoader' + graph.add(loader) + await afterFlush() + + expect(minted[0]).toMatchObject({ + op: 'add_node', + node: { + widgets_values: { + video: 'clip.mp4', + videopreview: { hidden: false, params: {} } + } + } + }) + }) + describe("link ops address the document's own input order", () => { /** A sink whose live input order (`mask`, `image`) is the reverse of the document's. */ function seedReorderedSink() { diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.ts b/src/workbench/extensions/agent/crdt/docOpMinter.ts index bcb580259d0..8231dcfeb38 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.ts @@ -31,6 +31,7 @@ import { isWidgetValue } from '@/lib/litegraph/src/types/widgets' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { reportError } from '@/platform/telemetry/reportError' import { isComponentWidget, isDOMWidget } from '@/scripts/domWidget' +import { useNodeDefStore } from '@/stores/nodeDefStore' import { useWidgetValueStore } from '@/stores/widgetValueStore' import type { RootGraphId } from '@/types/graphScopeId' import type { NodeId } from '@/types/nodeId' @@ -173,18 +174,20 @@ function isValueWidget( /** * A DOM or component widget kept out of the prompt (`options.serialize: false`) - * is display state, not a node input: the catalog's `widget_order` comes from - * the node's prompt inputs, so it never names one. Litegraph still persists it - * in the workflow because its widget-level `serialize` is unset — a custom - * pack's video preview (VHS `videopreview`) is the case seen in prod. Sent as a - * named value it makes the applier refuse the whole `add_node` as - * `unknown_widget`, which aborted an undo's restore batch (PM-2165). + * that the node's definition does not declare is display state, not a node + * input: the catalog's `widget_order` comes from the definition's inputs, so it + * never names one. Litegraph still persists it in the workflow because its + * widget-level `serialize` is unset — a custom pack's video preview (VHS + * `videopreview`) is the case seen in prod. Sent as a named value it makes the + * applier refuse the whole `add_node` as `unknown_widget`, which aborted an + * undo's restore batch (PM-2165). A declared one (a custom widget type + * registered for one of the definition's inputs) stays a value. */ function isDisplayOnlyDomWidget(widget: IBaseWidget): boolean { - return ( - (isDOMWidget(widget) || isComponentWidget(widget)) && - widget.options.serialize === false - ) + if (!isDOMWidget(widget) && !isComponentWidget(widget)) return false + if (widget.options.serialize !== false) return false + const definition = useNodeDefStore().fromLGraphNode(widget.node) + return !definition || !Object.hasOwn(definition.inputs, widget.name) } function nodeKey(graphId: string, nodeId: NodeId): string { From fdb07fa07a5df71110023a54bbead3ccedaa1a83 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 18 Oct 2026 07:20:21 +0000 Subject: [PATCH 4/6] fix(agent): judge display-only widgets by a dynamic-aware definition lookup and keep them without one (PM-2165) Review feedback: a missing definition no longer drops a value, dynamic children resolve through getInputSpecForWidget, the declared case is applied against a catalog that names it, and the new comments go. --- .../extensions/agent/crdt/docOpMinter.test.ts | 76 ++++++++++++------- .../extensions/agent/crdt/docOpMinter.ts | 16 +--- .../agent/crdt/restoreOpMinter.test.ts | 29 ++++--- 3 files changed, 68 insertions(+), 53 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts index b18d6f6b934..613f1a10da7 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts @@ -24,6 +24,7 @@ import { import { reportError } from '@/platform/telemetry/reportError' import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration' import { useLitegraphService } from '@/services/litegraphService' +import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema' import { useNodeDefStore } from '@/stores/nodeDefStore' import { useWidgetValueStore } from '@/stores/widgetValueStore' import { toRootGraphId } from '@/types/graphScopeId' @@ -103,13 +104,6 @@ class TestPrompt extends LGraphNode { } } -/** - * Mirrors a custom node pack's video loader (VHS_LoadVideo): a catalog value - * widget plus a display-only DOM preview the pack registers with - * `serialize: false` in its OPTIONS. Litegraph still persists that preview - * into the workflow (widget-level `serialize` is unset), but it is not a - * prompt input, so the catalog's `widget_order` never names it. - */ class TestVideoLoader extends LGraphNode { constructor() { super('Test Video Loader') @@ -169,6 +163,23 @@ class TestEmptyComboGroup extends LGraphNode { } } +function addVideoLoaderDef( + optional: NonNullable['optional'] = {} +) { + useNodeDefStore().addNodeDef({ + name: 'TestVideoLoader', + display_name: 'Test Video Loader', + category: 'test', + python_module: 'test', + description: '', + output_node: false, + input: { required: { video: [['clip.mp4'], {}] }, optional }, + output: [], + output_is_list: [], + output_name: [] + }) +} + const CATALOG: WidgetCatalog = { types: { TestSource: { widget_order: ['steps'] }, @@ -617,13 +628,10 @@ describe('attachDocOpMinter', () => { doc.destroy() }) - // PM-2165: undoing an agent's deletion re-adds each node as a human - // add_node. A pack's display-only DOM preview (VHS `videopreview`) rode - // along as a named value, the applier refused it as `unknown_widget`, and - // the rest of the restore batch was aborted, so Ctrl+Z could not bring the - // workflow back. it('leaves a display-only DOM widget out of a catalogued add_node, and the applier takes it', async () => { + addVideoLoaderDef() const loader = new TestVideoLoader() + loader.type = 'TestVideoLoader' graph.add(loader) await afterFlush() @@ -647,23 +655,8 @@ describe('attachDocOpMinter', () => { }) it('keeps a DOM widget out of the prompt as a value when its definition declares it', async () => { - useNodeDefStore().addNodeDef({ - name: 'TestVideoLoader', - display_name: 'Test Video Loader', - category: 'test', - python_module: 'test', - description: '', - output_node: false, - input: { - required: { video: [['clip.mp4'], {}] }, - optional: { videopreview: ['VIDEO_PREVIEW', {}] } - }, - output: [], - output_is_list: [], - output_name: [] - }) + addVideoLoaderDef({ videopreview: ['VIDEO_PREVIEW', {}] }) const loader = new TestVideoLoader() - // A directly constructed test node carries no type; a created one does. loader.type = 'TestVideoLoader' graph.add(loader) await afterFlush() @@ -677,6 +670,33 @@ describe('attachDocOpMinter', () => { } } }) + const catalog: WidgetCatalog = { + types: { TestVideoLoader: { widget_order: ['video', 'videopreview'] } } + } + const doc = mint({ nodes: [], links: [] }, catalog) + const { outcomes } = applyOps( + doc, + mintWireOps(minted, { actor: 'human:user:tab', baseVersion: 1 }), + catalog + ) + expect(outcomes).toEqual([expect.objectContaining({ outcome: 'applied' })]) + doc.destroy() + }) + + it('keeps a display-only DOM widget when the node has no definition to judge it by', async () => { + const loader = new TestVideoLoader() + loader.type = 'TestVideoLoader' + graph.add(loader) + await afterFlush() + + expect(minted[0]).toMatchObject({ + node: { + widgets_values: { + video: 'clip.mp4', + videopreview: { hidden: false, params: {} } + } + } + }) }) describe("link ops address the document's own input order", () => { diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.ts b/src/workbench/extensions/agent/crdt/docOpMinter.ts index 8231dcfeb38..44076914847 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.ts @@ -172,22 +172,12 @@ function isValueWidget( return !(widget && isDisplayOnlyDomWidget(widget)) } -/** - * A DOM or component widget kept out of the prompt (`options.serialize: false`) - * that the node's definition does not declare is display state, not a node - * input: the catalog's `widget_order` comes from the definition's inputs, so it - * never names one. Litegraph still persists it in the workflow because its - * widget-level `serialize` is unset — a custom pack's video preview (VHS - * `videopreview`) is the case seen in prod. Sent as a named value it makes the - * applier refuse the whole `add_node` as `unknown_widget`, which aborted an - * undo's restore batch (PM-2165). A declared one (a custom widget type - * registered for one of the definition's inputs) stays a value. - */ function isDisplayOnlyDomWidget(widget: IBaseWidget): boolean { if (!isDOMWidget(widget) && !isComponentWidget(widget)) return false if (widget.options.serialize !== false) return false - const definition = useNodeDefStore().fromLGraphNode(widget.node) - return !definition || !Object.hasOwn(definition.inputs, widget.name) + const nodeDefStore = useNodeDefStore() + if (!nodeDefStore.fromLGraphNode(widget.node)) return false + return !nodeDefStore.getInputSpecForWidget(widget.node, widget.name) } function nodeKey(graphId: string, nodeId: NodeId): string { diff --git a/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts b/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts index 375a919590b..d8edab8fcb7 100644 --- a/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts +++ b/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts @@ -3,6 +3,7 @@ import type { WidgetCatalog, WorkflowJSON } from '@comfyorg/comfy-multi-player' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' +import { useNodeDefStore } from '@/stores/nodeDefStore' import type { GraphOperation } from './graphOperations' import { mintWireOps } from './opEnvelope' @@ -23,7 +24,6 @@ class TestSource extends LGraphNode { } } -/** A pack node whose display-only DOM preview is persisted but not a catalog widget (VHS). */ class TestPreviewSource extends LGraphNode { constructor() { super('Test Preview Source') @@ -147,9 +147,6 @@ describe('attachRestoreOpMinter', () => { ]) }) - // PM-2165: undoing an agent's deletion of a custom-pack node minted its - // display-only preview as a named widget value; the doc host refused the - // add_node as unknown_widget and aborted the rest of the restore batch. it('restores a deleted node with a display-only DOM widget in a batch the applier takes whole', () => { const catalog: WidgetCatalog = { types: { @@ -158,12 +155,25 @@ describe('attachRestoreOpMinter', () => { TestPreviewSource: { widget_order: ['image'] } } } + useNodeDefStore().addNodeDef({ + name: 'TestPreviewSource', + display_name: 'Test Preview Source', + category: 'test', + python_module: 'test', + description: '', + output_node: false, + input: { required: { image: ['STRING', {}] } }, + output: ['IMAGE'], + output_is_list: [false], + output_name: ['image'] + }) const preview = new TestPreviewSource() + preview.type = 'TestPreviewSource' graph.add(preview) graph.remove(preview) - // The document as the host holds it after the agent's deletion. const doc = mint(graph.serialize() as unknown as WorkflowJSON, catalog) const restored = new TestPreviewSource() + restored.type = 'TestPreviewSource' restored.id = preview.id restoreThrough(() => { @@ -171,13 +181,8 @@ describe('attachRestoreOpMinter', () => { restored.connect(0, sink, 0) }) - expect(minted[0]).toMatchObject({ - op: 'add_node', - node: { widgets_values: { image: 'a.png' } } - }) - expect( - (minted[0] as { node: { widgets_values: object } }).node.widgets_values - ).not.toHaveProperty('videopreview') + expect(minted[0]).toMatchObject({ op: 'add_node' }) + expect(minted[0]).toHaveProperty('node.widgets_values', { image: 'a.png' }) const { outcomes } = applyOps( doc, mintWireOps(minted, { actor: 'human:user:tab', baseVersion: 1 }), From c7582399d5c6f6622c19de3bedb892e31e0af22b Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 18 Oct 2026 08:28:08 +0000 Subject: [PATCH 5/6] fix(agent): judge display-only widgets by the node's own input slots, not cross-domain stores (PM-2165) Review feedback: the agent integration zone may not import the node-def store or the DOM widget helpers. A definition-backed widget always owns an input slot named after it; an undeclared DOM preview does not. --- .../extensions/agent/crdt/docOpMinter.test.ts | 44 ++----------------- .../extensions/agent/crdt/docOpMinter.ts | 26 ++++++----- .../agent/crdt/restoreOpMinter.test.ts | 15 ------- 3 files changed, 18 insertions(+), 67 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts index 613f1a10da7..7d6727ea5a8 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts @@ -24,8 +24,6 @@ import { import { reportError } from '@/platform/telemetry/reportError' import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration' import { useLitegraphService } from '@/services/litegraphService' -import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema' -import { useNodeDefStore } from '@/stores/nodeDefStore' import { useWidgetValueStore } from '@/stores/widgetValueStore' import { toRootGraphId } from '@/types/graphScopeId' import type { RootGraphId } from '@/types/graphScopeId' @@ -163,23 +161,6 @@ class TestEmptyComboGroup extends LGraphNode { } } -function addVideoLoaderDef( - optional: NonNullable['optional'] = {} -) { - useNodeDefStore().addNodeDef({ - name: 'TestVideoLoader', - display_name: 'Test Video Loader', - category: 'test', - python_module: 'test', - description: '', - output_node: false, - input: { required: { video: [['clip.mp4'], {}] }, optional }, - output: [], - output_is_list: [], - output_name: [] - }) -} - const CATALOG: WidgetCatalog = { types: { TestSource: { widget_order: ['steps'] }, @@ -629,9 +610,7 @@ describe('attachDocOpMinter', () => { }) it('leaves a display-only DOM widget out of a catalogued add_node, and the applier takes it', async () => { - addVideoLoaderDef() const loader = new TestVideoLoader() - loader.type = 'TestVideoLoader' graph.add(loader) await afterFlush() @@ -654,10 +633,11 @@ describe('attachDocOpMinter', () => { doc.destroy() }) - it('keeps a DOM widget out of the prompt as a value when its definition declares it', async () => { - addVideoLoaderDef({ videopreview: ['VIDEO_PREVIEW', {}] }) + it('keeps a DOM widget out of the prompt as a value when it backs a declared input', async () => { const loader = new TestVideoLoader() - loader.type = 'TestVideoLoader' + loader.addInput('videopreview', 'VIDEO_PREVIEW', { + widget: { name: 'videopreview' } + }) graph.add(loader) await afterFlush() @@ -683,22 +663,6 @@ describe('attachDocOpMinter', () => { doc.destroy() }) - it('keeps a display-only DOM widget when the node has no definition to judge it by', async () => { - const loader = new TestVideoLoader() - loader.type = 'TestVideoLoader' - graph.add(loader) - await afterFlush() - - expect(minted[0]).toMatchObject({ - node: { - widgets_values: { - video: 'clip.mp4', - videopreview: { hidden: false, params: {} } - } - } - }) - }) - describe("link ops address the document's own input order", () => { /** A sink whose live input order (`mask`, `image`) is the reverse of the document's. */ function seedReorderedSink() { diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.ts b/src/workbench/extensions/agent/crdt/docOpMinter.ts index 44076914847..51d02d4c6e2 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.ts @@ -30,8 +30,6 @@ import type { ISerialisedNode } from '@/lib/litegraph/src/types/serialisation' import { isWidgetValue } from '@/lib/litegraph/src/types/widgets' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { reportError } from '@/platform/telemetry/reportError' -import { isComponentWidget, isDOMWidget } from '@/scripts/domWidget' -import { useNodeDefStore } from '@/stores/nodeDefStore' import { useWidgetValueStore } from '@/stores/widgetValueStore' import type { RootGraphId } from '@/types/graphScopeId' import type { NodeId } from '@/types/nodeId' @@ -152,14 +150,15 @@ function valueWidgetsOnly( const stored = rootGraphId ? widgetValueStore.getWidget(widgetId(rootGraphId, node.id, name)) : undefined - if (isValueWidget(widget, stored)) filtered[name] = value + if (isValueWidget(widget, stored, node)) filtered[name] = value } return filtered } function isValueWidget( widget: IBaseWidget | undefined, - stored?: WidgetState + stored: WidgetState | undefined, + node: LGraphNode | null ): boolean { if (!widget && !stored) return false // A destructuring default fires on absent AND present-but-undefined alike, @@ -169,15 +168,18 @@ function isValueWidget( // drift apart again. const { type = stored?.type, serialize = stored?.serialize } = widget ?? {} if (type === 'button' || serialize === false) return false - return !(widget && isDisplayOnlyDomWidget(widget)) + return !(widget && node && isDisplayOnlyDomWidget(node, widget)) } -function isDisplayOnlyDomWidget(widget: IBaseWidget): boolean { - if (!isDOMWidget(widget) && !isComponentWidget(widget)) return false - if (widget.options.serialize !== false) return false - const nodeDefStore = useNodeDefStore() - if (!nodeDefStore.fromLGraphNode(widget.node)) return false - return !nodeDefStore.getInputSpecForWidget(widget.node, widget.name) +function isDisplayOnlyDomWidget( + node: LGraphNode, + widget: IBaseWidget +): boolean { + const rendersOwnElement = + ('element' in widget && Boolean(widget.element)) || + ('component' in widget && Boolean(widget.component)) + if (!rendersOwnElement || widget.options.serialize !== false) return false + return !node.inputs.some((input) => input.widget?.name === widget.name) } function nodeKey(graphId: string, nodeId: NodeId): string { @@ -211,7 +213,7 @@ function isValueWidgetWrite( const widget = owner?.widgets?.find( (candidate) => candidate.name === event.name ) - return isValueWidget(widget, stored) + return isValueWidget(widget, stored, owner) } function promotedHostWrite( diff --git a/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts b/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts index d8edab8fcb7..bfc4cde55fd 100644 --- a/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts +++ b/src/workbench/extensions/agent/crdt/restoreOpMinter.test.ts @@ -3,7 +3,6 @@ import type { WidgetCatalog, WorkflowJSON } from '@comfyorg/comfy-multi-player' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' -import { useNodeDefStore } from '@/stores/nodeDefStore' import type { GraphOperation } from './graphOperations' import { mintWireOps } from './opEnvelope' @@ -155,25 +154,11 @@ describe('attachRestoreOpMinter', () => { TestPreviewSource: { widget_order: ['image'] } } } - useNodeDefStore().addNodeDef({ - name: 'TestPreviewSource', - display_name: 'Test Preview Source', - category: 'test', - python_module: 'test', - description: '', - output_node: false, - input: { required: { image: ['STRING', {}] } }, - output: ['IMAGE'], - output_is_list: [false], - output_name: ['image'] - }) const preview = new TestPreviewSource() - preview.type = 'TestPreviewSource' graph.add(preview) graph.remove(preview) const doc = mint(graph.serialize() as unknown as WorkflowJSON, catalog) const restored = new TestPreviewSource() - restored.type = 'TestPreviewSource' restored.id = preview.id restoreThrough(() => { From 6307221a11eaca51b7b8253b149e3eec193141a2 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 18 Oct 2026 08:33:08 +0000 Subject: [PATCH 6/6] refactor(agent): keep the display-only check beside isValueWidget instead of inside it --- .../extensions/agent/crdt/docOpMinter.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.ts b/src/workbench/extensions/agent/crdt/docOpMinter.ts index 51d02d4c6e2..e3654cc7ef2 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.ts @@ -150,15 +150,15 @@ function valueWidgetsOnly( const stored = rootGraphId ? widgetValueStore.getWidget(widgetId(rootGraphId, node.id, name)) : undefined - if (isValueWidget(widget, stored, node)) filtered[name] = value + if (isValueWidget(widget, stored) && !isDisplayOnlyDomWidget(node, widget)) + filtered[name] = value } return filtered } function isValueWidget( widget: IBaseWidget | undefined, - stored: WidgetState | undefined, - node: LGraphNode | null + stored?: WidgetState ): boolean { if (!widget && !stored) return false // A destructuring default fires on absent AND present-but-undefined alike, @@ -167,14 +167,14 @@ function isValueWidget( // One construct for both fields, so the two halves of the guard cannot // drift apart again. const { type = stored?.type, serialize = stored?.serialize } = widget ?? {} - if (type === 'button' || serialize === false) return false - return !(widget && node && isDisplayOnlyDomWidget(node, widget)) + return type !== 'button' && serialize !== false } function isDisplayOnlyDomWidget( node: LGraphNode, - widget: IBaseWidget + widget: IBaseWidget | undefined ): boolean { + if (!widget) return false const rendersOwnElement = ('element' in widget && Boolean(widget.element)) || ('component' in widget && Boolean(widget.component)) @@ -213,7 +213,10 @@ function isValueWidgetWrite( const widget = owner?.widgets?.find( (candidate) => candidate.name === event.name ) - return isValueWidget(widget, stored, owner) + return ( + isValueWidget(widget, stored) && + !(owner && isDisplayOnlyDomWidget(owner, widget)) + ) } function promotedHostWrite(