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.
This commit is contained in:
orca-bug-scan-bot
2026-07-11 14:51:24 -07:00
parent dcfa91919f
commit d6eef7ee0c
2 changed files with 43 additions and 2 deletions
@@ -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' })
@@ -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
}