Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions src/server/__tests__/isolated/terminalProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,49 @@ describe('TerminalProxy', () => {
options: expect.objectContaining({ timeout: 15000 }),
})
})

test('disposes the grouped session when tmux attach spawn fails', async () => {
const harness = createSpawnHarness()
const failingSpawn = (
args: string[],
options: Parameters<typeof Bun.spawn>[1]
) => {
harness.spawnCalls.push({ args, options })
throw new Error('pty exhausted')
}

const proxy = new TerminalProxy({
connectionId: 'attach-fail',
sessionName: 'agentboard-ws-attach-fail',
baseSession: 'agentboard',
onData: () => {},
spawn: failingSpawn,
spawnSync: harness.spawnSync,
wait: async () => {},
})

await expect(proxy.start()).rejects.toMatchObject({
code: 'ERR_TMUX_ATTACH_FAILED',
})

// new-session created the grouped session before attach; dispose must
// kill it so a failed spawn cannot orphan a pty-holding session.
expect(harness.spawnSyncCalls).toContainEqual({
args: [
'tmux',
'new-session',
'-d',
'-t',
'agentboard',
'-s',
'agentboard-ws-attach-fail',
],
options: expect.objectContaining({ timeout: 15000 }),
})
expect(harness.spawnSyncCalls).toContainEqual({
args: ['tmux', 'kill-session', '-t', 'agentboard-ws-attach-fail'],
options: expect.objectContaining({ timeout: 15000 }),
})
expect(proxy.isReady()).toBe(false)
})
})
5 changes: 4 additions & 1 deletion src/server/terminal/PtyTerminalProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ class PtyTerminalProxy extends TerminalProxyBase {
},
})
} catch (error) {
this.state = TerminalState.DEAD
// Tear down the grouped session created just above; otherwise a failed
// attach orphans a `…-ws-<uuid>` session that holds a pty until the next
// restart's reaper.
await this.dispose()
throw new TerminalProxyError(
'ERR_TMUX_ATTACH_FAILED',
error instanceof Error ? error.message : 'Failed to attach tmux client',
Expand Down
Loading