Skip to content

feat(phai): add refresh_session ACP method for Codex#1722

Merged
skoob13 merged 1 commit intomainfrom
feat/refresh-method-for-codex-sandbox
Apr 20, 2026
Merged

feat(phai): add refresh_session ACP method for Codex#1722
skoob13 merged 1 commit intomainfrom
feat/refresh-method-for-codex-sandbox

Conversation

@skoob13
Copy link
Copy Markdown
Contributor

@skoob13 skoob13 commented Apr 17, 2026

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:

  • Add extMethod on CodexAcpAgent handling _posthog/refresh_session with the same payload validation (mcpServers required, array-typed) and in-flight guard (promptRunning) as the Claude side.
  • Implement refreshSession(mcpServers) by respawning the codex-acp subprocess: abort the current controller, cancel the stale connection, kill the process, spawn a fresh one with the same codexProcessOptions, replay the snapshotted initialize request, then call loadSession with the new MCP set to rehydrate conversation history from disk.
  • Track promptRunning around prompt() to enforce the between-turns contract.
  • Retain codexProcessOptions, processCallbacks, and lastInitRequest on 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 at newSession/loadSession time. Respawning gives the caller-supplied server set the same overwrite guarantee the Claude path relies on.

How did you test this?

  • New suite 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 check on the changed files — clean.

@skoob13 skoob13 requested a review from a team April 20, 2026 07:30
@skoob13 skoob13 force-pushed the feat/refresh-method-for-codex-sandbox branch from 8a2b1e1 to 62cf9e3 Compare April 20, 2026 12:22
@skoob13 skoob13 merged commit be7f6fd into main Apr 20, 2026
15 checks passed
@skoob13 skoob13 deleted the feat/refresh-method-for-codex-sandbox branch April 20, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants