fix(ai): drive Codex Ask AI via codex app-server (#971)#976
Open
backnotprop wants to merge 3 commits into
Open
fix(ai): drive Codex Ask AI via codex app-server (#971)#976backnotprop wants to merge 3 commits into
backnotprop wants to merge 3 commits into
Conversation
…pts (#971) Codex Ask AI previously ran via @openai/codex-sdk (codex exec), which forces approval_policy=never and breaks in enterprise-managed Codex environments that ban it (#971). Replace the transport with a long-lived 'codex app-server' process over JSON-RPC. - New provider packages/ai/providers/codex-app-server.ts (registered as 'codex-sdk' to preserve cookie/agents.ts/UI-gate); omits approvalPolicy so Codex resolves the user's + managed policy, pins read-only sandbox, and surfaces interactive approvals through the existing PermissionCard. - Delete codex-sdk.ts and drop the @openai/codex-sdk dependency (and its 6 prebuilt platform binaries); gate registration on 'which codex'. - SessionManager: additive, optional dispose?() hook to kill the spawned process on evict/remove — a no-op for Claude/OpenCode/Pi (they don't implement it). Also rework the Ask AI prompts (all providers, separate from the transport): - Every mode now instructs the agent to answer the user's message directly and not launch an unprompted review of the context. - Code review stops pasting the whole diff for git-reproducible diff types and instead tells the agent how to inspect it (git diff <base>..HEAD, three-dot for merge-base); non-git/PR/workspace types still paste. - Claude gains the Bash tool so it can run git (still gated by approvals). - The UI passes diffType/base (session) and what the user is viewing (per question) into the context. Verified: full typecheck, full test suite (101 ai tests), and a live end-to-end smoke against codex app-server.
Render pending approval cards just above the input + provider/model bar in both the document chat (DocumentAIChatPanel) and code-review AI tab, instead of at the top of the scroll, so the user sees them where they act.
Addresses code-review findings on the codex app-server provider: - turn/interrupt was sent as a notification (no id) so Codex ignored it and abort never took effect. It's now a proper JSON-RPC request. - Filter turn events/approvals by turnId and reject an aborted turn's stragglers, so a stopped turn can no longer leak output into — or prematurely finish — the next turn (ask-stop-ask race). - Guard listeners by query generation and end the drain loop on the abort signal, so a superseded/stopped turn can't touch the live one and abort returns promptly instead of waiting for turn/completed. - Handle abort during startup: once the turn id is known, interrupt it instead of running it in the background. - Add a sendAndWait timeout so a stalled (alive-but-unresponsive) process errors instead of hanging forever. - Drain stderr (stdio 'ignore') to avoid a pipe-buffer deadlock. Also add a Stop button to both Ask AI surfaces (plan/annotate DocumentAIChatPanel and code-review AITab via ReviewSidebar). It replaces Send while streaming and calls the hook's abort -> /api/ai/abort -> session.abort(); the hook already exposed abort but nothing surfaced it.
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.
Summary
Ask AI on Codex previously launched
codex exec(via@openai/codex-sdk), which forcesapproval_policy=never. In enterprise-managed Codex environments that bannever, this breaks the chat with an "approval policy disallowed by requirements" error (#971).This replaces the Codex transport with a long-lived
codex app-serverprocess over JSON-RPC that inherits the user's and the org's configured approval policy and supports interactive Allow/Deny approvals through the existing permission UI.Closes #971
What changed
Transport (the fix)
packages/ai/providers/codex-app-server.ts(registered under the unchanged namecodex-sdkto preserve saved prefs, theagents.tsmapping, and the UI reasoning-effort gate). It omitsapprovalPolicyatthread/startso Codex resolves the user + managed policy itself, pinssandbox: read-only, and maps Codex's approval requests onto the existingpermission_request→PermissionCard→respondToPermissionflow.codex-sdk.tsand dropped the@openai/codex-sdkdependency (and its prebuilt platform binaries); registration now gates onwhich codex.SessionManager: additive, optionaldispose?()hook to kill the spawned process on evict/remove — a no-op for the Claude/OpenCode/Pi providers (they don't implement it).Prompt quality (all Ask AI providers)
Bashtool so it can rungit(still gated by approvals).Verification
codex-app-servermapper/router tests).codex app-server(handshake → thread/start → streamed answer → clean dispose, no orphaned processes).