Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/lib/litegraph/src/LGraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,31 @@ describe('LGraph', () => {
expect(graph.last_node_id).toBe(7)
})

it.for(['constructor', 'toString', '__proto__'])(
'does not return inherited property %s as a node',
(id) => {
expect(new LGraph().getNodeById(toNodeId(id))).toBeNull()
}
)

it('registers and retrieves a node whose id is __proto__ without polluting the registry', () => {
const graph = new LGraph()
const node = new LGraphNode('proto-id')
Reflect.set(node, 'id', '__proto__')

graph.add(node, true)

expect(graph.getNodeById(toNodeId('__proto__'))).toBe(node)
expect(Object.getPrototypeOf(graph._nodes_by_id)).toBeNull()

const otherNode = new LGraphNode('other')
graph.add(otherNode, true)
expect(graph.getNodeById(otherNode.id)).toBe(otherNode)

graph.remove(node)
expect(graph.getNodeById(toNodeId('__proto__'))).toBeNull()
})

describe('duplicate node-instance invariants', () => {
function createGraphsSharingANodeId() {
const ownerGraph = new LGraph()
Expand Down
8 changes: 5 additions & 3 deletions src/lib/litegraph/src/LGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ export class LGraph
readonly events = new CustomEventTarget<LGraphEventMap>()
readonly _subgraphs: Map<SubgraphId, Subgraph> = new Map()
_nodes: (LGraphNode | SubgraphNode)[] = []
_nodes_by_id: Partial<Record<NodeId, LGraphNode>> = {}
_nodes_by_id: Partial<Record<NodeId, LGraphNode>> = Object.create(null)
_nodes_in_order: LGraphNode[] = []
_nodes_executable: LGraphNode[] | null = null
_groups: LGraphGroup[] = []
Expand Down Expand Up @@ -833,7 +833,7 @@ export class LGraph

this._subgraphs.clear()
this._nodes = []
this._nodes_by_id = {}
this._nodes_by_id = Object.create(null)
this._nodes_in_order = []
this._nodes_executable = null
this._groups = []
Expand Down Expand Up @@ -1627,7 +1627,9 @@ export class LGraph
* Returns a node by its id.
*/
getNodeById(id: NodeId | null | undefined): LGraphNode | null {
return id != null && id !== UNASSIGNED_NODE_ID
return id != null &&
id !== UNASSIGNED_NODE_ID &&
Object.hasOwn(this._nodes_by_id, id)
Comment thread
claude[bot] marked this conversation as resolved.
Resolved
? (this._nodes_by_id[id] ?? null)
: null
}
Expand Down
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
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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>
Expand All @@ -251,13 +268,15 @@ function createWidgetUpdateHandler({
options
)
}
executionErrorStore.clearWidgetRelatedErrors(
nodeExecId,
widgetName,
widgetName,
newValue,
options
)
if (nodeExecId) {
executionErrorStore.clearWidgetRelatedErrors(
nodeExecId,
widgetName,
widgetName,
newValue,
options
)
}
}
}

Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -492,8 +511,7 @@ export function computeProcessedWidgets({
const nodeExecId =
isGraphReady && rootGraph
? executionIdFromState(rootGraph, nodeData)
: createLeafNodeExecutionId(nodeData.id)
if (!nodeExecId) return []
: createNodeExecutionId([nodeData.id])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — getHostNode was migrated to getNodeByState so subgraph-interior nodes with colon-bearing ids now resolve, but nodeExecId still comes from executionIdFromState, which returns null for exactly those ids (both the createNodeExecutionId fallback and the locator path reject a colon in the local segment). For the nodes this PR enables, the new null guards therefore permanently suppress missing-model/missing-media highlighting and clearWidgetRelatedErrors even when the graph is ready, so the widget renders and updates but can never surface or clear execution errors; derive the exec id from the already-resolved hostNode (e.g. getExecutionIdByNode(rootGraph, hostNode)) instead of accepting null.

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 executionIdFromState for a subgraph-interior node whose local id contains a colon (state.graphId !== rootGraph.id, so subgraphIdFromState is non-null):

  • locatorIdFromState → createLeafNodeLocatorId(subgraphUuid, id): with a truthy subgraphUuid, the strict segment check fails (colon) and if (subgraphUuid) return null kicks in → null.
  • So node is never resolved by locator, and the function returns its fallback, which for this branch is createNodeExecutionId([localNodeId]) — the strict constructor, which also rejects the colon → null.

So yes, nodeExecId is null for exactly the nodes this PR newly renders, and the nodeExecId !== null / if (nodeExecId) guards added here do skip missingModelStore/missingMediaStore lookups and clearWidgetRelatedErrors for them.

However, the suggested fix — getExecutionIdByNode(rootGraph, hostNode) — returns null too in this exact case: for a non-root node.graph, it calls createExecutionIdFromPath(parentPath, node.id), which runs node.id through the same strict, colon-rejecting requireNodeIdSegment as the leaf of the joined path. There's no existing "leaf-tolerant" constructor for a multi-segment execution id anywhere in the codebase — createLeafNodeExecutionId/createLeafNodeLocatorId only tolerate a colon when there's no ancestor segment to disambiguate it from (root-owned nodes). Calling getExecutionIdByNode here would change nothing.

I also checked whether this is a regression at all: scanNodeModelCandidates/scanNodeMediaCandidates (unchanged by this PR) already call the same strict getExecutionIdByNode and return [] when it's null, so missingModelStore/missingMediaStore never had entries for these nodes even before this fix — the new guards don't change that observable behavior. For clearWidgetRelatedErrors/backend execution-error correlation, this is a real, narrower gap, but before #18634 the widget for such a node didn't render in Vue mode at all, so there's no working prior behavior being regressed — it's "renders and updates, but can't yet correlate backend-reported errors for this node" rather than a regression.

A real fix needs a colon-tolerant, leaf-safe multi-segment execution-id builder shared across getExecutionIdByNode and its several callers (the two scan pipelines, isAncestorPathActive, etc.) — a cross-cutting change with its own test/verification needs, not something I want to rush into a stable-branch backport under review-response pressure. Filing this as a follow-up rather than fixing it here.


Generated by Claude Code


const hostNode = getHostNode(rootGraph, nodeData)
const liveWidgets = hostNode
Expand Down Expand Up @@ -525,7 +543,9 @@ export function computeProcessedWidgets({
liveWidgets,
slotMetadata,
nodeExecId,
nodeErrors: executionErrorStore.lastNodeErrors?.[nodeExecId],
nodeErrors: nodeExecId
? getOwnNodeErrors(executionErrorStore.lastNodeErrors, nodeExecId)
: undefined,
widgetValueStore,
executionErrorStore,
missingModelStore,
Expand Down
Loading
Loading