Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6940eaa
fix(agent-status): admit hook process presence on the execution host
brennanb2025 Sep 29, 2026
9f844a8
fix(agent-status): restrict process checks to real hook ingress
brennanb2025 Sep 29, 2026
fe8d2e3
fix(agent-status): keep presence checks from causing false exits or l…
brennanb2025 Sep 29, 2026
9cbba4c
refactor(agent-status): own pane presence by the agent's process, not…
brennanb2025 Sep 30, 2026
75f9211
fix(agent-status): close round-3 review gaps in presence handling
brennanb2025 Sep 30, 2026
6ce43e1
refactor(agent-status): record the pane's owning agent even without a…
brennanb2025 Sep 30, 2026
089e085
test(agent-status): read the optional process id in the relay presenc…
brennanb2025 Sep 30, 2026
39b2660
fix(agent-status): other agents' SessionEnd hooks settle their status…
brennanb2025 Sep 30, 2026
603af1c
test(agent-status): cover the owner's own SessionEnd through the relay
brennanb2025 Sep 30, 2026
ed826bc
fix(agent-status): rows without a process identity keep today's comma…
brennanb2025 Sep 30, 2026
721de1c
fix(agent-status): panes without an identified owner keep today's exi…
brennanb2025 Sep 30, 2026
a1f6b47
Merge remote-tracking branch 'origin/main' into brennanb2025/agent-pr…
brennanb2025 Sep 30, 2026
5e2abfd
Merge remote-tracking branch 'origin/main' into brennanb2025/agent-pr…
brennanb2025 Sep 30, 2026
ffc659b
fix(desktop): read agent presence from the execution host
brennanb2025 Sep 30, 2026
8cecc0f
test(desktop): give the pty-connection store fixture the presence map
brennanb2025 Sep 30, 2026
3b82a62
test(desktop): note why the pty-connection store fixture keeps its cast
brennanb2025 Sep 30, 2026
32b6e0f
fix(desktop): end or release host process owners on explicit cleanup …
brennanb2025 Sep 30, 2026
528f84d
fix(desktop): resolve agent presence per pane and stop polling identi…
brennanb2025 Sep 30, 2026
c8f56e2
fix(desktop): skip the finished-task notice when an owner ends with i…
brennanb2025 Sep 30, 2026
80ebc20
test(desktop): pin the runtime exit path and unverified-cleanup repla…
brennanb2025 Sep 30, 2026
6e5c7f2
fix(desktop): release an owner to renderers when its terminal is torn…
brennanb2025 Sep 30, 2026
5d386b5
fix(desktop): keep step 1's answered-shell exit confirmation for unve…
brennanb2025 Sep 30, 2026
0685d61
fix(desktop): one owner handover rule for every host; release torn-do…
brennanb2025 Sep 30, 2026
e730b7b
test(desktop): type the handover test's recorded presence instead of …
brennanb2025 Sep 30, 2026
6f2fd65
fix(desktop): quiet owner republications and keep main's Chat and rea…
brennanb2025 Sep 30, 2026
c71a327
fix(desktop): narrow the owner check to a present row and update a st…
brennanb2025 Sep 30, 2026
54cfd99
fix(desktop): send a relay owner handover as a restatement, not a sec…
brennanb2025 Sep 30, 2026
ed67472
fix(desktop): hand a dead owner's pane to the first process that doub…
brennanb2025 Sep 30, 2026
94933ee
test(desktop): name the handover case parameter for its role
brennanb2025 Sep 30, 2026
650b20c
test(desktop): type the handover test's owners as process presences
brennanb2025 Sep 30, 2026
c6f1307
fix(desktop): read pane presence through the existing agent-type subs…
brennanb2025 Sep 30, 2026
27d335d
test(desktop): give terminal-pane store fixtures the presence map
brennanb2025 Sep 30, 2026
2efdd7c
test(desktop): give the fish pty fixture the presence map and retire …
brennanb2025 Oct 1, 2026
becadc2
Merge origin/main (step 1 #23947 squash-merged) into agent-presence-s…
brennanb2025 Oct 1, 2026
c2919e5
fix(desktop): drop the replay-only owner recheck the merge kept besid…
brennanb2025 Oct 1, 2026
b61212c
fix(desktop): keep an exited owner's leftovers off the tab icon until…
brennanb2025 Oct 1, 2026
47bd3e7
test(desktop): type the exit test's ended owner as a process presence
brennanb2025 Oct 1, 2026
e9b8573
fix(desktop): release an owner whose session ends while Orca sleeps i…
brennanb2025 Oct 1, 2026
574b46f
fix(desktop): announce an owner's exit only for a turn not yet notified
brennanb2025 Oct 1, 2026
85f4d2c
Merge remote-tracking branch 'origin/main' into brennanb2025/agent-pr…
brennanb2025 Oct 1, 2026
0ff278b
Merge remote-tracking branch 'origin/main' into brennanb2025/agent-pr…
brennanb2025 Oct 2, 2026
ab97c9e
fix(desktop): drop an exited owner's row the way a confirmed shell re…
brennanb2025 Oct 2, 2026
730863b
test(desktop): expect the batch projection to drop an exited owner's row
brennanb2025 Oct 2, 2026
3b7566f
fix(agent-presence): recheck each live process owner on its execution…
brennanb2025 Oct 2, 2026
921caa2
Merge remote-tracking branch 'origin/main' into brennanb2025/agent-pr…
brennanb2025 Oct 2, 2026
93fea62
refactor(orcad): keep the session-tabs republish comment beside its i…
brennanb2025 Oct 2, 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
12 changes: 6 additions & 6 deletions src/main/agent-hooks/ended-process-reconciliation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('reconcileEndedProcessForPaneKeys', () => {
claudeRow(server, 'working')
expect(paneState(server)).toBe('working')

expect(server.reconcileEndedProcessForPaneKeys([PANE])).toBe(1)
expect(server.reconcileEndedProcessForPaneKeys([PANE], { kind: 'terminal-ended' })).toBe(1)

expect(paneState(server)).toBe('missing')
} finally {
Expand All @@ -83,7 +83,7 @@ describe('reconcileEndedProcessForPaneKeys', () => {
server._getStateForTests().claudeRunningNonAgentTaskPaneKeys.add(PANE)
server._getStateForTests().claudeActiveSessionCronPaneKeys.add(PANE)

expect(server.reconcileEndedProcessForPaneKeys([PANE])).toBe(1)
expect(server.reconcileEndedProcessForPaneKeys([PANE], { kind: 'terminal-ended' })).toBe(1)

expect(server._getStateForTests().claudeRunningNonAgentTaskPaneKeys.has(PANE)).toBe(false)
expect(server._getStateForTests().claudeActiveSessionCronPaneKeys.has(PANE)).toBe(false)
Expand All @@ -95,7 +95,7 @@ describe('reconcileEndedProcessForPaneKeys', () => {
it('is a no-op for a pane with nothing to retire', async () => {
const server = await startServer()
try {
expect(server.reconcileEndedProcessForPaneKeys([PANE])).toBe(0)
expect(server.reconcileEndedProcessForPaneKeys([PANE], { kind: 'terminal-ended' })).toBe(0)
} finally {
server.stop()
}
Expand All @@ -115,7 +115,7 @@ describe('reconcileEndedProcessForPaneKeys', () => {
expect(afterDrop?.providerSession?.id).toBe('resume-me')

expect(
server.reconcileEndedProcessForPaneKeys([PANE], { preserveResumeIdentity: true })
server.reconcileEndedProcessForPaneKeys([PANE], { kind: 'legacy-shell-foreground' })
).toBe(1)

const kept = server.getStatusSnapshotForPane(PANE)[0]
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('reconcileEndedProcessForPaneKeys', () => {
resumableClaudeRow(server)
server.dropStatusEntry(PANE)

expect(server.reconcileEndedProcessForPaneKeys([PANE])).toBe(1)
expect(server.reconcileEndedProcessForPaneKeys([PANE], { kind: 'terminal-ended' })).toBe(1)

expect(paneState(server)).toBe('missing')
} finally {
Expand All @@ -157,7 +157,7 @@ describe('reconcileEndedProcessForPaneKeys', () => {
claudeRow(server, 'working')
server._getStateForTests().claudeSessionOwnerByPaneKey.set(PANE, 'session-a')

server.reconcileEndedProcessForPaneKeys([PANE])
server.reconcileEndedProcessForPaneKeys([PANE], { kind: 'terminal-ended' })

expect(server._getStateForTests().claudeSessionOwnerByPaneKey.has(PANE)).toBe(false)
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/main/agent-hooks/manual-compact-status-cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('manual compact status cleanup', () => {
}

begin()
server.clearPaneState(PANE_KEY)
server.clearPaneState(PANE_KEY, 'released')
server.ingestRemote(compactEvent('PostCompact', 'done'), 'conn-a')
expect(server.getStatusSnapshot()).toEqual([])

Expand Down
120 changes: 120 additions & 0 deletions src/main/agent-hooks/server-agent-owner-liveness-recheck.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { AgentHookServer } from './server'
import { FRESH_PANE, GOOD_PANE, PANE } from './server.test-fixtures'
import { probeAgentProcessPresence } from '../../shared/agent-process-presence-probe'
import { AGENT_OWNER_RECHECK_INTERVAL_MS } from '../../shared/agent-owner-liveness-recheck'
import type { AgentHookEventPayload } from '../../shared/agent-hook-listener/listener-event'
import type { AgentProcessPresence } from '../../shared/agent-process-presence'

vi.mock('../telemetry/client', () => ({ track: vi.fn() }))
vi.mock('../telemetry/cohort-classifier', () => ({ getCohortAtEmit: () => ({}) }))
vi.mock('../../shared/agent-process-presence-probe', () => ({
probeAgentProcessPresence: vi.fn(async () => 'live')
}))

const owner = {
agent: 'claude',
process: { pid: 4001, platform: 'linux', startTime: 'boot:123' }
} satisfies AgentProcessPresence
const sibling = {
agent: 'claude',
process: { pid: 4002, platform: 'linux', startTime: 'boot:456' }
} satisfies AgentProcessPresence

class RecheckServer extends AgentHookServer {
publish(overrides: Partial<AgentHookEventPayload> = {}): void {
this.applyNormalizedStatus({
paneKey: PANE,
tabId: 'tab-1',
worktreeId: 'folder-1',
connectionId: null,
source: 'claude',
hookEventName: 'UserPromptSubmit',
agentPresence: owner,
payload: { agentType: 'claude', state: 'working', prompt: 'task' },
...overrides
})
}
}

const servers: RecheckServer[] = []
function createServer(): RecheckServer {
const server = new RecheckServer()
servers.push(server)
return server
}
const probe = vi.mocked(probeAgentProcessPresence)
async function beat(times = 1): Promise<void> {
await vi.advanceTimersByTimeAsync(AGENT_OWNER_RECHECK_INTERVAL_MS * times)
}

beforeEach(() => {
vi.useFakeTimers()
probe.mockReset().mockResolvedValue('live')
})
afterEach(() => {
for (const server of servers.splice(0)) {
server.stop()
}
vi.useRealTimers()
})

describe('host recheck of live process owners', () => {
it('checks each live owner once per beat and never touches ownerless panes', async () => {
const server = createServer()
server.publish({ paneKey: GOOD_PANE, tabId: 'tab-good', agentPresence: undefined })
await beat(3)
expect(probe).not.toHaveBeenCalled()

server.publish()
server.publish({ paneKey: FRESH_PANE, tabId: 'tab-fresh', agentPresence: sibling })
await beat(2)
expect(probe).toHaveBeenCalledTimes(4)
expect(probe.mock.calls.map(([identity]) => identity?.pid).sort()).toEqual([
4001, 4001, 4002, 4002
])
})

it.each([
['its release', (server: RecheckServer) => server.clearPaneState(PANE, 'released')],
['its tab closing', (server: RecheckServer) => server.dropStatusEntriesByTabPrefix('tab-1')],
[
'its terminal being replaced',
(server: RecheckServer) =>
server.reconcileEndedProcessForPaneKeys([PANE], { kind: 'terminal-ended' })
],
['the service stopping', (server: RecheckServer) => server.stop()]
])('stops checking an owner after %s', async (_case, end) => {
const server = createServer()
server.publish()
await beat()
expect(probe).toHaveBeenCalledTimes(1)
end(server)
await beat(3)
expect(probe).toHaveBeenCalledTimes(1)
})

it('never ends an owner its check cannot answer for', async () => {
const server = createServer()
server.publish()
probe.mockResolvedValue('unverifiable')
await beat(5)
expect(server.getStatusSnapshot()[0]?.agentPresence).toEqual(owner)
})

it('ends an owner whose process is gone and stops checking it', async () => {
const server = createServer()
const ended: unknown[] = []
server.setListener((event) => {
if (event.agentPresence?.ended) {
ended.push(event.agentPresence)
}
})
server.publish()
probe.mockResolvedValue('exited')
await beat()
expect(ended).toEqual([{ ...owner, ended: true }])
await beat(3)
expect(probe).toHaveBeenCalledTimes(1)
})
})
Loading
Loading