Prevent empty agent-launch fallback on automation dispatch (#13068)

The automation session owns the prompt-bearing agent tab.
Passing undefined for createdWithAgent prevents spurious
empty agent tabs from opening when dispatching automations.
This commit is contained in:
Jinjing
2026-08-07 11:41:50 -07:00
committed by GitHub
parent bc1e049b3f
commit 2a2b517a85
2 changed files with 49 additions and 36 deletions
@@ -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'))
@@ -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