feat(agent-client): Codex process owner + per-surface views + pool#10
Open
huntharo wants to merge 1 commit into
Open
feat(agent-client): Codex process owner + per-surface views + pool#10huntharo wants to merge 1 commit into
huntharo wants to merge 1 commit into
Conversation
Introduce CodexProcessOwner: one owned `codex app-server` process/connection that hands out lightweight per-surface CodexBackendViews (each an AgentBackend). Inbound notifications AND tool-call/approval server-requests are demultiplexed by threadId to the owning view, so many chat surfaces share ONE Codex process without clobbering each other's handlers — the gap plain CodexThreadClient has (a single global handler slot). Feasible because every Codex notification and every server-request carries threadId (DynamicToolCallParams, the v2 *RequestApprovalParams; legacy v1 carry conversationId). The owner also exposes listModels() and a structured runOneShot() (outputSchema, local images, per-turn rollback, token usage capture, abort) over the SAME connection — so model-picker refreshes and capture enrichment stop spawning their own App Server processes. CodexProcessOwnerPool mirrors AcpAgentClientPool (acquire/warm/has/release/ closeAll), keyed on connection identity (command, CODEX_HOME/env): one process per key, deduped concurrent warm-ups, app-level shutdown. Fold the existing clients onto the owner: - CodexThreadClient → thin shim over an owner + a single default view (its historical single-global-handler behavior, preserved). - CodexOneShotClient → thin shim over owner.runOneShot()/listModels(). Both public APIs and behaviors unchanged; all existing tests stay green. New tests cover per-view event/tool/approval routing isolation, view detach (stops routing without killing the process), one-shot structured turn + rollback + no-leak-to-views, model listing without a thread, and the pool. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
A Codex process owner/pool for
@pwrdrvr/agent-client, equivalent in spirit to the ACP pool — so a host stops accidentally spawning multiplecodex app-serverprocesses (one for chat, another for one-shot, another for a model-picker refresh).New API
CodexProcessOwner— owns ONEcodex app-serverprocess + JSON-RPC connection. Hands out lightweight per-surface **CodexBackendView**s (each anAgentBackend, drop-in forChatThreadController). Inbound notifications and tool-call/approval server-requests are demultiplexed bythreadIdto the view that owns that thread — so multiple chat surfaces share one process without clobbering each other's handlers. Also exposes:listModels()over the shared connection (no extra process, no one-shot client needed) — req docs: the zod 3/4 split is intentional — don't dedupe it #4.runOneShot()structured turn over a persistent worker thread on the same connection:outputSchema, local image inputs, per-turnthread/rollback, token-usage capture, abort/interrupt — req fix(agent-acp): send session/set_config_option without the_extension prefix #5.connect()(warm) andclose()(tear down the process) — req Version Packages #6.CodexProcessOwnerPool— mirrorsAcpAgentClientPool:acquire/warm/has/release/closeAll, keyed by the host on connection identity(command, CODEX_HOME/env)— reqs AcpSessionNormalizer drops tool-call file locations (path) on NormalizedToolCall #1, Version Packages #6.Why per-thread routing works
Every Codex notification and every server-request carries a
threadId:DynamicToolCallParams(item/tool/call) and the v2*RequestApprovalParamsall havethreadId+turnId; legacy v1 approvals carryconversationId. PlainCodexThreadClientjust never used it — it routes server-requests by method into one global handler slot. That's the clobber this fixes (req #3).Fold (no breaking changes)
CodexThreadClientandCodexOneShotClientare now thin shims:CodexThreadClient→ an owner + a single default view (its historical single-global-handler behavior, preserved).CodexOneShotClient→owner.runOneShot()/owner.listModels().Their public APIs and behavior are unchanged; all pre-existing tests stay green. This deletes PwrSnap's need to reach into
CodexThreadClientinternals (getConnection()/initialize()/handleNotification()) for model-listing and structured one-shot — those are now supported owner API.Tests
agent-client 49 passing (40 prior + 9 new). New coverage: per-view event/tool/approval routing isolation; view
close()detaches routing without killing the process; one-shot structured turn +outputSchema+ rollback + no leak to surface views;listModels()without opening a thread; pool dedup/keying/release/closeAll. Full workspace: typecheck (7), boundaries (no violations), all package tests green.Consumer migration (PwrSnap)
Replace the local
codex-agent-pool.tscompat layer:🤖 Generated with Claude Code