Skip to content

fix(ai): drive Codex Ask AI via codex app-server (#971)#976

Open
backnotprop wants to merge 4 commits into
mainfrom
fix/971-codex-app-server
Open

fix(ai): drive Codex Ask AI via codex app-server (#971)#976
backnotprop wants to merge 4 commits into
mainfrom
fix/971-codex-app-server

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Summary

Ask AI on Codex previously launched codex exec (via @openai/codex-sdk), which forces approval_policy=never. In enterprise-managed Codex environments that ban never, this breaks the chat with an "approval policy disallowed by requirements" error (#971).

This replaces the Codex transport with a long-lived codex app-server process 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)

  • New provider packages/ai/providers/codex-app-server.ts (registered under the unchanged name codex-sdk to preserve saved prefs, the agents.ts mapping, and the UI reasoning-effort gate). It omits approvalPolicy at thread/start so Codex resolves the user + managed policy itself, pins sandbox: read-only, and maps Codex's approval requests onto the existing permission_requestPermissionCardrespondToPermission flow.
  • Deleted codex-sdk.ts and dropped the @openai/codex-sdk dependency (and its prebuilt platform binaries); registration now gates on which codex.
  • SessionManager: additive, optional dispose?() 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)

  • Every mode now instructs the agent to answer the user's message directly instead of launching an unprompted review.
  • Code review tells the agent how to inspect the diff with git (for git-reproducible diff types) instead of pasting the whole patch; non-git/PR/workspace types still paste.
  • Claude gains the Bash tool so it can run git (still gated by approvals).
  • The approval card is pinned just above the input/model bar in both chat surfaces.

Verification

  • Full typecheck (all packages incl. Pi) and full test suite green (incl. new codex-app-server mapper/router tests).
  • Live end-to-end smoke against a real codex app-server (handshake → thread/start → streamed answer → clean dispose, no orphaned processes).
  • Locally compiled binary tested for plan review, annotate, and the approval card.

…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.
- Codex provider fetches model/list at startup (throwaway app-server, like
  Pi/OpenCode) and populates the real models plus each model's actual
  supportedReasoningEfforts + defaultReasoningEffort. Replaces the hardcoded
  model list and the static AI_REASONING_EFFORTS (which mislabeled xhigh as
  'Max' and omitted minimal).
- AIProviderBar + AIConfigBar now show the selected model's real efforts and
  hide the control when a model reports none. xhigh is shown verbatim.
- Fix: the Stop button now also appears in the populated code-review chat
  state (a prior edit missed the second GeneralInput due to indentation).
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.

Document chat / Ask launches Codex with approval_policy=Never, breaking enterprise-managed Codex requirements

1 participant