bug(chat): Resume agent returns 500 forever when a Codex thread was never materialized
Bug
If a Codex Chat session stops before its first user turn, "Resume agent" fails every time with a bare "Internal server error". Codex reserves a thread id on thread/start but writes no rollout until the first message. AO saves that reserved id as provider_conversation_id, and every resume sends thread/resume for it, which Codex rejects. The session can't be recovered from the UI: you can't send a message while the controller is stopped, and you can't restart the controller without a message. A project Orchestrator stuck this way blocks the whole project's coordinator.
Reported by: @Ayash-Bera | Analyzed against: f006182a5 (origin/main), reproduced on desktop 0.13.1-nightly.202609170454, codex-cli 0.153.4, Linux
Confidence: High
Evidence
Banner in the Orchestrator chat: "The agent controller stopped" / "Internal server error", and Resume agent fails on every click.
Daemon log for POST /api/v1/sessions/agent-orchestrator-1/resume-agent (captured with a scratch daemon on a copy of the same database, because the desktop app sends daemon output to /dev/null):
status=500 error="resume agent agent-orchestrator-1: resume chat: chat conversation resume failed:
thread/resume: app-server error -32600: no rollout found for thread id 01a07f69-d0ce-7790-91e5-9922da24e81b"
Session and conversation state:
sessions.agent-orchestrator-1: kind=orchestrator mode=chat harness=codex activity=exited
provider_conversation_id=01a07f69-d0ce-7790-91e5-9922da24e81b
conversation 2a5645d1 (scope=project): conversation_turns=0, conversation_messages=0, provider_events=68
No rollout file exists for that id. ~/.codex/sessions/2026/09/08/ has rollouts on both sides of it (01a07f53… at 10:12, 01a07f9a… at 11:30) and nothing for 01a07f69…, and no archived copy exists. That fits a thread that was reserved and never materialized, since zero turns were ever sent.
Reproduction
- Create a Codex Chat session or project Orchestrator (chat mode).
- Don't send a message. Stop the controller, for example by quitting or updating the desktop app.
- Reopen the chat and click Resume agent.
- HTTP 500
INTERNAL_ERROR, and it fails again on every retry.
Root Cause
backend/internal/session_manager/manager.gorestoreArgv(TUI) already guards this case:conversationLost := ok && nativeConversationMissing(...), then falls back tofreshLaunchArgv. Its comment describes this exact situation ("a session torn down before its first turn").- The Chat path has no such guard.
relaunchSessionWithPolicyAndGenerationonly rejects an emptyProviderConversationID, andresumeChatController(chat_spawn.go) passes the saved id straight toStartChatwith nonativeConversationMissingcheck. codex.Plugin.NativeConversationExists(adapters/agent/codex/codex.go) was written for this case too. Its doc saysthread/resume"rejects that reserved-only UUID with 'no rollout found for thread id'".- The error is not mapped to an API error, so the client only sees "Internal server error".
Fix
In the Chat resume path, when native history is not required (requireNativeHistory == false) and the harness probe reports the native conversation missing, drop the dead provider id and start a fresh provider thread. That matches the TUI path. For orchestrators, chat.Service already records an "Agent context reset" boundary when ProviderConversationID is empty. Callers that require native history (account switch, interface transitions) should keep failing, with a mapped error instead of a 500.
Impact
- A chat session or project Orchestrator stuck this way stays unusable until someone edits the database by hand or replaces the orchestrator.
- The message "Internal server error" gives no clue about the cause.
Related
Fixed by #7276 together with #6273: an untouched Chat whose provider never saved its thread can resume in place. Please reopen if Resume agent still fails for this case on a current build.