From 8ddda6cb61a73013b78f8df5564ad888efa111aa Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 1 Nov 2026 06:01:50 -0800 Subject: [PATCH] fix(agent): re-send the canvas whenever an unsaved tab's remembered workflow is not its own (PM-2401) (#22518) The agent could still read an old graph on an unsaved tab in three rarer cases. Fixed. - Chat's workflow tab closed: the canvas is now sent, not the old workflow - No canvas available: the send is held and the message stays in the composer - Reply with no adoptable workflow: the tab no longer mints a new one each turn - Blank tab after the chat's tab closed: stays on the chat's workflow Linear: https://linear.app/comfyorg/issue/PM-2401
Full context for agent readers ## Summary Follow-up to https://github.com/Comfy-Org/ComfyUI_frontend/pull/22310, which re-sent the canvas only when the session's bound workflow was still open in another tab. These are the three edges cursor-review raised on that PR. ## Changes - **What**: `isUnboundTarget` no longer needs the bound workflow to appear in `open_tabs` when the tab has content. A selected tab with no cloud id has no workflow of its own, so with a draft holding nodes or groups the turn carries `current_tab_unbound` and the draft. A blank tab whose bound workflow is open nowhere keeps today's thread fallback: minting would replace a built thread workflow with an empty one. A blank tab whose bound workflow is open elsewhere still re-flags, as #22310 does. - **Mint memo**: `unadoptedMintBinding` records, per tab path, the binding at the reply to a mint the tab did not adopt. Such a tab does not re-flag while the binding is unchanged, so there is no one-workflow-per-turn loop. An id with a tab binding is not recorded: an adopted mint shows in the binding, and temp-tab paths are reused after close. Cleared with the binding by `newChat`, `loadThread` and a deleted thread. The memo lives with the session: after a panel remount an unadopted mint can re-mint once. - **Hold**: a continuing turn from such a tab with no canvas is refused with the existing `agent.targetNavigationUnavailable` failure instead of silently retargeting. `current_tab_unbound` without a draft would mint an empty workflow, so sending is not an option. `performSend` returns false, so the composer keeps the text. - `postTurn` now takes the built input so `performSend` can read whether the turn was flagged. - **Tests**: red on `main`, green here: `(h10b)` hold, `(h10e)` closed tab re-flags, `(h10f)` reply without an id does not re-flag. Added after adversarial review, red before the second commit: `(h10e2)` blank tab keeps the thread workflow, `(h10e3)` reused path of a closed adopted tab mints for itself. Guards: `(h10d)` unadopted mint not re-minted, `(h10g)` new chat clears the memo. ## Review Focus - Accepted cost, per the ticket: renaming a bound unsaved tab loses its binding, so the next turn mints a copy of that tab's canvas and leaves the old draft workflow orphaned. - Held sends apply only when the host provides a canvas reader. They reuse the existing "target no longer available" text to keep this PR inside the agent paths. `draft` is undefined only when the tab has no `activeState`. - Not changed: a flagged first turn (nothing bound) with no draft can still mint empty. Same as `main`. - After a reply with no id, later turns on that tab send neither flag nor draft. The server (`agent_handler.go`) always returns `workflow_id`, so this is a loop guard only.
--- .../composables/agent/useAgentSession.test.ts | 302 +++++++++++++++++- .../composables/agent/useAgentSession.ts | 150 ++++++--- 2 files changed, 399 insertions(+), 53 deletions(-) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts index a072e4e8c0a..7a1acd4f3d5 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts @@ -54,7 +54,11 @@ import { useAgentSendGateStore } from '@/workbench/extensions/agent/stores/agent import { useAgentWorkflowTabBindingStore } from '@/workbench/extensions/agent/stores/agent/agentWorkflowTabBindingStore' import type { SelectedNode } from './useCanvasSelection' -import type { AgentEventSource, TurnOrigin } from './useAgentSession' +import type { + AgentEventSource, + TurnOrigin, + WorkflowTurnContext +} from './useAgentSession' import { useAgentSession } from './useAgentSession' vi.mock(import('@/platform/telemetry/reportError')) @@ -4953,6 +4957,71 @@ describe('useAgentSession (v1 composition root)', () => { expect(session.notices.value).toEqual([]) }) + it('(g11a) a deleted thread invalidates an in-flight send before its acknowledgement', async () => { + let resolvePost: ((ack: AgentTurnAccepted) => void) | undefined + const postMessage = vi + .fn() + .mockResolvedValueOnce({ + thread_id: 'th-1', + message_id: 'msg-1', + workflow_id: 'wf-bound' + }) + .mockImplementationOnce( + () => + new Promise((resolve) => { + resolvePost = resolve + }) + ) + .mockResolvedValueOnce({ + thread_id: 'th-2', + message_id: 'msg-3', + workflow_id: 'wf-fresh' + }) + const rest = fakeRest({ + postMessage, + getMessages: vi.fn(async (): Promise => { + throw new AgentApiError('gone', 404, undefined) + }) + }) + const { source, emit, status } = fakeEvents() + let target: WorkflowTurnContext = { + id: 'wf-bound', + tabPath: 'workflows/bound.json' + } + const session = useAgentSession({ + rest, + events: source, + workflow: { + current: () => target, + adopted: vi.fn(), + draft: () => ({ content: { nodes: [{ id: 1 }], links: [] } }) + } + }) + session.start() + status(true) + + await session.sendMessage('first') + emit(delta('msg-1', 'partial')) + target = { tabPath: 'workflows/Unsaved Workflow.json' } + const staleSend = session.sendMessage('second') + await vi.waitFor(() => expect(postMessage).toHaveBeenCalledTimes(2)) + + status(false) + status(true) + await vi.waitFor(() => expect(session.threadId.value).toBeNull()) + resolvePost?.({ + thread_id: 'th-1', + message_id: 'msg-2', + workflow_id: 'wf-minted' + }) + + await expect(staleSend).resolves.toBe(false) + expect(session.threadId.value).toBeNull() + await session.sendMessage('start over') + expect(postMessage.mock.calls[2][0]).toBe('new') + expect(postMessage.mock.calls[2][1].currentTabUnbound).toBe(true) + }) + it('(g15) a deleted team-workspace thread is forgotten without touching another workspace', async () => { sessionStorage.setItem( 'Comfy.Workspace.Current', @@ -5562,6 +5631,7 @@ describe('useAgentSession (v1 composition root)', () => { draft: () => DraftSnapshot | undefined tabs?: () => OpenTabsSnapshot | undefined adoptIntoStore?: boolean + currentTabPath?: () => string }) { const postMessage = vi.fn() options.acks.forEach((workflowId, index) => @@ -5573,12 +5643,13 @@ describe('useAgentSession (v1 composition root)', () => { ) const bindingStore = useAgentWorkflowTabBindingStore() bindingStore.bind('wf-other-tab', 'workflows/other.json') - const tabPath = 'workflows/Unsaved Workflow.json' + const defaultTabPath = 'workflows/Unsaved Workflow.json' const session = useAgentSession({ rest: fakeRest({ postMessage }), events: fakeEvents().source, workflow: { current: () => { + const tabPath = options.currentTabPath?.() ?? defaultTabPath const id = bindingStore.workflowIdFor(tabPath) return id === undefined ? { tabPath } : { id, tabPath } }, @@ -5591,14 +5662,15 @@ describe('useAgentSession (v1 composition root)', () => { } }) session.start() - return { session, postMessage } + return { session, postMessage, bindingStore } } it('(h10) a continuing turn re-flags a tab that never adopted the workflow another tab holds, with its draft', async () => { const draftSnapshot = { content: { nodes: [], links: [] } } + const draft = vi.fn(() => draftSnapshot) const { session, postMessage } = unboundTabSession({ acks: ['wf-other-tab', 'wf-minted'], - draft: () => draftSnapshot + draft }) await session.sendMessage('add a text input node') @@ -5608,21 +5680,22 @@ describe('useAgentSession (v1 composition root)', () => { expect(second).not.toHaveProperty('workflowId') expect(second.currentTabUnbound).toBe(true) expect(second.draft).toEqual(draftSnapshot) + expect(draft).toHaveBeenCalledTimes(2) }) - it('(h10b) a continuing turn with no draft is not re-flagged, so it cannot mint an empty workflow', async () => { + it('(h10b) a continuing turn with no canvas is held instead of retargeting the remembered workflow', async () => { let draft: DraftSnapshot | undefined = { content: { nodes: [], links: [] } } const { session, postMessage } = unboundTabSession({ - acks: ['wf-other-tab', 'wf-other-tab'], + acks: ['wf-other-tab'], draft: () => draft }) await session.sendMessage('add a text input node') draft = undefined - await session.sendMessage('and a load image node') + const sent = await session.sendMessage('and a load image node') - expect(postMessage.mock.calls[1][1]).not.toHaveProperty('currentTabUnbound') - expect(postMessage.mock.calls[1][1]).not.toHaveProperty('draft') + expect(sent).toBe(false) + expect(postMessage).toHaveBeenCalledTimes(1) }) it('(h10c) once the re-flagged mint is adopted, the next turn names it instead of minting again', async () => { @@ -5642,9 +5715,9 @@ describe('useAgentSession (v1 composition root)', () => { expect(third.workflowId).toBe('wf-minted') }) - it('(h10d) a continuing turn is not re-flagged when the bound workflow is open in no tab', async () => { + it('(h10d) a mint the tab could not adopt is not minted again', async () => { const { session, postMessage } = unboundTabSession({ - acks: ['wf-closed', 'wf-closed'], + acks: ['wf-minted', 'wf-minted'], draft: () => ({ content: { nodes: [], links: [] } }), tabs: () => ({ open_tabs: [] }) }) @@ -5656,6 +5729,213 @@ describe('useAgentSession (v1 composition root)', () => { expect(postMessage.mock.calls[1][1]).not.toHaveProperty('currentTabUnbound') }) + it('(h10e) a continuing turn re-flags the tab once the tab holding the remembered workflow has closed', async () => { + const draftSnapshot = { content: { nodes: [{ id: 1 }], links: [] } } + const { session, postMessage, bindingStore } = unboundTabSession({ + acks: ['wf-other-tab', 'wf-minted'], + draft: () => draftSnapshot, + tabs: () => ({ open_tabs: [] }) + }) + + await session.sendMessage('add a text input node') + bindingStore.unbindWorkflow('wf-other-tab') + await session.sendMessage('and a load image node') + + const second = postMessage.mock.calls[1][1] + expect(second).not.toHaveProperty('workflowId') + expect(second.currentTabUnbound).toBe(true) + expect(second.draft).toEqual(draftSnapshot) + }) + + it('(h10e2) a blank tab keeps the thread workflow once the tab holding it has closed', async () => { + const { session, postMessage, bindingStore } = unboundTabSession({ + acks: ['wf-other-tab', 'wf-other-tab'], + draft: () => ({ content: { nodes: [], links: [] } }), + tabs: () => ({ open_tabs: [] }) + }) + + await session.sendMessage('build a workflow') + bindingStore.unbindWorkflow('wf-other-tab') + await session.sendMessage('now add a sampler') + + expect(postMessage.mock.calls[1][1]).not.toHaveProperty('currentTabUnbound') + expect(postMessage.mock.calls[1][1]).not.toHaveProperty('draft') + }) + + it('(h10e2b) a tab holding only a group is not blank', async () => { + let currentTabPath = 'workflows/other.json' + const draftSnapshot = { + content: { nodes: [], links: [], groups: [{ id: 1 }] } + } + const { session, postMessage, bindingStore } = unboundTabSession({ + acks: ['wf-other-tab', 'wf-minted'], + draft: () => draftSnapshot, + tabs: () => ({ open_tabs: [] }), + currentTabPath: () => currentTabPath + }) + + await session.sendMessage('build a workflow') + currentTabPath = 'workflows/Unsaved Workflow.json' + bindingStore.unbindWorkflow('wf-other-tab') + await session.sendMessage('what is in the group?') + + expect(postMessage.mock.calls[1][1].currentTabUnbound).toBe(true) + }) + + it('(h10e3) a new tab reusing the path of a closed adopted tab mints for itself', async () => { + const draftSnapshot = { content: { nodes: [{ id: 1 }], links: [] } } + const { session, postMessage, bindingStore } = unboundTabSession({ + acks: ['wf-minted', 'wf-minted', 'wf-reused'], + draft: () => draftSnapshot, + adoptIntoStore: true + }) + + await session.sendMessage('add a text input node') + await session.sendMessage('and a load image node') + bindingStore.unbindWorkflow('wf-minted') + await session.sendMessage('and a sampler') + + const third = postMessage.mock.calls[2][1] + expect(third.currentTabUnbound).toBe(true) + expect(third.draft).toEqual(draftSnapshot) + }) + + it('(h10f) a reply without a workflow id does not mint again on every later turn', async () => { + const postMessage = vi.fn(async () => ({ + thread_id: 'th-9', + message_id: 'msg-1' + })) + const session = useAgentSession({ + rest: fakeRest({ postMessage }), + events: fakeEvents().source, + workflow: { + current: () => ({ tabPath: 'workflows/Unsaved Workflow.json' }), + adopted: vi.fn(), + draft: () => ({ content: { nodes: [], links: [] } }) + } + }) + session.start() + + await session.sendMessage('add a text input node') + await session.sendMessage('and a load image node') + + expect(postMessage.mock.calls[0][1].currentTabUnbound).toBe(true) + expect(postMessage.mock.calls[1][1]).not.toHaveProperty('currentTabUnbound') + }) + + function movableTabSession(acks: (string | undefined)[]) { + const postMessage = vi.fn() + acks.forEach((workflowId, index) => + postMessage.mockResolvedValueOnce({ + thread_id: 'th-9', + message_id: `msg-${index + 1}`, + ...(workflowId === undefined ? {} : { workflow_id: workflowId }) + }) + ) + const target: { context: WorkflowTurnContext } = { + context: { id: 'wf-a', tabPath: 'workflows/a.json' } + } + const canvas: { draft: DraftSnapshot | undefined } = { + draft: { content: { nodes: [{ id: 1 }], links: [] } } + } + const session = useAgentSession({ + rest: fakeRest({ postMessage }), + events: fakeEvents().source, + workflow: { + current: () => target.context, + adopted: vi.fn(), + draft: () => canvas.draft + } + }) + session.start() + return { session, postMessage, target, canvas } + } + + it('(h10f2) an id-less reply stops suppressing the mint once the binding moves', async () => { + const { session, postMessage, target } = movableTabSession([ + 'wf-a', + undefined, + 'wf-b', + 'wf-minted' + ]) + const unsaved = { tabPath: 'workflows/Unsaved Workflow.json' } + + await session.sendMessage('on a') + target.context = unsaved + await session.sendMessage('on the unsaved tab') + target.context = { id: 'wf-b', tabPath: 'workflows/b.json' } + await session.sendMessage('on b') + target.context = unsaved + await session.sendMessage('back on the unsaved tab') + + expect(postMessage.mock.calls[1][1].currentTabUnbound).toBe(true) + expect(postMessage.mock.calls[3][1].currentTabUnbound).toBe(true) + }) + + it('(h10f3) a tab with a recorded mint still holds a send with no canvas', async () => { + const { session, postMessage, target, canvas } = movableTabSession([ + 'wf-a', + undefined + ]) + + await session.sendMessage('on a') + target.context = { tabPath: 'workflows/Unsaved Workflow.json' } + await session.sendMessage('on the unsaved tab') + canvas.draft = undefined + const sent = await session.sendMessage('with no canvas') + + expect(sent).toBe(false) + expect(postMessage).toHaveBeenCalledTimes(2) + }) + + it('(h10f4) a host with no canvas provider still sends', async () => { + const postMessage = vi.fn(async () => ({ + thread_id: 'th-9', + message_id: 'msg-1', + workflow_id: 'wf-a' + })) + let context: WorkflowTurnContext = { + id: 'wf-a', + tabPath: 'workflows/a.json' + } + const session = useAgentSession({ + rest: fakeRest({ postMessage }), + events: fakeEvents().source, + workflow: { current: () => context, adopted: vi.fn() } + }) + session.start() + + await session.sendMessage('on a') + context = { tabPath: 'workflows/Unsaved Workflow.json' } + + expect(await session.sendMessage('on the unsaved tab')).toBe(true) + }) + + it('(h10g) a new chat forgets the mint a tab already requested', async () => { + const postMessage = vi.fn(async () => ({ + thread_id: 'th-9', + message_id: 'msg-1' + })) + const conversation = useAgentConversationStore() + const session = useAgentSession({ + rest: fakeRest({ postMessage }), + events: fakeEvents().source, + workflow: { + current: () => ({ tabPath: 'workflows/Unsaved Workflow.json' }), + adopted: vi.fn(), + draft: () => ({ content: { nodes: [], links: [] } }) + } + }) + session.start() + + await session.sendMessage('add a text input node') + session.newChat() + conversation.setThreadId('th-10') + await session.sendMessage('start over') + + expect(postMessage.mock.calls[1][1].currentTabUnbound).toBe(true) + }) + const LINKED_DRAFT: DraftSnapshot = { content: { nodes: [ diff --git a/src/workbench/extensions/agent/composables/agent/useAgentSession.ts b/src/workbench/extensions/agent/composables/agent/useAgentSession.ts index 418a57d1e08..cc9cf69ed20 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.ts @@ -531,6 +531,8 @@ export function useAgentSession(deps: AgentSessionDeps) { */ const boundWorkflowId = ref(rememberedWorkflowId) + const unadoptedMintBinding = new Map() + /** * H8 reporting state, kept beside the binding it describes: the workflow * last reported for the current thread (suppresses the ack's re-report of a @@ -636,6 +638,12 @@ export function useAgentSession(deps: AgentSessionDeps) { ) } + function forgetBinding(): void { + boundWorkflowId.value = null + rememberedWorkflowId = null + unadoptedMintBinding.clear() + } + function initializeWorkflowContext(hasThread: boolean): void { workflow?.initialize?.(hasThread) // The binding only outlives a remount together with its thread: a page @@ -1010,28 +1018,24 @@ export function useAgentSession(deps: AgentSessionDeps) { ) } - function postTurn( - threadId: string, + function refusesTarget( text: string, - origin: TurnOrigin, + originContext: WorkflowTurnContext | undefined, wfContext: WorkflowTurnContext | undefined, - attachments?: SentAttachment[], - tags?: SentTag[], - workflowReferences?: WorkflowReference[], - selectionWorkflowId?: () => string | undefined, - clientMessageId?: string + draft: DraftSnapshot | undefined + ): boolean { + const refused = + workflowTargetChanged(originContext, wfContext) || + lacksCanvasForRemint(wfContext, draft) + if (refused) recordUnavailableTarget(text) + return refused + } + + function postTurn( + threadId: string, + input: PostMessageInput, + wfContext: WorkflowTurnContext | undefined ): Promise { - const input = buildPostInput( - threadId, - text, - origin, - wfContext, - attachments, - tags, - workflowReferences, - selectionWorkflowId, - clientMessageId - ) if (wfContext?.id === undefined) return rest.postMessage(threadId, input) return rest.postMessage(threadId, { ...input, workflowId: wfContext.id }) } @@ -1041,13 +1045,13 @@ export function useAgentSession(deps: AgentSessionDeps) { text: string, origin: TurnOrigin, wfContext: WorkflowTurnContext | undefined, + draft: DraftSnapshot | undefined, attachments?: SentAttachment[], tags?: SentTag[], workflowReferences?: WorkflowReference[], selectionWorkflowId?: () => string | undefined, clientMessageId?: string ): PostMessageInput { - const draft = workflow?.draft?.(origin) const tabs = workflow?.tabs?.(origin) const unboundTarget = isUnboundTarget( wfContext, @@ -1112,8 +1116,17 @@ export function useAgentSession(deps: AgentSessionDeps) { tabs: OpenTabsSnapshot | undefined ): boolean { if (wfContext === undefined || wfContext.id !== undefined) return false + if (mintAlreadyRequested(wfContext.tabPath, boundWorkflowId)) return false if (boundWorkflowId === null) return true - return draft !== undefined && isOpenInATab(boundWorkflowId, tabs) + if (draft === undefined) return false + return hasContent(draft) || isOpenInATab(boundWorkflowId, tabs) + } + + function hasContent(draft: DraftSnapshot): boolean { + const { nodes, groups } = draft.content + return [nodes, groups].some( + (items) => Array.isArray(items) && items.length > 0 + ) } function isOpenInATab( @@ -1123,6 +1136,38 @@ export function useAgentSession(deps: AgentSessionDeps) { return (tabs?.open_tabs ?? []).some((tab) => tab.workflow_id === workflowId) } + function mintAlreadyRequested( + tabPath: string, + boundWorkflowId: string | null + ): boolean { + return ( + unadoptedMintBinding.has(tabPath) && + unadoptedMintBinding.get(tabPath) === boundWorkflowId + ) + } + + function rememberMint( + input: PostMessageInput, + wfContext: WorkflowTurnContext | undefined, + workflowId: string | undefined + ): void { + if (!input.currentTabUnbound || wfContext === undefined) return + const adoptedOrHeld = + workflowId !== undefined && + bindingStore.tabPathFor(workflowId) !== undefined + if (!adoptedOrHeld) + unadoptedMintBinding.set(wfContext.tabPath, boundWorkflowId.value) + } + + function lacksCanvasForRemint( + wfContext: WorkflowTurnContext | undefined, + draft: DraftSnapshot | undefined + ): boolean { + if (wfContext === undefined || wfContext.id !== undefined) return false + if (boundWorkflowId.value === null) return false + return workflow?.draft !== undefined && draft === undefined + } + function buildTargetFields( threadId: string, wfContext: WorkflowTurnContext | undefined, @@ -1334,6 +1379,33 @@ export function useAgentSession(deps: AgentSessionDeps) { return adoptedActiveTurn } + async function recoverFailedSend({ + error, + text, + sentContext, + accepted, + threadAtSend, + generation + }: { + error: unknown + text: string + sentContext: WorkflowTurnContext | undefined + accepted: boolean + threadAtSend: string + generation: number + }): Promise { + releaseDisownedWorkflow(sentContext, error) + if (generation !== loadGeneration) return false + const reattached = await reattachRefusedTurn( + error, + threadAtSend, + generation + ) + if (generation !== loadGeneration) return false + recordCurrentSendError(error, text, accepted, reattached, threadAtSend) + return false + } + async function performSend( text: string, attachments?: SentAttachment[], @@ -1355,22 +1427,22 @@ export function useAgentSession(deps: AgentSessionDeps) { await prepareWorkflow() if (generation !== loadGeneration) return false const wfContext = workflow?.current(origin) - if (workflowTargetChanged(originContext, wfContext)) { - recordUnavailableTarget(text) - return false - } + const draft = workflow?.draft?.(origin) + if (refusesTarget(text, originContext, wfContext, draft)) return false sentContext = wfContext - const ack = await postTurn( + const input = buildPostInput( threadAtSend, text, origin, wfContext, + draft, attachments, tags, workflowReferences, selectionWorkflowId, clientMessageId ) + const ack = await postTurn(threadAtSend, input, wfContext) accepted = true if (!observeAcceptedTurn(generation, onAccepted)) return false acceptTurn( @@ -1382,21 +1454,17 @@ export function useAgentSession(deps: AgentSessionDeps) { workflowReferences, skillScopeAtSend ) + rememberMint(input, wfContext, ack.workflow_id) return true } catch (error) { - // Before the generation guard: the binding store is page-global and - // persisted, so a refusal that lands after newChat()/loadThread() has - // moved on still has to release, or the dead id survives the reload. - releaseDisownedWorkflow(sentContext, error) - if (generation !== loadGeneration) return false - const reattached = await reattachRefusedTurn( + return recoverFailedSend({ error, + text, + sentContext, + accepted, threadAtSend, generation - ) - if (generation !== loadGeneration) return false - recordCurrentSendError(error, text, accepted, reattached, threadAtSend) - return false + }) } } @@ -1728,8 +1796,7 @@ export function useAgentSession(deps: AgentSessionDeps) { conversationStore.reset() pruneSkillTurns() onThreadActivated?.(null) - boundWorkflowId.value = null - rememberedWorkflowId = null + forgetBinding() pendingWorkflowBind = null malformedStreamReports.clear() localStorage.removeItem(threadStorageKey) @@ -1761,8 +1828,7 @@ export function useAgentSession(deps: AgentSessionDeps) { promptEditState.value = { phase: 'idle' } load.stashedTurn = conversationStore.activeTurnId !== null conversationStore.stashActiveTurn() - boundWorkflowId.value = null - rememberedWorkflowId = null + forgetBinding() pendingWorkflowBind = null malformedStreamReports.clear() conversationStore.setThreadId(threadId) @@ -2105,11 +2171,11 @@ export function useAgentSession(deps: AgentSessionDeps) { conversationStore.settleTurn(turn, undefined, 'failed') return } + loadGeneration++ conversationStore.reset() pruneSkillTurns() onThreadActivated?.(null) - boundWorkflowId.value = null - rememberedWorkflowId = null + forgetBinding() localStorage.removeItem(threadStorageKey) }