From 4f348553050e04ce61392edb05fc5bb05491cc2d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 2 Aug 2026 06:56:05 +0000 Subject: [PATCH 01/24] test: reproduce subgraph host dropping a second live-executing interior preview Two KSamplers in one subgraph, only one wired into previewExposureStore (the other simulates a node added after the subgraph's one-shot auto-expose already ran). The unit test targets the not-yet-existing useAmbientSubgraphPreviews composable; the e2e spec drives two live b_preview WS frames at distinct interior execution IDs and asserts both show on the collapsed SubgraphNode host. --- .../subgraph-with-two-live-samplers.json | 195 +++++++++++++++++ .../subgraphConcurrentPreviews.spec.ts | 78 +++++++ .../node/useAmbientSubgraphPreviews.test.ts | 207 ++++++++++++++++++ 3 files changed, 480 insertions(+) create mode 100644 browser_tests/assets/subgraphs/subgraph-with-two-live-samplers.json create mode 100644 browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts create mode 100644 src/composables/node/useAmbientSubgraphPreviews.test.ts diff --git a/browser_tests/assets/subgraphs/subgraph-with-two-live-samplers.json b/browser_tests/assets/subgraphs/subgraph-with-two-live-samplers.json new file mode 100644 index 00000000000..c049ee4dd96 --- /dev/null +++ b/browser_tests/assets/subgraphs/subgraph-with-two-live-samplers.json @@ -0,0 +1,195 @@ +{ + "id": "aa111111-2222-4333-8444-000000000001", + "revision": 0, + "last_node_id": 1, + "last_link_id": 0, + "nodes": [ + { + "id": 1, + "type": "bb222222-3333-4444-8555-000000000002", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [ + { "name": "output_a", "type": "LATENT", "links": null }, + { "name": "output_b", "type": "LATENT", "links": null } + ], + "title": "Two Sampler Subgraph", + "properties": { + "previewExposures": [ + { + "name": "$$canvas-image-preview", + "sourceNodeId": "2", + "sourcePreviewName": "$$canvas-image-preview" + } + ] + }, + "widgets_values": [] + } + ], + "links": [], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "bb222222-3333-4444-8555-000000000002", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 3, + "lastLinkId": 2, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Two Sampler Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "cc333333-4444-4555-8666-000000000003", + "name": "output_a", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 190 } + }, + { + "id": "dd444444-5555-4666-8777-000000000004", + "name": "output_b", + "type": "LATENT", + "linkIds": [2], + "pos": { "0": 920, "1": 250 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 2, + "type": "KSampler", + "pos": [250, 120], + "size": [280, 260], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "model", + "name": "model", + "type": "MODEL", + "link": null + }, + { + "localized_name": "positive", + "name": "positive", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "negative", + "name": "negative", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "LATENT", + "name": "LATENT", + "type": "LATENT", + "links": [1] + } + ], + "properties": { "Node name for S&R": "KSampler" }, + "widgets_values": [1, "increment", 20, 8, "euler", "normal", 1] + }, + { + "id": 3, + "type": "KSampler", + "pos": [250, 420], + "size": [280, 260], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "localized_name": "model", + "name": "model", + "type": "MODEL", + "link": null + }, + { + "localized_name": "positive", + "name": "positive", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "negative", + "name": "negative", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "LATENT", + "name": "LATENT", + "type": "LATENT", + "links": [2] + } + ], + "properties": { "Node name for S&R": "KSampler" }, + "widgets_values": [2, "increment", 20, 8, "euler", "normal", 1] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 2, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + }, + { + "id": 2, + "origin_id": 3, + "origin_slot": 0, + "target_id": -20, + "target_slot": 1, + "type": "LATENT" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": { + "ds": { "offset": [0, 0], "scale": 1 } + }, + "version": 0.4 +} diff --git a/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts new file mode 100644 index 00000000000..5e5eb01a8a3 --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts @@ -0,0 +1,78 @@ +import { mergeTests } from '@playwright/test' + +import { + comfyPageFixture, + comfyExpect as expect +} from '@e2e/fixtures/ComfyPage' +import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper' +import { webSocketFixture } from '@e2e/fixtures/ws' + +const test = mergeTests(comfyPageFixture, webSocketFixture) + +const SUBGRAPH_NODE_ID = '1' +// Only node 2 has an explicit exposure baked into the fixture's +// `properties.previewExposures` — node 3 simulates a KSampler added to the +// subgraph after the one-shot auto-expose already ran, so it has no +// exposure at all (incident-94 bug #3). +const FIRST_SAMPLER_ID = '2' +const SECOND_SAMPLER_ID = '3' +const FIRST_SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:${FIRST_SAMPLER_ID}` +const SECOND_SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:${SECOND_SAMPLER_ID}` + +test.describe( + 'Subgraph concurrent preview outputs (incident-94 bug #3)', + { tag: ['@vue-nodes', '@subgraph'] }, + () => { + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-with-two-live-samplers' + ) + await comfyPage.vueNodes.waitForNodes(1) + }) + + test('shows live previews from both concurrently-executing interior samplers, not just the exposed one', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const subgraphNode = comfyPage.vueNodes.getNodeLocator(SUBGRAPH_NODE_ID) + const previewImages = subgraphNode.locator('img[src^="blob:"]') + + await test.step('no preview is present before execution', async () => { + await expect(previewImages).toHaveCount(0) + }) + + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + + await test.step('the exposed sampler (node 2) shows its live preview', async () => { + exec.latentPreview(jobId, FIRST_SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(1) + }) + + await test.step('the second, unexposed sampler (node 3) also shows its live preview, appended rather than overwriting the first', async () => { + exec.latentPreview(jobId, SECOND_SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(2) + }) + + await test.step('both previews remain distinct as new frames arrive for each', async () => { + const firstSrcBefore = await previewImages.nth(0).getAttribute('src') + const secondSrcBefore = await previewImages.nth(1).getAttribute('src') + + exec.latentPreview(jobId, SECOND_SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(2) + + await expect(previewImages.nth(0)).toHaveAttribute( + 'src', + firstSrcBefore! + ) + await expect(previewImages.nth(1)).not.toHaveAttribute( + 'src', + secondSrcBefore! + ) + }) + }) + } +) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts new file mode 100644 index 00000000000..9d138c3b9c5 --- /dev/null +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -0,0 +1,207 @@ +import { createTestingPinia } from '@pinia/testing' +import { setActivePinia } from 'pinia' +import { reactive } from 'vue' +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { LGraphNode } from '@/lib/litegraph/src/litegraph' +import { + createTestSubgraph, + createTestSubgraphNode +} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' +import { useNodeOutputStore } from '@/stores/nodeOutputStore' +import { createNodeLocatorId } from '@/types/nodeIdentification' +import { toNodeId } from '@/types/nodeId' + +import { useAmbientSubgraphPreviews } from './useAmbientSubgraphPreviews' + +type MockNodeOutputStore = Pick< + ReturnType, + 'nodeOutputs' | 'nodePreviewImages' | 'getNodeImageUrls' +> + +vi.mock('@/stores/nodeOutputStore', () => { + const store: MockNodeOutputStore = { + nodeOutputs: reactive({}), + nodePreviewImages: reactive({}), + getNodeImageUrls: vi.fn() + } + return { useNodeOutputStore: () => store } +}) + +function clearMockNodeOutputStore() { + const { nodeOutputs, nodePreviewImages } = useNodeOutputStore() + for (const key of Object.keys(nodeOutputs)) delete nodeOutputs[key] + for (const key of Object.keys(nodePreviewImages)) + delete nodePreviewImages[key] +} + +function createSetup() { + const subgraph = createTestSubgraph() + const subgraphNode = createTestSubgraphNode(subgraph) + return { subgraph, subgraphNode } +} + +function addInteriorNode( + setup: ReturnType, + options: { + id: number + previewMediaType?: 'image' | 'video' | 'audio' | 'model' + } +): LGraphNode { + const node = new LGraphNode('test') + node.id = toNodeId(options.id) + if (options.previewMediaType) { + node.previewMediaType = options.previewMediaType + } + setup.subgraph.add(node) + return node +} + +function seedOutputs(subgraphId: string, nodeIds: Array) { + const store = useNodeOutputStore() + for (const nodeId of nodeIds) { + const locatorId = createNodeLocatorId(subgraphId, toNodeId(nodeId)) + store.nodeOutputs[locatorId] = { + images: [{ filename: 'output.png' }] + } + } +} + +describe(useAmbientSubgraphPreviews, () => { + beforeEach(() => { + setActivePinia(createTestingPinia({ stubActions: false })) + vi.resetAllMocks() + clearMockNodeOutputStore() + }) + + it('returns empty array for non-SubgraphNode', () => { + const node = new LGraphNode('test') + const { ambientPreviews } = useAmbientSubgraphPreviews(() => node) + expect(ambientPreviews.value).toEqual([]) + }) + + it('returns empty array for null node', () => { + const { ambientPreviews } = useAmbientSubgraphPreviews(() => null) + expect(ambientPreviews.value).toEqual([]) + }) + + it('returns empty array (does not throw) when SubgraphNode is detached', () => { + const setup = createSetup() + const parentGraph = setup.subgraphNode.graph! + parentGraph.add(setup.subgraphNode) + parentGraph.remove(setup.subgraphNode) + + expect(setup.subgraphNode.graph).toBeNull() + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(() => ambientPreviews.value).not.toThrow() + expect(ambientPreviews.value).toEqual([]) + }) + + it('returns empty array when no interior node has produced output', () => { + const setup = createSetup() + addInteriorNode(setup, { id: 10 }) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) + + it('returns a preview for an interior node with live output, without any exposure', () => { + const setup = createSetup() + const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraph.id, [10]) + const urls = ['/view?filename=output.png'] + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => + n === node ? urls : undefined + ) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ + sourceNodeId: '10', + type: 'image', + urls + }) + ]) + }) + + // Regression case for incident-94 bug #3: 2 KSamplers producing live + // previews concurrently in one subgraph must both surface, not just one. + it('returns separate entries for two concurrently-executing interior nodes', () => { + const setup = createSetup() + const node10 = addInteriorNode(setup, { + id: 10, + previewMediaType: 'image' + }) + const node20 = addInteriorNode(setup, { + id: 20, + previewMediaType: 'image' + }) + seedOutputs(setup.subgraph.id, [10, 20]) + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation( + (node) => { + if (node === node10) return ['/view?a=1'] + if (node === node20) return ['/view?b=2'] + return undefined + } + ) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toHaveLength(2) + const urlsBySourceNodeId = new Map( + ambientPreviews.value.map((p) => [p.sourceNodeId, p.urls]) + ) + expect(urlsBySourceNodeId.get(toNodeId(10))).toEqual(['/view?a=1']) + expect(urlsBySourceNodeId.get(toNodeId(20))).toEqual(['/view?b=2']) + }) + + it('skips interior nodes with no image output', () => { + const setup = createSetup() + addInteriorNode(setup, { id: 10 }) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) + + it('recomputes when outputs are populated after first evaluation', () => { + const setup = createSetup() + const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + + seedOutputs(setup.subgraph.id, [10]) + const urls = ['/view?filename=output.png'] + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => + n === node ? urls : undefined + ) + + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ sourceNodeId: '10', urls }) + ]) + }) + + it('skips nested SubgraphNode interior nodes (they derive their own previews)', () => { + const setup = createSetup() + const nestedSubgraph = createTestSubgraph() + const nestedHost = createTestSubgraphNode(nestedSubgraph, { id: 30 }) + setup.subgraph.add(nestedHost) + seedOutputs(setup.subgraph.id, [30]) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) +}) From 90958d4891d524b36da29d0b8225e2a9a567182a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 2 Aug 2026 06:58:17 +0000 Subject: [PATCH 02/24] fix: derive subgraph host previews from live execution state, not just exposures Subgraph previews were 1:1 with previewExposureStore, so a second interior node producing output concurrently (e.g. a 2nd KSampler with no exposure) had nowhere to render and stayed invisible on the collapsed host. Add useAmbientSubgraphPreviews, a computed rollup that mirrors how executionStore's nodeLocationProgressStates bubbles up progress regardless of promotion: it reads each direct interior node's own output/preview state from nodeOutputStore, independent of exposures. LGraphNode.vue merges it underneath the existing exposure-driven promotedPreviews (an explicit exposure still wins for that node), so every concurrently-executing interior node shows and updates on its own, not just the promoted one. --- .../node/useAmbientSubgraphPreviews.ts | 71 +++++++++++++++++++ src/composables/node/usePromotedPreviews.ts | 5 +- .../vueNodes/components/LGraphNode.vue | 21 +++++- 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/composables/node/useAmbientSubgraphPreviews.ts diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts new file mode 100644 index 00000000000..66ef8ac2506 --- /dev/null +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -0,0 +1,71 @@ +import type { MaybeRefOrGetter } from 'vue' +import { computed, toValue } from 'vue' + +import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' +import { useNodeOutputStore } from '@/stores/nodeOutputStore' +import { createNodeLocatorId } from '@/types/nodeIdentification' + +import type { PromotedPreview } from './usePromotedPreviews' +import { getPreviewMediaType } from './usePromotedPreviews' + +/** + * Synthetic `sourceWidgetName` for ambient previews, so they share + * {@link PromotedPreview}'s shape (and the render list's dedup/key logic) + * without implying a real promoted widget exists. + */ +const AMBIENT_PREVIEW_NAME = '$$ambient-preview' + +/** + * Live-execution previews for a SubgraphNode host, derived directly from + * each interior node's own output/preview state. + * + * Deliberately independent of `previewExposureStore` and the link-promotion + * system: it exists so any interior node currently producing output (e.g. a + * second KSampler nobody promoted) still shows on the collapsed host, the + * same way `nodeLocationProgressStates` bubbles up execution progress + * regardless of promotion. + */ +export function useAmbientSubgraphPreviews( + lgraphNode: MaybeRefOrGetter +) { + const nodeOutputStore = useNodeOutputStore() + + const ambientPreviews = computed((): PromotedPreview[] => { + const node = toValue(lgraphNode) + if (!(node instanceof SubgraphNode)) return [] + if (node.isDetached) return [] + + const { subgraph } = node + + return subgraph.nodes.flatMap((interiorNode): PromotedPreview[] => { + // Nested subgraph hosts derive their own previews independently. + if (interiorNode instanceof SubgraphNode) return [] + if (interiorNode.hideOutputImages) return [] + + const locatorId = createNodeLocatorId(subgraph.id, interiorNode.id) + if (!locatorId) return [] + + // Touch reactive sources for Vue tracking; getNodeImageUrls reads + // non-reactive app state. + const hasReactiveOutputs = + nodeOutputStore.nodeOutputs[locatorId]?.images?.length || + nodeOutputStore.nodePreviewImages[locatorId]?.length + if (!hasReactiveOutputs) return [] + + const urls = nodeOutputStore.getNodeImageUrls(interiorNode) + if (!urls?.length) return [] + + return [ + { + sourceNodeId: interiorNode.id, + sourceWidgetName: AMBIENT_PREVIEW_NAME, + type: getPreviewMediaType(interiorNode), + urls + } + ] + }) + }) + + return { ambientPreviews } +} diff --git a/src/composables/node/usePromotedPreviews.ts b/src/composables/node/usePromotedPreviews.ts index 03885471e78..3aa13e82491 100644 --- a/src/composables/node/usePromotedPreviews.ts +++ b/src/composables/node/usePromotedPreviews.ts @@ -13,7 +13,7 @@ import { } from '@/types/nodeIdentification' import type { NodeExecutionId } from '@/types/nodeIdentification' -interface PromotedPreview { +export interface PromotedPreview { sourceNodeId: NodeId sourceWidgetName: string type: 'image' | 'video' | 'audio' @@ -25,7 +25,8 @@ const PREVIEW_TYPES_BY_MEDIA = { audio: 'audio' } as const satisfies Partial> -function getPreviewMediaType(node: LGraphNode): PromotedPreview['type'] { +/** Shared with {@link useAmbientSubgraphPreviews} so both derive media type identically. */ +export function getPreviewMediaType(node: LGraphNode): PromotedPreview['type'] { const media = node.previewMediaType if (media && media in PREVIEW_TYPES_BY_MEDIA) { return PREVIEW_TYPES_BY_MEDIA[media as keyof typeof PREVIEW_TYPES_BY_MEDIA] diff --git a/src/renderer/extensions/vueNodes/components/LGraphNode.vue b/src/renderer/extensions/vueNodes/components/LGraphNode.vue index 0e808b14d84..2a993ce22ec 100644 --- a/src/renderer/extensions/vueNodes/components/LGraphNode.vue +++ b/src/renderer/extensions/vueNodes/components/LGraphNode.vue @@ -162,7 +162,7 @@ :media="nodeMedia" /> { // Check if node has custom content (like image/video outputs) const hasCustomContent = computed(() => { - if (promotedPreviews.value.length > 0) return true + if (subgraphPreviews.value.length > 0) return true return !!nodeMedia.value && nodeMedia.value.urls.length > 0 }) @@ -716,6 +717,22 @@ const lgraphNode = computed(() => { // TODO: Surface subgraph info more cleanly in VueNodeData instead of // reaching through lgraphNode for promoted preview resolution. const { promotedPreviews } = usePromotedPreviews(lgraphNode) +const { ambientPreviews } = useAmbientSubgraphPreviews(lgraphNode) + +// Ambient previews fill in interior nodes with live output but no explicit +// exposure; an exposure for the same node always wins so it keeps its +// promoted name/ordering. +const subgraphPreviews = computed(() => { + if (!ambientPreviews.value.length) return promotedPreviews.value + + const exposedNodeIds = new Set( + promotedPreviews.value.map((preview) => String(preview.sourceNodeId)) + ) + const unexposed = ambientPreviews.value.filter( + (preview) => !exposedNodeIds.has(String(preview.sourceNodeId)) + ) + return [...promotedPreviews.value, ...unexposed] +}) const { hideExecutedOutput } = useGLSLPreview(lgraphNode) From 1c1887574f24979caad093e26de1aaec124f2204 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 2 Aug 2026 07:33:00 +0000 Subject: [PATCH 03/24] fix: exclude input-only outputs from ambient subgraph previews useAmbientSubgraphPreviews treated any interior node with images in nodeOutputStore as a live preview candidate, including nodes whose only "output" is an input-type reference (e.g. an unpromoted LoadImage node's own selected file). That made every such node's thumbnail always visible on the collapsed subgraph host regardless of promotion state, breaking promotion exclusivity. CI caught this: browser_tests/tests/subgraph/subgraphPromotion.spec.ts "Can promote multiple previews" > "Promote both image previews" failed consistently (all 4 attempts) on PR #14569 - after promoting only one of two Load Image previews, the host showed 2 preview elements instead of 1, because the unpromoted node's own file leaked in via the new ambient rollup. Export isInputPreviewOutput from nodeOutputStore and use it to skip input-only outputs in the ambient computed, so only genuine live execution results (or streaming preview frames) surface ambiently - matching the feature's stated intent (a second concurrently-executing node with no exposure), not static input previews. Claude-Session: https://claude.ai/code/session_01FCL4Meqh8o8VYh9xV1h1Ky --- .../node/useAmbientSubgraphPreviews.test.ts | 38 ++++++++++++++++++- .../node/useAmbientSubgraphPreviews.ts | 10 ++++- src/stores/nodeOutputStore.ts | 1 + 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts index 9d138c3b9c5..187405a9888 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.test.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -16,14 +16,26 @@ import { useAmbientSubgraphPreviews } from './useAmbientSubgraphPreviews' type MockNodeOutputStore = Pick< ReturnType, - 'nodeOutputs' | 'nodePreviewImages' | 'getNodeImageUrls' + | 'nodeOutputs' + | 'nodePreviewImages' + | 'getNodeImageUrls' + | 'isInputPreviewOutput' > vi.mock('@/stores/nodeOutputStore', () => { const store: MockNodeOutputStore = { nodeOutputs: reactive({}), nodePreviewImages: reactive({}), - getNodeImageUrls: vi.fn() + getNodeImageUrls: vi.fn(), + isInputPreviewOutput: (output) => { + const images = (output as { images?: { type?: string }[] } | undefined) + ?.images + return ( + Array.isArray(images) && + images.length > 0 && + images.every((i) => i?.type === 'input') + ) + } } return { useNodeOutputStore: () => store } }) @@ -172,6 +184,28 @@ describe(useAmbientSubgraphPreviews, () => { expect(ambientPreviews.value).toEqual([]) }) + // Regression case: an unpromoted LoadImage-style node's own selected file + // is an "input" preview, not a live execution result. Surfacing it + // ambiently would make every such node's thumbnail always visible on the + // host regardless of promotion, breaking exclusivity of the promotion UI. + it('skips interior nodes whose only output is an input-type preview (e.g. LoadImage)', () => { + const setup = createSetup() + const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + const store = useNodeOutputStore() + const locatorId = createNodeLocatorId(setup.subgraph.id, toNodeId(10))! + store.nodeOutputs[locatorId] = { + images: [{ filename: 'input.png', type: 'input' }] + } + vi.mocked(store.getNodeImageUrls).mockImplementation((n) => + n === node ? ['/view?filename=input.png'] : undefined + ) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) + it('recomputes when outputs are populated after first evaluation', () => { const setup = createSetup() const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts index 66ef8ac2506..6938d301bd3 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -48,8 +48,16 @@ export function useAmbientSubgraphPreviews( // Touch reactive sources for Vue tracking; getNodeImageUrls reads // non-reactive app state. + const reactiveOutput = nodeOutputStore.nodeOutputs[locatorId] + // An input-only output (e.g. a LoadImage node's own selected file) is + // static reference data, not a live execution result — surfacing it + // ambiently would make every unpromoted input node's thumbnail always + // visible on the host, defeating explicit promotion for those nodes. + const hasLiveOutputImages = + reactiveOutput?.images?.length && + !nodeOutputStore.isInputPreviewOutput(reactiveOutput) const hasReactiveOutputs = - nodeOutputStore.nodeOutputs[locatorId]?.images?.length || + hasLiveOutputImages || nodeOutputStore.nodePreviewImages[locatorId]?.length if (!hasReactiveOutputs) return [] diff --git a/src/stores/nodeOutputStore.ts b/src/stores/nodeOutputStore.ts index 381ecd93883..6926e44f389 100644 --- a/src/stores/nodeOutputStore.ts +++ b/src/stores/nodeOutputStore.ts @@ -430,6 +430,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { getNodePreviewImagesByExecutionId, getNodePreviews, getPreviewParam, + isInputPreviewOutput, setNodeOutputs, setNodeOutputsByExecutionId, From 2a32423367e8cec0487d9aa1b45bb9c970240096 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 5 Aug 2026 11:30:21 +0000 Subject: [PATCH 04/24] test: port SamplerCustomAdvanced allowlist-gap coverage from #14551 #14551 was closed in favor of this PR's ambient-rollup mechanism, but it carried three artifacts not otherwise covered here: - browser_tests/assets/nodes/sampler_custom_advanced_in_subgraph.json + browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts: this PR's own e2e fixture uses two KSamplers, both allowlisted, so it would pass even if a node-type gate were reintroduced into the ambient path. This fixture pins a non-allowlisted node type (SamplerCustomAdvanced) instead. - Two incident-94 expected-fail regression tests (LGraphNode.test.ts, imagePreview.spec.ts) pinning the still-open `!lgraphNode?.isSubgraphNode()` guard at LGraphNode.vue:172, which neither PR touches. --- .../sampler_custom_advanced_in_subgraph.json | 136 ++++++++++++++++++ .../subgraphPreviewAllowlistGap.spec.ts | 59 ++++++++ .../interactions/node/imagePreview.spec.ts | 45 ++++++ .../vueNodes/components/LGraphNode.test.ts | 22 +++ 4 files changed, 262 insertions(+) create mode 100644 browser_tests/assets/nodes/sampler_custom_advanced_in_subgraph.json create mode 100644 browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts diff --git a/browser_tests/assets/nodes/sampler_custom_advanced_in_subgraph.json b/browser_tests/assets/nodes/sampler_custom_advanced_in_subgraph.json new file mode 100644 index 00000000000..69761f2d08c --- /dev/null +++ b/browser_tests/assets/nodes/sampler_custom_advanced_in_subgraph.json @@ -0,0 +1,136 @@ +{ + "id": "cc111111-2222-4333-8444-000000000002", + "revision": 0, + "last_node_id": 1, + "last_link_id": 0, + "nodes": [ + { + "id": 1, + "type": "dd999999-8888-4777-a666-555555555556", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [{ "name": "output", "type": "LATENT", "links": null }], + "title": "Sampler Subgraph", + "properties": {}, + "widgets_values": [] + } + ], + "links": [], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "dd999999-8888-4777-a666-555555555556", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 2, + "lastLinkId": 1, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Sampler Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "ee888888-7777-4666-a555-444444444445", + "name": "output", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 220 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 2, + "type": "SamplerCustomAdvanced", + "pos": [250, 180], + "size": [260, 130], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "noise", + "name": "noise", + "type": "NOISE", + "link": null + }, + { + "localized_name": "guider", + "name": "guider", + "type": "GUIDER", + "link": null + }, + { + "localized_name": "sampler", + "name": "sampler", + "type": "SAMPLER", + "link": null + }, + { + "localized_name": "sigmas", + "name": "sigmas", + "type": "SIGMAS", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "output", + "name": "output", + "type": "LATENT", + "links": [1] + }, + { + "localized_name": "denoised_output", + "name": "denoised_output", + "type": "LATENT", + "links": null + } + ], + "properties": { "Node name for S&R": "SamplerCustomAdvanced" }, + "widgets_values": [] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 2, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": { + "ds": { "offset": [0, 0], "scale": 1 } + }, + "version": 0.4 +} diff --git a/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts b/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts new file mode 100644 index 00000000000..91061bd3204 --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts @@ -0,0 +1,59 @@ +import { mergeTests } from '@playwright/test' + +import { + comfyPageFixture, + comfyExpect as expect +} from '@e2e/fixtures/ComfyPage' +import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper' +import { webSocketFixture } from '@e2e/fixtures/ws' + +const test = mergeTests(comfyPageFixture, webSocketFixture) + +const SUBGRAPH_NODE_ID = '1' +// `SamplerCustomAdvanced` is not in `CANVAS_IMAGE_PREVIEW_NODE_TYPES` +// (src/composables/node/canvasImagePreviewTypes.ts), so +// `autoExposeKnownPreviewNodes` never gives it a persisted +// `previewExposures` entry. Unlike this file's sibling +// `subgraphConcurrentPreviews.spec.ts` (two `KSampler`s, both +// allowlisted), this fixture only passes if the ambient rollup +// (`useAmbientSubgraphPreviews`) surfaces a live preview independent of +// node type — reintroducing a type gate into that path would fail this +// test while leaving the sibling spec green. +const INTERIOR_SAMPLER_NODE_ID = '2' +const SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:${INTERIOR_SAMPLER_NODE_ID}` + +test.describe( + 'Subgraph preview promotion allowlist gap (regression)', + { tag: ['@vue-nodes', '@subgraph'] }, + () => { + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow( + 'nodes/sampler_custom_advanced_in_subgraph' + ) + await comfyPage.vueNodes.waitForNodes(1) + }) + + test('promotes a mid-execution preview from a non-allowlisted interior node onto the outer SubgraphNode', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const subgraphNode = comfyPage.vueNodes.getNodeLocator(SUBGRAPH_NODE_ID) + const previewImage = subgraphNode.locator('img[src^="blob:"]') + + await test.step('no preview is present before execution', async () => { + await expect(previewImage).toHaveCount(0) + }) + + await test.step('a mid-execution preview promotes onto the outer SubgraphNode', async () => { + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + exec.latentPreview(jobId, SAMPLER_EXECUTION_ID) + + await expect(previewImage).toBeVisible() + }) + }) + } +) diff --git a/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts b/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts index 88fc034fb52..ee502482fde 100644 --- a/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts +++ b/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts @@ -181,6 +181,51 @@ test.describe('Vue Nodes Image Preview', { tag: '@vue-nodes' }, () => { await expect(subgraphNode.imagePreview.locator('img')).toHaveCount(1) } ) + + // Regression test for incident-94: a mid-execution sampler preview inside a + // subgraph must promote to the outer, non-entered SubgraphNode. + wstest( + 'Promotes a live sampler preview from inside a subgraph to the outer SubgraphNode', + async ({ comfyPage, getWebSocket }) => { + // Expected-fail for incident-94's `LGraphNode.vue:172` guard + // (`!lgraphNode?.isSubgraphNode()`), not this PR's allowlist gap. + // Remove this marker (don't just delete the test) once that guard ships. + test.fail() + + const execution = new ExecutionHelper(comfyPage, await getWebSocket()) + const samplerNode = new VueNodeFixture( + comfyPage.vueNodes.getNodeByTitle('KSampler') + ) + const subgraphNode = new VueNodeFixture( + comfyPage.vueNodes.getNodeByTitle('New Subgraph') + ) + + await test.step('Add node', async () => { + await comfyPage.menu.topbar.newWorkflowButton.click() + await comfyPage.nextFrame() + + await comfyPage.searchBoxV2.addNode('KSampler') + await expect(samplerNode.root).toBeVisible() + }) + + await test.step('Create subgraph', async () => { + await samplerNode.title.click() + await comfyPage.page.keyboard.press('Control+Shift+e') + await expect(subgraphNode.root).toBeVisible() + }) + + await test.step('Fire live preview for the nested sampler', async () => { + const jobId = await execution.run() + execution.executionStart(jobId) + execution.executing(jobId, '2:1') + execution.latentPreview(jobId, '2:1') + }) + + await expect( + subgraphNode.root.getByAltText('Live sampling preview') + ).toBeVisible() + } + ) }) async function countColumns(locator: Locator) { diff --git a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts index dab285c4d62..4eb90229db1 100644 --- a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts +++ b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts @@ -4,6 +4,7 @@ import { setActivePinia } from 'pinia' import { beforeEach, describe, expect, it, vi } from 'vitest' import { toNodeId } from '@/types/nodeId' +import { createNodeLocatorId } from '@/types/nodeIdentification' import { computed } from 'vue' import type { ComponentProps } from 'vue-component-type-helpers' import { createI18n } from 'vue-i18n' @@ -12,6 +13,7 @@ import type { VueNodeData } from '@/composables/graph/useGraphNodeManager' import { TitleMode } from '@/lib/litegraph/src/types/globalEnums' import LGraphNode from '@/renderer/extensions/vueNodes/components/LGraphNode.vue' import { useVueElementTracking } from '@/renderer/extensions/vueNodes/composables/useVueNodeResizeTracking' +import { useNodePreviewState } from '@/renderer/extensions/vueNodes/preview/useNodePreviewState' import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' import { useSettingStore } from '@/platform/settings/settingStore' import { app } from '@/scripts/app' @@ -388,4 +390,24 @@ describe('LGraphNode', () => { expect(app.dragOverNode).toBe(mockData.mockLgraphNode) }) }) + + describe('Subgraph live preview promotion (incident-94 regression)', () => { + // Expected-fail for incident-94's `LGraphNode.vue:172` guard + // (`!lgraphNode?.isSubgraphNode()`), not this PR's allowlist gap. + // Remove this marker (don't just delete the test) once that guard ships. + it.fails('renders the live preview image on a subgraph node with a populated preview', () => { + mockData.mockLgraphNode = { isSubgraphNode: () => true } + vi.mocked(useNodePreviewState).mockReturnValue({ + locatorId: computed(() => createNodeLocatorId(null, mockNodeData.id)), + previewUrls: computed(() => ['blob:preview-url']), + hasPreview: computed(() => true), + latestPreviewUrl: computed(() => 'blob:preview-url'), + shouldShowPreviewImg: computed(() => true) + }) + + renderLGraphNode({ nodeData: mockNodeData }) + + expect(screen.getByRole('img')).toHaveAttribute('src', 'blob:preview-url') + }) + }) }) From 203bd88c75bcfdcac974db2d455e961b78b10a7c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 5 Aug 2026 17:10:15 +0000 Subject: [PATCH 05/24] chore: clean up comments per review feedback Remove comments that restate what the code does or reference the incident/PR that motivated the change. Keep only comments that capture a genuine non-obvious invariant, rewritten to describe the invariant itself instead of pointing at an incident or ticket number. --- .../subgraph/subgraphConcurrentPreviews.spec.ts | 8 +++----- .../subgraph/subgraphPreviewAllowlistGap.spec.ts | 13 ++++--------- .../vueNodes/interactions/node/imagePreview.spec.ts | 9 ++++----- .../node/useAmbientSubgraphPreviews.test.ts | 10 ++++------ .../vueNodes/components/LGraphNode.test.ts | 9 +++++---- 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts index 5e5eb01a8a3..71fbaabc8a5 100644 --- a/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts +++ b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts @@ -10,17 +10,15 @@ import { webSocketFixture } from '@e2e/fixtures/ws' const test = mergeTests(comfyPageFixture, webSocketFixture) const SUBGRAPH_NODE_ID = '1' -// Only node 2 has an explicit exposure baked into the fixture's -// `properties.previewExposures` — node 3 simulates a KSampler added to the -// subgraph after the one-shot auto-expose already ran, so it has no -// exposure at all (incident-94 bug #3). +// Node 3 has no `properties.previewExposures` entry, simulating a KSampler +// added to the subgraph after the one-shot auto-expose already ran. const FIRST_SAMPLER_ID = '2' const SECOND_SAMPLER_ID = '3' const FIRST_SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:${FIRST_SAMPLER_ID}` const SECOND_SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:${SECOND_SAMPLER_ID}` test.describe( - 'Subgraph concurrent preview outputs (incident-94 bug #3)', + 'Subgraph concurrent preview outputs', { tag: ['@vue-nodes', '@subgraph'] }, () => { test.beforeEach(async ({ comfyPage }) => { diff --git a/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts b/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts index 91061bd3204..55242dc74cf 100644 --- a/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts +++ b/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts @@ -10,15 +10,10 @@ import { webSocketFixture } from '@e2e/fixtures/ws' const test = mergeTests(comfyPageFixture, webSocketFixture) const SUBGRAPH_NODE_ID = '1' -// `SamplerCustomAdvanced` is not in `CANVAS_IMAGE_PREVIEW_NODE_TYPES` -// (src/composables/node/canvasImagePreviewTypes.ts), so -// `autoExposeKnownPreviewNodes` never gives it a persisted -// `previewExposures` entry. Unlike this file's sibling -// `subgraphConcurrentPreviews.spec.ts` (two `KSampler`s, both -// allowlisted), this fixture only passes if the ambient rollup -// (`useAmbientSubgraphPreviews`) surfaces a live preview independent of -// node type — reintroducing a type gate into that path would fail this -// test while leaving the sibling spec green. +// `SamplerCustomAdvanced` isn't in `CANVAS_IMAGE_PREVIEW_NODE_TYPES`, so it +// never gets a persisted `previewExposures` entry — this fixture only +// passes if the ambient rollup surfaces a live preview independent of node +// type. const INTERIOR_SAMPLER_NODE_ID = '2' const SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:${INTERIOR_SAMPLER_NODE_ID}` diff --git a/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts b/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts index ee502482fde..35210e42545 100644 --- a/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts +++ b/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts @@ -182,14 +182,13 @@ test.describe('Vue Nodes Image Preview', { tag: '@vue-nodes' }, () => { } ) - // Regression test for incident-94: a mid-execution sampler preview inside a - // subgraph must promote to the outer, non-entered SubgraphNode. wstest( 'Promotes a live sampler preview from inside a subgraph to the outer SubgraphNode', async ({ comfyPage, getWebSocket }) => { - // Expected-fail for incident-94's `LGraphNode.vue:172` guard - // (`!lgraphNode?.isSubgraphNode()`), not this PR's allowlist gap. - // Remove this marker (don't just delete the test) once that guard ships. + // Expected-fail until the `!lgraphNode?.isSubgraphNode()` guard in + // LGraphNode.vue is relaxed to allow rendering previews on subgraph + // nodes. Keep this test (don't delete) so it flips green automatically + // once that guard changes. test.fail() const execution = new ExecutionHelper(comfyPage, await getWebSocket()) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts index 187405a9888..48dad21398a 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.test.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -142,8 +142,6 @@ describe(useAmbientSubgraphPreviews, () => { ]) }) - // Regression case for incident-94 bug #3: 2 KSamplers producing live - // previews concurrently in one subgraph must both surface, not just one. it('returns separate entries for two concurrently-executing interior nodes', () => { const setup = createSetup() const node10 = addInteriorNode(setup, { @@ -184,10 +182,10 @@ describe(useAmbientSubgraphPreviews, () => { expect(ambientPreviews.value).toEqual([]) }) - // Regression case: an unpromoted LoadImage-style node's own selected file - // is an "input" preview, not a live execution result. Surfacing it - // ambiently would make every such node's thumbnail always visible on the - // host regardless of promotion, breaking exclusivity of the promotion UI. + // An unpromoted LoadImage-style node's own selected file is an "input" + // preview, not a live execution result. Surfacing it ambiently would make + // every such node's thumbnail always visible regardless of promotion, + // breaking exclusivity of the promotion UI. it('skips interior nodes whose only output is an input-type preview (e.g. LoadImage)', () => { const setup = createSetup() const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) diff --git a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts index 4eb90229db1..35afa7b721c 100644 --- a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts +++ b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts @@ -391,10 +391,11 @@ describe('LGraphNode', () => { }) }) - describe('Subgraph live preview promotion (incident-94 regression)', () => { - // Expected-fail for incident-94's `LGraphNode.vue:172` guard - // (`!lgraphNode?.isSubgraphNode()`), not this PR's allowlist gap. - // Remove this marker (don't just delete the test) once that guard ships. + describe('Subgraph live preview promotion', () => { + // Expected-fail until the `!lgraphNode?.isSubgraphNode()` guard in + // LGraphNode.vue is relaxed to allow rendering previews on subgraph + // nodes. Keep this test (don't delete) so it flips green automatically + // once that guard changes. it.fails('renders the live preview image on a subgraph node with a populated preview', () => { mockData.mockLgraphNode = { isSubgraphNode: () => true } vi.mocked(useNodePreviewState).mockReturnValue({ From d0d7c908d7ebc664c0547b0bc32aa1cfbd2f04d4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 8 Aug 2026 23:54:17 +0000 Subject: [PATCH 06/24] fix: gate ambient subgraph previews on streaming preview frames only Admitting committed nodeOutputs alongside nodePreviewImages made demoting an exposure a permanent no-op (the ambient rollup kept re-rendering what removeExposure just deleted, and queueStore repopulates nodeOutputs on history load so it survived reload), stacked a preview on the host for every interior output node after every run, and fed committed-output nodes into buildImageUrls, which appends a fresh &rand= per call and re-fetches at latent-preview frame rate. Narrow the gate to nodePreviewImages only. isInputPreviewOutput was exported from nodeOutputStore solely for the dropped branch and has no other external callers, so drop the export too - nodeOutputStore.ts's diff against main is now empty. Also correct two docblock claims: previews render when the host is expanded (v-else-if="!isCollapsed" in LGraphNode.vue), not collapsed, and this composable bails at depth 1 instead of recursing like nodeLocationProgressStates. --- .../node/useAmbientSubgraphPreviews.ts | 27 ++++++------------- src/stores/nodeOutputStore.ts | 1 - 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts index 6938d301bd3..a1623167035 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -18,13 +18,15 @@ const AMBIENT_PREVIEW_NAME = '$$ambient-preview' /** * Live-execution previews for a SubgraphNode host, derived directly from - * each interior node's own output/preview state. + * each interior node's own streaming preview state. * * Deliberately independent of `previewExposureStore` and the link-promotion - * system: it exists so any interior node currently producing output (e.g. a - * second KSampler nobody promoted) still shows on the collapsed host, the - * same way `nodeLocationProgressStates` bubbles up execution progress - * regardless of promotion. + * system: it exists so any interior node currently producing a live preview + * (e.g. a second KSampler nobody promoted) still shows on the expanded host, + * loosely analogous to how `nodeLocationProgressStates` bubbles up execution + * progress regardless of promotion — though unlike that store, this only + * looks at the host's immediate interior nodes and does not recurse into + * nested subgraphs. */ export function useAmbientSubgraphPreviews( lgraphNode: MaybeRefOrGetter @@ -46,20 +48,7 @@ export function useAmbientSubgraphPreviews( const locatorId = createNodeLocatorId(subgraph.id, interiorNode.id) if (!locatorId) return [] - // Touch reactive sources for Vue tracking; getNodeImageUrls reads - // non-reactive app state. - const reactiveOutput = nodeOutputStore.nodeOutputs[locatorId] - // An input-only output (e.g. a LoadImage node's own selected file) is - // static reference data, not a live execution result — surfacing it - // ambiently would make every unpromoted input node's thumbnail always - // visible on the host, defeating explicit promotion for those nodes. - const hasLiveOutputImages = - reactiveOutput?.images?.length && - !nodeOutputStore.isInputPreviewOutput(reactiveOutput) - const hasReactiveOutputs = - hasLiveOutputImages || - nodeOutputStore.nodePreviewImages[locatorId]?.length - if (!hasReactiveOutputs) return [] + if (!nodeOutputStore.nodePreviewImages[locatorId]?.length) return [] const urls = nodeOutputStore.getNodeImageUrls(interiorNode) if (!urls?.length) return [] diff --git a/src/stores/nodeOutputStore.ts b/src/stores/nodeOutputStore.ts index 6926e44f389..381ecd93883 100644 --- a/src/stores/nodeOutputStore.ts +++ b/src/stores/nodeOutputStore.ts @@ -430,7 +430,6 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { getNodePreviewImagesByExecutionId, getNodePreviews, getPreviewParam, - isInputPreviewOutput, setNodeOutputs, setNodeOutputsByExecutionId, From f0e4eafa46f5c8d5466bb84fe011d9080d1fd073 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 8 Aug 2026 23:55:23 +0000 Subject: [PATCH 07/24] fix: build subgraph preview dedup set from the host's own exposures exposedNodeIds was built from promotedPreviews[].sourceNodeId, which is the chain-resolved leaf id for exposures that come from a nested subgraph. useAmbientSubgraphPreviews emits immediate-interior ids instead. Since last_node_id is per-LGraph, ids restart at 1 in every subgraph, so a nested exposure resolving to leaf id N could collide with and suppress the host's own interior node N. Build the exclusion set from previewExposureStore.getExposures( rootGraphId, hostLocator) instead - those are, by schema, direct children of the host's own subgraph, so both sides of the dedup are in the same id space. Also extract the promoted/ambient merge into a pure mergeSubgraphPreviews function with unit tests covering no overlap, an overlapping exposure winning over its ambient duplicate, and the namespace-collision regression above. --- .../node/mergeSubgraphPreviews.test.ts | 65 +++++++++++++++++++ src/composables/node/mergeSubgraphPreviews.ts | 30 +++++++++ .../vueNodes/components/LGraphNode.vue | 25 +++---- 3 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 src/composables/node/mergeSubgraphPreviews.test.ts create mode 100644 src/composables/node/mergeSubgraphPreviews.ts diff --git a/src/composables/node/mergeSubgraphPreviews.test.ts b/src/composables/node/mergeSubgraphPreviews.test.ts new file mode 100644 index 00000000000..774c339f9d4 --- /dev/null +++ b/src/composables/node/mergeSubgraphPreviews.test.ts @@ -0,0 +1,65 @@ +import { describe, expect, it } from 'vitest' + +import { toNodeId } from '@/types/nodeId' + +import { mergeSubgraphPreviews } from './mergeSubgraphPreviews' +import type { PromotedPreview } from './usePromotedPreviews' + +function preview( + sourceNodeId: number | string, + overrides: Partial = {} +): PromotedPreview { + return { + sourceNodeId: toNodeId(sourceNodeId), + sourceWidgetName: 'preview', + type: 'image', + urls: ['/view?filename=test.png'], + ...overrides + } +} + +describe(mergeSubgraphPreviews, () => { + it('returns both when there is no overlap', () => { + const promoted = [preview(1)] + const ambient = [preview(2)] + + const result = mergeSubgraphPreviews(promoted, ambient, [toNodeId(1)]) + + expect(result).toEqual([preview(1), preview(2)]) + }) + + it('drops the ambient entry for a node the host has exposed, keeping the exposure', () => { + const promoted = [preview(3, { sourceWidgetName: 'exposed-name' })] + const ambient = [preview(3, { sourceWidgetName: '$$ambient-preview' })] + + const result = mergeSubgraphPreviews(promoted, ambient, [toNodeId(3)]) + + expect(result).toEqual([preview(3, { sourceWidgetName: 'exposed-name' })]) + }) + + it('does not drop an ambient node whose id only collides with a nested exposure leaf id', () => { + // `promoted` resolved through a nested subgraph to leaf id 3 in that + // nested graph's id space. The host's own exposures (what actually + // shares this host's id space) don't include node 3, so the host's own + // interior node 3 must still surface ambiently instead of being + // suppressed by the unrelated leaf id. + const promoted = [preview(3, { sourceWidgetName: 'nested-exposure' })] + const ambient = [preview(3, { sourceWidgetName: '$$ambient-preview' })] + const hostsOwnExposedIds = [toNodeId(7)] + + const result = mergeSubgraphPreviews(promoted, ambient, hostsOwnExposedIds) + + expect(result).toEqual([ + preview(3, { sourceWidgetName: 'nested-exposure' }), + preview(3, { sourceWidgetName: '$$ambient-preview' }) + ]) + }) + + it('returns promoted unchanged when there are no ambient previews', () => { + const promoted = [preview(1)] + + const result = mergeSubgraphPreviews(promoted, [], []) + + expect(result).toEqual(promoted) + }) +}) diff --git a/src/composables/node/mergeSubgraphPreviews.ts b/src/composables/node/mergeSubgraphPreviews.ts new file mode 100644 index 00000000000..6ce8d99c0e2 --- /dev/null +++ b/src/composables/node/mergeSubgraphPreviews.ts @@ -0,0 +1,30 @@ +import type { NodeId } from '@/types/nodeId' + +import type { PromotedPreview } from './usePromotedPreviews' + +/** + * Merges a subgraph host's exposure-promoted previews with its ambient + * previews, keeping the promoted entry whenever both cover the same + * interior node. + * + * `exposedSourceNodeIds` must be the host's own first-hop exposures (e.g. + * from `previewExposureStore.getExposures(rootGraphId, hostLocator)`), not + * `promoted`'s resolved `sourceNodeId`s. A promoted preview's `sourceNodeId` + * can be a leaf id resolved through a nested subgraph, which lives in a + * different `LGraph`'s id space than `ambient`'s immediate-interior ids — + * deduping against it can drop an unrelated ambient node that happens to + * share the same numeric id one level down. + */ +export function mergeSubgraphPreviews( + promoted: readonly PromotedPreview[], + ambient: readonly PromotedPreview[], + exposedSourceNodeIds: readonly NodeId[] +): PromotedPreview[] { + if (!ambient.length) return [...promoted] + + const exposed = new Set(exposedSourceNodeIds.map(String)) + const unexposed = ambient.filter( + (preview) => !exposed.has(String(preview.sourceNodeId)) + ) + return [...promoted, ...unexposed] +} diff --git a/src/renderer/extensions/vueNodes/components/LGraphNode.vue b/src/renderer/extensions/vueNodes/components/LGraphNode.vue index 2a993ce22ec..d2222442d29 100644 --- a/src/renderer/extensions/vueNodes/components/LGraphNode.vue +++ b/src/renderer/extensions/vueNodes/components/LGraphNode.vue @@ -275,6 +275,7 @@ import { useCanvasInteractions } from '@/renderer/core/canvas/useCanvasInteracti import { layoutStore } from '@/renderer/core/layout/store/layoutStore' import { useGLSLPreview } from '@/renderer/glsl/useGLSLPreview' import { useAmbientSubgraphPreviews } from '@/composables/node/useAmbientSubgraphPreviews' +import { mergeSubgraphPreviews } from '@/composables/node/mergeSubgraphPreviews' import { usePromotedPreviews } from '@/composables/node/usePromotedPreviews' import NodeBadges from '@/renderer/extensions/vueNodes/components/NodeBadges.vue' import { LayoutSource } from '@/renderer/core/layout/types' @@ -297,6 +298,7 @@ import { useMissingModelStore } from '@/platform/missingModel/missingModelStore' import { useExecutionErrorStore } from '@/stores/executionErrorStore' import { useMissingNodesErrorStore } from '@/platform/nodeReplacement/missingNodesErrorStore' import { useNodeOutputStore } from '@/stores/nodeOutputStore' +import { usePreviewExposureStore } from '@/stores/previewExposureStore' import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore' import { useRightSidePanelStore } from '@/stores/workspace/rightSidePanelStore' import { isVideoOutput } from '@/utils/litegraphUtil' @@ -718,20 +720,21 @@ const lgraphNode = computed(() => { // reaching through lgraphNode for promoted preview resolution. const { promotedPreviews } = usePromotedPreviews(lgraphNode) const { ambientPreviews } = useAmbientSubgraphPreviews(lgraphNode) +const previewExposureStore = usePreviewExposureStore() -// Ambient previews fill in interior nodes with live output but no explicit -// exposure; an exposure for the same node always wins so it keeps its -// promoted name/ordering. const subgraphPreviews = computed(() => { - if (!ambientPreviews.value.length) return promotedPreviews.value - - const exposedNodeIds = new Set( - promotedPreviews.value.map((preview) => String(preview.sourceNodeId)) - ) - const unexposed = ambientPreviews.value.filter( - (preview) => !exposedNodeIds.has(String(preview.sourceNodeId)) + const node = lgraphNode.value + const exposedSourceNodeIds = + node instanceof SubgraphNode + ? previewExposureStore + .getExposures(node.rootGraph.id, String(node.id)) + .map((exposure) => exposure.sourceNodeId) + : [] + return mergeSubgraphPreviews( + promotedPreviews.value, + ambientPreviews.value, + exposedSourceNodeIds ) - return [...promotedPreviews.value, ...unexposed] }) const { hideExecutedOutput } = useGLSLPreview(lgraphNode) From 339e7beb2268bb4e3df4644714109a13ec85940c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 8 Aug 2026 23:56:23 +0000 Subject: [PATCH 08/24] test: make ambient subgraph preview guard tests mutation-killing getNodeImageUrls is an unstubbed vi.fn(), reset to undefined by vi.resetAllMocks(), so `if (!urls?.length) return []` short-circuited before the isDetached bail, the nested-SubgraphNode skip, or the hideOutputImages guard ever ran - deleting any of the three still left every test green. Add mockReturnValue stubs so the detached and nested-SubgraphNode tests actually reach their guard, and add a test for the previously uncovered hideOutputImages guard. Also dedupe the byte-identical "no output" test by differentiating it into a test for the getNodeImageUrls-returns-nothing case, add a regression test locking in the nodeOutputs exclusion from the previous commit, and assert media type via getPreviewMediaType instead of a hardcoded 'image' literal so a change to that derivation isn't invisible to the suite. --- .../node/useAmbientSubgraphPreviews.test.ts | 73 +++++++++++-------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts index 48dad21398a..71e80a375e9 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.test.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -12,30 +12,19 @@ import { useNodeOutputStore } from '@/stores/nodeOutputStore' import { createNodeLocatorId } from '@/types/nodeIdentification' import { toNodeId } from '@/types/nodeId' +import { getPreviewMediaType } from './usePromotedPreviews' import { useAmbientSubgraphPreviews } from './useAmbientSubgraphPreviews' type MockNodeOutputStore = Pick< ReturnType, - | 'nodeOutputs' - | 'nodePreviewImages' - | 'getNodeImageUrls' - | 'isInputPreviewOutput' + 'nodeOutputs' | 'nodePreviewImages' | 'getNodeImageUrls' > vi.mock('@/stores/nodeOutputStore', () => { const store: MockNodeOutputStore = { nodeOutputs: reactive({}), nodePreviewImages: reactive({}), - getNodeImageUrls: vi.fn(), - isInputPreviewOutput: (output) => { - const images = (output as { images?: { type?: string }[] } | undefined) - ?.images - return ( - Array.isArray(images) && - images.length > 0 && - images.every((i) => i?.type === 'input') - ) - } + getNodeImageUrls: vi.fn() } return { useNodeOutputStore: () => store } }) @@ -73,9 +62,7 @@ function seedOutputs(subgraphId: string, nodeIds: Array) { const store = useNodeOutputStore() for (const nodeId of nodeIds) { const locatorId = createNodeLocatorId(subgraphId, toNodeId(nodeId)) - store.nodeOutputs[locatorId] = { - images: [{ filename: 'output.png' }] - } + store.nodePreviewImages[locatorId] = ['seeded-preview-url'] } } @@ -99,6 +86,12 @@ describe(useAmbientSubgraphPreviews, () => { it('returns empty array (does not throw) when SubgraphNode is detached', () => { const setup = createSetup() + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraph.id, [10]) + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockReturnValue([ + '/view?filename=output.png' + ]) + const parentGraph = setup.subgraphNode.graph! parentGraph.add(setup.subgraphNode) parentGraph.remove(setup.subgraphNode) @@ -136,7 +129,7 @@ describe(useAmbientSubgraphPreviews, () => { expect(ambientPreviews.value).toEqual([ expect.objectContaining({ sourceNodeId: '10', - type: 'image', + type: getPreviewMediaType(node), urls }) ]) @@ -172,9 +165,11 @@ describe(useAmbientSubgraphPreviews, () => { expect(urlsBySourceNodeId.get(toNodeId(20))).toEqual(['/view?b=2']) }) - it('skips interior nodes with no image output', () => { + it('skips interior nodes when getNodeImageUrls returns no urls despite a preview entry', () => { const setup = createSetup() - addInteriorNode(setup, { id: 10 }) + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraph.id, [10]) + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockReturnValue(undefined) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode @@ -182,20 +177,20 @@ describe(useAmbientSubgraphPreviews, () => { expect(ambientPreviews.value).toEqual([]) }) - // An unpromoted LoadImage-style node's own selected file is an "input" - // preview, not a live execution result. Surfacing it ambiently would make - // every such node's thumbnail always visible regardless of promotion, - // breaking exclusivity of the promotion UI. - it('skips interior nodes whose only output is an input-type preview (e.g. LoadImage)', () => { + // Regression coverage for narrowing the gate to `nodePreviewImages` only: + // a committed output (as opposed to a streaming preview frame) must never + // surface ambiently, even when it looks like a valid image output — + // otherwise demoting an exposure becomes a no-op and every interior output + // node stacks a permanent preview on the host after every run. + it('does not surface a committed output that was never a streaming preview', () => { const setup = createSetup() const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) - const store = useNodeOutputStore() const locatorId = createNodeLocatorId(setup.subgraph.id, toNodeId(10))! - store.nodeOutputs[locatorId] = { - images: [{ filename: 'input.png', type: 'input' }] + useNodeOutputStore().nodeOutputs[locatorId] = { + images: [{ filename: 'output.png' }] } - vi.mocked(store.getNodeImageUrls).mockImplementation((n) => - n === node ? ['/view?filename=input.png'] : undefined + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => + n === node ? ['/view?filename=output.png'] : undefined ) const { ambientPreviews } = useAmbientSubgraphPreviews( @@ -230,6 +225,24 @@ describe(useAmbientSubgraphPreviews, () => { const nestedHost = createTestSubgraphNode(nestedSubgraph, { id: 30 }) setup.subgraph.add(nestedHost) seedOutputs(setup.subgraph.id, [30]) + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockReturnValue([ + '/view?filename=output.png' + ]) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) + + it('skips interior nodes with hideOutputImages set', () => { + const setup = createSetup() + const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + node.hideOutputImages = true + seedOutputs(setup.subgraph.id, [10]) + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockReturnValue([ + '/view?filename=output.png' + ]) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode From ab2e1c04139e8e7e647b8027a33c253d46e866dd Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 8 Aug 2026 23:57:16 +0000 Subject: [PATCH 09/24] docs: restore incident-94 breadcrumb on guard-blocked test markers A prior comment-cleanup pass reworded these it.fails/test.fail markers to drop the incident name and exact guard line. Without that pointer, whoever eventually fixes LGraphNode.vue:172's !lgraphNode?.isSubgraphNode() guard hits a bare "Error: Expect test to fail" with no context. Add the breadcrumb back. --- .../tests/vueNodes/interactions/node/imagePreview.spec.ts | 1 + src/renderer/extensions/vueNodes/components/LGraphNode.test.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts b/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts index 35210e42545..a1d36e5319c 100644 --- a/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts +++ b/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts @@ -189,6 +189,7 @@ test.describe('Vue Nodes Image Preview', { tag: '@vue-nodes' }, () => { // LGraphNode.vue is relaxed to allow rendering previews on subgraph // nodes. Keep this test (don't delete) so it flips green automatically // once that guard changes. + // incident-94: waiting on LGraphNode.vue:172's `!lgraphNode?.isSubgraphNode()` guard. test.fail() const execution = new ExecutionHelper(comfyPage, await getWebSocket()) diff --git a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts index 35afa7b721c..08a909ce70d 100644 --- a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts +++ b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts @@ -396,6 +396,7 @@ describe('LGraphNode', () => { // LGraphNode.vue is relaxed to allow rendering previews on subgraph // nodes. Keep this test (don't delete) so it flips green automatically // once that guard changes. + // incident-94: waiting on LGraphNode.vue:172's `!lgraphNode?.isSubgraphNode()` guard. it.fails('renders the live preview image on a subgraph node with a populated preview', () => { mockData.mockLgraphNode = { isSubgraphNode: () => true } vi.mocked(useNodePreviewState).mockReturnValue({ From 105125b69481678f0ca7a79084fefd4dd6476ea6 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 12 Aug 2026 04:30:07 +0000 Subject: [PATCH 10/24] test: find subgraph host node by title instead of hardcoded id --- .../tests/subgraph/subgraphConcurrentPreviews.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts index 71fbaabc8a5..6f0790a77f8 100644 --- a/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts +++ b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts @@ -10,6 +10,7 @@ import { webSocketFixture } from '@e2e/fixtures/ws' const test = mergeTests(comfyPageFixture, webSocketFixture) const SUBGRAPH_NODE_ID = '1' +const SUBGRAPH_NODE_TITLE = 'Two Sampler Subgraph' // Node 3 has no `properties.previewExposures` entry, simulating a KSampler // added to the subgraph after the one-shot auto-expose already ran. const FIRST_SAMPLER_ID = '2' @@ -34,7 +35,8 @@ test.describe( }) => { const ws = await getWebSocket() const exec = new ExecutionHelper(comfyPage, ws) - const subgraphNode = comfyPage.vueNodes.getNodeLocator(SUBGRAPH_NODE_ID) + const subgraphNode = + comfyPage.vueNodes.getNodeByTitle(SUBGRAPH_NODE_TITLE) const previewImages = subgraphNode.locator('img[src^="blob:"]') await test.step('no preview is present before execution', async () => { From 640bc645052c02a9fcc7810832a315ed2e5a5909 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 04:48:41 +0000 Subject: [PATCH 11/24] test: exercise more subgraph ambient preview pathways Adds e2e coverage for pathways the two existing preview specs don't reach: an ambient preview nested two subgraph levels deep bubbles to its immediate host only, not the outermost one; a committed (non-live) interior output never gets conflated with the ambient rollup; and un-promoting a still-live sampler's exposed preview falls back to its ambient preview instead of disappearing. Also fills a small unit gap: useAmbientSubgraphPreviews derives video/audio media types the same way the promoted path already does. --- .../subgraph-nested-with-live-sampler.json | 184 ++++++++++++++++++ ...ith-live-sampler-and-committed-output.json | 144 ++++++++++++++ ...aphAmbientCommittedOutputIsolation.spec.ts | 60 ++++++ .../subgraphConcurrentPreviews.spec.ts | 36 ++++ .../subgraphNestedAmbientPreviewScope.spec.ts | 62 ++++++ .../node/useAmbientSubgraphPreviews.test.ts | 25 +++ 6 files changed, 511 insertions(+) create mode 100644 browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json create mode 100644 browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json create mode 100644 browser_tests/tests/subgraph/subgraphAmbientCommittedOutputIsolation.spec.ts create mode 100644 browser_tests/tests/subgraph/subgraphNestedAmbientPreviewScope.spec.ts diff --git a/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json b/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json new file mode 100644 index 00000000000..199aae9eb47 --- /dev/null +++ b/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json @@ -0,0 +1,184 @@ +{ + "id": "11111111-1111-4111-8111-000000000001", + "revision": 0, + "last_node_id": 1, + "last_link_id": 0, + "nodes": [ + { + "id": 1, + "type": "22222222-2222-4222-8222-000000000002", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [{ "name": "output", "type": "LATENT", "links": null }], + "title": "Outer Subgraph", + "properties": {}, + "widgets_values": [] + } + ], + "links": [], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "22222222-2222-4222-8222-000000000002", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 2, + "lastLinkId": 1, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Outer Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "44444444-4444-4444-8444-000000000004", + "name": "output", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 220 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 2, + "type": "33333333-3333-4333-8333-000000000003", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [{ "name": "output", "type": "LATENT", "links": [1] }], + "title": "Middle Subgraph", + "properties": {}, + "widgets_values": [] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 2, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + } + ], + "extra": {} + }, + { + "id": "33333333-3333-4333-8333-000000000003", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 3, + "lastLinkId": 1, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Middle Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "55555555-5555-4555-8555-000000000005", + "name": "output", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 220 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 3, + "type": "KSampler", + "pos": [250, 120], + "size": [280, 260], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "model", + "name": "model", + "type": "MODEL", + "link": null + }, + { + "localized_name": "positive", + "name": "positive", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "negative", + "name": "negative", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "LATENT", + "name": "LATENT", + "type": "LATENT", + "links": [1] + } + ], + "properties": { "Node name for S&R": "KSampler" }, + "widgets_values": [1, "increment", 20, 8, "euler", "normal", 1] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 3, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": { + "ds": { "offset": [0, 0], "scale": 1 } + }, + "version": 0.4 +} diff --git a/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json b/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json new file mode 100644 index 00000000000..88893917864 --- /dev/null +++ b/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json @@ -0,0 +1,144 @@ +{ + "id": "66666666-6666-4666-8666-000000000006", + "revision": 0, + "last_node_id": 1, + "last_link_id": 0, + "nodes": [ + { + "id": 1, + "type": "77777777-7777-4777-8777-000000000007", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [{ "name": "output", "type": "LATENT", "links": null }], + "title": "Sampler And Preview Subgraph", + "properties": {}, + "widgets_values": [] + } + ], + "links": [], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "77777777-7777-4777-8777-000000000007", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 3, + "lastLinkId": 1, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Sampler And Preview Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "88888888-8888-4888-8888-000000000008", + "name": "output", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 220 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 2, + "type": "KSampler", + "pos": [250, 120], + "size": [280, 260], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "model", + "name": "model", + "type": "MODEL", + "link": null + }, + { + "localized_name": "positive", + "name": "positive", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "negative", + "name": "negative", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "LATENT", + "name": "LATENT", + "type": "LATENT", + "links": [1] + } + ], + "properties": { "Node name for S&R": "KSampler" }, + "widgets_values": [1, "increment", 20, 8, "euler", "normal", 1] + }, + { + "id": 3, + "type": "PreviewImage", + "pos": [250, 420], + "size": [220, 260], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "localized_name": "images", + "name": "images", + "type": "IMAGE", + "link": null + } + ], + "outputs": [], + "properties": { "Node name for S&R": "PreviewImage" }, + "widgets_values": [] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 2, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": { + "ds": { "offset": [0, 0], "scale": 1 } + }, + "version": 0.4 +} diff --git a/browser_tests/tests/subgraph/subgraphAmbientCommittedOutputIsolation.spec.ts b/browser_tests/tests/subgraph/subgraphAmbientCommittedOutputIsolation.spec.ts new file mode 100644 index 00000000000..29086486bb2 --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphAmbientCommittedOutputIsolation.spec.ts @@ -0,0 +1,60 @@ +import { mergeTests } from '@playwright/test' + +import { + comfyPageFixture, + comfyExpect as expect +} from '@e2e/fixtures/ComfyPage' +import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper' +import { webSocketFixture } from '@e2e/fixtures/ws' + +const test = mergeTests(comfyPageFixture, webSocketFixture) + +const SUBGRAPH_NODE_ID = '1' +const SUBGRAPH_NODE_TITLE = 'Sampler And Preview Subgraph' +// Neither interior node has a `previewExposures` entry: the sampler (2) is +// only ever surfaced by the ambient rollup, and the PreviewImage node (3) +// only ever receives a committed `executed` output, never a streaming +// preview frame. +const SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:2` +const PREVIEW_IMAGE_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:3` + +test.describe( + 'Subgraph ambient preview vs. committed output isolation (regression)', + { tag: ['@vue-nodes', '@subgraph'] }, + () => { + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-with-live-sampler-and-committed-output' + ) + await comfyPage.vueNodes.waitForNodes(1) + }) + + test('a committed (non-live) interior output never counts as an ambient preview, and does not mask or duplicate the live one', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const subgraphNode = + comfyPage.vueNodes.getNodeByTitle(SUBGRAPH_NODE_TITLE) + const previewImages = subgraphNode.locator('img[src^="blob:"]') + + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + + await test.step('a committed output from the unexposed PreviewImage node does not surface as an ambient preview', async () => { + exec.executed(jobId, PREVIEW_IMAGE_EXECUTION_ID, { + images: [{ filename: 'example.png', type: 'input' }] + }) + await comfyPage.nextFrame() + await expect(previewImages).toHaveCount(0) + }) + + await test.step('the live sampler preview still surfaces ambiently afterward, unaffected by the earlier committed output', async () => { + exec.latentPreview(jobId, SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(1) + }) + }) + } +) diff --git a/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts index 6f0790a77f8..25d05c32fe6 100644 --- a/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts +++ b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts @@ -74,5 +74,41 @@ test.describe( ) }) }) + + // Regression coverage for `mergeSubgraphPreviews`: it excludes an + // ambient preview only while its source node is in the host's *current* + // exposure set, not permanently at merge time. Un-promoting a still-live + // sampler's `$$canvas-image-preview` must not blank it — the ambient + // rollup immediately takes back over for any interior node that's still + // producing preview frames. + test('un-promoting a still-live sampler falls back to its ambient preview instead of disappearing', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const subgraphNode = + comfyPage.vueNodes.getNodeByTitle(SUBGRAPH_NODE_TITLE) + const previewImages = subgraphNode.locator('img[src^="blob:"]') + + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + + await test.step('the exposed sampler shows its live preview', async () => { + exec.latentPreview(jobId, FIRST_SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(1) + }) + + await test.step('un-promoting its canvas image preview keeps it visible via the ambient rollup', async () => { + await comfyPage.subgraph.editor.togglePromotion(subgraphNode, { + nodeId: FIRST_SAMPLER_ID, + widgetName: '$$canvas-image-preview', + toState: false + }) + + await expect(previewImages).toHaveCount(1) + }) + }) } ) diff --git a/browser_tests/tests/subgraph/subgraphNestedAmbientPreviewScope.spec.ts b/browser_tests/tests/subgraph/subgraphNestedAmbientPreviewScope.spec.ts new file mode 100644 index 00000000000..4255da24199 --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphNestedAmbientPreviewScope.spec.ts @@ -0,0 +1,62 @@ +import { mergeTests } from '@playwright/test' + +import { + comfyPageFixture, + comfyExpect as expect +} from '@e2e/fixtures/ComfyPage' +import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper' +import { webSocketFixture } from '@e2e/fixtures/ws' + +const test = mergeTests(comfyPageFixture, webSocketFixture) + +const OUTER_HOST_ID = '1' +const OUTER_HOST_TITLE = 'Outer Subgraph' +// `Middle Subgraph` (node 2, interior to the outer host) wraps the live +// sampler one level further down. Neither host has a `previewExposures` +// entry, so this fixture only passes if the ambient rollup — not the +// exposure/promotion system — is what surfaces the preview. +const MIDDLE_HOST_TITLE = 'Middle Subgraph' +const SAMPLER_EXECUTION_ID = `${OUTER_HOST_ID}:2:3` + +test.describe( + 'Subgraph ambient preview nesting scope (regression)', + { tag: ['@vue-nodes', '@subgraph'] }, + () => { + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-nested-with-live-sampler' + ) + await comfyPage.vueNodes.waitForNodes(1) + }) + + test('an ambient preview two levels deep bubbles to its immediate host only, not the outermost host', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const outerHost = comfyPage.vueNodes.getNodeByTitle(OUTER_HOST_TITLE) + const outerPreviewImages = outerHost.locator('img[src^="blob:"]') + + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + exec.latentPreview(jobId, SAMPLER_EXECUTION_ID) + + await test.step('the outermost host shows no preview: ambient rollup does not recurse past its immediate interior nodes', async () => { + // `useAmbientSubgraphPreviews` explicitly skips interior nodes that + // are themselves `SubgraphNode`s, so `Middle Subgraph` never + // contributes its own interior sampler's preview to `Outer Subgraph`. + await comfyPage.nextFrame() + await expect(outerPreviewImages).toHaveCount(0) + }) + + await test.step('entering the outer subgraph shows the preview on the immediate (middle) host', async () => { + await comfyPage.vueNodes.enterSubgraph(OUTER_HOST_ID) + + const middleHost = comfyPage.vueNodes.getNodeByTitle(MIDDLE_HOST_TITLE) + await expect(middleHost.locator('img[src^="blob:"]')).toHaveCount(1) + }) + }) + } +) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts index 71e80a375e9..173549a25ff 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.test.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -135,6 +135,31 @@ describe(useAmbientSubgraphPreviews, () => { ]) }) + it.for([ + ['video', '/view?filename=output.webm'], + ['audio', '/view?filename=output.mp3'] + ] as const)( + 'derives %s type from previewMediaType, same as the promoted path', + ([mediaType, url]) => { + const setup = createSetup() + const node = addInteriorNode(setup, { + id: 10, + previewMediaType: mediaType + }) + seedOutputs(setup.subgraph.id, [10]) + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation( + (n) => (n === node ? [url] : undefined) + ) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ sourceNodeId: '10', type: mediaType }) + ]) + } + ) + it('returns separate entries for two concurrently-executing interior nodes', () => { const setup = createSetup() const node10 = addInteriorNode(setup, { From ea3a929c5f5c521460338b838061fea0a6da3362 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 21:12:30 +0000 Subject: [PATCH 12/24] fix: suppress ambient subgraph previews after explicit exposure removal removeExposure had no tombstone, so useAmbientSubgraphPreviews would re-surface a preview the next frame after a user explicitly demoted it, as long as the interior node kept producing live output. Add a suppressedAmbientNodeIds tombstone set to previewExposureStore, keyed per (rootGraphId, hostNodeLocator): removeExposure adds the removed source node to it, addExposure clears it, and clearGraph drops it with the rest of the host's state. useAmbientSubgraphPreviews now excludes suppressed node ids from its interior-node scan. Also documents two invariants raised in review: nodePreviewImages is only ever written by live execution/streaming frames, never static input data, so the single-branch gate needs no isInputPreviewOutput guard; and subgraph.nodes is a plain non-reactive array, so structural add/remove while collapsed isn't tracked until the next preview frame. --- .../node/useAmbientSubgraphPreviews.test.ts | 28 +++++++ .../node/useAmbientSubgraphPreviews.ts | 12 +++ src/stores/previewExposureStore.test.ts | 75 +++++++++++++++++++ src/stores/previewExposureStore.ts | 69 ++++++++++++++++- 4 files changed, 183 insertions(+), 1 deletion(-) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts index 173549a25ff..4e673b5f5d6 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.test.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -9,6 +9,7 @@ import { createTestSubgraphNode } from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' import { useNodeOutputStore } from '@/stores/nodeOutputStore' +import { usePreviewExposureStore } from '@/stores/previewExposureStore' import { createNodeLocatorId } from '@/types/nodeIdentification' import { toNodeId } from '@/types/nodeId' @@ -274,4 +275,31 @@ describe(useAmbientSubgraphPreviews, () => { ) expect(ambientPreviews.value).toEqual([]) }) + + it('does not resurface an ambient preview after its exposure is explicitly removed', () => { + const setup = createSetup() + const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraph.id, [10]) + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => + n === node ? ['/view?filename=output.png'] : undefined + ) + + const previewExposureStore = usePreviewExposureStore() + const rootGraphId = setup.subgraphNode.rootGraph.id + const hostLocator = String(setup.subgraphNode.id) + const exposure = previewExposureStore.addExposure( + rootGraphId, + hostLocator, + { + sourceNodeId: node.id, + sourcePreviewName: 'preview' + } + ) + previewExposureStore.removeExposure(rootGraphId, hostLocator, exposure.name) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) }) diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts index a1623167035..ecd94dea992 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -4,6 +4,7 @@ import { computed, toValue } from 'vue' import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' import { useNodeOutputStore } from '@/stores/nodeOutputStore' +import { usePreviewExposureStore } from '@/stores/previewExposureStore' import { createNodeLocatorId } from '@/types/nodeIdentification' import type { PromotedPreview } from './usePromotedPreviews' @@ -32,6 +33,7 @@ export function useAmbientSubgraphPreviews( lgraphNode: MaybeRefOrGetter ) { const nodeOutputStore = useNodeOutputStore() + const previewExposureStore = usePreviewExposureStore() const ambientPreviews = computed((): PromotedPreview[] => { const node = toValue(lgraphNode) @@ -39,15 +41,25 @@ export function useAmbientSubgraphPreviews( if (node.isDetached) return [] const { subgraph } = node + const suppressedNodeIds = previewExposureStore.getSuppressedAmbientNodeIds( + node.rootGraph.id, + String(node.id) + ) + // `subgraph.nodes` (`LGraph._nodes`) is a plain, non-reactive array, so + // interior node add/remove while collapsed isn't tracked here; the next + // WS preview frame (nodeOutputs/nodePreviewImages change) self-heals it. return subgraph.nodes.flatMap((interiorNode): PromotedPreview[] => { // Nested subgraph hosts derive their own previews independently. if (interiorNode instanceof SubgraphNode) return [] if (interiorNode.hideOutputImages) return [] + if (suppressedNodeIds.has(interiorNode.id)) return [] const locatorId = createNodeLocatorId(subgraph.id, interiorNode.id) if (!locatorId) return [] + // Only ever populated by live execution/streaming frames, never by + // static input data, so no isInputPreviewOutput-style guard is needed. if (!nodeOutputStore.nodePreviewImages[locatorId]?.length) return [] const urls = nodeOutputStore.getNodeImageUrls(interiorNode) diff --git a/src/stores/previewExposureStore.test.ts b/src/stores/previewExposureStore.test.ts index 0bbb0299ff7..c76fcc2d4dd 100644 --- a/src/stores/previewExposureStore.test.ts +++ b/src/stores/previewExposureStore.test.ts @@ -1,5 +1,6 @@ import { beforeEach, describe, expect, it } from 'vitest' +import { toNodeId } from '@/types/nodeId' import type { UUID } from '@/utils/uuid' import { usePreviewExposureStore } from './previewExposureStore' @@ -121,6 +122,65 @@ describe(usePreviewExposureStore, () => { }) }) + describe('getSuppressedAmbientNodeIds', () => { + it('returns an empty set for a host with no removed exposures', () => { + expect(store.getSuppressedAmbientNodeIds(rootGraphA, hostA).size).toBe(0) + }) + + it('suppresses a node whose exposure was explicitly removed', () => { + const entry = store.addExposure(rootGraphA, hostA, { + sourceNodeId: '42', + sourcePreviewName: 'preview' + }) + store.removeExposure(rootGraphA, hostA, entry.name) + + expect( + store.getSuppressedAmbientNodeIds(rootGraphA, hostA).has(toNodeId('42')) + ).toBe(true) + }) + + it('does not suppress when removeExposure is a no-op', () => { + store.addExposure(rootGraphA, hostA, { + sourceNodeId: '42', + sourcePreviewName: 'preview' + }) + store.removeExposure(rootGraphA, hostA, 'does-not-exist') + + expect(store.getSuppressedAmbientNodeIds(rootGraphA, hostA).size).toBe(0) + }) + + it('clears the suppression once the node is exposed again', () => { + const entry = store.addExposure(rootGraphA, hostA, { + sourceNodeId: '42', + sourcePreviewName: 'preview' + }) + store.removeExposure(rootGraphA, hostA, entry.name) + expect( + store.getSuppressedAmbientNodeIds(rootGraphA, hostA).has(toNodeId('42')) + ).toBe(true) + + store.addExposure(rootGraphA, hostA, { + sourceNodeId: '42', + sourcePreviewName: 'preview' + }) + + expect( + store.getSuppressedAmbientNodeIds(rootGraphA, hostA).has(toNodeId('42')) + ).toBe(false) + }) + + it('keeps suppressions isolated per (rootGraphId, hostNodeLocator) pair', () => { + const entryA = store.addExposure(rootGraphA, hostA, { + sourceNodeId: '42', + sourcePreviewName: 'preview' + }) + store.removeExposure(rootGraphA, hostA, entryA.name) + + expect(store.getSuppressedAmbientNodeIds(rootGraphA, hostB).size).toBe(0) + expect(store.getSuppressedAmbientNodeIds(rootGraphB, hostA).size).toBe(0) + }) + }) + describe('getExposuresAsPromotionShape', () => { it('returns an empty array for unknown host', () => { expect(store.getExposuresAsPromotionShape(rootGraphA, hostA)).toEqual([]) @@ -165,6 +225,21 @@ describe(usePreviewExposureStore, () => { expect(store.getExposures(rootGraphA, hostB)).toEqual([]) expect(store.getExposures(rootGraphB, hostInB)).toHaveLength(1) }) + + it('also clears ambient-preview suppressions under the rootGraphId', () => { + const entry = store.addExposure(rootGraphA, hostA, { + sourceNodeId: '42', + sourcePreviewName: 'preview' + }) + store.removeExposure(rootGraphA, hostA, entry.name) + expect( + store.getSuppressedAmbientNodeIds(rootGraphA, hostA).has(toNodeId('42')) + ).toBe(true) + + store.clearGraph(rootGraphA) + + expect(store.getSuppressedAmbientNodeIds(rootGraphA, hostA).size).toBe(0) + }) }) describe('isolation between (rootGraphId, hostNodeLocator) pairs', () => { diff --git a/src/stores/previewExposureStore.ts b/src/stores/previewExposureStore.ts index 7e55bc67145..53515d96818 100644 --- a/src/stores/previewExposureStore.ts +++ b/src/stores/previewExposureStore.ts @@ -10,10 +10,11 @@ import type { PromotedWidgetSource } from '@/core/graph/subgraph/promotedWidgetT import type { PreviewExposure } from '@/core/schemas/previewExposureSchema' import { nextUniqueName } from '@/lib/litegraph/src/strings' import { toNodeId } from '@/types/nodeId' -import type { SerializedNodeId } from '@/types/nodeId' +import type { NodeId, SerializedNodeId } from '@/types/nodeId' import type { UUID } from '@/utils/uuid' const EMPTY_EXPOSURES: readonly PreviewExposure[] = Object.freeze([]) +const EMPTY_SUPPRESSED_IDS: ReadonlySet = new Set() type ResolveNestedHostFn = NonNullable< PreviewExposureChainContext['resolveNestedHost'] @@ -34,6 +35,15 @@ function normalizePreviewExposure( export const usePreviewExposureStore = defineStore('previewExposure', () => { const exposures = ref(new Map>()) + /** + * Tombstones for ambient-preview suppression: nodes whose exposure was + * explicitly removed, so `useAmbientSubgraphPreviews` can tell "removed by + * the user" apart from "never promoted" and keep it hidden even though the + * node is still producing live output. + */ + const suppressedAmbientNodeIds = ref( + new Map>>() + ) function _getHostsForGraph( rootGraphId: UUID @@ -46,6 +56,52 @@ export const usePreviewExposureStore = defineStore('previewExposure', () => { return nextHosts } + function _getSuppressedHostsForGraph( + rootGraphId: UUID + ): Map> { + const hosts = suppressedAmbientNodeIds.value.get(rootGraphId) + if (hosts) return hosts + + const nextHosts = new Map>() + suppressedAmbientNodeIds.value.set(rootGraphId, nextHosts) + return nextHosts + } + + function getSuppressedAmbientNodeIds( + rootGraphId: UUID, + hostNodeLocator: string + ): ReadonlySet { + return ( + suppressedAmbientNodeIds.value.get(rootGraphId)?.get(hostNodeLocator) ?? + EMPTY_SUPPRESSED_IDS + ) + } + + function _suppressAmbientPreview( + rootGraphId: UUID, + hostNodeLocator: string, + sourceNodeId: NodeId + ): void { + const hosts = _getSuppressedHostsForGraph(rootGraphId) + const existing = hosts.get(hostNodeLocator) + if (existing) { + existing.add(sourceNodeId) + } else { + hosts.set(hostNodeLocator, new Set([sourceNodeId])) + } + } + + function _unsuppressAmbientPreview( + rootGraphId: UUID, + hostNodeLocator: string, + sourceNodeId: NodeId + ): void { + suppressedAmbientNodeIds.value + .get(rootGraphId) + ?.get(hostNodeLocator) + ?.delete(sourceNodeId) + } + function _getExposuresRef( rootGraphId: UUID, hostNodeLocator: string @@ -89,6 +145,7 @@ export const usePreviewExposureStore = defineStore('previewExposure', () => { sourcePreviewName: source.sourcePreviewName } hosts.set(hostNodeLocator, [...current, entry]) + _unsuppressAmbientPreview(rootGraphId, hostNodeLocator, entry.sourceNodeId) return entry } @@ -99,13 +156,22 @@ export const usePreviewExposureStore = defineStore('previewExposure', () => { ): void { const current = _getExposuresRef(rootGraphId, hostNodeLocator) if (!current?.length) return + const removed = current.find((e) => e.name === name) const next = current.filter((e) => e.name !== name) if (next.length === current.length) return setExposures(rootGraphId, hostNodeLocator, next) + if (removed) { + _suppressAmbientPreview( + rootGraphId, + hostNodeLocator, + removed.sourceNodeId + ) + } } function clearGraph(rootGraphId: UUID): void { exposures.value.delete(rootGraphId) + suppressedAmbientNodeIds.value.delete(rootGraphId) } function getExposuresAsPromotionShape( @@ -138,6 +204,7 @@ export const usePreviewExposureStore = defineStore('previewExposure', () => { return { getExposures, getExposuresAsPromotionShape, + getSuppressedAmbientNodeIds, setExposures, addExposure, removeExposure, From 182cf3d919c1323765dc801ac0738e2e8c44d4dd Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 21:24:00 +0000 Subject: [PATCH 13/24] revert: drop ambient-preview suppression, which contradicted the PR's own regression test b6bc646 added a suppressedAmbientNodeIds tombstone so removeExposure would permanently hide an interior node's ambient preview. That directly reverses this PR's stated design ("any interior node currently producing output shows on the host, whether or not anyone promoted it") and broke the e2e regression test added earlier in this branch (subgraphConcurrentPreviews.spec.ts: "un-promoting a still-live sampler falls back to its ambient preview instead of disappearing"), which was failing in CI. Un-promoting a node only removes its explicit exposure (name/ordering in the promoted slot); it was never meant to blacklist the node from the ambient rollup while it keeps producing live output. Revert the tombstone mechanism and its tests, restoring the pre-b6bc646 behavior that the existing regression test expects. --- .../node/useAmbientSubgraphPreviews.test.ts | 28 ------- .../node/useAmbientSubgraphPreviews.ts | 12 --- src/stores/previewExposureStore.test.ts | 75 ------------------- src/stores/previewExposureStore.ts | 69 +---------------- 4 files changed, 1 insertion(+), 183 deletions(-) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts index 4e673b5f5d6..173549a25ff 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.test.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -9,7 +9,6 @@ import { createTestSubgraphNode } from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' import { useNodeOutputStore } from '@/stores/nodeOutputStore' -import { usePreviewExposureStore } from '@/stores/previewExposureStore' import { createNodeLocatorId } from '@/types/nodeIdentification' import { toNodeId } from '@/types/nodeId' @@ -275,31 +274,4 @@ describe(useAmbientSubgraphPreviews, () => { ) expect(ambientPreviews.value).toEqual([]) }) - - it('does not resurface an ambient preview after its exposure is explicitly removed', () => { - const setup = createSetup() - const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) - seedOutputs(setup.subgraph.id, [10]) - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => - n === node ? ['/view?filename=output.png'] : undefined - ) - - const previewExposureStore = usePreviewExposureStore() - const rootGraphId = setup.subgraphNode.rootGraph.id - const hostLocator = String(setup.subgraphNode.id) - const exposure = previewExposureStore.addExposure( - rootGraphId, - hostLocator, - { - sourceNodeId: node.id, - sourcePreviewName: 'preview' - } - ) - previewExposureStore.removeExposure(rootGraphId, hostLocator, exposure.name) - - const { ambientPreviews } = useAmbientSubgraphPreviews( - () => setup.subgraphNode - ) - expect(ambientPreviews.value).toEqual([]) - }) }) diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts index ecd94dea992..a1623167035 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -4,7 +4,6 @@ import { computed, toValue } from 'vue' import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' import { useNodeOutputStore } from '@/stores/nodeOutputStore' -import { usePreviewExposureStore } from '@/stores/previewExposureStore' import { createNodeLocatorId } from '@/types/nodeIdentification' import type { PromotedPreview } from './usePromotedPreviews' @@ -33,7 +32,6 @@ export function useAmbientSubgraphPreviews( lgraphNode: MaybeRefOrGetter ) { const nodeOutputStore = useNodeOutputStore() - const previewExposureStore = usePreviewExposureStore() const ambientPreviews = computed((): PromotedPreview[] => { const node = toValue(lgraphNode) @@ -41,25 +39,15 @@ export function useAmbientSubgraphPreviews( if (node.isDetached) return [] const { subgraph } = node - const suppressedNodeIds = previewExposureStore.getSuppressedAmbientNodeIds( - node.rootGraph.id, - String(node.id) - ) - // `subgraph.nodes` (`LGraph._nodes`) is a plain, non-reactive array, so - // interior node add/remove while collapsed isn't tracked here; the next - // WS preview frame (nodeOutputs/nodePreviewImages change) self-heals it. return subgraph.nodes.flatMap((interiorNode): PromotedPreview[] => { // Nested subgraph hosts derive their own previews independently. if (interiorNode instanceof SubgraphNode) return [] if (interiorNode.hideOutputImages) return [] - if (suppressedNodeIds.has(interiorNode.id)) return [] const locatorId = createNodeLocatorId(subgraph.id, interiorNode.id) if (!locatorId) return [] - // Only ever populated by live execution/streaming frames, never by - // static input data, so no isInputPreviewOutput-style guard is needed. if (!nodeOutputStore.nodePreviewImages[locatorId]?.length) return [] const urls = nodeOutputStore.getNodeImageUrls(interiorNode) diff --git a/src/stores/previewExposureStore.test.ts b/src/stores/previewExposureStore.test.ts index c76fcc2d4dd..0bbb0299ff7 100644 --- a/src/stores/previewExposureStore.test.ts +++ b/src/stores/previewExposureStore.test.ts @@ -1,6 +1,5 @@ import { beforeEach, describe, expect, it } from 'vitest' -import { toNodeId } from '@/types/nodeId' import type { UUID } from '@/utils/uuid' import { usePreviewExposureStore } from './previewExposureStore' @@ -122,65 +121,6 @@ describe(usePreviewExposureStore, () => { }) }) - describe('getSuppressedAmbientNodeIds', () => { - it('returns an empty set for a host with no removed exposures', () => { - expect(store.getSuppressedAmbientNodeIds(rootGraphA, hostA).size).toBe(0) - }) - - it('suppresses a node whose exposure was explicitly removed', () => { - const entry = store.addExposure(rootGraphA, hostA, { - sourceNodeId: '42', - sourcePreviewName: 'preview' - }) - store.removeExposure(rootGraphA, hostA, entry.name) - - expect( - store.getSuppressedAmbientNodeIds(rootGraphA, hostA).has(toNodeId('42')) - ).toBe(true) - }) - - it('does not suppress when removeExposure is a no-op', () => { - store.addExposure(rootGraphA, hostA, { - sourceNodeId: '42', - sourcePreviewName: 'preview' - }) - store.removeExposure(rootGraphA, hostA, 'does-not-exist') - - expect(store.getSuppressedAmbientNodeIds(rootGraphA, hostA).size).toBe(0) - }) - - it('clears the suppression once the node is exposed again', () => { - const entry = store.addExposure(rootGraphA, hostA, { - sourceNodeId: '42', - sourcePreviewName: 'preview' - }) - store.removeExposure(rootGraphA, hostA, entry.name) - expect( - store.getSuppressedAmbientNodeIds(rootGraphA, hostA).has(toNodeId('42')) - ).toBe(true) - - store.addExposure(rootGraphA, hostA, { - sourceNodeId: '42', - sourcePreviewName: 'preview' - }) - - expect( - store.getSuppressedAmbientNodeIds(rootGraphA, hostA).has(toNodeId('42')) - ).toBe(false) - }) - - it('keeps suppressions isolated per (rootGraphId, hostNodeLocator) pair', () => { - const entryA = store.addExposure(rootGraphA, hostA, { - sourceNodeId: '42', - sourcePreviewName: 'preview' - }) - store.removeExposure(rootGraphA, hostA, entryA.name) - - expect(store.getSuppressedAmbientNodeIds(rootGraphA, hostB).size).toBe(0) - expect(store.getSuppressedAmbientNodeIds(rootGraphB, hostA).size).toBe(0) - }) - }) - describe('getExposuresAsPromotionShape', () => { it('returns an empty array for unknown host', () => { expect(store.getExposuresAsPromotionShape(rootGraphA, hostA)).toEqual([]) @@ -225,21 +165,6 @@ describe(usePreviewExposureStore, () => { expect(store.getExposures(rootGraphA, hostB)).toEqual([]) expect(store.getExposures(rootGraphB, hostInB)).toHaveLength(1) }) - - it('also clears ambient-preview suppressions under the rootGraphId', () => { - const entry = store.addExposure(rootGraphA, hostA, { - sourceNodeId: '42', - sourcePreviewName: 'preview' - }) - store.removeExposure(rootGraphA, hostA, entry.name) - expect( - store.getSuppressedAmbientNodeIds(rootGraphA, hostA).has(toNodeId('42')) - ).toBe(true) - - store.clearGraph(rootGraphA) - - expect(store.getSuppressedAmbientNodeIds(rootGraphA, hostA).size).toBe(0) - }) }) describe('isolation between (rootGraphId, hostNodeLocator) pairs', () => { diff --git a/src/stores/previewExposureStore.ts b/src/stores/previewExposureStore.ts index 53515d96818..7e55bc67145 100644 --- a/src/stores/previewExposureStore.ts +++ b/src/stores/previewExposureStore.ts @@ -10,11 +10,10 @@ import type { PromotedWidgetSource } from '@/core/graph/subgraph/promotedWidgetT import type { PreviewExposure } from '@/core/schemas/previewExposureSchema' import { nextUniqueName } from '@/lib/litegraph/src/strings' import { toNodeId } from '@/types/nodeId' -import type { NodeId, SerializedNodeId } from '@/types/nodeId' +import type { SerializedNodeId } from '@/types/nodeId' import type { UUID } from '@/utils/uuid' const EMPTY_EXPOSURES: readonly PreviewExposure[] = Object.freeze([]) -const EMPTY_SUPPRESSED_IDS: ReadonlySet = new Set() type ResolveNestedHostFn = NonNullable< PreviewExposureChainContext['resolveNestedHost'] @@ -35,15 +34,6 @@ function normalizePreviewExposure( export const usePreviewExposureStore = defineStore('previewExposure', () => { const exposures = ref(new Map>()) - /** - * Tombstones for ambient-preview suppression: nodes whose exposure was - * explicitly removed, so `useAmbientSubgraphPreviews` can tell "removed by - * the user" apart from "never promoted" and keep it hidden even though the - * node is still producing live output. - */ - const suppressedAmbientNodeIds = ref( - new Map>>() - ) function _getHostsForGraph( rootGraphId: UUID @@ -56,52 +46,6 @@ export const usePreviewExposureStore = defineStore('previewExposure', () => { return nextHosts } - function _getSuppressedHostsForGraph( - rootGraphId: UUID - ): Map> { - const hosts = suppressedAmbientNodeIds.value.get(rootGraphId) - if (hosts) return hosts - - const nextHosts = new Map>() - suppressedAmbientNodeIds.value.set(rootGraphId, nextHosts) - return nextHosts - } - - function getSuppressedAmbientNodeIds( - rootGraphId: UUID, - hostNodeLocator: string - ): ReadonlySet { - return ( - suppressedAmbientNodeIds.value.get(rootGraphId)?.get(hostNodeLocator) ?? - EMPTY_SUPPRESSED_IDS - ) - } - - function _suppressAmbientPreview( - rootGraphId: UUID, - hostNodeLocator: string, - sourceNodeId: NodeId - ): void { - const hosts = _getSuppressedHostsForGraph(rootGraphId) - const existing = hosts.get(hostNodeLocator) - if (existing) { - existing.add(sourceNodeId) - } else { - hosts.set(hostNodeLocator, new Set([sourceNodeId])) - } - } - - function _unsuppressAmbientPreview( - rootGraphId: UUID, - hostNodeLocator: string, - sourceNodeId: NodeId - ): void { - suppressedAmbientNodeIds.value - .get(rootGraphId) - ?.get(hostNodeLocator) - ?.delete(sourceNodeId) - } - function _getExposuresRef( rootGraphId: UUID, hostNodeLocator: string @@ -145,7 +89,6 @@ export const usePreviewExposureStore = defineStore('previewExposure', () => { sourcePreviewName: source.sourcePreviewName } hosts.set(hostNodeLocator, [...current, entry]) - _unsuppressAmbientPreview(rootGraphId, hostNodeLocator, entry.sourceNodeId) return entry } @@ -156,22 +99,13 @@ export const usePreviewExposureStore = defineStore('previewExposure', () => { ): void { const current = _getExposuresRef(rootGraphId, hostNodeLocator) if (!current?.length) return - const removed = current.find((e) => e.name === name) const next = current.filter((e) => e.name !== name) if (next.length === current.length) return setExposures(rootGraphId, hostNodeLocator, next) - if (removed) { - _suppressAmbientPreview( - rootGraphId, - hostNodeLocator, - removed.sourceNodeId - ) - } } function clearGraph(rootGraphId: UUID): void { exposures.value.delete(rootGraphId) - suppressedAmbientNodeIds.value.delete(rootGraphId) } function getExposuresAsPromotionShape( @@ -204,7 +138,6 @@ export const usePreviewExposureStore = defineStore('previewExposure', () => { return { getExposures, getExposuresAsPromotionShape, - getSuppressedAmbientNodeIds, setExposures, addExposure, removeExposure, From 0245637339b9c77e0b27dc99b4cd6f1920fb59c0 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sun, 23 Aug 2026 05:49:12 +0000 Subject: [PATCH 14/24] docs: add comment noting subgraph.nodes is non-reactive in ambient computed --- src/composables/node/useAmbientSubgraphPreviews.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts index a1623167035..d3ec2490832 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -40,6 +40,9 @@ export function useAmbientSubgraphPreviews( const { subgraph } = node + // `subgraph.nodes` (`LGraph._nodes`) is a plain, non-reactive array, so + // interior node add/remove while collapsed isn't tracked here; the next + // WS preview frame (nodeOutputs/nodePreviewImages change) self-heals it. return subgraph.nodes.flatMap((interiorNode): PromotedPreview[] => { // Nested subgraph hosts derive their own previews independently. if (interiorNode instanceof SubgraphNode) return [] From 5394f8bba85f1b0332b620199bcb0ca42f91b1a0 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 25 Aug 2026 13:19:44 +0000 Subject: [PATCH 15/24] test: reproduce ambient preview missing its first frame on a late-added node --- .../node/useAmbientSubgraphPreviews.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts index 173549a25ff..c7c49d20628 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.test.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -244,6 +244,26 @@ describe(useAmbientSubgraphPreviews, () => { ]) }) + it('self-heals once an interior node added after the first evaluation gets its first preview frame', () => { + const setup = createSetup() + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + + const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraph.id, [10]) + const urls = ['/view?filename=output.png'] + vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => + n === node ? urls : undefined + ) + + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ sourceNodeId: '10', urls }) + ]) + }) + it('skips nested SubgraphNode interior nodes (they derive their own previews)', () => { const setup = createSetup() const nestedSubgraph = createTestSubgraph() From f195b6a5414b8f01e01641b78d893626fff6b880 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 25 Aug 2026 13:21:13 +0000 Subject: [PATCH 16/24] fix: invalidate ambient subgraph previews when interior nodes are added or removed --- .../node/useAmbientSubgraphPreviews.ts | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts index d3ec2490832..025e5aad4ac 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -1,7 +1,9 @@ -import type { MaybeRefOrGetter } from 'vue' -import { computed, toValue } from 'vue' +import type { MaybeRefOrGetter, Ref } from 'vue' +import { computed, ref, toValue } from 'vue' +import { useChainCallback } from '@/composables/functional/useChainCallback' import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { Subgraph } from '@/lib/litegraph/src/litegraph' import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' import { useNodeOutputStore } from '@/stores/nodeOutputStore' import { createNodeLocatorId } from '@/types/nodeIdentification' @@ -9,6 +11,29 @@ import { createNodeLocatorId } from '@/types/nodeIdentification' import type { PromotedPreview } from './usePromotedPreviews' import { getPreviewMediaType } from './usePromotedPreviews' +/** + * One shared, ever-incrementing version `ref` per {@link Subgraph}, bumped + * whenever an interior node is added or removed. `subgraph.nodes` itself is + * a plain, non-reactive array, so {@link useAmbientSubgraphPreviews} reads + * this alongside it purely to give Vue something reactive to invalidate on. + */ +const topologyVersions = new WeakMap>() + +function useSubgraphTopologyVersion(subgraph: Subgraph): Ref { + const existing = topologyVersions.get(subgraph) + if (existing) return existing + + const version = ref(0) + subgraph.onNodeAdded = useChainCallback(subgraph.onNodeAdded, () => { + version.value++ + }) + subgraph.onNodeRemoved = useChainCallback(subgraph.onNodeRemoved, () => { + version.value++ + }) + topologyVersions.set(subgraph, version) + return version +} + /** * Synthetic `sourceWidgetName` for ambient previews, so they share * {@link PromotedPreview}'s shape (and the render list's dedup/key logic) @@ -39,10 +64,8 @@ export function useAmbientSubgraphPreviews( if (node.isDetached) return [] const { subgraph } = node + void useSubgraphTopologyVersion(subgraph).value - // `subgraph.nodes` (`LGraph._nodes`) is a plain, non-reactive array, so - // interior node add/remove while collapsed isn't tracked here; the next - // WS preview frame (nodeOutputs/nodePreviewImages change) self-heals it. return subgraph.nodes.flatMap((interiorNode): PromotedPreview[] => { // Nested subgraph hosts derive their own previews independently. if (interiorNode instanceof SubgraphNode) return [] From a2cb727c3632637bfc5b8742a3512139b4c6edfc Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 25 Aug 2026 13:27:47 +0000 Subject: [PATCH 17/24] test: reproduce ambient preview collision between shared subgraph instances --- ...entSubgraphPreviews.sharedInstance.test.ts | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts diff --git a/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts b/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts new file mode 100644 index 00000000000..bd68caabef5 --- /dev/null +++ b/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts @@ -0,0 +1,89 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import type { LGraphNode as LGraphNodeType } from '@/lib/litegraph/src/litegraph' +import { LGraphNode } from '@/lib/litegraph/src/litegraph' +import { + createTestSubgraph, + createTestSubgraphNode +} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' +import { app } from '@/scripts/app' +import { useNodeOutputStore } from '@/stores/nodeOutputStore' +import { toNodeId } from '@/types/nodeId' +import { + createNodeExecutionId, + createNodeLocatorId +} from '@/types/nodeIdentification' +import { isSubgraph } from '@/utils/typeGuardUtil' + +import { useAmbientSubgraphPreviews } from './useAmbientSubgraphPreviews' + +// Deliberately left unmocked: `@/utils/graphTraversalUtil`. The whole point +// of this regression is exercising the real `executionIdToNodeLocatorId` +// collapse — two instances of the same subgraph definition resolve to the +// same `NodeLocatorId` — rather than a mock that pretends instances stay +// distinct at the storage layer. +vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({ + useWorkflowStore: vi.fn(() => ({ + nodeIdToNodeLocatorId: vi.fn((id: string | number) => + createNodeLocatorId(null, toNodeId(id)) + ), + nodeToNodeLocatorId: vi.fn((node: LGraphNodeType) => + isSubgraph(node.graph) + ? createNodeLocatorId(node.graph.id, node.id) + : createNodeLocatorId(null, node.id) + ) + })) +})) + +describe('useAmbientSubgraphPreviews with a shared subgraph definition', () => { + beforeEach(() => { + app.nodeOutputs = {} + app.nodePreviewImages = {} + }) + + it('keeps each host instance showing only its own live preview frame', () => { + const subgraph = createTestSubgraph() + const interiorNode = new LGraphNode('test') + interiorNode.id = toNodeId(10) + interiorNode.previewMediaType = 'image' + subgraph.add(interiorNode) + + const rootGraph = subgraph.rootGraph + const firstHost = createTestSubgraphNode(subgraph, { id: 11 }) + const secondHost = createTestSubgraphNode(subgraph, { id: 12 }) + rootGraph.add(firstHost) + rootGraph.add(secondHost) + + vi.spyOn(app, 'rootGraph', 'get').mockReturnValue(rootGraph) + + const nodeOutputStore = useNodeOutputStore() + nodeOutputStore.setNodePreviewsByExecutionId( + createNodeExecutionId([toNodeId(11), toNodeId(10)]), + ['blob:first'] + ) + nodeOutputStore.setNodePreviewsByExecutionId( + createNodeExecutionId([toNodeId(12), toNodeId(10)]), + ['blob:second'] + ) + + const firstHostPreviews = useAmbientSubgraphPreviews( + () => firstHost + ).ambientPreviews + const secondHostPreviews = useAmbientSubgraphPreviews( + () => secondHost + ).ambientPreviews + + expect(firstHostPreviews.value).toEqual([ + expect.objectContaining({ + sourceNodeId: toNodeId(10), + urls: ['blob:first'] + }) + ]) + expect(secondHostPreviews.value).toEqual([ + expect.objectContaining({ + sourceNodeId: toNodeId(10), + urls: ['blob:second'] + }) + ]) + }) +}) From 8b97015b73d867ebcbbbf332d073e10cf993fd70 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 25 Aug 2026 13:42:50 +0000 Subject: [PATCH 18/24] fix: keep ambient subgraph previews instance-aware across shared definitions NodeLocatorId is intentionally definition-scoped, so two SubgraphNode instances of the same definition collapsed to the same preview storage key once production writes went through executionIdToNodeLocatorId(). The later frame overwrote the earlier one and both hosts rendered it. Store live preview frames by their own NodeExecutionId (instance-scoped) alongside the existing NodeLocatorId-keyed map, and read ambient previews through that execution-id path instead of the shared locator. --- .../node/useAmbientSubgraphPreviews.test.ts | 150 ++++++++++-------- .../node/useAmbientSubgraphPreviews.ts | 30 +++- src/stores/nodeOutputStore.ts | 70 ++++++-- 3 files changed, 170 insertions(+), 80 deletions(-) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts index c7c49d20628..8778fc348c1 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.test.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -9,7 +9,6 @@ import { createTestSubgraphNode } from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' import { useNodeOutputStore } from '@/stores/nodeOutputStore' -import { createNodeLocatorId } from '@/types/nodeIdentification' import { toNodeId } from '@/types/nodeId' import { getPreviewMediaType } from './usePromotedPreviews' @@ -17,14 +16,29 @@ import { useAmbientSubgraphPreviews } from './useAmbientSubgraphPreviews' type MockNodeOutputStore = Pick< ReturnType, - 'nodeOutputs' | 'nodePreviewImages' | 'getNodeImageUrls' + | 'nodeOutputs' + | 'nodePreviewImages' + | 'getNodeImageUrls' + | 'getNodePreviewImagesByExecutionId' + | 'getNodeImageUrlsByExecutionId' > vi.mock('@/stores/nodeOutputStore', () => { + // Reused (keyed by `NodeExecutionId` strings, not `NodeLocatorId`s) as the + // backing store for `getNodePreviewImagesByExecutionId` below, so seeding + // it stays a plain reactive write — see "Mocking Composables with Reactive + // State" in docs/testing/unit-testing.md. + const nodePreviewImages = reactive( + {} + ) const store: MockNodeOutputStore = { nodeOutputs: reactive({}), - nodePreviewImages: reactive({}), - getNodeImageUrls: vi.fn() + nodePreviewImages, + getNodeImageUrls: vi.fn(), + getNodePreviewImagesByExecutionId: vi.fn( + (executionId: string) => nodePreviewImages[executionId] + ), + getNodeImageUrlsByExecutionId: vi.fn() } return { useNodeOutputStore: () => store } }) @@ -58,11 +72,14 @@ function addInteriorNode( return node } -function seedOutputs(subgraphId: string, nodeIds: Array) { - const store = useNodeOutputStore() +/** + * Seeds a live preview frame for an interior node, keyed the same way + * production writes it: `:`. + */ +function seedOutputs(hostId: number | string, nodeIds: Array) { + const { nodePreviewImages } = useNodeOutputStore() for (const nodeId of nodeIds) { - const locatorId = createNodeLocatorId(subgraphId, toNodeId(nodeId)) - store.nodePreviewImages[locatorId] = ['seeded-preview-url'] + nodePreviewImages[`${hostId}:${nodeId}`] = ['seeded-preview-url'] } } @@ -87,10 +104,10 @@ describe(useAmbientSubgraphPreviews, () => { it('returns empty array (does not throw) when SubgraphNode is detached', () => { const setup = createSetup() addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) - seedOutputs(setup.subgraph.id, [10]) - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockReturnValue([ - '/view?filename=output.png' - ]) + seedOutputs(setup.subgraphNode.id, [10]) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(['/view?filename=output.png']) const parentGraph = setup.subgraphNode.graph! parentGraph.add(setup.subgraphNode) @@ -117,11 +134,12 @@ describe(useAmbientSubgraphPreviews, () => { it('returns a preview for an interior node with live output, without any exposure', () => { const setup = createSetup() const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) - seedOutputs(setup.subgraph.id, [10]) + seedOutputs(setup.subgraphNode.id, [10]) const urls = ['/view?filename=output.png'] - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => - n === node ? urls : undefined - ) + const executionId = `${setup.subgraphNode.id}:10` + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((id) => (id === executionId ? urls : undefined)) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode @@ -142,14 +160,15 @@ describe(useAmbientSubgraphPreviews, () => { 'derives %s type from previewMediaType, same as the promoted path', ([mediaType, url]) => { const setup = createSetup() - const node = addInteriorNode(setup, { + addInteriorNode(setup, { id: 10, previewMediaType: mediaType }) - seedOutputs(setup.subgraph.id, [10]) - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation( - (n) => (n === node ? [url] : undefined) - ) + seedOutputs(setup.subgraphNode.id, [10]) + const executionId = `${setup.subgraphNode.id}:10` + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((id) => (id === executionId ? [url] : undefined)) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode @@ -162,22 +181,23 @@ describe(useAmbientSubgraphPreviews, () => { it('returns separate entries for two concurrently-executing interior nodes', () => { const setup = createSetup() - const node10 = addInteriorNode(setup, { + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) - const node20 = addInteriorNode(setup, { + addInteriorNode(setup, { id: 20, previewMediaType: 'image' }) - seedOutputs(setup.subgraph.id, [10, 20]) - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation( - (node) => { - if (node === node10) return ['/view?a=1'] - if (node === node20) return ['/view?b=2'] - return undefined - } - ) + seedOutputs(setup.subgraphNode.id, [10, 20]) + const hostId = setup.subgraphNode.id + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((executionId) => { + if (executionId === `${hostId}:10`) return ['/view?a=1'] + if (executionId === `${hostId}:20`) return ['/view?b=2'] + return undefined + }) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode @@ -190,11 +210,13 @@ describe(useAmbientSubgraphPreviews, () => { expect(urlsBySourceNodeId.get(toNodeId(20))).toEqual(['/view?b=2']) }) - it('skips interior nodes when getNodeImageUrls returns no urls despite a preview entry', () => { + it('skips interior nodes when getNodeImageUrlsByExecutionId returns no urls despite a preview entry', () => { const setup = createSetup() addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) - seedOutputs(setup.subgraph.id, [10]) - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockReturnValue(undefined) + seedOutputs(setup.subgraphNode.id, [10]) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(undefined) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode @@ -202,21 +224,17 @@ describe(useAmbientSubgraphPreviews, () => { expect(ambientPreviews.value).toEqual([]) }) - // Regression coverage for narrowing the gate to `nodePreviewImages` only: - // a committed output (as opposed to a streaming preview frame) must never - // surface ambiently, even when it looks like a valid image output — - // otherwise demoting an exposure becomes a no-op and every interior output - // node stacks a permanent preview on the host after every run. + // Regression coverage for narrowing the gate to a live streaming preview + // frame only: a committed output must never surface ambiently, even when + // an image url is otherwise resolvable — otherwise demoting an exposure + // becomes a no-op and every interior output node stacks a permanent + // preview on the host after every run. it('does not surface a committed output that was never a streaming preview', () => { const setup = createSetup() - const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) - const locatorId = createNodeLocatorId(setup.subgraph.id, toNodeId(10))! - useNodeOutputStore().nodeOutputs[locatorId] = { - images: [{ filename: 'output.png' }] - } - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => - n === node ? ['/view?filename=output.png'] : undefined - ) + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(['/view?filename=output.png']) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode @@ -226,18 +244,19 @@ describe(useAmbientSubgraphPreviews, () => { it('recomputes when outputs are populated after first evaluation', () => { const setup = createSetup() - const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode ) expect(ambientPreviews.value).toEqual([]) - seedOutputs(setup.subgraph.id, [10]) + seedOutputs(setup.subgraphNode.id, [10]) const urls = ['/view?filename=output.png'] - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => - n === node ? urls : undefined - ) + const executionId = `${setup.subgraphNode.id}:10` + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((id) => (id === executionId ? urls : undefined)) expect(ambientPreviews.value).toEqual([ expect.objectContaining({ sourceNodeId: '10', urls }) @@ -252,12 +271,13 @@ describe(useAmbientSubgraphPreviews, () => { ) expect(ambientPreviews.value).toEqual([]) - const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) - seedOutputs(setup.subgraph.id, [10]) + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraphNode.id, [10]) const urls = ['/view?filename=output.png'] - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockImplementation((n) => - n === node ? urls : undefined - ) + const executionId = `${setup.subgraphNode.id}:10` + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((id) => (id === executionId ? urls : undefined)) expect(ambientPreviews.value).toEqual([ expect.objectContaining({ sourceNodeId: '10', urls }) @@ -269,10 +289,10 @@ describe(useAmbientSubgraphPreviews, () => { const nestedSubgraph = createTestSubgraph() const nestedHost = createTestSubgraphNode(nestedSubgraph, { id: 30 }) setup.subgraph.add(nestedHost) - seedOutputs(setup.subgraph.id, [30]) - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockReturnValue([ - '/view?filename=output.png' - ]) + seedOutputs(setup.subgraphNode.id, [30]) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(['/view?filename=output.png']) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode @@ -284,10 +304,10 @@ describe(useAmbientSubgraphPreviews, () => { const setup = createSetup() const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) node.hideOutputImages = true - seedOutputs(setup.subgraph.id, [10]) - vi.mocked(useNodeOutputStore().getNodeImageUrls).mockReturnValue([ - '/view?filename=output.png' - ]) + seedOutputs(setup.subgraphNode.id, [10]) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(['/view?filename=output.png']) const { ambientPreviews } = useAmbientSubgraphPreviews( () => setup.subgraphNode diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts index 025e5aad4ac..81c19ab28af 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -6,7 +6,10 @@ import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import type { Subgraph } from '@/lib/litegraph/src/litegraph' import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' import { useNodeOutputStore } from '@/stores/nodeOutputStore' -import { createNodeLocatorId } from '@/types/nodeIdentification' +import { + appendNodeExecutionId, + tryNormalizeNodeExecutionId +} from '@/types/nodeIdentification' import type { PromotedPreview } from './usePromotedPreviews' import { getPreviewMediaType } from './usePromotedPreviews' @@ -66,17 +69,34 @@ export function useAmbientSubgraphPreviews( const { subgraph } = node void useSubgraphTopologyVersion(subgraph).value + // The host's own id, treated as its (single-segment) execution id — see + // `usePromotedPreviews`'s identical `hostLocator` construction. Scoping + // interior lookups to this instance's own execution path, rather than + // the subgraph definition's shared `NodeLocatorId`, is what keeps two + // hosts of the same definition from displaying each other's preview. + const hostExecutionId = tryNormalizeNodeExecutionId(node.id) + if (!hostExecutionId) return [] + return subgraph.nodes.flatMap((interiorNode): PromotedPreview[] => { // Nested subgraph hosts derive their own previews independently. if (interiorNode instanceof SubgraphNode) return [] if (interiorNode.hideOutputImages) return [] - const locatorId = createNodeLocatorId(subgraph.id, interiorNode.id) - if (!locatorId) return [] + const executionId = appendNodeExecutionId( + hostExecutionId, + interiorNode.id + ) + if (!executionId) return [] - if (!nodeOutputStore.nodePreviewImages[locatorId]?.length) return [] + if ( + !nodeOutputStore.getNodePreviewImagesByExecutionId(executionId)?.length + ) + return [] - const urls = nodeOutputStore.getNodeImageUrls(interiorNode) + const urls = nodeOutputStore.getNodeImageUrlsByExecutionId( + executionId, + interiorNode + ) if (!urls?.length) return [] return [ diff --git a/src/stores/nodeOutputStore.ts b/src/stores/nodeOutputStore.ts index 381ecd93883..3e6f8af93dd 100644 --- a/src/stores/nodeOutputStore.ts +++ b/src/stores/nodeOutputStore.ts @@ -52,23 +52,38 @@ interface SetOutputOptions { export const useNodeOutputStore = defineStore('nodeOutput', () => { const { nodeIdToNodeLocatorId, nodeToNodeLocatorId } = useWorkflowStore() const scheduledRevoke: Record void }> = {} + const scheduledRevokeByExecutionId: Record void }> = {} const latestPreview = ref([]) - function scheduleRevoke(locator: NodeLocatorId, cb: () => void) { - scheduledRevoke[locator]?.stop() + function scheduleRevoke( + tracker: Record void }>, + key: string, + cb: () => void + ) { + tracker[key]?.stop() const { stop } = useTimeoutFn(() => { - delete scheduledRevoke[locator] + delete tracker[key] cb() }, PREVIEW_REVOKE_DELAY_MS) - scheduledRevoke[locator] = { stop } + tracker[key] = { stop } } const nodeOutputs = ref>({}) const nodePreviewImages = ref>( app.nodePreviewImages || {} ) + /** + * Preview frames keyed by the writer's own `NodeExecutionId`, distinct from + * `nodePreviewImages`'s `NodeLocatorId` keying: `NodeLocatorId` is + * definition-scoped by design, so multiple instances of one subgraph + * definition collapse to the same key there. Live preview frames are + * instance-scoped — two instances executing concurrently must not overwrite + * each other's frame — so `getNodePreviewImagesByExecutionId` reads this + * map instead. + */ + const nodePreviewImagesByExecutionId = ref>({}) function getNodeOutputs( node: LGraphNode @@ -139,9 +154,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { function getNodePreviewImagesByExecutionId( executionId: NodeExecutionId ): string[] | undefined { - const locatorId = executionIdToNodeLocatorId(app.rootGraph, executionId) - if (!locatorId) return undefined - return nodePreviewImages.value[locatorId] + return nodePreviewImagesByExecutionId.value[executionId] } function getNodeImageUrlsByExecutionId( @@ -250,9 +263,34 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { const nodeLocatorId = executionIdToNodeLocatorId(app.rootGraph, executionId) if (!nodeLocatorId) return setNodePreviewsByLocatorId(nodeLocatorId, previewImages) + setInstancePreviewImages(executionId, previewImages) latestPreview.value = previewImages } + function setInstancePreviewImages( + executionId: NodeExecutionId, + previewImages: string[] + ) { + const existing = nodePreviewImagesByExecutionId.value[executionId] + if (scheduledRevokeByExecutionId[executionId]) { + scheduledRevokeByExecutionId[executionId].stop() + delete scheduledRevokeByExecutionId[executionId] + } + if (existing?.[Symbol.iterator]) { + for (const url of existing) releaseSharedObjectUrl(url) + } + for (const url of previewImages) retainSharedObjectUrl(url) + nodePreviewImagesByExecutionId.value[executionId] = previewImages + } + + function revokeInstancePreviewImages(executionId: NodeExecutionId) { + const previews = nodePreviewImagesByExecutionId.value[executionId] + if (!previews?.[Symbol.iterator]) return + + for (const url of previews) releaseSharedObjectUrl(url) + delete nodePreviewImagesByExecutionId.value[executionId] + } + function setNodePreviewsByLocatorId( nodeLocatorId: NodeLocatorId, previewImages: string[] @@ -280,9 +318,13 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { function revokePreviewsByExecutionId(executionId: NodeExecutionId) { const nodeLocatorId = executionIdToNodeLocatorId(app.rootGraph, executionId) - if (!nodeLocatorId) return - scheduleRevoke(nodeLocatorId, () => - revokePreviewsByLocatorId(nodeLocatorId) + if (nodeLocatorId) { + scheduleRevoke(scheduledRevoke, nodeLocatorId, () => + revokePreviewsByLocatorId(nodeLocatorId) + ) + } + scheduleRevoke(scheduledRevokeByExecutionId, executionId, () => + revokeInstancePreviewImages(executionId) ) } @@ -309,6 +351,14 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { } app.nodePreviewImages = {} nodePreviewImages.value = {} + + for (const executionId of Object.keys( + nodePreviewImagesByExecutionId.value + )) { + const previews = nodePreviewImagesByExecutionId.value[executionId] + for (const url of previews) releaseSharedObjectUrl(url) + } + nodePreviewImagesByExecutionId.value = {} } function revokeSubgraphPreviews(subgraphNode: SubgraphNode) { From d99c6d9c897be23e538c0f1d3a1c102327313ecc Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 26 Aug 2026 00:55:18 +0000 Subject: [PATCH 19/24] fix: clone preview array before storing in setInstancePreviewImages --- src/stores/nodeOutputStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stores/nodeOutputStore.ts b/src/stores/nodeOutputStore.ts index 313cbaceecc..4d7c30e553b 100644 --- a/src/stores/nodeOutputStore.ts +++ b/src/stores/nodeOutputStore.ts @@ -299,7 +299,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { for (const url of existing) releaseSharedObjectUrl(url) } for (const url of previewImages) retainSharedObjectUrl(url) - nodePreviewImagesByExecutionId.value[executionId] = previewImages + nodePreviewImagesByExecutionId.value[executionId] = [...previewImages] } function revokeInstancePreviewImages(executionId: NodeExecutionId) { From 790cd75a21a54d3406c1c202b9927dc7f780f8b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 21:24:53 +0000 Subject: [PATCH 20/24] fix: remap previewExposures.sourceNodeId on subgraph node id dedup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Loading a workflow with two subgraph definitions that collide on an interior node id renumbers the colliding node via deduplicateSubgraphNodeIds, but properties.previewExposures on the host was never patched to follow — same as patchProxyWidgets already does for legacy proxyWidgets. The stale sourceNodeId then resolves to nothing, so the promoted preview silently disappears after reload. Adds patchPreviewExposures, applied alongside patchProxyWidgets for both interior and root-level hosts, plus a regression test. Claude-Session: https://claude.ai/code/session_011BPhqLweRXNznT3YWP9Mx5 --- .../subgraph/subgraphDeduplication.test.ts | 71 +++++++++++++++++++ .../src/subgraph/subgraphDeduplication.ts | 28 ++++++++ 2 files changed, 99 insertions(+) diff --git a/src/lib/litegraph/src/subgraph/subgraphDeduplication.test.ts b/src/lib/litegraph/src/subgraph/subgraphDeduplication.test.ts index eeebacb5e64..d7ce92ea81e 100644 --- a/src/lib/litegraph/src/subgraph/subgraphDeduplication.test.ts +++ b/src/lib/litegraph/src/subgraph/subgraphDeduplication.test.ts @@ -133,6 +133,77 @@ describe('deduplicateSubgraphNodeIds', () => { }) }) +describe('deduplicateSubgraphNodeIds - previewExposures', () => { + function makeSubgraphWithNodeId( + id: string, + nodeId: number + ): ExportedSubgraph { + const subgraph = makeSubgraph(id, ['KSampler']) + const node = subgraph.nodes?.[0] + if (node) node.id = nodeId + return subgraph + } + + function makeHost( + id: number, + type: string, + previewExposures?: { + name: string + sourceNodeId: string + sourcePreviewName: string + }[] + ) { + return { + id, + type, + pos: [0, 0] as [number, number], + size: [100, 100] as [number, number], + flags: {}, + order: id, + mode: 0, + inputs: [], + outputs: [], + properties: previewExposures ? { previewExposures } : {} + } + } + + it('remaps a host previewExposures entry when its interior node id is reassigned', () => { + // Both definitions use interior node id 3, so whichever loads second gets + // its node 3 remapped to a fresh id. + const subgraphA = makeSubgraphWithNodeId('sg-a', 3) + const subgraphB = makeSubgraphWithNodeId('sg-b', 3) + const hostA = makeHost(1, 'sg-a', [ + { + name: '$$canvas-image-preview', + sourceNodeId: '3', + sourcePreviewName: '$$canvas-image-preview' + } + ]) + const hostB = makeHost(2, 'sg-b') + const state = freshState() + + const result = deduplicateSubgraphNodeIds( + [subgraphB, subgraphA], + new Set([1, 2]), + state, + [hostB, hostA] as unknown as Parameters< + typeof deduplicateSubgraphNodeIds + >[3] + ) + + const remappedHostA = result.rootNodes?.find((node) => node.type === 'sg-a') + const defA = result.subgraphs.find((subgraph) => subgraph.id === 'sg-a') + const interiorId = String(defA?.nodes?.[0]?.id) + + const exposures = remappedHostA?.properties?.previewExposures as + | { sourceNodeId: string }[] + | undefined + + expect(interiorId).not.toBe('3') + expect(exposures?.[0]?.sourceNodeId).toBe(interiorId) + }) +}) + describe('deduplicateSubgraphLinkIds', () => { it('patches every reference to a remapped regular link', () => { const subgraph = makeSubgraph('sg', ['dummy']) diff --git a/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts b/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts index 49793a7ed1a..23bc3322701 100644 --- a/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts +++ b/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts @@ -226,10 +226,12 @@ function deduplicateClonedSubgraphNodeIds( for (const subgraph of clonedSubgraphs) { patchProxyWidgets(subgraph.nodes ?? [], subgraphIdSet, remapBySubgraph) + patchPreviewExposures(subgraph.nodes ?? [], subgraphIdSet, remapBySubgraph) } if (clonedRootNodes) { patchProxyWidgets(clonedRootNodes, subgraphIdSet, remapBySubgraph) + patchPreviewExposures(clonedRootNodes, subgraphIdSet, remapBySubgraph) } } @@ -552,6 +554,32 @@ export function topologicalSortSubgraphs( return sorted } +/** Patches `properties.previewExposures[].sourceNodeId` for a remapped interior node. */ +function patchPreviewExposures( + hostNodes: ISerialisedNode[], + subgraphIdSet: Set, + remapBySubgraph: Map> +): void { + for (const node of hostNodes) { + if (!subgraphIdSet.has(node.type)) continue + const remappedIds = remapBySubgraph.get(node.type) + if (!remappedIds) continue + + const previewExposures = node.properties?.previewExposures + if (!Array.isArray(previewExposures)) continue + + for (const exposure of previewExposures) { + if (!exposure || typeof exposure !== 'object') continue + const { sourceNodeId } = exposure as { sourceNodeId?: unknown } + if (typeof sourceNodeId !== 'string') continue + const newId = remappedIds.get(toNodeId(sourceNodeId)) + if (newId !== undefined) { + ;(exposure as { sourceNodeId: string }).sourceNodeId = String(newId) + } + } + } +} + /** Patches legacy proxyWidgets in root-level SubgraphNode instances. */ function patchProxyWidgets( rootNodes: ISerialisedNode[], From 67cd018613f82d3f433b9b9e134f52c91e193580 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 21:25:55 +0000 Subject: [PATCH 21/24] fix: use root-relative execution id for ambient preview host lookup useAmbientSubgraphPreviews built its interior-node lookup key from the host's own bare local id (e.g. "10"), not its root-relative execution id (e.g. "9:10" for a host nested one level deep). For any host that is itself nested inside another subgraph, that means the ambient rollup never finds the frames app.ts's ancestor fan-out already wrote for it, so a live interior preview never renders on a nested host. Reuses the existing getExecutionIdByNode graph-traversal helper (already used the same way by error reporting, missing-node/model scanning, etc.) instead of the bare-id normalization, plus a regression test with a host nested inside another subgraph. Claude-Session: https://claude.ai/code/session_011BPhqLweRXNznT3YWP9Mx5 --- ...entSubgraphPreviews.sharedInstance.test.ts | 45 +++++++++++++++++++ .../node/useAmbientSubgraphPreviews.ts | 21 ++++----- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts b/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts index bd68caabef5..49f8440be59 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts @@ -87,3 +87,48 @@ describe('useAmbientSubgraphPreviews with a shared subgraph definition', () => { ]) }) }) + +describe('useAmbientSubgraphPreviews for a host nested inside another subgraph', () => { + beforeEach(() => { + app.nodeOutputs = {} + app.nodePreviewImages = {} + }) + + it('surfaces a live preview for its own interior node', () => { + const innerSubgraph = createTestSubgraph() + const interiorSampler = new LGraphNode('test') + interiorSampler.id = toNodeId(11) + interiorSampler.previewMediaType = 'image' + innerSubgraph.add(interiorSampler) + + const outerSubgraph = createTestSubgraph() + const innerHost = createTestSubgraphNode(innerSubgraph, { id: 10 }) + outerSubgraph.add(innerHost) + + const rootGraph = outerSubgraph.rootGraph + const outerHost = createTestSubgraphNode(outerSubgraph, { id: 9 }) + rootGraph.add(outerHost) + + vi.spyOn(app, 'rootGraph', 'get').mockReturnValue(rootGraph) + + const nodeOutputStore = useNodeOutputStore() + // Mirrors production ancestor fan-out (`app.ts`'s `b_preview_with_metadata` + // handler), which writes the frame at every prefix of the full path. + for (const executionId of [ + createNodeExecutionId([toNodeId(9)]), + createNodeExecutionId([toNodeId(9), toNodeId(10)]), + createNodeExecutionId([toNodeId(9), toNodeId(10), toNodeId(11)]) + ]) { + nodeOutputStore.setNodePreviewsByExecutionId(executionId, ['blob:nested']) + } + + const { ambientPreviews } = useAmbientSubgraphPreviews(() => innerHost) + + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ + sourceNodeId: toNodeId(11), + urls: ['blob:nested'] + }) + ]) + }) +}) diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts index 81c19ab28af..189444a8f27 100644 --- a/src/composables/node/useAmbientSubgraphPreviews.ts +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -6,10 +6,8 @@ import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import type { Subgraph } from '@/lib/litegraph/src/litegraph' import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' import { useNodeOutputStore } from '@/stores/nodeOutputStore' -import { - appendNodeExecutionId, - tryNormalizeNodeExecutionId -} from '@/types/nodeIdentification' +import { appendNodeExecutionId } from '@/types/nodeIdentification' +import { getExecutionIdByNode } from '@/utils/graphTraversalUtil' import type { PromotedPreview } from './usePromotedPreviews' import { getPreviewMediaType } from './usePromotedPreviews' @@ -69,12 +67,15 @@ export function useAmbientSubgraphPreviews( const { subgraph } = node void useSubgraphTopologyVersion(subgraph).value - // The host's own id, treated as its (single-segment) execution id — see - // `usePromotedPreviews`'s identical `hostLocator` construction. Scoping - // interior lookups to this instance's own execution path, rather than - // the subgraph definition's shared `NodeLocatorId`, is what keeps two - // hosts of the same definition from displaying each other's preview. - const hostExecutionId = tryNormalizeNodeExecutionId(node.id) + // The host's own root-relative execution id (e.g. `9:10` for a host + // nested one level deep), not just its bare local id — otherwise a + // nested host looks up its interior previews under the wrong key and + // never finds the frames `app.ts`'s ancestor fan-out already wrote for + // it. Scoping interior lookups to this instance's own execution path, + // rather than the subgraph definition's shared `NodeLocatorId`, is also + // what keeps two hosts of the same definition from displaying each + // other's preview. + const hostExecutionId = getExecutionIdByNode(node.rootGraph, node) if (!hostExecutionId) return [] return subgraph.nodes.flatMap((interiorNode): PromotedPreview[] => { From ae9a4267421d6d141ede4a3f9f155e2f3c4ecf9f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 21:31:06 +0000 Subject: [PATCH 22/24] fix: look up a subgraph host's own exposures by its instance locator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LGraphNode.vue's subgraphPreviews merge excluded a host's own exposed nodes from its ambient previews by querying previewExposureStore.getExposures(rootGraphId, String(node.id)) — the node's bare id. SubgraphNode._hydratePreviewExposures always stores a nested host's exposures under its instance-scoped locator (definition UUID + bare id) instead, so for any host nested inside another subgraph this lookup silently found nothing, leaving the exclusion set empty. Extracts the lookup into getHostExposedSourceNodeIds (colocated with mergeSubgraphPreviews, which already documents this exact contract), using getPreviewExposureHostLocator like every other read/write site for this data. Root-level hosts are unaffected, since their instance locator and bare id already coincide. Claude-Session: https://claude.ai/code/session_011BPhqLweRXNznT3YWP9Mx5 --- .../node/mergeSubgraphPreviews.test.ts | 39 ++++++++++++++++++- src/composables/node/mergeSubgraphPreviews.ts | 20 ++++++++++ .../vueNodes/components/LGraphNode.vue | 13 +++---- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/composables/node/mergeSubgraphPreviews.test.ts b/src/composables/node/mergeSubgraphPreviews.test.ts index 774c339f9d4..db2d3f36462 100644 --- a/src/composables/node/mergeSubgraphPreviews.test.ts +++ b/src/composables/node/mergeSubgraphPreviews.test.ts @@ -1,8 +1,19 @@ import { describe, expect, it } from 'vitest' +import { + createTestSubgraph, + createTestSubgraphNode +} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' +import { + getPreviewExposureHostLocator, + usePreviewExposureStore +} from '@/stores/previewExposureStore' import { toNodeId } from '@/types/nodeId' -import { mergeSubgraphPreviews } from './mergeSubgraphPreviews' +import { + getHostExposedSourceNodeIds, + mergeSubgraphPreviews +} from './mergeSubgraphPreviews' import type { PromotedPreview } from './usePromotedPreviews' function preview( @@ -63,3 +74,29 @@ describe(mergeSubgraphPreviews, () => { expect(result).toEqual(promoted) }) }) + +describe(getHostExposedSourceNodeIds, () => { + it("finds a nested host's own exposures under its instance locator, not its bare id", () => { + const outerSubgraph = createTestSubgraph() + const innerSubgraph = createTestSubgraph() + const innerHost = createTestSubgraphNode(innerSubgraph, { id: 5 }) + outerSubgraph.add(innerHost) + const outerHost = createTestSubgraphNode(outerSubgraph, { id: 1 }) + outerSubgraph.rootGraph.add(outerHost) + + // `SubgraphNode._hydratePreviewExposures` stores a nested host's + // exposures under its instance-scoped locator (definition UUID + bare + // id), never under the bare id alone. + const instanceLocator = getPreviewExposureHostLocator(innerHost) + expect(instanceLocator).not.toBe(String(innerHost.id)) + if (!instanceLocator) return + + const store = usePreviewExposureStore() + store.addExposure(innerHost.rootGraph.id, instanceLocator, { + sourceNodeId: '3', + sourcePreviewName: 'exposure' + }) + + expect(getHostExposedSourceNodeIds(innerHost)).toEqual([toNodeId(3)]) + }) +}) diff --git a/src/composables/node/mergeSubgraphPreviews.ts b/src/composables/node/mergeSubgraphPreviews.ts index 6ce8d99c0e2..549cd49e22c 100644 --- a/src/composables/node/mergeSubgraphPreviews.ts +++ b/src/composables/node/mergeSubgraphPreviews.ts @@ -1,7 +1,27 @@ +import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' +import { + getPreviewExposureHostLocator, + usePreviewExposureStore +} from '@/stores/previewExposureStore' import type { NodeId } from '@/types/nodeId' import type { PromotedPreview } from './usePromotedPreviews' +/** + * A host's own first-hop exposures, keyed the same way + * {@link getPreviewExposureHostLocator} stores them — i.e. by the host's + * instance-scoped locator, not its bare `node.id`. The two only coincide for + * root-level hosts; a nested host's exposures live under its definition- + * scoped locator, so looking them up by bare id silently finds nothing. + */ +export function getHostExposedSourceNodeIds(node: SubgraphNode): NodeId[] { + const hostLocator = getPreviewExposureHostLocator(node) + if (!hostLocator) return [] + return usePreviewExposureStore() + .getExposures(node.rootGraph.id, hostLocator) + .map((exposure) => exposure.sourceNodeId) +} + /** * Merges a subgraph host's exposure-promoted previews with its ambient * previews, keeping the promoted entry whenever both cover the same diff --git a/src/renderer/extensions/vueNodes/components/LGraphNode.vue b/src/renderer/extensions/vueNodes/components/LGraphNode.vue index 9ed3aeb45ad..90a773a69db 100644 --- a/src/renderer/extensions/vueNodes/components/LGraphNode.vue +++ b/src/renderer/extensions/vueNodes/components/LGraphNode.vue @@ -265,7 +265,10 @@ import { useCanvasInteractions } from '@/renderer/core/canvas/useCanvasInteracti import { layoutStore } from '@/renderer/core/layout/store/layoutStore' import { useGLSLPreview } from '@/renderer/glsl/useGLSLPreview' import { useAmbientSubgraphPreviews } from '@/composables/node/useAmbientSubgraphPreviews' -import { mergeSubgraphPreviews } from '@/composables/node/mergeSubgraphPreviews' +import { + getHostExposedSourceNodeIds, + mergeSubgraphPreviews +} from '@/composables/node/mergeSubgraphPreviews' import { usePromotedPreviews } from '@/composables/node/usePromotedPreviews' import NodeBadges from '@/renderer/extensions/vueNodes/components/NodeBadges.vue' import { LayoutSource } from '@/renderer/core/layout/types' @@ -293,7 +296,6 @@ import { } from '@/renderer/extensions/vueNodes/utils/nodeStyleUtils' import { app } from '@/scripts/app' import { useNodeOutputStore } from '@/stores/nodeOutputStore' -import { usePreviewExposureStore } from '@/stores/previewExposureStore' import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore' import { stripGraphPrefix, @@ -634,16 +636,11 @@ const lgraphNode = computed(resolveLGraphNode) // reaching through lgraphNode for promoted preview resolution. const { promotedPreviews } = usePromotedPreviews(lgraphNode) const { ambientPreviews } = useAmbientSubgraphPreviews(lgraphNode) -const previewExposureStore = usePreviewExposureStore() const subgraphPreviews = computed(() => { const node = lgraphNode.value const exposedSourceNodeIds = - node instanceof SubgraphNode - ? previewExposureStore - .getExposures(node.rootGraph.id, String(node.id)) - .map((exposure) => exposure.sourceNodeId) - : [] + node instanceof SubgraphNode ? getHostExposedSourceNodeIds(node) : [] return mergeSubgraphPreviews( promotedPreviews.value, ambientPreviews.value, From d4f00cb7296878e43f0ed677c4d718be6ba33782 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 21:53:53 +0000 Subject: [PATCH 23/24] test: guard e2e ambient-preview fixtures against auto-expose masking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit subgraphNestedAmbientPreviewScope.spec.ts and subgraphAmbientCommittedOutputIsolation.spec.ts both assert a live preview appears on a subgraph host with no promoted exposure for it, to pin the ambient-rollup code path specifically. Neither fixture's host node declares a persisted `previewExposures` property, so LGraph.configure's one-shot autoExposeKnownPreviewNodes pass runs on load and auto-promotes the interior KSampler via the ordinary promotion path instead — the e2e assertion is satisfied either way, so stubbing the ambient composable out entirely still leaves both specs green. Adds a unit-level guard reading the two fixture JSON files directly and asserting each host already declares an empty `previewExposures: []`, which is what actually trips the one-shot gate. Confirmed red against the current (undefined-property) fixtures before the next commit sets it. Claude-Session: https://claude.ai/code/session_011BPhqLweRXNznT3YWP9Mx5 --- .../graph/subgraph/promotionUtils.test.ts | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/core/graph/subgraph/promotionUtils.test.ts b/src/core/graph/subgraph/promotionUtils.test.ts index 4d9763e2855..b2b602f7781 100644 --- a/src/core/graph/subgraph/promotionUtils.test.ts +++ b/src/core/graph/subgraph/promotionUtils.test.ts @@ -1,3 +1,6 @@ +import fs from 'node:fs' +import path from 'node:path' + import { fromPartial } from '@total-typescript/shoehorn' import { describe, expect, it, vi } from 'vitest' @@ -453,6 +456,60 @@ describe('autoExposeKnownPreviewNodes', () => { }) }) +describe('e2e ambient-preview fixtures stay ambient-only', () => { + // These fixtures back subgraphNestedAmbientPreviewScope.spec.ts and + // subgraphAmbientCommittedOutputIsolation.spec.ts, both of which assert a + // live preview appears on a subgraph host with no promoted exposure for + // it. If a host's `previewExposures` property is left undefined, the + // one-shot `autoExposeKnownPreviewNodes` gate above runs on load and + // auto-promotes the interior KSampler, so the e2e assertion passes via the + // promotion path even with the ambient composable stubbed out — the exact + // gap this test guards against. + const hostFixtures = [ + { + file: 'subgraph-nested-with-live-sampler.json', + hostTitles: ['Outer Subgraph', 'Middle Subgraph'] + }, + { + file: 'subgraph-with-live-sampler-and-committed-output.json', + hostTitles: ['Sampler And Preview Subgraph'] + } + ] + + function loadFixtureNodes(fileName: string) { + const fullPath = path.resolve( + __dirname, + `../../../../browser_tests/assets/subgraphs/${fileName}` + ) + const workflow = JSON.parse(fs.readFileSync(fullPath, 'utf-8')) as { + nodes: Array<{ title?: string; properties?: Record }> + definitions?: { + subgraphs?: Array<{ + nodes: Array<{ + title?: string + properties?: Record + }> + }> + } + } + return [ + ...workflow.nodes, + ...(workflow.definitions?.subgraphs?.flatMap((sg) => sg.nodes) ?? []) + ] + } + + it.for(hostFixtures)( + 'declares an empty previewExposures on every host in $file', + ({ file, hostTitles }) => { + const nodes = loadFixtureNodes(file) + for (const title of hostTitles) { + const host = nodes.find((n) => n.title === title) + expect(host?.properties?.previewExposures).toEqual([]) + } + } + ) +}) + describe('hasUnpromotedWidgets', () => { it('returns true when subgraph has at least one enabled unpromoted widget', () => { const subgraph = createTestSubgraph() From 222a0088c30f13d30784aa37624d78e194c08fb9 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 21:55:14 +0000 Subject: [PATCH 24/24] fix: trip the auto-expose gate in two ambient-preview e2e fixtures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sets `properties.previewExposures: []` on the subgraph hosts in subgraph-nested-with-live-sampler.json and subgraph-with-live-sampler-and-committed-output.json. Both fixtures' hosts previously left `previewExposures` undefined, so autoExposeKnownPreviewNodes' one-shot gate (`if (subgraphNode.properties.previewExposures !== undefined) return`) ran on load and auto-promoted the interior KSampler through the ordinary exposure path — the same path the ambient rollup exists to supplement, not replace, for these fixtures. An explicit empty array trips the gate so it no longer runs, leaving the host with no promoted exposure and forcing subgraphNestedAmbientPreviewScope.spec.ts and subgraphAmbientCommittedOutputIsolation.spec.ts to actually exercise the ambient composable to pass. Claude-Session: https://claude.ai/code/session_011BPhqLweRXNznT3YWP9Mx5 --- .../assets/subgraphs/subgraph-nested-with-live-sampler.json | 4 ++-- .../subgraph-with-live-sampler-and-committed-output.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json b/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json index 199aae9eb47..832cfb13722 100644 --- a/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json +++ b/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json @@ -15,7 +15,7 @@ "inputs": [], "outputs": [{ "name": "output", "type": "LATENT", "links": null }], "title": "Outer Subgraph", - "properties": {}, + "properties": { "previewExposures": [] }, "widgets_values": [] } ], @@ -66,7 +66,7 @@ "inputs": [], "outputs": [{ "name": "output", "type": "LATENT", "links": [1] }], "title": "Middle Subgraph", - "properties": {}, + "properties": { "previewExposures": [] }, "widgets_values": [] } ], diff --git a/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json b/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json index 88893917864..9822a903535 100644 --- a/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json +++ b/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json @@ -15,7 +15,7 @@ "inputs": [], "outputs": [{ "name": "output", "type": "LATENT", "links": null }], "title": "Sampler And Preview Subgraph", - "properties": {}, + "properties": { "previewExposures": [] }, "widgets_values": [] } ],