Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
256f83b
Unify terminal starts under one host operation
brennanb2025 Oct 22, 2026
d1156f5
Pin winning geometry across a late terminal join
brennanb2025 Oct 22, 2026
04b4271
Use terminal creation options type in launch race test
brennanb2025 Oct 22, 2026
a311773
Check closed panes after acquiring the terminal spawn lease
brennanb2025 Oct 22, 2026
62c15b5
Preserve terminal start resource and join boundaries
brennanb2025 Oct 22, 2026
0f9abfc
Keep terminal attach regression within project boundaries
brennanb2025 Oct 22, 2026
2f7ccfe
Capture terminal spawn authority and preserve image coverage
brennanb2025 Oct 22, 2026
da3062f
Use checked fixtures for terminal image replay regression
brennanb2025 Oct 22, 2026
8af7dc2
test: expose persisted pane to main layout in attach race
brennanb2025 Oct 22, 2026
7273c51
Merge origin/main into brennanb2025/conv-c6-build
brennanb2025 Oct 23, 2026
1711d5c
test: contract terminal spawn scaling and retention
brennanb2025 Oct 23, 2026
eeb8681
test: correct spawn scaling fixture types and CI selection
brennanb2025 Oct 23, 2026
9393ee0
test(terminal): cover exited prompt claims and adopted team cleanup
brennanb2025 Oct 23, 2026
7294039
Merge main and preserve unified terminal spawn ownership
brennanb2025 Oct 25, 2026
f7f4fea
Merge main and retain terminal pane withdrawal ownership
brennanb2025 Oct 25, 2026
8a71108
Merge main and preserve terminal lifecycle tests across PTY moves
brennanb2025 Oct 25, 2026
be1251a
Merge main and preserve saved-resume ownership in shared spawn
brennanb2025 Oct 25, 2026
bbea78e
Merge main to include CI line-limit repair
brennanb2025 Oct 26, 2026
7eec8f7
test(pty): consolidate mock registry imports
brennanb2025 Oct 26, 2026
fd0fb1a
fix(pty): retain untyped IPC resume inputs in common contract
brennanb2025 Oct 26, 2026
fa3a98d
Merge origin/main into brennanb2025/conv-c6-build
brennanb2025 Oct 26, 2026
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
48 changes: 47 additions & 1 deletion src/main/ipc/pty-agent-pane-launch.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { ptyIncarnationById, ptyOwnership } from './pty/provider/ownership-state'
import { createLaunchRaceRuntime } from './pty-launch-race-test-fixture'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { afterEach, describe, expect, it, onTestFinished, vi } from 'vitest'
import type { AgentPaneLaunchRequest } from '../../shared/agent-pane-launch-request'
import { setupPtyIpcSuite } from './pty-ipc-test-harness'
import { statSyncMock } from './pty-ipc-mock-registry'
import { registerPtyHandlers } from './pty/register-handlers'
import {
isAgentLaunchRunningIn,
markAgentLaunchesClosedByUser,
resetAgentLaunchPanesForTests
} from '../agent-launch/agent-launch-pane-attachment'
import { AGENT_LAUNCH_PANE_REFUSED_CODE } from '../../shared/agent-launch-pane-verdict'
import { makePaneKey } from '../../shared/stable-pane-id'
import {
makePaneSpawnReservationKey,
paneSpawnReservationsByOwnerKey
} from './pty/pane/spawn-reservation'
import { acquireWatcherRemovalGate } from './watcher-removal-gate'

vi.mock('electron', () => import('./pty-ipc-mock-registry').then((m) => m.electronModuleMock()))
vi.mock('fs', () => import('./pty-ipc-mock-registry').then((m) => m.fsModuleMock()))
Expand Down Expand Up @@ -269,4 +276,43 @@ describe('a pane that starts its own agent launch', () => {
expect(providerSpawn).not.toHaveBeenCalled()
expect(runtime.reportAgentLaunchPaneVerdict).not.toHaveBeenCalled()
})

it('starts nothing and releases its preparation when the pane closes while its lease waits', async () => {
let resolveLease!: (release: () => void) => void
const lease = new Promise<() => void>((resolve) => {
resolveLease = resolve
})
const releaseLease = vi.fn()
const acquireWorktreeTerminalSpawn = vi.fn(() => lease)
const providerSpawn = vi.fn(async () => ({ id: 'pty-agent' }))
const runtime = register(providerSpawn)
Object.assign(runtime, { acquireWorktreeTerminalSpawn })

const spawned = spawnPane().catch((error: unknown) => error)
await vi.waitFor(() => expect(acquireWorktreeTerminalSpawn).toHaveBeenCalledOnce())
const key = makePaneSpawnReservationKey(worktreeId, null, makePaneKey(tabId, leafId))!
const reservation = paneSpawnReservationsByOwnerKey.get(key)!
expect(reservation).toBeDefined()
const closedPane = { kind: 'pane', tabId, leafId } as const
expect(isAgentLaunchRunningIn(worktreeId, closedPane)).toBe(true)
const removal = acquireWatcherRemovalGate('/tmp/pane-launch')
onTestFinished(() => removal.release())
const drained = vi.fn()
const preparationDone = removal.ready.then(drained)
await Promise.resolve()
expect(drained).not.toHaveBeenCalled()

markAgentLaunchesClosedByUser(worktreeId, closedPane)
resolveLease(releaseLease)

expect(await spawned).toMatchObject({ message: 'agent_launch_tab_closed' })
expect(providerSpawn).not.toHaveBeenCalled()
expect(releaseLease).toHaveBeenCalledOnce()
await expect(reservation.promise).rejects.toThrow('agent_launch_tab_closed')
expect(paneSpawnReservationsByOwnerKey.has(key)).toBe(false)
expect(isAgentLaunchRunningIn(worktreeId, closedPane)).toBe(false)
await preparationDone
expect(drained).toHaveBeenCalledOnce()
expect(runtime.reportAgentLaunchPaneVerdict).not.toHaveBeenCalled()
})
})
4 changes: 2 additions & 2 deletions src/main/ipc/pty-hidden-at-spawn-mark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ describe('registerPtyHandlers', () => {
sessionId: 'daemon-session',
initiallyHidden: true
}) as Promise<{ id: string }>
// Let the handler run up to the awaited provider.spawn.
await Promise.resolve()
// The hidden mark must precede the provider, regardless of preparation awaits.
await vi.waitFor(() => expect(daemon.spawn).toHaveBeenCalledOnce())
mainWindow.webContents.send.mockClear()

// Daemon PTYs can emit prompt bytes before spawn() resolves, so the pre-spawn mark must already gate them.
Expand Down
211 changes: 210 additions & 1 deletion src/main/ipc/pty-launch-race-parity.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { OrcaRuntimeService } from '../runtime/orca-runtime'
import type { TerminalCreateOptions } from '../runtime/runtime-terminal-contracts'
import { spawnInAdmittedPane } from '../runtime/runtime-pane-admission'
import { registerPtyHandlers } from './pty/register-handlers'
import { makePaneKey } from '../../shared/stable-pane-id'
import { launchWorkspaceId } from '../../shared/launch-parity-window-request.test-fixture'
import { POSIX_PATH } from '../../shared/launch-parity-window-cases.test-fixture'
import { statSyncMock } from './pty-ipc-mock-registry'
Expand All @@ -18,6 +23,7 @@
import { RestoredPaneStarter } from '../runtime/terminal/recovery/restored-pane-start'
import {
LAUNCH_RACE_LANES,
createPaneBindingStore,
createLaunchRaceRuntime,
gatedClaudeAuth,
launchRacePane,
Expand Down Expand Up @@ -89,6 +95,205 @@
const suite = setupPtyIpcSuite()
const { handlers, mainWindow, installDaemonTestProvider } = suite

it.each([
{ winner: 'producer', surface: 'existing' },
{ winner: 'producer', surface: 'new' },
{ winner: 'window', surface: 'existing' },
{ winner: 'producer', surface: 'successor' }
])(
'$winner registration exit crosses the real producer/admission barrier ($surface)',
async ({ winner, surface }) => {
const pane = launchRacePane(
`cross-${winner}-${surface}`,
'94949494-9494-4494-8494-949494949494'
)
const store = Object.assign(createPaneBindingStore(), { getSettings: () => ({}) })
const runtime = new OrcaRuntimeService()
Object.assign(runtime, {
store,
resolveTerminalWorkspaceLaunchScope: async () => ({
id: pane.worktreeId,
path: pane.args.cwd,
connectionId: null
}),
resolveAgentTerminalCreateOptions: async (
_workspace: unknown,
opts: TerminalCreateOptions
) => opts,
resolveWorkspaceTerminalStartupCwd: () => pane.args.cwd
})
const controllerSet = vi.spyOn(runtime, 'setPtyController')
// SAFETY: the handler fixture supplies window ports; only the real mutable session and binding store are used.
registerPtyHandlers(
mainWindow as never,
runtime,
undefined,
undefined,
undefined,
store as never
)
const controller = controllerSet.mock.calls.at(-1)![0]
const admission = {
type: 'createTerminalTab',
workspace: pane.worktreeId,
tabId: pane.tabId,
leafId: pane.leafId
} as const
if (surface !== 'new') {
runtime.attachWindow(1)
runtime.syncWindowGraph(1, {
tabs: [
{
tabId: pane.tabId,
worktreeId: pane.worktreeId,
title: 'terminal',
activeLeafId: pane.leafId,
layout: null
}
],
leaves: [
{
tabId: pane.tabId,
worktreeId: pane.worktreeId,
leafId: pane.leafId,
paneRuntimeId: 1,
ptyId: null
}
]
})
await store.admitTerminalPane(admission)
}
let release!: () => void
const gate = new Promise<void>((done) => {
release = done
})
const spawn = vi.fn(async () => {
await gate
return {
id: 'cross-exited',
incarnationId: 'cross-inc',
snapshot: 'final output',
snapshotKittyKeyboardFlags: 3
}
})
installDaemonTestProvider({ spawn })
vi.spyOn(runtime, 'registerPty').mockImplementation(() => {
throw new Error('agent_session_exited_during_start')
})
vi.spyOn(runtime, 'getPtyLivenessVerdict').mockReturnValue({ status: 'exited' })
const withdraw = vi.spyOn(store, 'withdrawTerminalPane')
const windowStart = () => Promise.resolve(handlers.get('pty:spawn')!(null, pane.args))
const producerStart = () =>
runtime.createTerminal(`id:${pane.worktreeId}`, { tabId: pane.tabId, leafId: pane.leafId })
const admittedStart = () =>
spawnInAdmittedPane(store, controller, { ...pane.args, preAllocatedHandle: 'cross-handle' })

Check failure on line 189 in src/main/ipc/pty-launch-race-parity.test.ts

View workflow job for this annotation

GitHub Actions / static analysis and typecheck

Argument of type '{ runDurableMutation<Value>(mutate: () => DurableProfileStateMutation<Value>): Promise<Value>; retirePtyBinding(binding: { worktreeId: string; tabId: string; leafId: string; ptyId: string; }, hostId?: string | ... 1 more ... | undefined, fence?: { ...; } | undefined): Promise<...>; ... 6 more ...; bindingWrites: Moc...' is not assignable to parameter of type 'RuntimeStore | null | undefined'.
const first = winner === 'producer' ? producerStart() : windowStart()
const firstObserved = first.catch((error: unknown) => error)
await vi.waitFor(() => expect(spawn).toHaveBeenCalledOnce())
const joined = vi.spyOn(paneSpawnReservations, 'joinPaneSpawn')
onTestFinished(() => joined.mockRestore())
const second = winner === 'producer' ? windowStart() : admittedStart()
const secondObserved = second.catch((error: unknown) => error)
const key = paneSpawnReservations.makePaneSpawnReservationKey(
pane.worktreeId,
null,
makePaneKey(pane.tabId, pane.leafId)
)!
if (winner === 'producer') {
const pending = paneSpawnReservations.pendingRuntimePaneCreatesByOwnerKey.get(key)!
const barrier = pending.promise
const waiting = vi.fn(() => barrier)
Object.defineProperty(pending, 'promise', { configurable: true, get: waiting })
await vi.waitFor(() => expect(waiting).toHaveBeenCalled())
} else {
await vi.waitFor(() => expect(joined).toHaveBeenCalledOnce())
}
if (surface === 'successor') {
const mutate = store.runDurableMutation.bind(store)
vi.spyOn(store, 'runDurableMutation').mockImplementation(async (write) => {
const value = await mutate(write)
if (!store.getWorkspaceSession().terminalLayoutsByTabId[pane.tabId]) {
await store.admitTerminalPane(admission)
await store.persistPtyBinding({
worktreeId: pane.worktreeId,
tabId: pane.tabId,
leafId: pane.leafId,
ptyId: 'successor',
incarnationId: 'successor-inc'
})
}
return value
})
}
release()
const [firstResult, secondResult] = await Promise.all([firstObserved, secondObserved])
const host = winner === 'producer' ? firstResult : secondResult
const window = winner === 'producer' ? secondResult : firstResult
expect(host).toMatchObject({ message: 'agent_session_exited_during_start' })
if (surface === 'existing') {
expect(window).toMatchObject({
id: 'cross-exited',
snapshot: 'final output',
snapshotKittyKeyboardFlags: undefined
})
} else {
expect(window).toMatchObject({ message: 'terminal_pane_owner_changed' })
}
expect(spawn).toHaveBeenCalledOnce()
if (surface === 'new') {
expect(withdraw).toHaveBeenCalledOnce()
expect(store.getWorkspaceSession().terminalLayoutsByTabId[pane.tabId]).toBeUndefined()
}
clearProviderPtyState('cross-exited')
}
)
it('restores a persisted window owner without imposing the runtime handle requirement', async () => {
const pane = launchRacePane('restore-no-handle', '95959595-9595-4595-8595-959595959595')
const id = 'persisted-no-handle'
const store = createPaneBindingStore()
await store.admitTerminalPane({
type: 'createTerminalTab',
workspace: pane.worktreeId,
tabId: pane.tabId,
leafId: pane.leafId
})
await store.persistPtyBinding({
worktreeId: pane.worktreeId,
tabId: pane.tabId,
leafId: pane.leafId,
ptyId: id
})
const runtime = createLaunchRaceRuntime({
resolveTerminalPane: vi.fn(() => {
throw new Error('terminal_not_found')
})
})
installDaemonTestProvider({ spawn: vi.fn(async () => ({ id, isReattach: true })) })
const lanes = registerLaunchRaceLanes({ handlers, mainWindow, runtime, store })
await expect(lanes.spawn.runtime(pane.args)).rejects.toThrow('terminal_pane_owner_unknown')
await expect(lanes.spawn.ipc(pane.args)).resolves.toMatchObject({ id, isReattach: true })
clearProviderPtyState(id)
})
it('seeds a fresh same-id incarnation before provider byte zero and restores a failed start', async () => {
const id = 'fresh-same-id-grid'
const old = { cols: 91, rows: 31 }
ptySizes.set(id, old)
const spawn = vi.fn(async () => {
expect(ptySizes.get(id)).toEqual({ cols: 132, rows: 45 })
throw new Error('provider refused')
})
installDaemonTestProvider({ spawn })
const lanes = registerLaunchRaceLanes({
handlers,
mainWindow,
runtime: createLaunchRaceRuntime()
})
await expect(
lanes.spawn.runtime({ cols: 132, rows: 45, sessionId: id, isNewSession: true })
).rejects.toThrow('provider refused')
expect(ptySizes.get(id)).toEqual(old)
ptySizes.delete(id)
})
it('allows fallback for an unreadable request without healing its saved folder or mobile snapshot', async () => {
setMainPlatform('darwin')
onTestFinished(restoreMainPlatform)
Expand Down Expand Up @@ -224,7 +429,11 @@
leafId: pane.leafId
})
const automatic = lanes.spawn
.runtime({ ...pane.args, refuseSleptWorktree: true })
.runtime({
...pane.args,
refuseSleptWorktree: true,
paneSpawnOperation: { mustExist: false }
})
.finally(release)
await vi.waitFor(() => expect(lock.acquireWorktreeTerminalSpawn).toHaveBeenCalledOnce())
const mount = lanes.spawn.ipc(pane.args)
Expand Down
4 changes: 3 additions & 1 deletion src/main/ipc/pty-pane-materialization-race.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ describe('registerPtyHandlers', () => {

const runtimeSpawn = (controller as unknown as RuntimeSpawnController).spawn({
...paneArgs,
cols: 132,
rows: 45,
command: 'printf runtime'
})
await vi.waitFor(() => expect(providerSpawn).toHaveBeenCalledOnce())
Expand All @@ -262,7 +264,7 @@ describe('registerPtyHandlers', () => {
expect(providerSpawn).toHaveBeenCalledOnce()
await expect(
handlers.get('pty:getSize')!(null, { id: 'pty-runtime-reservation' })
).resolves.toEqual({ cols: 80, rows: 24 })
).resolves.toEqual({ cols: 132, rows: 45 })
})
it('reuses renderer spawn when runtime materialization starts for the same pane', async () => {
type RuntimeSpawnController = {
Expand Down
Loading
Loading