Repository navigation
[backport cloud/1.55] fix: subgraph-interior widgets don't render in Vue mode after insert_workflow #18679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[backport cloud/1.55] fix: subgraph-interior widgets don't render in Vue mode after insert_workflow #18679
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| import { applyOps, mint } from '@comfyorg/comfy-multi-player' | ||
| import type { | ||
| InsertWorkflowOp, | ||
| WidgetCatalog | ||
| } from '@comfyorg/comfy-multi-player' | ||
| import { assert, beforeEach, expect, it, onTestFinished } from 'vitest' | ||
| import * as Y from 'yjs' | ||
|
|
||
| import { | ||
| LGraph, | ||
| LGraphNode, | ||
| LiteGraph, | ||
| SubgraphNode | ||
| } from '@/lib/litegraph/src/litegraph' | ||
| import { | ||
| createTestSubgraph, | ||
| createTestSubgraphNode, | ||
| enableSubgraphNodeCreation | ||
| } from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' | ||
| import { | ||
| stripGraphPrefix, | ||
| useWidgetValueStore | ||
| } from '@/stores/widgetValueStore' | ||
| import { graphScopeOf } from '@/types/graphScopeId' | ||
| import { toNodeId } from '@/types/nodeId' | ||
| import { inertPlacementPort } from '@/workbench/extensions/agent/crdt/__fixtures__/inertPlacementPort' | ||
| import { AgentCrdtProjection } from '@/workbench/extensions/agent/crdt/agentCrdtProjection' | ||
| import { FollowerDoc } from '@/workbench/extensions/agent/crdt/followerDoc' | ||
| import { createGraphMutations } from '@/workbench/extensions/agent/crdt/graphMutations' | ||
|
|
||
| import type { WidgetUiCallbacks } from './processedWidgetRenderModel' | ||
| import { computeProcessedWidgets } from './useProcessedWidgets' | ||
|
|
||
| class InteriorWidgetNode extends LGraphNode { | ||
| constructor() { | ||
| super('interior-widget') | ||
| this.serialize_widgets = true | ||
| this.addWidget('text', 'prompt', 'before insert', () => {}) | ||
| } | ||
| } | ||
|
|
||
| const catalog: WidgetCatalog = { | ||
| types: { | ||
| 'interior-widget': { widget_order: ['prompt'] } | ||
| } | ||
| } | ||
|
|
||
| const noopUi: WidgetUiCallbacks = { | ||
| getTooltipConfig: () => ({}), | ||
| handleNodeRightClick: () => {} | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| LiteGraph.registerNodeType('interior-widget', InteriorWidgetNode) | ||
| }) | ||
|
|
||
| function bindProjection(workflowId: string, graph: LGraph) { | ||
| const follower = new FollowerDoc() | ||
| const projection = new AgentCrdtProjection( | ||
| createGraphMutations({ | ||
| getScope: () => graphScopeOf(graph), | ||
| layout: { createNode: () => {}, deleteNodes: () => {} }, | ||
| placement: inertPlacementPort | ||
| }), | ||
| () => graph, | ||
| () => follower.doc | ||
| ) | ||
| projection.bind(workflowId, follower) | ||
| onTestFinished(() => { | ||
| projection.destroy() | ||
| follower.destroy() | ||
| }) | ||
|
|
||
| let sequence = 0 | ||
| return (update: Uint8Array, opIds: string[]) => { | ||
| follower.applyRemoteUpdate(update) | ||
| const committed = projection.applyFrame({ | ||
| workflowId, | ||
| seq: ++sequence, | ||
| update, | ||
| actor: 'agent:test', | ||
| opIds | ||
| }) | ||
| projection.reconcileLiveGraph(workflowId) | ||
| return committed | ||
| } | ||
| } | ||
|
|
||
| function serializeWorkflow(graph: LGraph): InsertWorkflowOp['workflow'] { | ||
| return JSON.parse( | ||
| JSON.stringify(graph.serialize()) | ||
| ) as InsertWorkflowOp['workflow'] | ||
| } | ||
|
|
||
| it('produces a live Vue widget model for an inserted subgraph-interior node', () => { | ||
| const graph = new LGraph() | ||
| onTestFinished(enableSubgraphNodeCreation(graph)) | ||
|
|
||
| const blueprint = new LGraph() | ||
| const subgraph = createTestSubgraph({ rootGraph: blueprint }) | ||
| blueprint.subgraphs.set(subgraph.id, subgraph) | ||
|
|
||
| const interior = LiteGraph.createNode('interior-widget') | ||
| assert(interior) | ||
| interior.id = toNodeId(42) | ||
| subgraph.add(interior) | ||
| assert(interior.widgets?.[0]) | ||
| interior.widgets[0].value = 'after insert' | ||
| blueprint.add(createTestSubgraphNode(subgraph, { id: 1 })) | ||
|
|
||
| const hostDoc = mint({ nodes: [], links: [] }, catalog) | ||
| onTestFinished(() => hostDoc.destroy()) | ||
| const deliver = bindProjection('inserted-subgraph-widget', graph) | ||
| deliver(Y.encodeStateAsUpdate(hostDoc), []) | ||
|
|
||
| const operation: InsertWorkflowOp = { | ||
| op_id: 'inserted-subgraph-widget-test-0001', | ||
| actor: 'agent:test', | ||
| base_version: 1, | ||
| stamp: [1, 'agent:test'], | ||
| op: 'insert_workflow', | ||
| workflow: serializeWorkflow(blueprint) | ||
| } | ||
| const vector = Y.encodeStateVector(hostDoc) | ||
| expect(applyOps(hostDoc, [operation], catalog).outcomes).toEqual([ | ||
| { op_id: operation.op_id, outcome: 'applied' } | ||
| ]) | ||
| expect( | ||
| deliver(Y.encodeStateAsUpdate(hostDoc, vector), [operation.op_id]) | ||
| ).toBe(true) | ||
|
|
||
| const instance = graph._nodes.find( | ||
| (node): node is SubgraphNode => node instanceof SubgraphNode | ||
| ) | ||
| assert(instance) | ||
| const materialized = instance.subgraph._nodes.find( | ||
| (node) => node.type === 'interior-widget' | ||
| ) | ||
| assert(materialized) | ||
| expect(String(materialized.id)).toContain(':') | ||
|
|
||
| const rootGraphId = graph.rootGraph.id | ||
| const localNodeId = stripGraphPrefix(String(materialized.id)) | ||
| assert(localNodeId) | ||
| const widgetIds = useWidgetValueStore().getNodeWidgetIds( | ||
| rootGraphId, | ||
| localNodeId | ||
| ) | ||
| const processed = computeProcessedWidgets({ | ||
| nodeData: materialized._state, | ||
| widgetIds, | ||
| graphId: rootGraphId, | ||
| showAdvanced: false, | ||
| isGraphReady: true, | ||
| rootGraph: graph, | ||
| ui: noopUi | ||
| }) | ||
|
|
||
| expect( | ||
| processed.map(({ visible, simplified }) => ({ | ||
| name: simplified.name, | ||
| value: simplified.value, | ||
| visible | ||
| })) | ||
| ).toEqual([{ name: 'prompt', value: 'after insert', visible: true }]) | ||
|
|
||
| assert(processed[0]) | ||
| processed[0].updateHandler('updated through Vue') | ||
| expect(materialized.widgets?.[0]?.value).toBe('updated through Vue') | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,8 @@ import { | |
| useWidgetValueStore | ||
| } from '@/stores/widgetValueStore' | ||
| import { | ||
| createLeafNodeExecutionId, | ||
| createLeafNodeLocatorId | ||
| createLeafNodeLocatorId, | ||
| createNodeExecutionId | ||
| } from '@/types/nodeIdentification' | ||
| import type { NodeExecutionId, NodeLocatorId } from '@/types/nodeIdentification' | ||
| import type { NodeId } from '@/types/nodeId' | ||
|
|
@@ -47,8 +47,7 @@ import type { WidgetId } from '@/types/widgetId' | |
| import { | ||
| executionIdFromState, | ||
| executionIdToNodeLocatorId, | ||
| getNodeByLocatorId, | ||
| locatorIdFromState, | ||
| getNodeByState, | ||
| subgraphIdFromState | ||
| } from '@/utils/graphTraversalUtil' | ||
| import { mapLiveWidgetsById } from '@/utils/litegraphUtil' | ||
|
|
@@ -166,8 +165,7 @@ function getHostNode( | |
| nodeData: NodeState | ||
| ): LGraphNode | null { | ||
| if (!rootGraph) return null | ||
| const locatorId = locatorIdFromState(nodeData, rootGraph.id) | ||
| return locatorId ? getNodeByLocatorId(rootGraph, locatorId) : null | ||
| return getNodeByState(rootGraph, nodeData) | ||
| } | ||
|
|
||
| function isWidgetVisible( | ||
|
|
@@ -181,9 +179,24 @@ function isWidgetVisible( | |
| }) | ||
| } | ||
|
|
||
| /** | ||
| * `lastNodeErrors` is a plain record keyed by execution id; a node whose id | ||
| * is `constructor`/`toString`/`valueOf` (accepted by `parseNodeId`) would | ||
| * otherwise resolve to the inherited `Object.prototype` member instead of | ||
| * `undefined` when it has no recorded error. | ||
| */ | ||
| function getOwnNodeErrors<T>( | ||
| nodeErrors: Record<string, T> | null | undefined, | ||
| id: string | ||
| ): T | undefined { | ||
| return nodeErrors && Object.hasOwn(nodeErrors, id) | ||
| ? nodeErrors[id] | ||
| : undefined | ||
| } | ||
|
|
||
| function hasWidgetError( | ||
| widget: { name: string; errorTarget?: WidgetErrorTarget }, | ||
| nodeExecId: NodeExecutionId, | ||
| nodeExecId: NodeExecutionId | null, | ||
| nodeErrors: | ||
| | { errors: { extra_info?: { input_name?: string } }[] } | ||
| | undefined, | ||
|
|
@@ -195,12 +208,16 @@ function hasWidgetError( | |
| !!nodeErrors?.errors.some( | ||
| (e) => e.extra_info?.input_name === widget.name | ||
| ) || | ||
| missingModelStore.isWidgetMissingModel(nodeExecId, widget.name) || | ||
| missingMediaStore.isWidgetMissingMedia(nodeExecId, widget.name) | ||
| (nodeExecId !== null && | ||
| (missingModelStore.isWidgetMissingModel(nodeExecId, widget.name) || | ||
| missingMediaStore.isWidgetMissingMedia(nodeExecId, widget.name))) | ||
| const target = widget.errorTarget | ||
| if (!target) return hasHostError | ||
|
|
||
| const sourceErrors = executionErrorStore.lastNodeErrors?.[target.executionId] | ||
| const sourceErrors = getOwnNodeErrors( | ||
| executionErrorStore.lastNodeErrors, | ||
| target.executionId | ||
| ) | ||
| return ( | ||
| hasHostError || | ||
| !!sourceErrors?.errors.some( | ||
|
|
@@ -226,7 +243,7 @@ function createWidgetUpdateHandler({ | |
| id: WidgetId | ||
| live?: { node: LGraphNode; widget: IBaseWidget } | ||
| errorTarget?: WidgetErrorTarget | ||
| nodeExecId: NodeExecutionId | ||
| nodeExecId: NodeExecutionId | null | ||
| widgetName: string | ||
| widgetOptions: IWidgetOptions | ||
| executionErrorStore: ReturnType<typeof useExecutionErrorStore> | ||
|
|
@@ -251,13 +268,15 @@ function createWidgetUpdateHandler({ | |
| options | ||
| ) | ||
| } | ||
| executionErrorStore.clearWidgetRelatedErrors( | ||
| nodeExecId, | ||
| widgetName, | ||
| widgetName, | ||
| newValue, | ||
| options | ||
| ) | ||
| if (nodeExecId) { | ||
| executionErrorStore.clearWidgetRelatedErrors( | ||
| nodeExecId, | ||
| widgetName, | ||
| widgetName, | ||
| newValue, | ||
| options | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -353,7 +372,7 @@ interface WidgetProcessingContext { | |
| hostNode: LGraphNode | null | ||
| liveWidgets: Map<WidgetId, IBaseWidget> | ||
| slotMetadata: Map<string, WidgetSlotMetadata> | ||
| nodeExecId: NodeExecutionId | ||
| nodeExecId: NodeExecutionId | null | ||
| nodeErrors: Parameters<typeof hasWidgetError>[2] | ||
| widgetValueStore: ReturnType<typeof useWidgetValueStore> | ||
| executionErrorStore: ReturnType<typeof useExecutionErrorStore> | ||
|
|
@@ -492,8 +511,7 @@ export function computeProcessedWidgets({ | |
| const nodeExecId = | ||
| isGraphReady && rootGraph | ||
| ? executionIdFromState(rootGraph, nodeData) | ||
| : createLeafNodeExecutionId(nodeData.id) | ||
| if (!nodeExecId) return [] | ||
| : createNodeExecutionId([nodeData.id]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High — Raised by 5 of 8 reviewers (gpt-5.6-sol-max adversarial, gpt-5.6-sol-max edge-case, claude-opus-5-thinking-max adversarial, claude-opus-5-thinking-max edge-case, kimi-k3-max edge-case).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified against the actual code on this branch (identical to the merged main version after #18634) — this is real, but not safely fixable with the one-line change suggested, and I did not want to ship a partial fix that only looks like it works. Traced
So yes, However, the suggested fix — I also checked whether this is a regression at all: A real fix needs a colon-tolerant, leaf-safe multi-segment execution-id builder shared across Generated by Claude Code |
||
|
|
||
| const hostNode = getHostNode(rootGraph, nodeData) | ||
| const liveWidgets = hostNode | ||
|
|
@@ -525,7 +543,9 @@ export function computeProcessedWidgets({ | |
| liveWidgets, | ||
| slotMetadata, | ||
| nodeExecId, | ||
| nodeErrors: executionErrorStore.lastNodeErrors?.[nodeExecId], | ||
| nodeErrors: nodeExecId | ||
| ? getOwnNodeErrors(executionErrorStore.lastNodeErrors, nodeExecId) | ||
| : undefined, | ||
| widgetValueStore, | ||
| executionErrorStore, | ||
| missingModelStore, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.