Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5366,6 +5366,9 @@
"workflowReferenceUnavailableReason": "This referenced workflow is no longer available or you do not have access to it.",
"removeWorkflowReference": "Remove {name} reference",
"targetNavigationUnavailable": "This workflow target is no longer available.",
"workflowSyncFailedTitle": "This workflow can't sync",
"workflowSyncFailedDetail": "This workflow was created with an incompatible document version. Your canvas has been left unchanged.",
"workflowSyncFailedDetailCatalogMismatch": "This workflow uses a node catalog that is incompatible with this workspace. Your canvas has been left unchanged.",
"runModeTriggerAutoLimit": "Auto (limited)",
"runModeTriggerAutoLimitTooltip": "Ask when credit limit is reached",
"showMore": "Show more",
Expand Down
28 changes: 27 additions & 1 deletion src/workbench/extensions/agent/AgentPanelRoot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ const ws = vi.hoisted(() => {
listeners.get(type)?.delete(listener)
}
const emit = (type: string, data?: unknown): void => {
for (const listener of listeners.get(type) ?? []) listener({ detail: data })
// The doc-frame pipeline ignores events that are not CustomEvent instances.
const event = new CustomEvent(type, { detail: data })
for (const listener of listeners.get(type) ?? []) listener(event)
}
const clear = (): void => listeners.clear()
return { add, remove, emit, clear }
Expand Down Expand Up @@ -4342,6 +4344,30 @@ describe('AgentPanelRoot workflow binding', () => {
).toBeInTheDocument()
})

it('shows a sticky error toast when the doc-host permanently refuses the subscribe', async () => {
makeTab('wf-42')
mockMessagesEndpoint('wf-42')

await renderAndSend('add a node')

ws.emit('doc_subscribed', {
v: 1,
workflow_id: 'wf-42',
ok: false,
code: 'schema_version_mismatch',
message: 'Expected schema 2, found 1'
})

expect(useToastStore().messagesToAdd).toContainEqual(
expect.objectContaining({
severity: 'error',
summary: i18n.global.t('agent.workflowSyncFailedTitle'),
detail: `${i18n.global.t('agent.workflowSyncFailedDetail')} (Expected schema 2, found 1)`,
life: 0
})
)
})

it('moves the spinner to the tab the agent creates mid-turn', async () => {
makeTab('wf-42')
mockMessagesEndpoint('wf-42')
Expand Down
11 changes: 10 additions & 1 deletion src/workbench/extensions/agent/AgentPanelRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useTelemetry } from '@/platform/telemetry'
import { useSettingStore } from '@/platform/settings/settingStore'
import type { LiveAutogrowGroupAnswer } from '@/workbench/extensions/agent/crdt/graphMutations'
import { createGraphMutations } from '@/workbench/extensions/agent/crdt/graphMutations'
import { formatWorkflowSyncErrorDetail } from '@/workbench/extensions/agent/crdt/workflowSyncErrorDetail'
import { useWorkflowService } from '@/platform/workflow/core/services/workflowService'
import type { ComfyWorkflow } from '@/platform/workflow/management/stores/comfyWorkflow'
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
Expand Down Expand Up @@ -684,7 +685,15 @@ const {
if (status.value === 'idle') graphActivity.finishTurn()
}
},
onReset: graphActivity.resetWorkflow
onReset: graphActivity.resetWorkflow,
onSyncError: (message, code) =>
toast.add({
severity: 'error',
summary: t('agent.workflowSyncFailedTitle'),
detail: formatWorkflowSyncErrorDetail(t, message, code),
// A permanent desync remains visible until the person dismisses it.
life: 0
})
}
)
// The bound document's serialized root graph id, independent of what is
Expand Down
220 changes: 220 additions & 0 deletions src/workbench/extensions/agent/crdt/agentCrdtDocLifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,223 @@ describe('AgentCrdtDocLifecycle refusal exhaustion', () => {
])
})
})

describe('AgentCrdtDocLifecycle schema_version_mismatch refusal', () => {
beforeEach(() => {
vi.useFakeTimers()
})

it('gives up immediately with no retry and reports it once', () => {
const { lifecycle, resubscribe, onGaveUp } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)

lifecycle.onSubscribeRefused('schema_version_mismatch')
vi.advanceTimersByTime(10 * SUBSCRIBE_ACK_TIMEOUT_MS)

expect(resubscribe).not.toHaveBeenCalled()
expect(onGaveUp).toHaveBeenCalledTimes(1)
expect(lifecycle.shouldDeferSubscribe()).toBe(true)
expect(reportError).toHaveBeenCalledExactlyOnceWith(
expect.any(Error),
GAVE_UP_REPORT
)
expect(devEvents()).toEqual([
{
kind: 'subscribe_refused_permanent',
detail: { code: 'schema_version_mismatch', terminal: true }
}
])
})

it('a different refusal code still retries with backoff', () => {
const { lifecycle, resubscribe, onGaveUp } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)

lifecycle.onSubscribeRefused('doc_not_found')
vi.advanceTimersByTime(500)

expect(resubscribe).toHaveBeenCalledTimes(1)
expect(onGaveUp).not.toHaveBeenCalled()
expect(reportError).not.toHaveBeenCalled()
})

it('a reconnect releases the permanent give-up latch', () => {
const { lifecycle, resubscribe, onGaveUp } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeRefused('schema_version_mismatch')
expect(onGaveUp).toHaveBeenCalledTimes(1)

lifecycle.onReconnected()
lifecycle.onSubscribeSent(WORKFLOW_ID)
vi.advanceTimersByTime(SUBSCRIBE_ACK_TIMEOUT_MS)

expect(resubscribe).toHaveBeenCalledTimes(1)
})

it('a redelivered refusal after already giving up does not re-run the latch', () => {
const { lifecycle, onGaveUp } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeRefused('schema_version_mismatch')
expect(onGaveUp).toHaveBeenCalledTimes(1)
expect(reportError).toHaveBeenCalledTimes(1)
vi.mocked(recordDevEvent).mockClear()

// A duplicate/redelivered doc_subscribed refusal frame for the same,
// already-latched attempt must not double the toast/telemetry.
lifecycle.onSubscribeRefused('schema_version_mismatch')

expect(onGaveUp).toHaveBeenCalledTimes(1)
expect(reportError).toHaveBeenCalledTimes(1)
expect(devEvents()).toEqual([])
})

it('giving up permanently cancels an already-armed retryable backoff', () => {
const { lifecycle, resubscribe } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)
// Schedules a 500 ms retryable backoff.
lifecycle.onSubscribeRefused('doc_not_found')
// A later permanent refusal must cancel that still-armed timer, not let
// it fire a resubscribe after the channel has been given up on.
lifecycle.onSubscribeRefused('schema_version_mismatch')

vi.advanceTimersByTime(10 * SUBSCRIBE_ACK_TIMEOUT_MS)

expect(resubscribe).not.toHaveBeenCalled()
})

it.for(['schema_version_mismatch', 'catalog_mismatch'] as const)(
'%s gives up immediately with no retry and reports it once',
(code) => {
const { lifecycle, resubscribe, onGaveUp } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)

lifecycle.onSubscribeRefused(code)
vi.advanceTimersByTime(10 * SUBSCRIBE_ACK_TIMEOUT_MS)

expect(resubscribe).not.toHaveBeenCalled()
expect(onGaveUp).toHaveBeenCalledTimes(1)
expect(lifecycle.shouldDeferSubscribe()).toBe(true)
expect(reportError).toHaveBeenCalledExactlyOnceWith(
expect.any(Error),
GAVE_UP_REPORT
)
expect(devEvents()).toEqual([
{
kind: 'subscribe_refused_permanent',
detail: { code, terminal: true }
}
])
}
)

it('unsupported gives up immediately with no retry but never notifies', () => {
const { lifecycle, resubscribe, onGaveUp } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)

lifecycle.onSubscribeRefused('unsupported')
vi.advanceTimersByTime(10 * SUBSCRIBE_ACK_TIMEOUT_MS)

expect(resubscribe).not.toHaveBeenCalled()
expect(lifecycle.shouldDeferSubscribe()).toBe(true)
expect(onGaveUp).not.toHaveBeenCalled()
expect(reportError).not.toHaveBeenCalled()
expect(devEvents()).toEqual([])
})

it('a reconnect does not re-notify a permanent refusal for the same workflow', () => {
const { lifecycle, onGaveUp } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeRefused('schema_version_mismatch')
expect(onGaveUp).toHaveBeenCalledTimes(1)
expect(reportError).toHaveBeenCalledTimes(1)

lifecycle.onReconnected()
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeRefused('schema_version_mismatch')

expect(onGaveUp).toHaveBeenCalledTimes(1)
expect(reportError).toHaveBeenCalledTimes(1)

lifecycle.onReconnected()
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeRefused('schema_version_mismatch')

expect(onGaveUp).toHaveBeenCalledTimes(1)
expect(reportError).toHaveBeenCalledTimes(1)
})

it('a successful confirm after a permanent refusal re-arms notification for a later independent refusal', () => {
const { lifecycle, onGaveUp } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeRefused('schema_version_mismatch')
expect(onGaveUp).toHaveBeenCalledTimes(1)
expect(reportError).toHaveBeenCalledTimes(1)

// The reconnect recovers this time: the doc-host confirms the subscribe.
lifecycle.onReconnected()
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeConfirmed()

// A later, independent permanent refusal for the SAME workflow is a new
// failure episode, not a duplicate of the one already reported - it
// must notify again rather than being suppressed by the stale marker.
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeRefused('schema_version_mismatch')

expect(onGaveUp).toHaveBeenCalledTimes(2)
expect(reportError).toHaveBeenCalledTimes(2)
})

it('a stale permanent refusal answering a superseded attempt does not undo a confirm that already won', () => {
const { lifecycle, resubscribe, onGaveUp } = wire()
// Attempt 1 leaves the transport and gets no answer within the ack
// budget, so the timeout fires a second attempt while attempt 1 is
// still outstanding at the doc-host.
lifecycle.onSubscribeSent(WORKFLOW_ID)
vi.advanceTimersByTime(SUBSCRIBE_ACK_TIMEOUT_MS)
expect(resubscribe).toHaveBeenCalledTimes(1)

// Attempt 2 confirms first - the channel is healthy again.
lifecycle.onSubscribeConfirmed()
expect(lifecycle.shouldDeferSubscribe()).toBe(false)

// Attempt 1's answer finally lands, refusing permanently. It cannot be
// answering attempt 2 (which already confirmed), so it must be
// attempt 1's stale answer - it must not undo the confirmed channel.
const notified = lifecycle.onSubscribeRefused('schema_version_mismatch')

expect(notified).toBe(false)
expect(onGaveUp).not.toHaveBeenCalled()
expect(reportError).not.toHaveBeenCalled()
expect(lifecycle.shouldDeferSubscribe()).toBe(false)
expect(devEvents()).toEqual([
{
kind: 'subscribe_ack_timeout',
detail: { attempt: 1, workflowId: WORKFLOW_ID }
}
])

// A genuinely new failure after a fresh send still latches normally.
lifecycle.onSubscribeSent(WORKFLOW_ID)
const notifiedAgain = lifecycle.onSubscribeRefused(
'schema_version_mismatch'
)
expect(notifiedAgain).toBe(true)
expect(onGaveUp).toHaveBeenCalledTimes(1)
})

it('clearForRetarget re-arms notification for the same workflow id', () => {
const { lifecycle, onGaveUp } = wire()
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeRefused('schema_version_mismatch')
expect(onGaveUp).toHaveBeenCalledTimes(1)
expect(reportError).toHaveBeenCalledTimes(1)

lifecycle.clearForRetarget()
lifecycle.onSubscribeSent(WORKFLOW_ID)
lifecycle.onSubscribeRefused('schema_version_mismatch')

expect(onGaveUp).toHaveBeenCalledTimes(2)
expect(reportError).toHaveBeenCalledTimes(2)
})
})
Loading
Loading