Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3a4b4a9
test: add failing test for agent delete-all leaving stale nodes on ca…
claude Sep 22, 2026
5f12a64
fix: retry agent reconcile promptly after a scope race, not just on t…
claude Sep 22, 2026
0dcf33e
fix: close reconcile-retry gaps found in review (reset, scope-only, l…
claude Sep 22, 2026
bddb824
Merge branch 'main' into fix/agent-delete-all-scope-drop-retry
christian-byrne Sep 23, 2026
aad1228
Merge remote-tracking branch 'origin/main' into takeover-18404
christian-byrne Sep 24, 2026
b5bbf7b
fix(agent): keep scope-race reconcile recovery armed
christian-byrne Sep 24, 2026
82e386d
test(agent): cover delete and clear canvas journeys
christian-byrne Sep 24, 2026
5a7e813
test(agent): satisfy full-repo lint for clear fixture
christian-byrne Sep 24, 2026
255dbbb
refactor(agent): isolate retry outcome handling
christian-byrne Sep 24, 2026
f57e02d
fix(agent): keep live-graph sweep armed and close retry test gaps
claude Sep 24, 2026
f15a709
test(agent): wait for the add frame to land before dropping scope
claude Sep 24, 2026
6159d0d
fix(agent): cancel and throttle live sweep retries
christian-byrne Sep 24, 2026
51b1061
Merge remote-tracking branch 'origin/main' into takeover-18404
christian-byrne Sep 24, 2026
ca0bd3a
test(agent): exercise scope-loss retry through tab closure
christian-byrne Sep 24, 2026
a7a2246
test(agent): lock retry provenance across interleaved frames
christian-byrne Sep 24, 2026
ce23c46
fix: make live-sweep retry scheduling idempotent, fix red projection …
claude Sep 24, 2026
1e0e21e
fix(agent): drop the cloud-name fallback too when simulating scope loss
claude Sep 24, 2026
a0feb23
refactor(test): extract branches in agentWorkflowScopeFixture to cut …
claude Sep 24, 2026
5691f1b
fix: harden agent scope recovery
ampagent Sep 25, 2026
62e40d7
Merge origin/main into fix/agent-delete-all-scope-drop-retry
ampagent Sep 25, 2026
ad6f36b
refactor(agent): split follower and harness branches for fallow
christian-byrne Sep 26, 2026
5b916de
Merge remote-tracking branch 'origin/main' into shepherd-18404-179048…
christian-byrne Sep 27, 2026
b6a464c
test(agent): adapt reconcile hook to replay options
christian-byrne Sep 27, 2026
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
193 changes: 166 additions & 27 deletions browser_tests/fixtures/agentConversationFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { z } from 'zod'
import { createI18n } from 'vue-i18n'

import enMessages from '@/locales/en/main.json' with { type: 'json' }
import type { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
import type { ComfyNodeDef, ObjectInfoResponse } from '@/schemas/nodeDefSchema'
import { toNodeId } from '@/types/nodeId'
import type {
Expand All @@ -16,12 +17,14 @@ import type {
import { parseAgentWsEvent } from '@/workbench/extensions/agent/schemas/agentApiSchema'
import { parseServerDocFrame } from '@/workbench/extensions/agent/crdt/docFrameClient'
import type { GraphOperation } from '@/workbench/extensions/agent/crdt/graphOperations'
import type { useAgentWorkflowTabBindingStore } from '@/workbench/extensions/agent/stores/agent/agentWorkflowTabBindingStore'

import {
agentTest,
bootAgentApp,
mockWorkflowPersistence
} from '@e2e/fixtures/agentPanelFixture'
import type { HostFrame } from '@e2e/fixtures/agentConversationHostDoc'
import { HostDoc } from '@e2e/fixtures/agentConversationHostDoc'
import { AgentFollowerHostSocket } from '@e2e/fixtures/agentFollowerHostSocket'
import type {
Expand Down Expand Up @@ -170,6 +173,35 @@ async function withTimeout(
}
}

type WorkflowBindingActions = Pick<
ReturnType<typeof useAgentWorkflowTabBindingStore>,
'tabPathFor'
>

type WorkflowLookup = Pick<
ReturnType<typeof useWorkflowStore>,
'getWorkflowByPath'
>

type WorkflowScopeAction =
| { kind: 'drop'; workflowId: string }
| {
kind: 'restore'
tabPath: string
graphId: string
}

interface DroppedWorkflowScope {
tabPath: string
graphId: string
}

interface ReplayResponseOptions {
beforeFirstGraphOps?: () => Promise<void>
beforeGraphOps?: (ops: readonly RecordedGraphOperation[]) => Promise<void>
waitForGraphOpsDelivery?: (ops: readonly RecordedGraphOperation[]) => boolean
}

// Runs one recorded prompt/response through the real panel over a routed /ws socket.
export class AgentConversationHarness {
readonly panel: Locator
Expand Down Expand Up @@ -341,7 +373,7 @@ export class AgentConversationHarness {

async replayResponse(
turn = 0,
beforeFirstGraphOps?: () => Promise<void>
options: ReplayResponseOptions = {}
): Promise<void> {
const startedAt = Date.now()
const response = this.conversation.turns[turn].response
Expand All @@ -354,8 +386,12 @@ export class AgentConversationHarness {
this.hostSocket.send(this.stampTurn(entry.event, turn))
else {
await this.hostSocket.waitForSubscribe()
if (index === firstGraphOps) await beforeFirstGraphOps?.()
this.hostSocket.send(this.host.apply(entry.ops))
if (index === firstGraphOps) await options.beforeFirstGraphOps?.()
await options.beforeGraphOps?.(entry.ops)
await this.sendHostFrame(
this.host.apply(entry.ops),
options.waitForGraphOpsDelivery?.(entry.ops) === true
)
for (const id of Object.keys(this.host.graph().nodes))
this.seenIds.add(id)
}
Expand All @@ -370,7 +406,7 @@ export class AgentConversationHarness {
for (const turn of this.conversation.turns.keys()) {
const before = await this.panelCounts()
await this.sendPrompt(turn)
await this.replayResponse(turn, beforeFirstGraphOps)
await this.replayResponse(turn, { beforeFirstGraphOps })
await this.waitForTurnComplete()
await this.expectTurnRendered(turn, before)
await this.expectCanvasReplayed(turn)
Expand Down Expand Up @@ -939,31 +975,115 @@ export class AgentConversationHarness {
await this.selectWorkflowTarget()
}

// Sends one more doc_update that resyncs `widget` on `nodeId` to its
// current doc value — the same effect on a live widget as a stale echo,
// a reconnect resync, or an unrelated full-graph reconcile has whenever
// that frame's changed-widgets sweep happens to touch it. Lets a test
// race this deterministically against a live keystroke instead of
// waiting on the timing a real run happens to produce.
async resyncWidget(nodeId: string, widget: string): Promise<void> {
const widgets = z
.record(z.string(), z.unknown())
.optional()
.parse(this.host.graph().nodes[nodeId]?.widgets)
const value = widgets?.[widget]
if (value === undefined)
throw new Error(`Host widget ${nodeId}.${widget} does not exist`)
const operation = {
op: 'set_widget',
node_id: nodeId,
widget,
value,
old: value
} satisfies GraphOperation
const frame = this.host.apply([operation])
async dropWorkflowScope(): Promise<() => Promise<void>> {
const workflowId = this.conversation.workflow.id
const dropped = await this.runWorkflowScopeAction({
kind: 'drop',
workflowId
})
if (!dropped)
throw new Error(`no bound tab path for workflow ${workflowId}`)

let restored = false
return async () => {
if (restored) return
await this.runWorkflowScopeAction({ kind: 'restore', ...dropped })
restored = true
}
}

async rememberRecoveryGraph(): Promise<void> {
await this.page.evaluate(() => {
if (!window.app?.rootGraph) throw new Error('root graph is unavailable')
window.__agentRecoveryGraph = window.app.rootGraph
})
}

async isRecoveryGraphUnchanged(): Promise<boolean> {
return await this.page.evaluate(
() => window.__agentRecoveryGraph === window.app?.rootGraph
)
}

private async runWorkflowScopeAction(
action: WorkflowScopeAction
): Promise<DroppedWorkflowScope | undefined> {
if (action.kind === 'drop')
return await this.dropWorkflowScopeInPage(action)
await this.restoreWorkflowScopeInPage(action)
return undefined
}

private async dropWorkflowScopeInPage(
action: Extract<WorkflowScopeAction, { kind: 'drop' }>
): Promise<DroppedWorkflowScope> {
return await this.page.evaluate((workflowId) => {
const isBinding = (value: unknown): value is WorkflowBindingActions =>
typeof value === 'object' &&
value !== null &&
'tabPathFor' in value &&
typeof value.tabPathFor === 'function'
const isWorkflowLookup = (value: unknown): value is WorkflowLookup =>
typeof value === 'object' &&
value !== null &&
'getWorkflowByPath' in value &&
typeof value.getWorkflowByPath === 'function'

const mount = document.getElementById('vue-app')
const pinia = mount?.__vue_app__?.config.globalProperties.$pinia
if (!pinia) throw new Error('Pinia is not mounted')
const stores = [...pinia._s.values()]
const binding = stores.find(isBinding)
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
const workflows = stores.find(isWorkflowLookup)
if (!binding)
throw new Error('agentWorkflowTabBinding store is not mounted')
if (!workflows) throw new Error('workflow store is not mounted')

const tabPath = binding.tabPathFor(workflowId)
if (!tabPath)
throw new Error(`no bound tab path for workflow ${workflowId}`)
const tab = workflows.getWorkflowByPath(tabPath)
if (!tab) throw new Error(`no open tab at ${tabPath}`)
const graphId = tab.activeState?.id
if (!graphId) throw new Error(`workflow at ${tabPath} has no graph id`)
delete tab.activeState?.id
return { tabPath, graphId }
}, action.workflowId)
}

private async restoreWorkflowScopeInPage(
action: Extract<WorkflowScopeAction, { kind: 'restore' }>
): Promise<void> {
await this.page.evaluate((action) => {
const isWorkflowLookup = (value: unknown): value is WorkflowLookup =>
typeof value === 'object' &&
value !== null &&
'getWorkflowByPath' in value &&
typeof value.getWorkflowByPath === 'function'
const mount = document.getElementById('vue-app')
const pinia = mount?.__vue_app__?.config.globalProperties.$pinia
if (!pinia) throw new Error('Pinia is not mounted')
const workflows = [...pinia._s.values()].find(isWorkflowLookup)
if (!workflows) throw new Error('workflow store is not mounted')
const tab = workflows.getWorkflowByPath(action.tabPath)
if (!tab) throw new Error(`no open tab at ${action.tabPath}`)
if (!tab.activeState)
throw new Error(`workflow at ${action.tabPath} has no active state`)
tab.activeState.id = action.graphId
}, action)
}

private async sendHostFrame(
frame: HostFrame,
waitForDelivery = false
): Promise<void> {
if (!waitForDelivery) {
this.hostSocket.send(frame)
return
}
const parsedFrame = parseServerDocFrame(frame)
if (parsedFrame?.type !== 'doc_update')
throw new Error('Host widget resync did not produce a doc_update')
throw new Error('Host operation did not produce a doc_update')

const receipt = crypto.randomUUID()
await this.page.evaluate(
Expand Down Expand Up @@ -1015,6 +1135,25 @@ export class AgentConversationHarness {
}, receipt)
}
}

async resyncWidget(nodeId: string, widget: string): Promise<void> {
const widgets = z
.record(z.string(), z.unknown())
.optional()
.parse(this.host.graph().nodes[nodeId]?.widgets)
const value = widgets?.[widget]
if (value === undefined)
throw new Error(`Host widget ${nodeId}.${widget} does not exist`)
const operation = {
op: 'set_widget',
node_id: nodeId,
widget,
value,
old: value
} satisfies GraphOperation
const frame = this.host.apply([operation])
await this.sendHostFrame(frame, true)
}
}

export type ReplayTiming = 'immediate' | 'recorded'
Expand Down
16 changes: 9 additions & 7 deletions browser_tests/tests/agent/agentCrdtReconcileOverwrite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,15 @@ test.describe(

await agentConversation.sendPrompt(0)

await agentConversation.replayResponse(0, async () => {
await test.step('the user completes and leaves a widget edit', async () => {
await textField.fill(localValue)
await textField.press('Tab')
await expect(textField).not.toBeFocused()
await expect(textField).toHaveValue(localValue)
})
await agentConversation.replayResponse(0, {
beforeFirstGraphOps: async () => {
await test.step('the user completes and leaves a widget edit', async () => {
await textField.fill(localValue)
await textField.press('Tab')
await expect(textField).not.toBeFocused()
await expect(textField).toHaveValue(localValue)
})
}
})
await agentConversation.waitForTurnComplete()

Expand Down
85 changes: 85 additions & 0 deletions browser_tests/tests/agent/agentDeleteAndClearWorkflow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { expect } from '@playwright/test'

import { agentConversationTest as test } from '@e2e/fixtures/agentConversationFixture'
import type { RecordedGraphOperation } from '@e2e/fixtures/data/agent/agentConversation'

test.describe(
'Agent delete and clear operations',
{ tag: ['@cloud', '@vue-nodes'] },
() => {
test.describe('delete_node', () => {
test.use({ conversationCase: 'agent-rec-add-set-delete' })

test('removes the requested node while preserving the workflow', async ({
agentConversation
}) => {
test.setTimeout(90_000)

await agentConversation.rememberRecoveryGraph()
await agentConversation.runTurns()
expect(await agentConversation.isRecoveryGraphUnchanged()).toBe(true)
})
})

test.describe('clear_canvas', () => {
test.use({ conversationCase: 'agent-rec-clear-workflow' })

test('leaves the canvas empty after clearing the workflow', async ({
agentConversation
}) => {
test.setTimeout(90_000)

await agentConversation.rememberRecoveryGraph()
await agentConversation.runTurns()
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
expect(await agentConversation.isRecoveryGraphUnchanged()).toBe(true)
})

test('clears the canvas on its own after the clear frame is rejected for a dropped workflow scope', async ({
agentConversation
}) => {
test.setTimeout(90_000)
let restoreScope: (() => Promise<void>) | undefined
const isClear = (ops: readonly RecordedGraphOperation[]) =>
ops.some((op) => op.op === 'clear')

await agentConversation.rememberRecoveryGraph()
try {
await test.step('deliver the clear while workflow scope is unavailable', async () => {
await agentConversation.sendPrompt(0)
await agentConversation.replayResponse(0, {
beforeGraphOps: async (ops) => {
if (!isClear(ops)) return
await expect(agentConversation.vueNodes.nodes).not.toHaveCount(
0
)
restoreScope = await agentConversation.dropWorkflowScope()
},
waitForGraphOpsDelivery: isClear
})
})

if (!restoreScope)
throw new Error('the clear frame never dropped workflow scope')
const restore = restoreScope

await test.step('keep the same graph stale after the rejected clear', async () => {
await expect(agentConversation.vueNodes.nodes).not.toHaveCount(0)
expect(await agentConversation.isRecoveryGraphUnchanged()).toBe(
true
)
})

await test.step('clear without another frame when scope returns', async () => {
await restore()
await expect(agentConversation.vueNodes.nodes).toHaveCount(0)
expect(await agentConversation.isRecoveryGraphUnchanged()).toBe(
true
)
})
} finally {
await restoreScope?.()
}
})
})
}
)
Loading
Loading