From d6eef7ee0ccbcbc36562938499ea053660a17657 Mon Sep 17 00:00:00 2001 From: orca-bug-scan-bot Date: Sat, 11 Jul 2026 14:51:24 -0700 Subject: [PATCH] fix: address pr-bug-scan validated finding from #7862 Oversized Hermes automation prompts no longer fail: launcher falls back to launching 'hermes --tui' empty and pasting the prompt after ready, so buildAgentStartupPlan-null no longer returns null. --- .../launch-agent-background-session.test.ts | 21 ++++++++++++++++ .../lib/launch-agent-background-session.ts | 24 +++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/lib/launch-agent-background-session.test.ts b/src/renderer/src/lib/launch-agent-background-session.test.ts index 652fddb9bcf..4850cf532dd 100644 --- a/src/renderer/src/lib/launch-agent-background-session.test.ts +++ b/src/renderer/src/lib/launch-agent-background-session.test.ts @@ -516,6 +516,27 @@ describe('launchAgentBackgroundSession', () => { expect(mockPasteDraftWhenAgentReady).not.toHaveBeenCalled() }) + it('falls back to paste delivery when a Hermes prompt overflows the startup-query budget', async () => { + const oversizedPrompt = 'x'.repeat(30_000) + const { launchAgentBackgroundSession } = await import('./launch-agent-background-session') + + const result = await launchAgentBackgroundSession({ + agent: 'hermes', + worktreeId: 'wt-1', + prompt: oversizedPrompt + }) + + expect(result).not.toBeNull() + expect(mockSpawn).toHaveBeenCalledWith( + expect.objectContaining({ command: 'hermes --tui' }) + ) + const spawnArgs = mockSpawn.mock.calls[0]?.[0] + expect(spawnArgs?.env?.ORCA_HERMES_STARTUP_QUERY).toBeUndefined() + expect(mockPasteDraftWhenAgentReady).toHaveBeenCalledWith( + expect.objectContaining({ agent: 'hermes', content: oversizedPrompt, submit: true }) + ) + }) + it('uses the configured cmd shell for Windows Hermes background launches', async () => { mockGetAgentLaunchPlatformForRepo.mockReturnValue('win32') Object.assign(state.settings, { terminalWindowsShell: 'cmd.exe' }) diff --git a/src/renderer/src/lib/launch-agent-background-session.ts b/src/renderer/src/lib/launch-agent-background-session.ts index edb4c6d9f68..59d273707cd 100644 --- a/src/renderer/src/lib/launch-agent-background-session.ts +++ b/src/renderer/src/lib/launch-agent-background-session.ts @@ -83,8 +83,8 @@ export async function launchAgentBackgroundSession( const hasPrompt = trimmedPrompt.length > 0 const isFollowupPath = TUI_AGENT_CONFIG[agent].promptInjectionMode === 'stdin-after-start' - const pasteDraftAfterLaunch = hasPrompt && isFollowupPath ? trimmedPrompt : null - const startupPlan = buildAgentStartupPlan({ + let pasteDraftAfterLaunch = hasPrompt && isFollowupPath ? trimmedPrompt : null + let startupPlan = buildAgentStartupPlan({ agent, prompt: hasPrompt && !isFollowupPath ? trimmedPrompt : '', cmdOverrides, @@ -95,6 +95,26 @@ export async function launchAgentBackgroundSession( isRemote, allowEmptyPromptLaunch: !hasPrompt || isFollowupPath }) + if (!startupPlan && hasPrompt && !isFollowupPath) { + // Why: a large prompt (e.g. an automation PR diff) can overflow the Hermes + // native startup-query env budget, making buildAgentStartupPlan return null. + // Rather than fail the whole dispatch, launch the agent with no prompt and + // paste it after the TUI is ready — the pre-native-query delivery path. + startupPlan = buildAgentStartupPlan({ + agent, + prompt: '', + cmdOverrides, + agentArgs, + agentEnv, + platform: launchPlatform, + shell: startupShell, + isRemote, + allowEmptyPromptLaunch: true + }) + if (startupPlan) { + pasteDraftAfterLaunch = trimmedPrompt + } + } if (!startupPlan) { return null }