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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions src/components/rightSidePanel/parameters/SectionWidgets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { useI18n } from 'vue-i18n'

import Button from '@/components/ui/button/Button.vue'
import { clearWidgetRelatedErrorScopes } from '@/composables/graph/widgetErrorClearing'
import { widgetPromotedSource } from '@/core/graph/subgraph/promotedInputWidget'
import { isWidgetPromotedOnSubgraphNode } from '@/core/graph/subgraph/promotionUtils'
import { resolvePromotedWidgetSource } from '@/core/graph/subgraph/resolvePromotedWidgetSource'
Expand Down Expand Up @@ -247,25 +248,20 @@ function clearWidgetErrors(
const executionId = getExecutionIdByNode(rootGraph, widgetNode)
if (!executionId) return

const options = { min: widget.options?.min, max: widget.options?.max }
const range = { min: widget.options?.min, max: widget.options?.max }
const source = resolvePromotedWidgetSource(rootGraph, widgetNode, widget)
if (source?.sourceExecutionId) {
executionErrorStore.clearWidgetRelatedErrors(
source.sourceExecutionId,
source.sourceWidgetName,
source.sourceWidgetName,
value,
options
)
}

executionErrorStore.clearWidgetRelatedErrors(
executionId,
widget.name,
widget.name,
clearWidgetRelatedErrorScopes({
clearWidgetRelatedErrors: executionErrorStore.clearWidgetRelatedErrors,
host: { executionId, widgetName: widget.name },
source: source?.sourceExecutionId
? {
executionId: source.sourceExecutionId,
widgetName: source.sourceWidgetName
}
: undefined,
value,
options
)
range
})
}

function setWidgetValue(
Expand Down
62 changes: 57 additions & 5 deletions src/composables/graph/useErrorClearingHooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,58 @@ describe('realtime verification staleness guards', () => {
expect(useMissingMediaStore().missingMediaCandidates).toBeNull()
})

it('skips adding verified promoted media when source is bypassed before verification resolved', async () => {
const subgraph = createTestSubgraph()
const interiorNode = new LGraphNode('LoadImage')
subgraph.add(interiorNode)

const host = createTestSubgraphNode(subgraph, { id: 65 })
const rootGraph = host.graph as LGraph
rootGraph.add(host)
vi.spyOn(app, 'rootGraph', 'get').mockReturnValue(rootGraph)

const promotedCandidate: MissingMediaCandidate = {
nodeId: String(host.id),
sourceExecutionId: createNodeExecutionId([host.id, interiorNode.id]),
nodeType: 'LoadImage',
widgetName: 'image',
mediaType: 'image',
name: 'promoted_image.png',
isMissing: undefined
}
vi.spyOn(missingModelScan, 'scanNodeModelCandidates').mockReturnValue([])
vi.spyOn(missingMediaScan, 'scanNodeMediaCandidates').mockImplementation(
(_rootGraph, node) => (node === host ? [promotedCandidate] : [])
)
let resolveVerify: (() => void) | undefined
const verifyPromise = new Promise<void>((r) => (resolveVerify = r))
const verifySpy = vi
.spyOn(missingMediaScan, 'verifyMediaCandidates')
.mockImplementation(async (candidates) => {
await verifyPromise
for (const c of candidates) c.isMissing = true
})

installErrorClearingHooks(rootGraph)

host.mode = LGraphEventMode.ALWAYS
rootGraph.onTrigger?.({
type: 'node:property:changed',
nodeId: host.id,
property: 'mode',
oldValue: LGraphEventMode.BYPASS,
newValue: LGraphEventMode.ALWAYS
})
await vi.waitFor(() => expect(verifySpy).toHaveBeenCalledOnce())

interiorNode.mode = LGraphEventMode.BYPASS

resolveVerify!()
await new Promise((r) => setTimeout(r, 0))

expect(useMissingMediaStore().missingMediaCandidates).toBeNull()
})

it('skips adding verified model when rootGraph switched before verification resolved', async () => {
// Workflow A has a pending candidate on node id=1. A is replaced
// by workflow B (fresh LGraph, potentially has a node with the
Expand Down Expand Up @@ -1075,10 +1127,10 @@ describe('clearWidgetRelatedErrors parameter routing', () => {
vi.spyOn(app, 'isGraphReady', 'get').mockReturnValue(false)
})

it('passes widgetName (not errorInputName) for model lookup', () => {
it('routes validation and missing-asset widget names separately', () => {
const graph = new LGraph()
const node = new LGraphNode('test')
const widget = node.addWidget('number', 'steps', 42, () => undefined, {
const widget = node.addWidget('number', 'store_name', 42, () => undefined, {
min: 0,
max: 100
})
Expand All @@ -1089,12 +1141,12 @@ describe('clearWidgetRelatedErrors parameter routing', () => {
vi.spyOn(app, 'rootGraph', 'get').mockReturnValue(graph)
const clearSpy = vi.spyOn(store, 'clearWidgetRelatedErrors')

node.onWidgetChanged!.call(node, 'steps', 42, 0, widget)
node.onWidgetChanged!.call(node, 'display_name', 42, 0, widget)

expect(clearSpy).toHaveBeenCalledWith(
String(node.id),
'steps',
'steps',
'display_name',
'store_name',
42,
{ min: 0, max: 100 }
)
Expand Down
48 changes: 21 additions & 27 deletions src/composables/graph/useErrorClearingHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* works in legacy canvas mode as well.
*/
import { useChainCallback } from '@/composables/functional/useChainCallback'
import { clearWidgetRelatedErrorScopes } from '@/composables/graph/widgetErrorClearing'
import { resolvePromotedWidgetSource } from '@/core/graph/subgraph/resolvePromotedWidgetSource'
import { LiteGraph } from '@/lib/litegraph/src/litegraph'
import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
Expand Down Expand Up @@ -93,25 +94,25 @@ function installNodeHooks(node: LGraphNode): void {
const hostExecId = getExecutionIdByNode(app.rootGraph, node)
if (!hostExecId) return

const options = { min: widget.options?.min, max: widget.options?.max }
const executionErrorStore = useExecutionErrorStore()
const range = { min: widget.options?.min, max: widget.options?.max }
const source = resolvePromotedWidgetSource(app.rootGraph, node, widget)
if (source?.sourceExecutionId) {
useExecutionErrorStore().clearWidgetRelatedErrors(
source.sourceExecutionId,
source.sourceWidgetName,
source.sourceWidgetName,
newValue,
options
)
}

useExecutionErrorStore().clearWidgetRelatedErrors(
hostExecId,
name,
widget.name,
newValue,
options
)
clearWidgetRelatedErrorScopes({
clearWidgetRelatedErrors: executionErrorStore.clearWidgetRelatedErrors,
host: {
executionId: hostExecId,
errorInputName: name,
widgetName: widget.name
},
source: source?.sourceExecutionId
? {
executionId: source.sourceExecutionId,
widgetName: source.sourceWidgetName
}
: undefined,
value: newValue,
range
})
}
)
}
Expand Down Expand Up @@ -265,14 +266,6 @@ function isModelCandidateStillActive(
return isMissingCandidateActive(app.rootGraph, candidate)
}

function isNodeCandidateStillActive(nodeId: unknown): boolean {
return (
app.rootGraph != null &&
nodeId != null &&
isExecutionPathActive(app.rootGraph, String(nodeId))
)
}

async function verifyAndAddPendingModels(
pending: MissingModelCandidate[]
): Promise<void> {
Expand Down Expand Up @@ -300,7 +293,7 @@ async function verifyAndAddPendingMedia(
await verifyMediaCandidates(pending, { isCloud })
if (app.rootGraph !== rootGraphAtScan) return
const verified = pending.filter(
(c) => c.isMissing === true && isNodeCandidateStillActive(c.nodeId)
(c) => c.isMissing === true && isMissingCandidateActive(app.rootGraph, c)
)
if (verified.length) useMissingMediaStore().addMissingMedia(verified)
} catch (error: unknown) {
Expand Down Expand Up @@ -382,6 +375,7 @@ function removeNodeErrors(node: LGraphNode, execId: string): void {
modelStore.removeMissingModelsByNodeId(execId)
modelStore.removeMissingModelsBySourceScope(execId)
mediaStore.removeMissingMediaByNodeId(execId)
mediaStore.removeMissingMediaBySourceScope(execId)
nodesStore.removeMissingNodesByNodeId(execId)

// For subgraph containers, also remove errors from interior nodes.
Expand Down
86 changes: 86 additions & 0 deletions src/composables/graph/widgetErrorClearing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { describe, expect, it, vi } from 'vitest'

import { clearWidgetRelatedErrorScopes } from '@/composables/graph/widgetErrorClearing'
import { createNodeExecutionId } from '@/types/nodeIdentification'

describe('clearWidgetRelatedErrorScopes', () => {
it('clears only the host scope for normal widgets', () => {
const clearWidgetRelatedErrors = vi.fn()

clearWidgetRelatedErrorScopes({
clearWidgetRelatedErrors,
host: {
executionId: createNodeExecutionId([65]),
widgetName: 'ckpt_name'
},
value: 'real_model.safetensors',
range: { min: 0, max: 10 }
})

expect(clearWidgetRelatedErrors).toHaveBeenCalledOnce()
expect(clearWidgetRelatedErrors).toHaveBeenCalledWith(
createNodeExecutionId([65]),
'ckpt_name',
'ckpt_name',
'real_model.safetensors',
{ min: 0, max: 10 }
)
})

it('preserves distinct validation and missing-asset widget names', () => {
const clearWidgetRelatedErrors = vi.fn()

clearWidgetRelatedErrorScopes({
clearWidgetRelatedErrors,
host: {
executionId: createNodeExecutionId([65]),
errorInputName: 'display_name',
widgetName: 'store_name'
},
value: 'real_model.safetensors'
})

expect(clearWidgetRelatedErrors).toHaveBeenCalledWith(
createNodeExecutionId([65]),
'display_name',
'store_name',
'real_model.safetensors',
undefined
)
})

it('clears promoted source scope before host scope', () => {
const clearWidgetRelatedErrors = vi.fn()

clearWidgetRelatedErrorScopes({
clearWidgetRelatedErrors,
source: {
executionId: createNodeExecutionId([65, 42]),
widgetName: 'ckpt_name'
},
host: {
executionId: createNodeExecutionId([65]),
widgetName: 'promoted_ckpt'
},
value: 'real_model.safetensors',
range: { min: undefined, max: undefined }
})

expect(clearWidgetRelatedErrors).toHaveBeenNthCalledWith(
1,
createNodeExecutionId([65, 42]),
'ckpt_name',
'ckpt_name',
'real_model.safetensors',
{ min: undefined, max: undefined }
)
expect(clearWidgetRelatedErrors).toHaveBeenNthCalledWith(
2,
createNodeExecutionId([65]),
'promoted_ckpt',
'promoted_ckpt',
'real_model.safetensors',
{ min: undefined, max: undefined }
)
})
})
63 changes: 63 additions & 0 deletions src/composables/graph/widgetErrorClearing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { NodeExecutionId } from '@/types/nodeIdentification'

interface WidgetErrorRangeOptions {
min?: number
max?: number
}

interface WidgetErrorScope {
executionId: NodeExecutionId
/** Validation error key matched against `error.extra_info.input_name`. */
errorInputName?: string
/** Missing model/media store lookup key. */
widgetName: string
}

type ClearWidgetRelatedErrors = (
executionId: NodeExecutionId,
errorInputName: string,
widgetName: string,
newValue: unknown,
range?: WidgetErrorRangeOptions
) => void

interface ClearWidgetRelatedErrorScopesOptions {
clearWidgetRelatedErrors: ClearWidgetRelatedErrors
host: WidgetErrorScope
source?: WidgetErrorScope
value: unknown
range?: WidgetErrorRangeOptions
}

/**
* Clear the interior promoted-widget source first, then the host widget.
* The range belongs to the widget surface that emitted the value.
*/
export function clearWidgetRelatedErrorScopes({
clearWidgetRelatedErrors,
host,
source,
value,
range
}: ClearWidgetRelatedErrorScopesOptions): void {
if (source) {
applyScopeClear(clearWidgetRelatedErrors, source, value, range)
}

applyScopeClear(clearWidgetRelatedErrors, host, value, range)
}

function applyScopeClear(
clearWidgetRelatedErrors: ClearWidgetRelatedErrors,
scope: WidgetErrorScope,
value: unknown,
range?: WidgetErrorRangeOptions
): void {
clearWidgetRelatedErrors(
scope.executionId,
scope.errorInputName ?? scope.widgetName,
scope.widgetName,
value,
range
)
}
Loading
Loading