Skip to content
Open
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
20 changes: 20 additions & 0 deletions src/scripts/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,26 @@ describe('ComfyApp', () => {
}
})

it('reports prompt construction failures with an id-free fingerprint', async () => {
prepareEmptyPromptQueue()
const failure = new Error(
'No output node found for id [632] slot [0] images'
)
vi.spyOn(app, 'graphToPrompt').mockRejectedValue(failure)

await expect(app.queuePrompt(0)).rejects.toThrow(failure)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P3] Check that the original rejection is preserved

I replaced this catch's throw error with a fresh Error carrying the same message, and this test still passed. toThrow(failure) compares Error contents, not identity, so it misses loss of the original stack, cause or subclass. The PR explicitly promises to rethrow the original exception; check that object directly.

Suggested change
await expect(app.queuePrompt(0)).rejects.toThrow(failure)
await expect(app.queuePrompt(0)).rejects.toBe(failure)

expect(reportError).toHaveBeenCalledWith(failure, {
surface: 'graph',
errorType: 'error_building_prompt',
fingerprint: [
'error_building_prompt',
'Error',
'No output node found for id [] slot []'
],
logToConsole: false
})
})

it('stores execution intent when workflow context collection fails', async () => {
prepareEmptyPromptQueue()
const registry = new TelemetryRegistry()
Expand Down
7 changes: 7 additions & 0 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ import type { NodeExecutionId } from '@comfyorg/graph-model/nodeIdentification'
import { getErrorMessage } from '@comfyorg/shared-frontend-utils/errorUtil'
import { normalizePromptError } from '@/utils/executionErrorUtil'
import { graphToPrompt, unwrapExportedWidgetValue } from '@/utils/executionUtil'
import { promptBuildErrorFingerprint } from '@/utils/promptBuildErrorFingerprint'
import { parseJsonWithNonFinite } from '@/utils/jsonUtil'
import { getCnrIdFromProperties } from '@/platform/workflowErrors/nodeReplacement/cnrIdUtil'
import { useMissingNodesErrorStore } from '@/platform/workflowErrors/nodeReplacement/missingNodesErrorStore'
Expand Down Expand Up @@ -1867,6 +1868,12 @@ export class ComfyApp implements IComfyApp {
failureReason: 'prompt_build_failed',
...workflowExecutionIntent
})
reportError(error, {
surface: 'graph',
errorType: 'error_building_prompt',
fingerprint: promptBuildErrorFingerprint(error),
logToConsole: false
})
throw error
}
)
Expand Down
71 changes: 71 additions & 0 deletions src/utils/promptBuildErrorFingerprint.producers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { beforeEach, describe, expect, it } from 'vitest'

import {
createTestSubgraph,
createTestSubgraphNode,
resetSubgraphFixtureState
} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers'
import { promptBuildErrorFingerprint } from '@/utils/promptBuildErrorFingerprint'

describe('promptBuildErrorFingerprint on real prompt build throwers', () => {
beforeEach(() => {
resetSubgraphFixtureState()
})

function fingerprintOfThrow(run: () => void): string[] {
try {
run()
} catch (error) {
return promptBuildErrorFingerprint(error)
}
throw new Error('expected the prompt build thrower to throw')
}

it('groups SubgraphNode.rootGraph NullGraphError across string node ids', () => {
function detachedRootGraphAccess(nodeId: string) {
const subgraphNode = createTestSubgraphNode(createTestSubgraph(), {
id: nodeId
})
subgraphNode.graph = null
return fingerprintOfThrow(() => subgraphNode.rootGraph)
}

expect(detachedRootGraphAccess('alpha')).toEqual([
'error_building_prompt',
'NullGraphError',
'SubgraphNode N has no graph'
])
expect(detachedRootGraphAccess('beta')).toEqual(
detachedRootGraphAccess('alpha')
)
})

it('groups SubgraphNode.getInnerNodes RecursionError across ids, titles and subgraph names', () => {
function selfVisitingInnerNodes(
nodeId: string,
title: string,
subgraphName: string
) {
const subgraphNode = createTestSubgraphNode(
createTestSubgraph({ name: subgraphName }),
{ id: nodeId }
)
subgraphNode.title = title
return fingerprintOfThrow(() =>
subgraphNode.getInnerNodes(new Map(), [], [], new Set([subgraphNode]))
)
}

expect(selfVisitingInnerNodes('alpha', 'Load. Image', 'Detailer')).toEqual([
'error_building_prompt',
'RecursionError',
'Circular reference detected at depth N in node N of subgraph N'
])
expect(selfVisitingInnerNodes('beta', 'Upscale', 'Refiner')).toEqual(
selfVisitingInnerNodes('alpha', 'Load. Image', 'Detailer')
)
expect(
selfVisitingInnerNodes('gamma', 'Load of node Image', 'Enhancer')
).toEqual(selfVisitingInnerNodes('alpha', 'Load. Image', 'Detailer'))
})
})
137 changes: 137 additions & 0 deletions src/utils/promptBuildErrorFingerprint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { describe, expect, it } from 'vitest'

import { promptBuildErrorFingerprint } from '@/utils/promptBuildErrorFingerprint'

describe('promptBuildErrorFingerprint', () => {
it('groups missing output nodes across ids, slots and output names', () => {
const first = new Error('No output node found for id [632] slot [0] images')
const second = new Error('No output node found for id [12:7] slot [3] mask')
Comment on lines +7 to +8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Obtain DTO errors from their actual producers

I changed only the real missing-output producer's wording from No output node found to Missing output node. Both fingerprint suites still passed all 12 tests, while the unchanged normalizer retained the real output name. These hand-built strings cannot detect drift in the exact message prefixes the regexes depend on. The local recursion builder and manually named NullGraphError have the same problem.

Replace the DTO-specific synthetic inputs with captured exceptions from real ExecutableNodeDTO methods in the existing producers suite, retaining literal expected fingerprints. Include the resolveInput NullGraphError site: the current real rootGraph case is a different producer and does not settle that earlier request. Use supported DTO entry points and existing graph fixtures; do not expose a private method or export a message factory just for tests. The app's rejected-promise stub can remain as the narrow reporting-boundary check.

This fix spans the unit and producers files, so a local suggestion cannot safely replace the required fixtures and delete their synthetic copies.


expect(promptBuildErrorFingerprint(first)).toEqual(
promptBuildErrorFingerprint(second)
)
})

it('keeps different failure kinds apart', () => {
const missingOutput = new Error(
'No output node found for id [1] slot [0] x'
)
const missingInput = new TypeError(
'No input found for flattened id [1] slot [0]'
)

expect(promptBuildErrorFingerprint(missingOutput)).not.toEqual(
promptBuildErrorFingerprint(missingInput)
)
Comment on lines +15 to +25

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Protect separation of same-class failure kinds

I mutated the result to replace resolving output with resolving input, merging both recursion origins into one group. All 12 fingerprint tests still passed: this test changes both the error class and message, while the direction table only checks equality within each direction.

Rewrite this separation assertion to compare real input- and output-recursion errors with the same RecursionError class, alongside the real DTO producer cases requested separately. That comparison fails for the demonstrated collision without adding an ID-by-direction cross-product. The current missing-output/missing-input pair does not exercise this defect.

The replacement needs the DTO fixtures in the producers suite and removal or rewriting of this assertion, so the fix spans files rather than fitting this local range.

})

it.for([
{
thrower: 'ExecutableNodeDTO.resolveInput',
suffix: ' during input resolution'
},
{ thrower: 'SubgraphNode.rootGraph', suffix: '' }
Comment on lines +32 to +33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P3] Nit: delete the duplicate synthetic rootGraph row

The real rootGraph producer case already checks the exact fingerprint and alpha/beta grouping. Numeric-versus-string handling remains covered by the input-resolution row through the same normalization rule, so this additional hand-built copy protects no independent behavior.

Suggested change
},
{ thrower: 'SubgraphNode.rootGraph', suffix: '' }
}

])(
'groups NullGraphError across numeric and string subgraph node ids ($thrower)',
({ suffix }) => {
function nullGraphError(nodeId: string) {
const error = new Error(`SubgraphNode ${nodeId} has no graph${suffix}`)
error.name = 'NullGraphError'
return error
}

expect(promptBuildErrorFingerprint(nullGraphError('alpha'))).toEqual([
'error_building_prompt',
'NullGraphError',
`SubgraphNode N has no graph${suffix}`
])
expect(promptBuildErrorFingerprint(nullGraphError('beta'))).toEqual(
promptBuildErrorFingerprint(nullGraphError('alpha'))
)
expect(promptBuildErrorFingerprint(nullGraphError('42'))).toEqual(
promptBuildErrorFingerprint(nullGraphError('alpha'))
)
}
)

it('keeps the two NullGraphError sites apart', () => {
const duringInput = new Error(
'SubgraphNode alpha has no graph during input resolution'
)
const rootGraph = new Error('SubgraphNode alpha has no graph')

expect(promptBuildErrorFingerprint(duringInput)).not.toEqual(
promptBuildErrorFingerprint(rootGraph)
)
})

it('groups subgraph hierarchy recursion errors across ids, titles, names and depths', () => {
function hierarchyRecursionError(
depth: number,
nodeInfo: string,
subgraphName: string
) {
const error = new Error(
`Circular reference detected at depth ${depth} in node ${nodeInfo} of subgraph '${subgraphName}'. ` +
`This creates an infinite loop in the subgraph hierarchy.`
)
error.name = 'RecursionError'
return error
}

expect(
promptBuildErrorFingerprint(
hierarchyRecursionError(2, 'alpha (Load. Image)', 'Detailer')
)
).toEqual(
promptBuildErrorFingerprint(
hierarchyRecursionError(3, 'beta', 'Unnamed Subgraph')
)
)
})
Comment on lines +68 to +91

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P3] Nit: delete the duplicate synthetic hierarchy case

I would keep the real SubgraphNode.getInnerNodes producer test instead. It already checks identity/title/name removal, including the delimiter-containing title, and the primitive boom 12 case independently protects numeric replacement. This copied hierarchy message adds no separate falsifier after composing those dimensions, and only the real producer catches message drift.

Suggested change
it('groups subgraph hierarchy recursion errors across ids, titles, names and depths', () => {
function hierarchyRecursionError(
depth: number,
nodeInfo: string,
subgraphName: string
) {
const error = new Error(
`Circular reference detected at depth ${depth} in node ${nodeInfo} of subgraph '${subgraphName}'. ` +
`This creates an infinite loop in the subgraph hierarchy.`
)
error.name = 'RecursionError'
return error
}
expect(
promptBuildErrorFingerprint(
hierarchyRecursionError(2, 'alpha (Load. Image)', 'Detailer')
)
).toEqual(
promptBuildErrorFingerprint(
hierarchyRecursionError(3, 'beta', 'Unnamed Subgraph')
)
)
})


it.for([
{ direction: 'input', path: '' },
{ direction: 'output', path: ' at path sub-a:sub-b' }
])(
'groups recursion errors across string node ids, titles and paths ($direction)',
({ direction, path }) => {
function recursionError(nodeInfo: string, uniqueId: string) {
const error = new Error(
`Circular reference detected while resolving ${direction} 0 of node ${nodeInfo}${path}. ` +
`This creates an infinite loop in link resolution. UniqueID: [${uniqueId}]`
)
error.name = 'RecursionError'
return error
}

expect(
promptBuildErrorFingerprint(
recursionError('alpha (Load. Image)', 'x:alpha[I]0')
)
).toEqual(
promptBuildErrorFingerprint(recursionError('beta', 'y:beta[I]0'))
)
}
)

it('groups errors that end with a string node id', () => {
expect(
promptBuildErrorFingerprint(
new TypeError('Node is not a subgraph node: alpha')
)
).toEqual(
promptBuildErrorFingerprint(
new TypeError('Node is not a subgraph node: beta')
)
)
})

it('uses the error name for values that are not errors', () => {
expect(promptBuildErrorFingerprint('boom 12')).toEqual([
'error_building_prompt',
'Error',
'boom N'
])
})
})
27 changes: 27 additions & 0 deletions src/utils/promptBuildErrorFingerprint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { toError } from '@comfyorg/shared-frontend-utils/errorUtil'

const IDENTITY_POSITIONS: readonly (readonly [RegExp, string])[] = [
[
/^(Circular reference detected while resolving (?:input|output) \d+ of node) [\s\S]*$/,
'$1 N'
],
[/ in node [\s\S]*? of subgraph [\s\S]*$/, ' in node N of subgraph N'],
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
[/\b(Subgraph)?Node \S+ has no graph/, '$1Node N has no graph'],
[
/^(No output node found for id \[[^\]]*\] slot \[[^\]]*\])\s+[\s\S]+$/,
'$1'
],
[/\[[^\]]*\]/g, '[]'],
Comment thread
christian-byrne marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Normalize all four input-name suffixes

I confirm the existing input-name finding and found one more affected format: No input node found for id [...] slot [...] ${input.name}. Calling the actual resolveInput missing-parent-link branch with width and height produces different fingerprints today. The missing-host-input, missing-outer-link and missing-origin-node formats retain names too, contrary to the one-group-per-failure-kind contract.

The suggestion covers all four prefixes without merging their failure kinds. Add one table in the existing producers suite that obtains these failures from resolveInput, varies the name and checks equal fingerprints. The current output-name case does not catch an implementation that normalizes only outputs; a second synthetic message table would retain the producer-drift problem raised separately.

Suggested change
[/\[[^\]]*\]/g, '[]'],
[
/^(No (?:link found in parent graph for id \[[^\]]*\] slot \[[^\]]*\]|input found for slot \[[^\]]*\]|outer link found for slot \[[^\]]*\]|input node found for id \[[^\]]*\] slot \[[^\]]*\]))\s+[\s\S]+$/,
'$1'
],
[/\[[^\]]*\]/g, '[]'],

[/: \S+$/, ': N'],
[/\d+/g, 'N']
]

/** Sentry fingerprint for a prompt build failure, with node ids, titles, subgraph names, paths and slot indexes removed. */
export function promptBuildErrorFingerprint(error: unknown): string[] {
const { name, message } = toError(error)
const shape = IDENTITY_POSITIONS.reduce(
(text, [position, placeholder]) => text.replace(position, placeholder),
message
)
return ['error_building_prompt', name, shape]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] Redact fingerprint components before sending them

I reproduced a new path around the existing telemetry privacy filter. A widget serializer can reject with Widget serializer failed for https://alice:password@files.example/image.png?token=privateAlpha#secretFragment. Passing that error and its fingerprint through the actual configured beforeSend removes credentials, token and fragment from exception.value but leaves the full URL in fingerprint. The focused boundary probe passed with both those assertions. These are synthetic credentials used for the probe.

The same error message is therefore safe in exception.value but leaks through the new fingerprint. The catch also handles extension/widget serializer exceptions, so stripping known DTO input names alone cannot fix this. Apply the existing redactTelemetryUrls policy to every fingerprint component, including the error name, and cover a credential-bearing serializer error at the configured Sentry boundary. A test that only inspects the redacted exception text misses this defect.

I am not providing a one-hunk suggestion because the preferred fix spans this new caller and the central initSentry redaction boundary and its tests. Keep URL redaction at that existing boundary rather than introducing a second sanitizer.

}
Loading