feat(phai): add refresh_session ACP method for Codex#1722
Merged
Conversation
tatoalo
approved these changes
Apr 20, 2026
8a2b1e1 to
62cf9e3
Compare
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 free
to 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
The Codex adapter doesn't implement
_posthog/refresh_session, so the sandbox agent-server's pre-prompt MCP refresh (added for Claude in #1717) silently falls through to "method not found" when the session is Codex-backed.Changes
Mirrors the Claude refresh shape (#1717), adapted to Codex's subprocess model:
extMethodonCodexAcpAgenthandling_posthog/refresh_sessionwith the same payload validation (mcpServersrequired, array-typed) and in-flight guard (promptRunning) as the Claude side.refreshSession(mcpServers)by respawning thecodex-acpsubprocess: abort the current controller, cancel the stale connection, kill the process, spawn a fresh one with the samecodexProcessOptions, replay the snapshottedinitializerequest, then callloadSessionwith the new MCP set to rehydrate conversation history from disk.promptRunningaroundprompt()to enforce the between-turns contract.codexProcessOptions,processCallbacks, andlastInitRequeston the agent so refresh doesn't need re-plumbing.Why respawn instead of hot-swapping MCPs on the running subprocess? codex-acp disables the user's local MCPs via spawn-time CLI args (
-c mcp_servers.<name>.enabled=false), and session-level MCP binding happens atnewSession/loadSessiontime. Respawning gives the caller-supplied server set the same overwrite guarantee the Claude path relies on.How did you test this?
codex-agent.refresh.test.ts(6 tests): methodNotFound, missing-payload rejection, non-array rejection, in-flight guard, happy-path subprocess/connection swap with state preservation, and cancel-throws resilience.pnpm --filter agent test— 263/263 pass.pnpm --filter agent typecheck— clean.pnpm --filter agent exec biome checkon the changed files — clean.