diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index 23eef9f22cf..ca28edbb796 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -6608,6 +6608,44 @@ describe('AgentPanelRoot workflow binding', () => { expect(bodies).toHaveLength(0) }) + it('puts the draft back when consent is cleared while the panel stays open', async () => { + makeTab('wf-42') + const bodies = mockMessagesEndpoint('wf-42') + const settleSubmission = vi.spyOn( + useAgentComposerStore(), + 'settleSubmission' + ) + renderWithSelectedTarget() + await sendHeldByCoach('build me a workflow') + + Object.assign(useAgentConsentStore(), { accepted: false }) + + await waitFor(() => + expect(settleSubmission).toHaveBeenCalledWith(expect.any(Number), false) + ) + expect(bodies).toHaveLength(0) + }) + + it('puts the draft back when the consent identity changes during the hold', async () => { + makeTab('wf-42') + const bodies = mockMessagesEndpoint('wf-42') + const settleSubmission = vi.spyOn( + useAgentComposerStore(), + 'settleSubmission' + ) + renderWithSelectedTarget() + await sendHeldByCoach('build me a workflow') + + Object.assign(useAgentConsentStore(), { + identity: JSON.stringify(['account-b', 'workspace-hold', 0]) + }) + + await waitFor(() => + expect(settleSubmission).toHaveBeenCalledWith(expect.any(Number), false) + ) + expect(bodies).toHaveLength(0) + }) + it('puts the draft back instead of sending when the panel closes', async () => { makeTab('wf-42') const bodies = mockMessagesEndpoint('wf-42') diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index 24f77883c4d..202b2e3106c 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -184,7 +184,9 @@ const { } = useBillingContext() const conversationStore = useAgentConversationStore() const history = useAgentChatHistoryStore() -const { accepted: consentAccepted } = storeToRefs(useAgentConsentStore()) +const { accepted: consentAccepted, identity: consentIdentity } = storeToRefs( + useAgentConsentStore() +) watch( subscription, (currentSubscription) => { @@ -641,10 +643,11 @@ function releaseCoachCompletionWaiters(proceed = true): void { coachCompletionWaiters.clear() } watch( - [consentAccepted, onboardingKey, coachDeferredBy], - ([accepted, key, reason]) => { + [consentAccepted, onboardingKey, coachDeferredBy, consentIdentity], + ([accepted, key, reason, identity], previous) => { if (accepted && key && !hasSeenCoach(key)) trackCoachDeferral(key, reason) - if (reason !== null) releaseCoachCompletionWaiters() + if (!accepted || reason !== null || identity !== previous[3]) + releaseCoachCompletionWaiters() }, { immediate: true } ) @@ -1693,10 +1696,12 @@ async function consentAllowsSubmission( ): Promise { let hasConsent = false let coachReleased = false + let acceptedIdentity: string | null = null consentHeldSubmissionId = submissionId try { await withConsent('first_message', () => { hasConsent = true + acceptedIdentity = consentIdentity.value }) if (hasConsent) coachReleased = await waitForCoachCompletion() } finally { @@ -1707,7 +1712,8 @@ async function consentAllowsSubmission( composerStore.submission?.id === submissionId && hasConsent && coachReleased && - consentAccepted.value + consentAccepted.value && + consentIdentity.value === acceptedIdentity ) }