diff --git a/src/renderer/src/hooks/useAutomationDispatchEvents.test.ts b/src/renderer/src/hooks/useAutomationDispatchEvents.test.ts index d49778b3a05..46585b0091c 100644 --- a/src/renderer/src/hooks/useAutomationDispatchEvents.test.ts +++ b/src/renderer/src/hooks/useAutomationDispatchEvents.test.ts @@ -293,6 +293,19 @@ describe('useAutomationDispatchEvents setup launch', () => { expect(mockLaunchAgentBackgroundSession).toHaveBeenCalled() }) + it('does not stamp the created workspace with an empty agent-launch fallback', async () => { + await registerAndDispatch() + + expect(mockCreateWorktree.mock.calls[0][10]).toBeUndefined() + expect(mockLaunchAgentBackgroundSession).toHaveBeenCalledWith( + expect.objectContaining({ + agent: 'claude', + prompt: 'run this', + worktreeId: 'wt-created' + }) + ) + }) + it('keeps launching the agent when background setup terminal launch fails', async () => { const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined) mockLaunchWorktreeBackgroundTerminals.mockRejectedValue(new Error('tab launch failed')) diff --git a/src/renderer/src/hooks/useAutomationDispatchEvents.ts b/src/renderer/src/hooks/useAutomationDispatchEvents.ts index 09009d40011..f4ae2067688 100644 --- a/src/renderer/src/hooks/useAutomationDispatchEvents.ts +++ b/src/renderer/src/hooks/useAutomationDispatchEvents.ts @@ -220,43 +220,43 @@ export function useAutomationDispatchEvents(): void { const automationWorkspaceCreateRequestId = createBrowserUuid() const createResult = automation.workspaceMode === 'new_per_run' - ? await useAppStore - .getState() - .createWorktree( - runRepoId, - buildAutomationWorkspaceName(run.title, run.scheduledFor), - automation.baseBranch ?? undefined, - automation.setupDecision ?? 'skip', - undefined, - 'unknown', - run.title, - undefined, - undefined, - undefined, - automation.agentId, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - { - automationProvenanceRequest: { - automationId: automation.id, - automationRunId: run.id, - dispatchToken, - createRequestId: automationWorkspaceCreateRequestId - } + ? await useAppStore.getState().createWorktree( + runRepoId, + buildAutomationWorkspaceName(run.title, run.scheduledFor), + automation.baseBranch ?? undefined, + automation.setupDecision ?? 'skip', + undefined, + 'unknown', + run.title, + undefined, + undefined, + undefined, + // Why: the automation session below owns the prompt-bearing + // agent tab; createdWithAgent would reopen an empty fallback. + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + { + automationProvenanceRequest: { + automationId: automation.id, + automationRunId: run.id, + dispatchToken, + createRequestId: automationWorkspaceCreateRequestId } - ) + } + ) : null const worktree = createResult ? createResult.worktree