Repository navigation
[backport core/1.54] fix: keep released subgraph definitions consistent across convert-to-subgraph - #18521
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
3 tasks
…subgraph (#18040) <!-- ccr-slack-attribution --> _Requested via [Slack thread](https://comfy-organization.slack.com/archives/C09KFK2ABB8/p1788424987450979?thread_ts=1788424987.450979&cid=C09KFK2ABB8)_ ## ELI5 Converting a selection to a subgraph is like packing a box into a bigger box. If the small box was the only one of its kind, the code threw away its packing list the moment it left the shelf, then put the box in the bigger box anyway. Every later save found a box with no list and raised an alarm. Now the packing list survives the move, because the box is being re-shelved, not discarded. ## Motivation `graph_serialization_state_mismatch` is currently the most frequent error type from `serialiseStoredNodes` in production. Datadog RUM shows nearly all of those events as "live node N has no stored state" with a subgraph `graphId`, in sessions that used Convert Selection to Subgraph, Unpack, or New Subgraph. The report fires on every save until reload, and the serialized definition for that subgraph falls back to live-node serialization, so the node store and the saved workflow disagree for the rest of the session. Fixing the trigger in the conversion path removes the dominant source of the alert. ## Provenance - **Authored by:** interactive session - **Verified:** `pnpm vitest run src/lib/litegraph/src/subgraph/SubgraphConversion.nestedDefinitions.test.ts`: 1 failed on the test-only commit ("live node 1 has no stored state"), 1 passed with the fix; `pnpm vitest run src/lib/litegraph/src/subgraph/`: 19 files, 356 passed; `pnpm vitest run src/lib/litegraph/src/LGraph` plus every test file referencing `releaseSubgraphs`, `convertToSubgraph`, `unpackSubgraph`, `findReleasableSubgraphs` or `detachAllNodesFromStores`: 46 files, 648 passed, 7 expected fail, 5 skipped; `pnpm typecheck` (via the pre-commit hook on both commits): clean; `eslint` and `oxlint --type-aware` on the two changed files: 0 errors; `oxfmt --check`: clean; `pnpm knip`: clean - **Deviations:** unknown ## Reviewer context - **Type:** bug fix, litegraph subgraph lifecycle - **Slots into:** no project or epic; ad-hoc production error fix - **Not in scope:** the general hazard that a registered subgraph node type keeps a closure over a released `Subgraph` instance and `LGraph.add()` re-inserts it into `rootGraph.subgraphs` without node state. This PR removes the trigger seen in production; hardening `releaseSubgraphs` / `add()` against resurrection is a follow-up. ## Summary - Convert-to-subgraph no longer releases the subgraph definitions referenced by the nodes it is about to re-create inside the new subgraph. - Adds a regression test that fails on `main` with the production mismatch report and passes with the fix. **Before:** convert nodes A and B into subgraph S1 (host node H1). Then select H1 plus another node and convert that into S2. Serializing the root graph reports `Graph serialization state mismatch` with `mismatch: "live node A has no stored state"` and `graphId: S1`, on every save until reload. **After:** the same sequence serializes cleanly. S1 stays a valid definition, nested inside S2, with all of its nodes stored. **Mechanism:** 1. `_convertToSubgraphImpl` removes the selected nodes with `this.remove(node)` before configuring the new subgraph from the serialized selection. 2. `removeNode` sees that H1 is a `SubgraphNode` and calls `releaseSubgraphs(findReleasableSubgraphs(...))`. H1 was S1's only instance, so S1 is released: its node store records are deleted and it is dropped from `rootGraph.subgraphs`, but the `Subgraph` instance keeps its `_nodes`. 3. The registered node type for S1 is a class whose constructor closes over that same `Subgraph` instance, so `LiteGraph.createNode(S1.id)` inside S2's configure returns a host pointing at the released instance. 4. `LGraph.add()` walks nested subgraph nodes and re-inserts S1 into `rootGraph.subgraphs`. S1 now has live nodes and zero stored state, and `serialiseStoredNodes` reports the mismatch on every serialize. **Fix choice:** option (a), skip the release for nodes that the conversion is moving. Every node removed in that loop is re-created inside the new subgraph from the same serialized data, so the set of definitions in use is identical before and after the operation and nothing should be released. This is a three-line change behind a new `GraphRemoveOptions.preserveSubgraphDefinitions` flag, used only by `_convertToSubgraphImpl`. The alternative (tearing down released instances fully and teaching `add()` to re-attach or refuse them) touches the release and add paths for every caller and is a broader behavioral change; unregistering the node type is not viable because the nested host inside the new subgraph is created through that type. ## Changes - **What**: `GraphRemoveOptions.preserveSubgraphDefinitions`; `removeNode` skips `releaseSubgraphs` when it is set; `_convertToSubgraphImpl` passes it when removing the moved nodes. New test `src/lib/litegraph/src/subgraph/SubgraphConversion.nestedDefinitions.test.ts`. If `createSubgraph` throws after the originals are removed, `_convertToSubgraphImpl` releases the removed nodes' definitions that no live node still references (`findOrphanedSubgraphs` in `subgraphUtils.ts`) and rethrows, so a failed conversion leaves no orphaned definitions registered. ## Red / green The first commit adds only the failing test (CI should be red on it), the second commit adds the fix (CI should be green). Unpack was checked and is not affected by this trigger: it materializes the inner nodes into the parent before removing the host, so the definitions are still live when the host is released. ## Review Focus - `findReleasableSubgraphs` is still called for every other removal path (delete, undo, unpack), so nothing else changes behavior. - If a moved node's type cannot be re-created inside the new subgraph, its definition stays registered but unused; `findUsedSubgraphIds` already excludes unused definitions from serialization. ## Test plan - [ ] CI red on the test-only commit, green on the fix commit - [ ] Convert nodes to a subgraph, then convert a selection containing that subgraph's host into another subgraph, save: no `graph_serialization_state_mismatch` in the console or RUM - [ ] Unpack the outer subgraph afterwards and save again: still clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01TsajsCwfDusee9F9rPWNb7 --- _Generated by [Claude Code](https://claude.ai/code/session_01TsajsCwfDusee9F9rPWNb7)_ --------- Co-authored-by: Christian Byrne <cbyrne@comfy.org> Co-authored-by: glary-bot <bot@comfy.org>
Contributor
🎭 Playwright: ✅ 1939 passed, 0 failed · 1 flaky📊 Browser Reports
🎨 Storybook: ✅ Built — View Storybook |
claude
Bot
force-pushed
the
backport-18040-to-core-1.54
branch
from
September 23, 2026 03:59
dfac680 to
e7dcbbd
Compare
christian-byrne
approved these changes
Sep 23, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## core/1.54 #18521 +/- ##
=============================================
- Coverage 83.58% 83.58% -0.01%
=============================================
Files 2096 2096
Lines 123796 123800 +4
Branches 31538 33389 +1851
=============================================
Hits 103481 103481
- Misses 20136 20140 +4
Partials 179 179
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #18040 to
core/1.54Automatically created by backport workflow.