fix(computer): keep the resumable session when an engine dies mid-turn (#9)
`mustResetSession` treated any error matching /resume|session|conversation/
as a stale `--resume` target. That text is not prose: `failurePreview`
(engine.ts) appends the tail of the engine's STDOUT to the error, and on the
Claude path that stdout is stream-json whose EVERY event line carries a
`"session_id"` field — plus the agent's own shim commands, which mention
`conversationId`.
So on any turn after the first (`hadResume` true), a mid-turn engine death —
OOM, laptop sleep, provider hangup, a stray SIGTERM, all of which
ClaudeSession.die() explicitly anticipates and logs as "engine process died
MID-TURN" — matched on the substring `session` and was misread as a dead
resume target. `resetEngineSession()` then nulled the id and deleted
~/.cumora/sessions/<id>.session, so the next wake spawned with no `--resume`
and the agent lost the running task's context. That is the exact loss the
persisted session file exists to prevent: the engine-side session was intact
and resumable.
Match only genuine stale-target wording, and match it against the human
prose in the failure — an event line's error text is kept (that IS a
diagnosis), its machine structure is not. A successful turn's `result` is the
agent's own answer, so it is never read as a diagnosis either.
Legitimate resets are unchanged: context-window overflow, poisoned
transcript, and a real stale target ("No conversation found with session ID",
"session not found", "could not resume", codex's "thread/resume failed"),
whether reported on stderr or inside a failed result event. X
Xialie Zhuang committed
c36d5cccf8ef8d53d7ad918a8c2bb8ffa8965219
Parent: 223372d
Committed by GitHub <noreply@github.com>
on 8/19/2026, 5:26:32 AM