Resume the real Codex session instead of starting a new one - #927
Merged
selfcontained merged 1 commit intoAug 10, 2026
Merged
Conversation
Restarting a Codex agent silently began a fresh conversation. `startAgent` only ever minted a `cli_session_id` for Claude agents, so Codex agents kept a null id, `shouldResume` stayed false, and the launch fell through to the new-session branch on every restart. Codex mints its own session id at launch, so it can't be pre-assigned the way Claude's is. Recover it from the rollout logs instead: rollouts carry the `[dispatch:<agentId>]` tag Dispatch stamps into the launch guidance, so the newest tagged rollout under the Codex sessions dir identifies the session to resume. `codex resume <id>` appends to that same rollout and keeps the id, so it stays valid across any number of restarts. Also fixes the resume command itself: passthrough args were dropped, which meant a full-access agent came back sandboxed after a restart, and the session id now trails the flags so codex binds it to SESSION_ID rather than the optional PROMPT positional. Rollout discovery moves to a shared `codex-sessions` module (the token harvester walked the same tree) and now honours `CODEX_HOME` like the CLI does, which also keeps the harvester test out of the real `~/.codex`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Uh oh!
There was an error while loading. Please reload this page.
selfcontained
deleted the
agt_ceb691d66594/build-codex-resume-starts-new-session
branch
August 10, 2026 15:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Restarting a Codex agent silently started a brand-new conversation.
startAgentonly ever minted acli_session_idfor Claude agents, so Codex agents kept a null id,shouldResumestayed false, and every restart fell through to the new-session branch — dropping the entire prior conversation.Fix
Codex mints its own session id at launch, so Dispatch can't pre-assign one the way it does for Claude. Recover it from the rollout logs instead:
[dispatch:<agentId>]tag Dispatch stamps into the launch guidance, so the newest tagged rollout under the Codex sessions dir identifies the session to resume.codex resume <id>appends to that same rollout and keeps the same id (verified against codex-cli 0.147.0), so once discovered the id stays valid across any number of restarts.cli_session_idthrough the same conditional-UPDATE race guard Claude uses, now extracted asclaimCliSessionId.Two related bugs in the resume command itself, both previously unreachable:
--dangerously-bypass-approvals-and-sandbox).SESSION_IDrather than sliding into the optional trailing[PROMPT]positional.Rollout discovery moves into a shared
codex-sessionsmodule — the token harvester walked the same tree — and now honoursCODEX_HOMElike the CLI does, which also keeps the harvester test out of the real~/.codex.Validation
Live on an isolated dev stack with a real Codex agent: launched it, stopped it, restarted it.
cliSessionIdto019fec2f-…and reportedSession resumed.codex resume -c mcp_servers.dispatch.url=… -c mcp_servers.dispatch.bearer_token_env_var=… 019fec2f-…— MCP wiring intact, session id trailing.Checks:
pnpm run checkclean, 2561 server unit tests pass, 178 E2E pass. Noapps/webchanges.🤖 Generated with Claude Code