From b3f7b79f7c6701b7414ae157f9fb60df46e8c59f Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 29 Oct 2026 15:07:51 +0000 Subject: [PATCH] fix(agent): send a tour-held first message when the tour ends in another tab (#22238) ## Summary A new user's first message waits behind the intro tour (#21285). If the tour is finished in another tab, the card here went away without telling the panel, so the held message waited until the panel was closed. Now it sends. ## Change `OnboardingCoach` emits `finished` when the tour completes outside this card (another tab, or any other write to the onboarding flag). Skip and Done still emit once; an emptied step list does not count as completion. This matters more once https://github.com/Comfy-Org/ComfyUI_frontend/pull/21857 stores tour completion in a synced setting, because the flag can then flip from outside the card while a message is held. ## Tests (written first) - `AgentPanelRoot.test.ts`: sends once when another tab finishes the tour during the hold (failed before the fix). - `OnboardingCoach.test.ts`: reports the tour finished when another tab completes it (failed before the fix); reports finished once on Skip and on Done; reports a later completion in another tab after a replay. - AgentPanelRoot + OnboardingCoach suites: 598/598. Typecheck clean. ## Review findings from the core/1.58 backport (#22223), and why the rest are not here - Consent cleared or account switched during the hold: already handled on main (consent-identity recheck from #21532); ported to the release lines in #22225, #22232, #22233, #22234. - Stall reported only once per coach: not reachable for the held send. The coach mounts when consent is accepted, and the hold only applies to a send made before consent, so a stall always happens during the hold and releases it. - Release and close in the same flush: clearing the held flag at release breaks draft restore on a plain close (existing test), so it is left as is and tracked in https://linear.app/comfyorg/issue/BE-24366. - Notice copy omits the automatic stall release: kept, the user cannot trigger it (https://linear.app/comfyorg/issue/BE-23265). Tracking: https://linear.app/comfyorg/issue/BE-21344 --- .../extensions/agent/AgentPanelRoot.test.ts | 20 +++++ .../components/agent/OnboardingCoach.test.ts | 84 +++++++++++++++++++ .../components/agent/OnboardingCoach.vue | 10 +++ 3 files changed, 114 insertions(+) diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index 446d73ddfa1..7f1f14bfd64 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -6528,6 +6528,26 @@ describe('AgentPanelRoot workflow binding', () => { expect(screen.queryByTestId('agent-coach-hold-notice')).toBeNull() }) + it('sends once when another tab finishes the tour during the hold', async () => { + const key = 'Comfy.AgentPanel.onboarded.account-a.workspace-hold' + makeTab('wf-42') + const bodies = mockMessagesEndpoint('wf-42') + renderWithSelectedTarget() + await sendHeldByCoach('build me a workflow') + expect(bodies).toHaveLength(0) + + localStorage.setItem(key, 'true') + window.dispatchEvent( + new StorageEvent('storage', { + key, + newValue: 'true', + storageArea: localStorage + }) + ) + + await waitFor(() => expect(bodies).toHaveLength(1)) + }) + it('sends once when a coach step never finds its target', async () => { vi.useFakeTimers({ shouldAdvanceTime: true }) const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) diff --git a/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts b/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts index cab87428dce..b1483cd2a40 100644 --- a/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts +++ b/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts @@ -449,6 +449,90 @@ describe('OnboardingCoach', () => { expect(useOnboardingOverlayStore().active).toBe(true) }) + function mountWithFinished( + storageKey: string, + onFinished: () => void, + steps = STEPS + ) { + return render( + { + components: { OnboardingCoach }, + setup: () => ({ steps, storageKey, onFinished }), + template: + '
' + }, + { global: { plugins: [i18n] } } + ) + } + + it('reports the tour finished when another tab completes it', async () => { + const onFinished = vi.fn() + mountWithFinished('coach-elsewhere', onFinished) + await screen.findByRole('dialog', { name: 'Meet the agent' }) + + localStorage.setItem('coach-elsewhere', 'true') + window.dispatchEvent( + new StorageEvent('storage', { + key: 'coach-elsewhere', + newValue: 'true', + storageArea: localStorage + }) + ) + + await waitFor(() => expect(onFinished).toHaveBeenCalled()) + await nextTick() + + expect(onFinished).toHaveBeenCalledOnce() + }) + + it('reports finished once when the user skips', async () => { + const onFinished = vi.fn() + mountWithFinished('coach-skip-once', onFinished) + await userEvent.click(await screen.findByRole('button', { name: 'Skip' })) + await nextTick() + await nextTick() + + expect(onFinished).toHaveBeenCalledOnce() + }) + + it('reports finished once when the user clicks Done', async () => { + const onFinished = vi.fn() + mountWithFinished('coach-done-once', onFinished, [STEPS[0]]) + await userEvent.click(await screen.findByRole('button', { name: 'Done' })) + await nextTick() + await nextTick() + + expect(onFinished).toHaveBeenCalledOnce() + }) + + it('reports a later completion in another tab after a replay', async () => { + const onFinished = vi.fn() + const coach = ref<{ restart: () => void } | null>(null) + render( + { + components: { OnboardingCoach }, + setup: () => ({ steps: STEPS, coach, onFinished }), + template: + '
' + }, + { global: { plugins: [i18n] } } + ) + await userEvent.click(await screen.findByRole('button', { name: 'Skip' })) + coach.value?.restart() + await screen.findByRole('dialog', { name: 'Meet the agent' }) + + localStorage.setItem('coach-replay-elsewhere', 'true') + window.dispatchEvent( + new StorageEvent('storage', { + key: 'coach-replay-elsewhere', + newValue: 'true', + storageArea: localStorage + }) + ) + + await waitFor(() => expect(onFinished).toHaveBeenCalledTimes(2)) + }) + describe('reporting a step whose target never mounts', () => { const renderMissing = (target: string) => render(OnboardingCoach, { diff --git a/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue b/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue index 697f4af2bc1..9dd4e17953b 100644 --- a/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue +++ b/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue @@ -108,19 +108,29 @@ function reportStep(action: AgentOnboardingAction): void { useTelemetry()?.trackAgentOnboardingStep({ step: index.value + 1, action }) } +let finishedHere = false + function onNext(): void { const finished = isLast.value reportStep(isLast.value ? 'finish' : 'next') + if (finished) finishedHere = true next() if (finished) emit('finished') } function onSkip(): void { reportStep('skip') + finishedHere = true finish() emit('finished') } +const completed = computed(() => !active.value && !!step.value) +watch(completed, (isCompleted) => { + if (isCompleted && !finishedHere) emit('finished') + finishedHere = false +}) + const targetObserver = new MutationObserver(resolveTargets) targetObserver.observe(document.body, { childList: true,