feat: deduplicate subgraph node IDs on workflow load (experimental) (#8762)

## Summary

Add `ensureGlobalIdUniqueness` to reassign duplicate node IDs across
subgraphs when loading workflows, gated behind an experimental setting.

## Changes

- **What**: Shared `LGraphState` between root graph and subgraphs so ID
counters are global. Added `ensureGlobalIdUniqueness()` method that
detects and remaps colliding node IDs in subgraphs, preserving root
graph IDs as canonical and patching link references. Gated behind
`Comfy.Graph.DeduplicateSubgraphNodeIds` (experimental, default
`false`).
- **Dependencies**: None

## Review Focus

- Shared state override on `Subgraph` (getter delegates to root, setter
is no-op) — verify no existing code sets `subgraph.state` directly.
- `Math.max` state merging in `configure()` prevents ID counter
regression when loading subgraph definitions.
- Feature flag wiring: static property on `LGraph`, synced from settings
via `useLitegraphSettings`.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8762-feat-deduplicate-subgraph-node-IDs-on-workflow-load-experimental-3036d73d36508184b6cee5876dc4d935)
by [Unito](https://www.unito.io)

---------

Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Alexander Brown
2026-02-09 18:01:58 -08:00
committed by GitHub
parent a6620a4ddc
commit ff9642d0cb
7 changed files with 1002 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ import { watchEffect } from 'vue'
import {
CanvasPointer,
LGraph,
LGraphNode,
LiteGraph
} from '@/lib/litegraph/src/litegraph'
@@ -162,4 +163,10 @@ export const useLitegraphSettings = () => {
'Comfy.EnableWorkflowViewRestore'
)
})
watchEffect(() => {
LGraph.deduplicateSubgraphIds = settingStore.get(
'Comfy.Graph.DeduplicateSubgraphNodeIds'
)
})
}

View File

@@ -1201,5 +1201,16 @@ export const CORE_SETTINGS: SettingParams[] = [
defaultValue: false,
experimental: true,
versionAdded: '1.40.0'
},
{
id: 'Comfy.Graph.DeduplicateSubgraphNodeIds',
category: ['Comfy', 'Graph', 'Subgraph'],
name: 'Deduplicate subgraph node IDs',
tooltip:
'Automatically reassign duplicate node IDs in subgraphs when loading a workflow.',
type: 'boolean',
defaultValue: false,
experimental: true,
versionAdded: '1.40.0'
}
]