Skip to content
Merged
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
34 changes: 33 additions & 1 deletion docs/reference/agent-status-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ call it.
one agent-status store; OSC, hooks, and structured sessions write it, while
desktop, `worktree ps`, and mobile only project it. Dismissal, certified PTY
exit, and provider-generation replacement remove the same row everywhere;
transport loss alone removes nothing.
transport loss alone removes nothing. Removing a row keeps its resume
identity (see "Resume identity after terminal loss").
- **Failure source:** the deleted runtime row store duplicated OSC observations,
keyed them by a different terminal identity, and outlived a dismissal from the
hook store. Relay replay could also make old evidence look fresh when readers
Expand Down Expand Up @@ -487,6 +488,37 @@ call it.
- Live: the parity check from #19217 (working, done, close, reload) repeated
against the merged store, with both surfaces read from the one row.

## Resume identity after terminal loss

A paired host re-creates a pane after a reboot, a daemon replacement or any
other loss of its terminal, so losing the terminal is not the agent ending.
PTY teardown (`clearPaneState`, a certified exit through
`reconcileEndedProcessForPaneKeys`, the boot sweep for a PTY that died while
Orca was down) removes the live row and every latch, but keeps the row's
provider session as a hidden `providerSessionOnly` remnant marked
`resumeAfterTerminalLoss`. The mark is persisted and hydrated with the row.

An identity kept after the agent itself ended never carries the mark: the
confirmed-shell route and a Claude `SessionEnd` whose reason is
`prompt_input_exit` or `logout` keep a plain remnant, for a manual resume only.
`SessionEnd` with `other` is how a signalled agent reports, so it changes
nothing; `/clear` needs nothing because its `SessionStart` replaces the
session. A plain remnant stays plain through later teardowns, and closing the
tab still drops everything.

When the host materializes a pane (`session.tabs.activate` on a pane whose
session is gone) and no launch was resolved for it, it reads the one store
through `selectTerminalLossResume` and resumes that session with its own agent
settings. Only a local pane qualifies (an SSH relay can outlive its client).
A WSL pane qualifies when its row carries `reportsUserEndedSessions`, which a
WSL relay stamps on every envelope once it forwards `SessionEnd` as a
`userEndedSessionId` notice (a payload state no host admits, so an older host
drops it); a row from an older relay cannot prove the user kept the agent. And
one conversation belongs to one pane: a pane whose terminal still runs it
keeps it, and otherwise the pane that reported it last does. A remnant's
status fields are placeholders, so the next event in the pane never inherits
its agent type, permission hold, verdict, compact ownership or terminal.

## Retired OMP pane recovery

A desktop renderer retirement carries an optional UUID through the existing
Expand Down
10 changes: 8 additions & 2 deletions src/main/agent-hooks/ended-process-reconciliation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,21 @@ describe('reconcileEndedProcessForPaneKeys', () => {
}
})

it('takes the resume identity too on a certified PTY exit, where no pane is left to resume into', async () => {
it('keeps a dismissed identity through a certified PTY exit without making it resumable', async () => {
// A paired host re-creates a pane whose PTY ended, so the identity outlives the PTY; the agent
// had already ended, so a re-created pane must not bring it back.
const server = await startServer()
try {
resumableClaudeRow(server)
server.dropStatusEntry(PANE)

expect(server.reconcileEndedProcessForPaneKeys([PANE])).toBe(1)

expect(paneState(server)).toBe('missing')
expect(server.getStatusSnapshotForPane(PANE)[0]).toMatchObject({
providerSessionOnly: true,
providerSession: { id: 'resume-me' }
})
expect(server.selectTerminalLossResume(PANE, () => false)).toBeNull()
} finally {
server.stop()
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/agent-hooks/manual-compact-status-cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ describe('manual compact status cleanup', () => {
begin()
server.clearPaneState(PANE_KEY)
server.ingestRemote(compactEvent('PostCompact', 'done'), 'conn-a')
expect(server.getStatusSnapshot()).toEqual([])
// Only the pane's retained resume identity is left; the late completion revived nothing.
expect(server.getStatusSnapshot()).toEqual([
expect.objectContaining({ providerSessionOnly: true, state: 'working' })
])

begin()
server.dropStatusEntriesByTabPrefix('manual-compact')
Expand Down
Loading
Loading