fix(terminal): a launch composer that never comes still refuses the send when the agent never exited

#427 settled the composer watch through failOnLaunchedAgentExit, whose finally() aborts the signal it handed the wait. That abort reached the watch's own stop controller, which a startup dialog uses to admit sends, so a composer timeout with the agent still in front admitted the send (terminal-send-launch-composer.test.ts). Only a dialog's abort admits now, and a failed composer wait refuses instead of reading as an exit.
This commit is contained in:
Neil
2026-11-11 05:38:17 -08:00
parent 07288af2a6
commit 6bd72b2bf2
2 changed files with 28 additions and 3 deletions
@@ -70,6 +70,16 @@ describe('the launch composer hold', () => {
expect(settled).toHaveBeenCalledWith(true)
})
it('still refuses when the composer never comes and the agent never exits', async () => {
const { host, exitRuntime } = pane()
exitRuntime.readLaunchedAgentForeground = vi.fn(async () => 'agent' as const)
const watches = new Map<string, Promise<boolean>>()
watchLaunchComposer(watches, host, 'pty-1', 'claude', exitRuntime)
const watch = watches.get('pty-1')!
await vi.runAllTimersAsync()
await expect(watch).resolves.toBe(false)
})
it('without the exit watch, the same pane is still held at that point (the old 8 s refusal)', async () => {
const { host, emit } = pane()
const watches = new Map<string, Promise<boolean>>()
@@ -81,8 +81,20 @@ export function watchLaunchComposer(
return
}
const stop = new AbortController()
// Only a startup dialog may admit sends through `stop`: the exit watch also aborts it once it settles,
// including after the composer wait timed out, which must still refuse.
let stoppedFromOutside = false
const waitForComposer = (signal?: AbortSignal): Promise<string | null> => {
signal?.addEventListener('abort', () => stop.abort(), { once: true })
signal?.addEventListener(
'abort',
() => {
if (!stop.signal.aborted) {
stoppedFromOutside = true
stop.abort()
}
},
{ once: true }
)
return waitForFreshComposerOnPty(host, ptyId, agent, resolveDraftPasteReadyTimeoutMs(agent), {
requireComposerMarker: false,
stopOnDialog: true,
@@ -90,14 +102,17 @@ export function watchLaunchComposer(
})
}
const watched = exitRuntime
? failOnLaunchedAgentExit(exitRuntime, ptyId, agent, undefined, waitForComposer).catch(
? failOnLaunchedAgentExit(exitRuntime, ptyId, agent, undefined, (signal) =>
// A failed composer wait refuses as before; only the exit watch's own rejection means the agent exited.
waitForComposer(signal).catch(() => null)
).catch(
// The agent exited to its shell: there is no composer to wait for, so sends go to the shell now.
() => 'agent-exited'
)
: waitForComposer()
const ready = watched.then(
// A startup dialog stops the watch: it takes the next input, so sends reach it as before.
(readyPtyId) => readyPtyId !== null || stop.signal.aborted,
(readyPtyId) => readyPtyId !== null || (stop.signal.aborted && !stoppedFromOutside),
() => false
)
watches.set(ptyId, ready)