Repository navigation
feat(agent): resume conversations on relaunch and ask after a mid-turn crash - #409
Conversation
…n crash When Codex stopped in the middle of a turn, the pane silently dropped the partial reply and sent queued follow-ups as soon as the thread was back. Now the partial reply stays, a notice explains what happened, and nothing is sent until the user chooses Retry, Continue, or Leave it. A clean quit used to archive the conversation and start a new Codex thread with a recap. Each workspace now saves its conversation and the next launch resumes the same thread when the pane opens or the first message is sent. One editor at a time owns a workspace's conversation. Host API 0.22.0 adds AgentPrepare, AgentResolveInterruption, agent:conversation_resumable, and the interrupted / resume_pending snapshot fields.
The owner claim treated every recorded pid as live off unix, so a claim left by a crashed editor was never taken over on Windows. Query the process with OpenProcess and GetExitCodeProcess instead.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b0d8f7211
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Keep host API 0.21.0: it is still unreleased, so the new calls, event and snapshot fields join that version instead of bumping to 0.22.0. - A failed save or removal no longer counts as saved, so it is retried and the forced exit save still runs; a failed removal keeps the workspace so the forgotten record is removed later. - :AgentNew no longer resumes the saved thread it is about to forget, and a late restore failure for a thread the pane left is ignored.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: da6180585f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…omic - A transcript loaded from an earlier launch may miss the last reply if Red quit between saves, so the resumed thread's history replaces it; only a same-process app-server restart keeps the visible transcript. - Owner claims are read and replaced under an OS lock on <key>.lock and the pid is published by an atomic rename, so two editors racing for a workspace can no longer both own it.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Lines 204 to 206 in 74d8b39
When a mid-turn crash has at least one queued follow-up, restore_pending leaves the lifecycle paused. Typing the advertised alternative to choosing Retry/Continue/Dismiss clears interrupted, but this condition then appends the new message and returns without unpausing or dispatching anything; the interruption choices disappear while every prompt remains stuck until the user separately invokes :AgentSendQueued. Treat this submission as the explicit continuation promised by the UI and advance the queue.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
If :AgentNew's replacement thread was created before the next save, the empty conversation counted as saved and the forgotten record survived a quit, so the next launch resumed the thread the user had abandoned.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c3704702a2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- A conversation recovered by --resume or a detached restart now claims its workspace first; if another live editor owns it, the recovered thread is not resumed and its transcript stays as archived context. - An editor denied ownership remembers it, so its separate thread is never saved over the owner's conversation, even after the owner exits.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d62995eb9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ersations - A recovered conversation whose ownership cannot be checked is not resumed, the same as one another editor owns. - A saved conversation from an older tool contract becomes the archived transcript (unless the pane kept one), so its history is recapped in the new thread instead of being lost.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 61b9c3fd0d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- A saved conversation whose claim fails at launch is archived as the transcript and this editor never saves over it. - When the conversation moves to another workspace, the old record is removed and its claim released; a failed removal stays pending and is retried on later saves and on exit.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Line 361 in fb32c0e
When an active turn ends unexpectedly with AgentTurnOutcome::Stopped—for example, a session-scoped agent:error or a non-completed agent:completed status while the app-server remains alive—this unconditionally discards the in-flight prompt. The queue is paused, but interrupted is never populated, so the new Retry/Continue recovery UI does not appear and cannot resend the original message; preserve the prompt for unexpected stopped outcomes while still excluding user-requested stops.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A turn that ended with an error or an unrequested stop while Codex kept running paused the queue but dropped its message, so the new recovery choices never appeared. It now becomes an interruption too; the pane shows just the choices under the error, since the error already explains what happened, and :AgentSendQueued counts as moving on.
|
Re: Codex review 5561149396 ( |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 42bd6e33ba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Adopting a saved conversation at launch rebuilds its source annotations, and syncing records keeps those on files that are not open, so a relaunch no longer deletes them. - A failed lazy resume clears the continuation hint and the composer keeps saying the conversation is archived.
Ownership was a pid file checked for liveness under a lock, with takeover of stale claims and per-platform process checks. Holding the lock for the editor's lifetime is the claim itself: the OS releases it when Red exits or crashes, so there is no stale owner to detect.
…on-continuity # Conflicts: # docs/plugin_api_changes.json # src/editor.rs
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c479797a8b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
An owner still exiting could save a newer record between the peek and the claim; adopting the peeked copy would later overwrite it.
An end-to-end evaluation of pair mode against real Codex found two gaps in how the Agent pane keeps a conversation going.
Why
A crash in the middle of a turn was silent. When the Codex app-server died while a reply streamed, Red resumed the thread correctly, but the partial reply vanished from the pane (the restore replaced the transcript with Codex's saved history, which has no incomplete turn). The only sign was a passing "Agent session restored" message. Worse, queued follow-ups were sent as soon as the thread came back, on top of a turn that had stopped halfway and might have applied some of its edits. A stopped turn should stop everything, explain what happened, and ask.
Quitting and relaunching started a new Codex thread. A real
thread/resumeonly happened with--resumeor after a detached editor restarted. A normal quit and relaunch archived the transcript and replayed a recap of up to 6,000 characters into a fresh thread, so the agent lost everything beyond that recap even though Codex still had the full thread on disk.What changed
Interrupted turns (
src/editor/agent_pane.rs,plugins/agent.hk):interruptedsnapshot field. The thread still resumes in the background, but nothing is sent, queued follow-ups included, until the user answers.]land Enter, with:AgentRecoverorSpace A(which open a picker), or with a click. Typing a new message also moves on. The status line says "Codex stopped mid-reply · Space A to choose what to do", so a hidden pane still gets the message.:AgentSendQueuedstill works.Resume on relaunch (
src/editor/agent_continuity.rs, new):<config>/agent/conversations/<sha256 of workspace>.json. The file is owner-only and written atomically. Saves happen at most once a second while idle and every 10 seconds while a reply streams, plus once on exit.agent:conversation_resumable. Resuming is lazy: the thread resumes when the pane opens (AgentPrepare) or when the first message is sent, so a launch that never uses the agent never starts Codex. The pane shows "↺ Picked up where you left off 2 hours ago" and the composer footer shows "Continuing · :AgentNew starts fresh".:AgentNewforgets the thread and deletes its saved conversation, so the old thread never comes back. If the thread can't be resumed, for example because of an incompatible tool contract or a missing thread, the message falls back to today's recap in a new thread. Prompts waiting on a failed resume now go to that new thread instead of sitting queued.<hash>.lockuntil it exits. A second Red in that workspace, including one started with--resume, doesn't adopt or overwrite the saved conversation. It starts its own thread, says so in the status line ("Agent conversation is open in another Red window; this window starts its own"), and never saves that thread, even after the first editor exits. The operating system releases the lock when its editor exits or crashes, so there is no stale claim to detect.AgentManagerkeeps aconversation_revisioncounter, so the editor can tell whether the saved copy is stale without comparing transcripts.Host API 0.22.0 (
src/plugin/host_api.json,docs/PLUGIN_API.md,docs/plugin_api_changes.json):AgentPrepare()andAgentResolveInterruption(choice, transcript).agent:conversation_resumable, which carries the conversation plus anagesuch as "2 hours ago".agent:pane_state.interruptedandresume_pending.User docs in
docs/AGENT_WORKFLOW.mddescribe both behaviours, the ownership rule and:AgentRecover.How to Test
Space Aand ask "Remember HERON. Reply OK". Then send "Without tools, write a 500-word essay about ledgers". While it streams, send "reply only QUEUED", then kill that red'scodex app-serverchild (pkill -9 -P <red pid> -f app-server).:AgentRecoverand pick Retry. Expected: the essay is rewritten, then "QUEUED" follows.:AgentSendQueued.~/.codex/sessions/**/rollout-*.jsonlfor the workspace holds all of this in one thread.:q!and startredagain in the same directory. Expected: nocodex app-serverchild until you pressSpace A. The pane then shows the earlier messages and "↺ Picked up where you left off …".:AgentNew, then:q!and relaunch. Expected: no resume divider. Asked about any codeword, the agent says it doesn't know one, in a new rollout file.redin the same directory. Expected: the status line says the conversation is open in another Red, and the first editor's saved conversation is untouched.All five flows were run against real Codex (
codex-cli0.163.0) in tmux with an isolated config.Targeted tests:
cargo test --lib agent_pane::tests(crash and resume transitions)cargo test --lib agent_continuity(save, adopt, ownership, forget, incompatible contract)cargo test --lib bundled_agent(pane rendering: partial reply kept, choices, nothing sent until chosen, Space A picker, Leave keeps the queue paused, saved conversation resumes on open)