Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(cli): a resume has started when its own engine process is running

0xken1541326f55f16d
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 364af3eed..7d141d0db 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -88,7 +88,6 @@ import { DEFAULT_HOST_THEME, loadHostTheme, saveHostTheme, type HostTheme } from
import { createAndRegisterPane } from './lib/createAgentPane.js'
import { forkName, planFork } from './lib/forkAgent.js'
import { restoreAgents } from './lib/restoreAgents.js'
-import { awaitsResumeHook } from './lib/resumeCapability.js'
import { createRetainExitedSession } from './lib/retainExitedSession.js'
import { repairClaudeCwd } from './lib/cwdRepair.js'
import { stoppedAgents } from './lib/stoppedAgents.js'
@@ -3119,14 +3118,17 @@ async function runForeground(session: AuthSession | null): Promise<void> {
if (observed.dsh && !current.dsh) registry.setDsh(current.agentId, observed.dsh)
const withDsh = registry.byAgent(current.agentId)
if (withDsh?.dsh) attachDsh(withDsh)
- // A strict-resume row waits for the hook that proves the engine reopened THAT conversation —
- // but only where such a hook is coming. For every other engine this live process, in this
- // row's own pane, IS the proof (`resumeCapability.ts`), and refusing to say so left an
- // opencode harness restored after a reboot reading "Starting" while it was working. The Open
- // path already marks those ready itself (`resumeAgentService.ts`); this is the same rule on
- // the door restore comes through.
- const waitingForResumeHook = !!current.resumeOnly && awaitsResumeHook(current.engine, current.sessionId)
- if (wasLaunching && !waitingForResumeHook) registry.setLaunch(current.agentId, { state: 'ready' })
+ // This live process, in this row's own pane, is what "started" means — for a resumed row as
+ // much as any other. A resume used to be held back here until its `SessionStart` hook landed,
+ // on the grounds that only the hook proves WHICH conversation reopened. Two things were wrong
+ // with that. The hook does not always come: measured on machine-remote-1, both resume-only
+ // codex rows carried `lastHookAt: 0` while every fresh launch beside them had hooked, and one
+ // of them sat at "Starting" for 19 hours over a pane its owner could type in — re-attached and
+ // re-announced every 5s for the whole time, because `wasLaunching` stays true for a row that
+ // nothing will ever mark ready (openharness#189). And nothing was actually protected by the
+ // wait: the wrong-conversation guard in `registry.register` keys on `lastHookAt`, not on this
+ // launch state, so it stays armed until the first hook whatever is written here.
+ if (wasLaunching) registry.setLaunch(current.agentId, { state: 'ready' })
await bindObservedAgent(observed)
if (wasDormant || wasLaunching || adopted) {
const active = registry.byAgent(current.agentId)
diff --git a/cli/src/lib/registry.spec.ts b/cli/src/lib/registry.spec.ts
index ec7fa4757..8cd42b078 100644
--- a/cli/src/lib/registry.spec.ts
+++ b/cli/src/lib/registry.spec.ts
@@ -1581,7 +1581,7 @@ describe('registry across a reboot and pane loss', () => {
})
})
- it('requires the exact resumed session hook; process discovery alone stays starting', async () => {
+ it('lets process discovery start a resumed row, and still refuses the wrong conversation', async () => {
const transcriptPath = join(dataDir, 'resume-target.jsonl')
writeFileSync(transcriptPath, '{}\n')
const { registry } = await loadRegistryModule()
@@ -1589,7 +1589,9 @@ describe('registry across a reboot and pane loss', () => {
registry.removeAgent(original.agentId)
registry.resumePendingAgent(original, [{ backend: 'tmux', paneId: '%22' }])
registry.openProcessAgent({ engine: 'claude', runtimes: [{ backend: 'tmux', paneId: '%22' }], processIdentity: processIdentity(122) })
- expect(registry.byAgent(original.agentId)?.launch?.state).toBe('starting')
+ // The engine is running in the row's pane, so the row has started — it no longer waits for a
+ // hook a resume may never send. What it has NOT yet been told is which conversation reopened.
+ expect(registry.byAgent(original.agentId)?.launch?.state).toBe('ready')
expect(registry.byAgent(original.agentId)?.lastHookAt).toBe(0)
expect(registry.register({ engine: 'claude', sessionId: 'unexpected-new-session', transcriptPath, tmuxPane: '%22', processIdentity: processIdentity(122) })).toBeNull()
expect(registry.byAgent(original.agentId)).toMatchObject({ sessionId: 'resume-target', launch: { state: 'failed', error: 'RESUME_SESSION_MISMATCH' } })
@@ -1597,6 +1599,24 @@ describe('registry across a reboot and pane loss', () => {
expect(confirmed?.entry).toMatchObject({ agentId: original.agentId, sessionId: 'resume-target', launch: { state: 'ready' } })
})
+ // The guard reads `lastHookAt`, not `launch`. A resume is now confirmed by its own live engine
+ // process (`resumeStoppedAgent.ts`), which marks the row ready BEFORE any hook arrives — and a
+ // guard keyed on `launch` would have been disarmed for exactly the resumes it protects.
+ it('still refuses another conversation on the first hook after the row was marked ready', async () => {
+ const transcriptPath = join(dataDir, 'ready-first.jsonl')
+ writeFileSync(transcriptPath, '{}\n')
+ const { registry } = await loadRegistryModule()
+ const original = registerProcess(registry, { engine: 'claude', sessionId: 'ready-first', transcriptPath, tmuxPane: '%31' })!.entry
+ registry.removeAgent(original.agentId)
+ registry.resumePendingAgent(original, [{ backend: 'tmux', paneId: '%32' }])
+ // What the resume service does the moment it sees the engine process in the pane.
+ registry.setLaunch(original.agentId, { state: 'ready' })
+ expect(registry.byAgent(original.agentId)?.lastHookAt).toBe(0)
+
+ expect(registry.register({ engine: 'claude', sessionId: 'somebody-elses-session', transcriptPath, tmuxPane: '%32', processIdentity: processIdentity(132) })).toBeNull()
+ expect(registry.byAgent(original.agentId)).toMatchObject({ sessionId: 'ready-first', launch: { state: 'failed', error: 'RESUME_SESSION_MISMATCH' } })
+ })
+
it('drops any launch state on the hook that proves the engine is up', async () => {
const transcriptPath = join(dataDir, 'session-f.jsonl')
writeFileSync(transcriptPath, '{}\n')
diff --git a/cli/src/lib/registry.ts b/cli/src/lib/registry.ts
index a1de055ed..5c5794232 100644
--- a/cli/src/lib/registry.ts
+++ b/cli/src/lib/registry.ts
@@ -1063,7 +1063,12 @@ class Registry {
if (!existing.sessionId || !existing.cwd) existing.cwd = input.cwd ?? existing.cwd
existing.processIdentity = processIdentity
existing.active = true
- if (existing.launch && !existing.resumeOnly) {
+ // The same rule the discovery callback applies on its own door (`cli.ts`): a verified engine
+ // process in this row's pane is what "started" means. Resume-only rows used to be excluded
+ // here, waiting for a startup hook that a resume does not reliably send — which left one
+ // reading "Starting" for 19 hours over a pane its owner could type in. The wrong-conversation
+ // guard in `register` keys on `lastHookAt`, untouched by this method, so it stays armed.
+ if (existing.launch) {
const before = existing.launch
existing.launch = { state: 'ready' }
this.traceLaunch(existing.agentId, before, existing.launch, 'openProcessAgent re-observed')
@@ -1331,7 +1336,15 @@ class Registry {
const now = Date.now()
const existing = this.agents.get(agentId)
- if (existing?.resumeOnly && existing.launch && existing.launch.state !== 'ready') {
+ // A resumed row that has not yet been told, by a hook, which conversation it actually reopened.
+ // Two ways to be in that state, and both have to count:
+ // - `lastHookAt === 0` — a resume allocated by `resumePendingAgent` and not yet hooked. Its
+ // `launch` may ALREADY read `ready`, because a resume is confirmed by its own live engine
+ // process now (`resumeStoppedAgent.ts`) and that is usually earlier than the hook. Reading
+ // only `launch` here disarmed this guard for exactly the resumes it exists to protect.
+ // - a launch that is not `ready` — a row put back by the post-reboot restore, which relaunches
+ // `--resume` against a row that kept `lastHookAt` from its previous life.
+ if (existing?.resumeOnly && (existing.lastHookAt === 0 || (existing.launch && existing.launch.state !== 'ready'))) {
// A native startup hook, carrying the verified process, must confirm this exact history —
// but only where an exact history was asked for. A resume that opened a NEW conversation (an
// engine with no resume argv, or a row with no id to reopen) reports a different id BECAUSE
diff --git a/cli/src/lib/resumeAgentService.spec.ts b/cli/src/lib/resumeAgentService.spec.ts
index a28b3933f..3d5e45701 100644
--- a/cli/src/lib/resumeAgentService.spec.ts
+++ b/cli/src/lib/resumeAgentService.spec.ts
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
+import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
import { createResumeAgentService, type ResumeAgentServiceDeps } from './resumeAgentService.js'
@@ -236,6 +236,23 @@ describe('existing runtime and readiness verification', () => {
expect(create).not.toHaveBeenCalled()
expect(announced).toEqual(['starting', 'ready'])
})
+ // The regression openharness#189 left behind. The fixture above fakes a SessionStart on every
+ // process probe; here it deliberately does not, which is the real shape of a re-check: the engine
+ // has been running for hours and will never send another hook. The re-check re-arms `starting` to
+ // withdraw the old verdict, and the readiness probe used to refuse to confirm while it read
+ // `starting` — so every Enter bought ten minutes of "Starting" and the same banner again.
+ it('confirms a live unconfirmed resume that has no further hook coming', async () => {
+ live({ processIdentity: identity, lastHookAt: 0, launch: { state: 'failed', error: 'RESUME_UNCONFIRMED', detail: 'fixture' } })
+ vi.mocked(checkPidRuntime).mockResolvedValue({ state: 'alive' })
+ vi.mocked(resolvePaneEngineProcess).mockResolvedValue(identity)
+ expect(await start()).toMatchObject({ ok: true, resumed: true })
+ // Ready, not `starting`: a row left starting is made dormant without being retained by
+ // discovery, and the desk reads its own resume receipt as unknown.
+ expect(registry.byAgent(saved.agentId)?.launch).toEqual({ state: 'ready' })
+ // The reservation is released, so the next Enter is not refused by `beginResume`.
+ expect(existsSync(join(dir, 'saved', `${saved.agentId}.resume`))).toBe(false)
+ expect(create).not.toHaveBeenCalled()
+ })
it('does not re-verify a live process that reported another conversation', async () => {
live({ processIdentity: identity, launch: { state: 'failed', error: 'RESUME_SESSION_MISMATCH', detail: 'fixture' } })
vi.mocked(checkPidRuntime).mockResolvedValue({ state: 'alive' })
diff --git a/cli/src/lib/resumeAgentService.ts b/cli/src/lib/resumeAgentService.ts
index 954b1e2a8..d1182218a 100644
--- a/cli/src/lib/resumeAgentService.ts
+++ b/cli/src/lib/resumeAgentService.ts
@@ -4,7 +4,6 @@ import { installedDsh } from '../dsh/installed.js'
import { engineKeepsTranscriptFile, registry as liveRegistry, validTranscriptPath, type RegisteredSession } from './registry.js'
import type { StoppedAgentStore } from './stoppedAgents.js'
import { resumeStoppedAgent, waitForResumedAgent, resumeChanged, resumeUnconfirmed } from './resumeStoppedAgent.js'
-import { awaitsResumeHook } from './resumeCapability.js'
import { checkPidRuntime } from './deleteAgentFallback.js'
import { checkSessionRuntime, clearPaneRemainOnExit, resolvePaneEngineProcess, tmuxPaneState } from './tmux.js'
import { listTmuxPanes } from './tmuxAgentDiscovery.js'
@@ -38,6 +37,8 @@ export function createResumeAgentService(deps: ResumeAgentServiceDeps) {
retainExitedSession, announceSession, relaunchOverrides, prepareSessionResume,
refreshGridWebSearch, clearDeleted, attachDsh } = deps
const resumeConversations = new Set<string>()
+ /** Same short form every other `[…]` line in the daemon logs uses. */
+ const sid = (id: string) => id.slice(0, 8)
const waitForResume = async (entry: RegisteredSession, current: () => boolean) => {
// Registry observations may update the same object; pin the route being verified.
const saved = { ...entry }
@@ -61,18 +62,25 @@ export function createResumeAgentService(deps: ResumeAgentServiceDeps) {
await clearPaneRemainOnExit(saved.tmuxPane)
if (!ownsRoute()) return resumeChanged
stoppedAgents.finishResume(saved.agentId)
- // A resume confirmed by its process rather than by a startup hook has nothing else coming to
- // mark the row ready, and a row left `starting` reads as "Starting" for ever and keeps
- // discovery out of it (see cli.ts's resumeOnly guard). Same condition as the proof itself in
- // `waitForResumedAgent`: only a resume that ASKED for a conversation, on an engine that hooks
- // at launch, is marked ready by `register` instead.
- const ready = awaitsResumeHook(saved.engine, saved.sessionId)
+ // Whoever got there first wins, and if nobody did, this does: a hook that already reached
+ // `register` has marked the row ready, and a resume confirmed by its process alone has nothing
+ // else coming. A row left `starting` reads as "Starting" for ever, is made dormant without
+ // being retained by discovery's `onExited`, and is refused by the desk's own resume receipt —
+ // asking WHICH proof confirmed it got that wrong in both directions, so ask the row instead.
+ const confirmed = registry.byAgent(saved.agentId)
+ const ready = confirmed?.launch?.state === 'ready'
? result.session
: registry.setLaunch(saved.agentId, { state: 'ready' }) ?? result.session
+ console.log(`[resume] ${sid(saved.agentId)} confirmed · engine=${saved.engine}`
+ + ` · hook=${(confirmed?.lastHookAt ?? 0) > 0 ? 'yes' : 'no'} · ${result.resumed ? 'same conversation' : 'fresh'}`)
announceSession(ready)
} else if (result.error !== 'AGENT_CHANGED') {
const row = registry.byAgent(saved.agentId)!
const failed = registry.setLaunch(row.agentId, { state: 'failed', error: result.error, detail: result.detail })
+ // Logged like the confirmation above, and for the same reason: this verdict clears `active`,
+ // makes the desk refuse to open the harness, and is the one a person comes asking about —
+ // openharness#189 was hard to place precisely because the resume path said nothing either way.
+ console.log(`[resume] ${sid(saved.agentId)} ${result.error} · engine=${saved.engine}${result.detail ? ` · ${result.detail}` : ''}`)
announceSession(failed!)
// A verified exit releases the reservation and keeps the shell/output. Unknown startup
// keeps both runtime and reservation; another Enter cannot launch a duplicate process.
diff --git a/cli/src/lib/resumeCapability.spec.ts b/cli/src/lib/resumeCapability.spec.ts
index a73eca238..438ebd298 100644
--- a/cli/src/lib/resumeCapability.spec.ts
+++ b/cli/src/lib/resumeCapability.spec.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
-import { ENGINES, type AgentEngine } from '../engines/types.js'
+import { ENGINES } from '../engines/types.js'
import { LAUNCH_RESUME_FLAG } from './engineLaunch.js'
-import { awaitsResumeHook, confirmsResumeByHook, resumeMode, resumesConversation } from './resumeCapability.js'
+import { resumeMode, resumesConversation } from './resumeCapability.js'
describe('what a paused harness can promise, per engine', () => {
it('gives every engine exactly one mode, from the launch table itself', () => {
@@ -30,35 +30,10 @@ describe('what a paused harness can promise, per engine', () => {
expect(resumesConversation('terminal', 'abc')).toBe(false)
})
- it('trusts a startup hook to confirm a resume only where one is sent on a resume', () => {
- expect(confirmsResumeByHook('claude')).toBe(true)
- expect(confirmsResumeByHook('codex')).toBe(true)
- // OpenCode re-attaches its session silently on `--session <id>` and posts nothing; copilot, pi
- // and amp hook on a turn; muse never hooks. Waiting for one only hangs the resume.
- for (const engine of ['opencode', 'kilo', 'copilot', 'pi', 'amp', 'muse', 'cursor', 'hermes', 'commandcode', 'devin', 'grok', 'agy', 'terminal'] as AgentEngine[]) {
- expect(confirmsResumeByHook(engine)).toBe(false)
- }
- })
-
- it('waits for a resume hook only where one is both asked for and sent', () => {
- // The pair that hooks, with a conversation to confirm: wait for it.
- expect(awaitsResumeHook('claude', 'sess-1')).toBe(true)
- expect(awaitsResumeHook('codex', 'sess-1')).toBe(true)
- // Nothing was asked for, so the id the engine reports is a new one by design.
- expect(awaitsResumeHook('claude', null)).toBe(false)
- expect(awaitsResumeHook('codex', '')).toBe(false)
- // The engine that made this rule worth naming: a restored opencode row waiting for a hook that
- // `--session <id>` never sends read "Starting" while it was working.
- expect(awaitsResumeHook('opencode', 'ses_f333bf6d8ffe')).toBe(false)
- for (const engine of ['kilo', 'copilot', 'pi', 'amp', 'muse', 'hermes', 'grok', 'agy', 'devin', 'terminal'] as AgentEngine[]) {
- expect(awaitsResumeHook(engine, 'sess-1')).toBe(false)
- }
- })
-
+ // A canary on the roster itself: adding an engine without deciding its resume mode should make
+ // the loop above fail, and this makes "the loop above ran over everything" explicit.
it('covers the whole roster, so a new engine cannot be forgotten', () => {
- // A new engine gets the weaker proof by default, never a ten-minute wait.
- const strict = ENGINES.filter(engine => confirmsResumeByHook(engine))
- expect(strict).toEqual(['claude', 'codex'])
+ expect(ENGINES.filter(engine => resumeMode(engine)).length).toBe(ENGINES.length)
expect(ENGINES.length).toBe(15)
})
})
diff --git a/cli/src/lib/resumeCapability.ts b/cli/src/lib/resumeCapability.ts
index 0425b6910..4c0786c08 100644
--- a/cli/src/lib/resumeCapability.ts
+++ b/cli/src/lib/resumeCapability.ts
@@ -1,6 +1,9 @@
/**
- * How much of a paused harness can be brought back, per engine, and what counts as proof that it
- * came back.
+ * How much of a paused harness can be brought back, per engine.
+ *
+ * What counts as PROOF that it came back is no longer an engine-by-engine question and does not
+ * live here: one verified engine process in the row's own pane answers it for all of them (see
+ * `resumeStoppedAgent.ts`).
*
* Pause/Resume used to be offered for claude and codex alone. Every other engine was refused at
* `resumeStoppedAgent`, which is stricter than the rest of the daemon already is: `agent_restart`
@@ -35,45 +38,3 @@ export function resumeMode(engine: AgentEngine): ResumeMode {
export function resumesConversation(engine: AgentEngine, sessionId: string | null | undefined): boolean {
return resumeMode(engine) === 'conversation' && !!sessionId
}
-
-/**
- * Whether this engine's startup hook fires on a RESUMED launch, so `SessionStart` carrying the new
- * pid is proof that it reopened the requested conversation.
- *
- * Measured, not assumed — and the measurement is narrower than "has a startup hook". OpenCode's
- * plugin posts on `session.created`, which a resume does not emit: relaunched with `--session <id>`
- * it re-attaches the conversation it already has, sends nothing, and a resume waiting for that hook
- * sat there until its ten-minute budget ran out (measured 2026-09-23, `scripts/pause-resume-e2e.mts`
- * against a bound opencode session). Copilot's `sessionStart` fires after the first prompt; pi's and
- * amp's plugins post on a turn; muse has no hooks at all (`sessionRepair.ts`: its store scan is "the
- * ONLY way a muse pane is ever bound").
- *
- * That leaves claude and codex, the two the strict path was written for and has always been proven
- * with. For every other engine the live engine process in its own pane is the proof — exactly the
- * bar `agent_restart` clears for all of them today (`restartAgent.ts` waits for the process and
- * nothing else). A new engine defaults to the weaker proof, which fails towards "answers in a
- * second" rather than "hangs for ten minutes".
- */
-export function confirmsResumeByHook(engine: AgentEngine): boolean {
- return engine === 'claude' || engine === 'codex'
-}
-
-/**
- * Whether a resumed row must WAIT for that hook before anything may call it started.
- *
- * Both halves have to hold: a conversation was actually requested (so there is something for a hook
- * to confirm), and this engine hooks at launch. Where either fails, the engine process alive in the
- * row's own pane is the proof, and whoever observes it says so.
- *
- * The one place this is read from is worth naming, because getting it wrong is invisible until a
- * person is looking at it: a strict-resume row that nobody marks ready stays `launch: starting`,
- * which every surface renders as "Starting" for ever. Measured 2026-09-23 — an opencode harness
- * opened from the catalog, then brought back by the post-reboot restore, sat at "Starting" while its
- * engine was up and typeable, because restore marks every row `starting` and hands the flip to
- * discovery, and discovery refused it for being resume-only. opencode's plugin posts on
- * `session.created`, which relaunching with `--session <id>` never emits, so the hook it was waiting
- * for was never coming.
- */
-export function awaitsResumeHook(engine: AgentEngine, sessionId: string | null | undefined): boolean {
- return resumesConversation(engine, sessionId) && confirmsResumeByHook(engine)
-}
diff --git a/cli/src/lib/resumeStoppedAgent.spec.ts b/cli/src/lib/resumeStoppedAgent.spec.ts
index a4322f996..2d28f0d9b 100644
--- a/cli/src/lib/resumeStoppedAgent.spec.ts
+++ b/cli/src/lib/resumeStoppedAgent.spec.ts
@@ -148,7 +148,7 @@ describe('exact conversation readiness', () => {
return {
current: vi.fn(() => true),
session: () => row,
- process: vi.fn(async () => process),
+ process: vi.fn(async (): Promise<typeof process | null> => process),
pane: vi.fn(async (): Promise<{ dead: boolean; engineExit?: number } | null> => ({ dead: false })),
sleep: vi.fn(async (ms: number) => { now += ms }),
now: () => now,
@@ -156,16 +156,26 @@ describe('exact conversation readiness', () => {
set: (next: Partial<RegisteredSession>) => { row = { ...row, ...next } },
}
}
- it('does not treat a visible process or saved session binding as readiness', async () => {
+ // The fixture row is a resume mid-flight: no hook has arrived (`lastHookAt: 0`) and the launch
+ // still reads `starting`. codex used to be held to its SessionStart here and would spin to the
+ // budget; a hook that is dropped, or an engine already running that will never send another, then
+ // cost the person the whole harness (openharness#189).
+ it('confirms a resume off its own live engine process, hook or no hook', async () => {
const deps = readiness()
- await expect(waitForResumedAgent(saved, deps)).resolves.toMatchObject({ ok: false, error: 'RESUME_UNCONFIRMED' })
- expect(deps.sleep).toHaveBeenCalled()
+ await expect(waitForResumedAgent(saved, deps)).resolves.toMatchObject({
+ ok: true,
+ resumed: true,
+ session: { sessionId: saved.sessionId },
+ })
+ expect(deps.sleep).not.toHaveBeenCalled()
})
- it('waits for the matching startup hook from the newly observed process', async () => {
+ // The one state the budget still exists for: the pane is up and nothing this row would recognise
+ // is running in it.
+ it('waits out the budget only when nothing recognisable is running in the pane', async () => {
const deps = readiness()
- deps.sleep.mockImplementation(async () => { deps.set({ lastHookAt: 100, launch: { state: 'ready' } }) })
- await expect(waitForResumedAgent(saved, deps)).resolves.toMatchObject({ ok: true, session: { sessionId: saved.sessionId } })
- expect(deps.process).toHaveBeenCalledTimes(2)
+ deps.process.mockResolvedValue(null)
+ await expect(waitForResumedAgent(saved, deps)).resolves.toMatchObject({ ok: false, error: 'RESUME_UNCONFIRMED' })
+ expect(deps.sleep).toHaveBeenCalled()
})
it('accepts a live process for an engine that has no startup hook to send', async () => {
// muse never hooks; copilot/pi/amp hook on the first turn. Waiting for one only converts a
@@ -201,11 +211,11 @@ describe('exact conversation readiness', () => {
deps.pane.mockResolvedValue(pane)
await expect(waitForResumedAgent(saved, deps)).resolves.toMatchObject({ ok: false, error: 'RESUME_FAILED' })
})
- it('does not accept a startup hook for another process or conversation', async () => {
+ // A row whose bound conversation is no longer the one being resumed is still refused — that check
+ // is on the row, ahead of any proof, and is what `registry.register`'s mismatch guard feeds.
+ it('still refuses a row that reports another conversation', async () => {
const deps = readiness()
- deps.set({ lastHookAt: 100, launch: { state: 'ready' }, processIdentity: { ...process, pid: 99 } })
- await expect(waitForResumedAgent(saved, deps)).resolves.toMatchObject({ ok: false, error: 'RESUME_UNCONFIRMED' })
- deps.set({ sessionId: 'fresh-conversation', processIdentity: process })
+ deps.set({ sessionId: 'fresh-conversation' })
await expect(waitForResumedAgent(saved, deps)).resolves.toMatchObject({ ok: false, error: 'AGENT_CHANGED' })
})
it('does not report success if the process exits between readiness probes', async () => {
@@ -272,7 +282,9 @@ describe('resume refusal and readiness edge cases', () => {
process: async () => mode === 'no process' ? null : process, pane: async () => ({ dead: false }),
sleep: async ms => { time += ms }, now: () => time, budgetMs: 250,
})
- expect(result.ok).toBe(mode === 'missing launch')
+ // `different start` is a row whose recorded identity is stale, not a pane with nothing in it:
+ // the engine process is there, which is the proof, and discovery re-reads the identity anyway.
+ expect(result.ok).toBe(mode === 'missing launch' || mode === 'different start')
})
it('uses the production clock and timeout defaults', async () => {
expect(await waitForResumedAgent(saved, { current: () => false, session: () => undefined, process: async () => null, pane: async () => null, sleep: async () => {} })).toMatchObject({ error: 'AGENT_CHANGED' })
diff --git a/cli/src/lib/resumeStoppedAgent.ts b/cli/src/lib/resumeStoppedAgent.ts
index 08b956174..2d451b819 100644
--- a/cli/src/lib/resumeStoppedAgent.ts
+++ b/cli/src/lib/resumeStoppedAgent.ts
@@ -1,6 +1,6 @@
import { isTerminalEngine } from '../engines/types.js'
import type { RegisteredSession, ProcessIdentity } from './registry.js'
-import { confirmsResumeByHook, resumesConversation } from './resumeCapability.js'
+import { resumesConversation } from './resumeCapability.js'
import type { RestartAgentReply } from './restartAgent.js'
import type { RuntimeCheck } from './tmux.js'
@@ -75,11 +75,12 @@ export interface ResumeReadinessDeps {
/**
* Wait for the replacement process to prove it came back.
*
- * For an engine that hooks at LAUNCH, the proof is its `SessionStart` carrying the new pid: process
- * discovery and a resume argument alone do not prove the conversation loaded. An engine that hooks
- * later — or not at all — cannot produce that, and waiting for it turns a working resume into ten
- * minutes of "Starting"; there the live engine process in its own pane is the proof, which is the
- * bar `agent_restart` clears for every engine today. See `resumeCapability.ts`.
+ * The proof is the engine process alive in this row's own pane — the bar `agent_restart` has cleared
+ * for every engine for as long as it has existed. Claude and Codex were held to their `SessionStart`
+ * hook instead; see the note at the check itself for why that is no longer a precondition.
+ *
+ * The budget is only reached when NO engine process was ever seen: the pane is up, and nothing this
+ * row would recognise is running in it. That is the one state worth reporting as unconfirmed.
*/
export async function waitForResumedAgent(saved: RegisteredSession, deps: ResumeReadinessDeps): Promise<RestartAgentReply> {
const now = deps.now ?? Date.now
@@ -96,23 +97,22 @@ export async function waitForResumedAgent(saved: RegisteredSession, deps: Resume
if (!pane || pane.dead || pane.engineExit != null) {
return { ok: false, error: 'RESUME_FAILED', detail: 'The agent exited before confirming the saved conversation. Its terminal output and conversation have been retained.' }
}
- // Two things decide what proof is available. A conversation was only REQUESTED when the engine
- // can reopen one and a row recorded one — otherwise there is nothing for a hook to confirm and
- // the id it eventually reports is a new one by design. And only some engines hook at launch at
- // all. Where both hold, the hook carrying the new pid is the proof; everywhere else the engine
- // process alive in its own pane is, which is the bar `agent_restart` clears for every engine.
- const resumed = resumesConversation(saved.engine, saved.sessionId)
- if (process && resumed && confirmsResumeByHook(saved.engine)) {
- if (row.lastHookAt > 0 && row.launch?.state !== 'starting'
- && row.processIdentity?.pid === process.pid && row.processIdentity.startMarker === process.startMarker) {
- return { ok: true, session: row, resumed }
- }
- } else if (process) {
- // The row's own `processIdentity` stays null until a hook binds it (`resumePendingAgent`), so
- // the evidence here is the pane's engine process itself, checked against a pane confirmed
- // alive above.
- return { ok: true, session: row, resumed }
- }
+ // ONE proof, for every engine: this row's own engine process, running in this row's own pane,
+ // which the checks above have just confirmed is alive. `deps.process()` resolves the engine
+ // binary beneath THAT pane, so it cannot be answered by somebody else's shell.
+ //
+ // Claude and Codex used to be held to a stricter one — their `SessionStart` hook, carrying the
+ // new pid, proving they had reopened this very conversation. It is better evidence, and it is
+ // evidence that does not reliably come to a RESUME, which is a narrower thing than "has a
+ // startup hook": opencode's plugin posts on `session.created`, which `--session <id>` never
+ // emits; a claude hook can announce a transcript path that never appears and be dropped
+ // (openharness#189); and measured on machine-remote-1, both resume-only codex rows carried
+ // `lastHookAt: 0` while every fresh launch beside them had hooked. Waiting for it turned a
+ // working harness into ten minutes of "Starting" and then a permanent "Start failed" over a pane
+ // the person could type in — with `active` cleared and the desk refusing to open it, the cost of
+ // the strict rule was never the resume, it was the harness. A resume that reopened the WRONG
+ // conversation is still caught, by `registry.register`'s mismatch guard, when the hook arrives.
+ if (process) return { ok: true, session: row, resumed: resumesConversation(saved.engine, saved.sessionId) }
await deps.sleep(250)
}
return resumeUnconfirmed