Skip to content

feat(codex): Codex SDK backend for agent and engineer runs - #179

Merged
kalil0321 merged 5 commits into
mainfrom
kalil0321/codex-sdk
Nov 15, 2026
Merged

kalil0321 merged 5 commits into
mainfrom
kalil0321/codex-sdk

Conversation

@kalil0321

@kalil0321 kalil0321 commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Why: rae ran on Claude, OpenCode, Copilot, Cursor and Hermes, but not on OpenAI Codex.

What:

  • sdk: "codex" runs agent and engineer mode on Codex through its official Python SDK (openai-codex, extra [codex]). The session shows Codex's messages, reasoning, plan, commands, file changes and browser steps; --json-stream emits them; /resume reopens the run's Codex thread; agent --dry-run checks the SDK and the sign-in.
  • Like the Claude backend, rae runs Codex in its own home (~/.reverse-api/codex) whose auth.json links to the user's Codex sign-in, so the user's config, MCP servers, hooks, skills, AGENTS.md and ChatGPT apps stay out of the agent. codex_home runs in a Codex home as it is.
  • codex_model and codex_effort, with /settings and /effort listing what the account and model offer.
  • Codex gets report_client_verified through a small stdio MCP server (verification_mcp.py), so its runs reach the verified step and the client card like Claude's.
  • Fixes found while testing, for every backend: the Chrome DevTools MCP prompt no longer treats a slow page's navigation timeout as Chrome's connection prompt; agent runs record their SDK in history; a second ctrl+c while a run wraps up leaves the session; --model takes the configured sdk's own model id instead of only Claude's.

Verification:

  • Unit tests for the backend against the SDK's own wire models, the Codex home and sign-in link, the verify server (started as Codex starts it), effort, settings and resume. Each fix was also broken on purpose to see a test fail.
  • Live on a real account: engineer and agent runs (Playwright, Chrome DevTools MCP) write a working client and report it verified; stopping a run, during a turn or while Codex starts, leaves no process behind; the session, driven in a pty, leaves cleanly with two ctrl+c.

Out of scope: the SDK installs its own Codex runtime (about 170 MB) even next to an installed Codex CLI. Browser MCP startup failures are not shown, as the SDK only exposes them through a private API.

# Conflicts:
#	CHANGELOG.md
#	README.md
#	src/reverse_api/cli.py
#	src/reverse_api/config.py
#	src/reverse_api/engineer.py
#	src/reverse_api/repl/app.py
#	src/reverse_api/repl/bridge.py
#	src/reverse_api/repl/view.py
#	src/reverse_api/utils.py
#	tests/test_cli_settings.py
#	tests/test_config.py
#	tests/test_repl.py
#	uv.lock
#	website/content/docs/cli/commands.mdx
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T11:54:02.216339Z 418a72f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

models = asyncio.run(codex_models(self.cli.config_manager.get("codex_home")))
except Exception as exc: # noqa: BLE001 # shown in the conversation, the settings stay open
message = f"could not load codex models: {exc}"
self.when_loaded(p, lambda: self.settings_failed(message, key))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Failed request keeps loading

When loading Codex models fails from /effort, key is None. settings_failed() shows the error but leaves the loading picker open. Enter keeps restoring that picker, so the user stays on “loading…” after the request has failed. Clear the picker when there is no settings page to return to.

Knowledge Base Used: Interactive REPL

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/reverse_api/repl/app.py
Line: 690

Comment:
**Failed request keeps loading**

When loading Codex models fails from `/effort`, `key` is `None`. `settings_failed()` shows the error but leaves the loading picker open. Enter keeps restoring that picker, so the user stays on “loading…” after the request has failed. Clear the picker when there is no settings page to return to.

**Knowledge Base Used:** [Interactive REPL](https://app.greptile.com/-/switch-tenant?tenant=kalil0321&next=%2Fcustom-context%2Fknowledge-base%2Fkalil0321%2Freverse-api-engineer%2F-%2Fdocs%2Frepl.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread src/reverse_api/codex_engineer.py Outdated
Comment on lines +67 to +71
if auth.is_file() and (linked is not None or not link.exists()) and linked != auth:
staged = home / f".auth.json.{os.getpid()}.{secrets.token_hex(4)}"
try:
staged.symlink_to(auth)
os.replace(staged, link) # atomic: concurrent runs never see a missing or half-made link

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Sign-in link points to itself

If RAE has already linked its auth.json to the user's sign-in and the user later sets CODEX_HOME=~/.reverse-api/codex, auth and link name the same file. This branch replaces the working link with a link to itself, breaking sign-in until the file is repaired. Skip linking when the source and destination are the same path.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/reverse_api/codex_engineer.py
Line: 67-71

Comment:
**Sign-in link points to itself**

If RAE has already linked its `auth.json` to the user's sign-in and the user later sets `CODEX_HOME=~/.reverse-api/codex`, `auth` and `link` name the same file. This branch replaces the working link with a link to itself, breaking sign-in until the file is repaired. Skip linking when the source and destination are the same path.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

continue with unrelated cleanup or documentation work. Claude SDK only
(`agent`/`engineer` with the default `sdk`); not emitted by the OpenCode,
Copilot, or Cursor backends.
Codex, Copilot, or Cursor backends.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Guide excludes a supported event

The guide explicitly says Codex does not emit client_executed, but the new backend calls _client_verified() after a successful verification report, which emits that event. Include Codex among the supported backends so wrapper authors know they can use this signal.

Knowledge Base Used: CLI flow

Prompt To Fix With AI
This is a comment left during a code review.
Path: website/content/docs/cli/scripted-usage.mdx
Line: 57

Comment:
**Guide excludes a supported event**

The guide explicitly says Codex does not emit `client_executed`, but the new backend calls `_client_verified()` after a successful verification report, which emits that event. Include Codex among the supported backends so wrapper authors know they can use this signal.

**Knowledge Base Used:** [CLI flow](https://app.greptile.com/-/switch-tenant?tenant=kalil0321&next=%2Fcustom-context%2Fknowledge-base%2Fkalil0321%2Freverse-api-engineer%2F-%2Fdocs%2Fcli-flow.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f980803f68

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +283 to +287
except asyncio.CancelledError as exc:
# Keep cancellation semantics for asyncio callers while retaining
# the partial result for the CLI, including SIGINT via Runner.
exc.partial_result = last_result # type: ignore[attr-defined]
raise

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve completed engineer results when cancelling a follow-up

When a Codex engineer run completes a turn and the user stops a subsequent turn, this re-raises cancellation with the completed result attached, but run_reverse_engineering() never reads partial_result: it either propagates CancelledError or catches Runner's KeyboardInterrupt and returns None. Consequently, run_engineer() skips recording the completed client's path and usage in history, and skips the local copy when real-time sync is disabled. The agent-mode wrapper already handles this exception attribute; add equivalent handling to the engineer execution path so stopping a follow-up does not discard the completed result.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3722ec6f41

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"approval_mode": ApprovalMode.deny_all,
"sandbox": Sandbox.full_access,
# The run's own folder: Codex explores its working folder, where other runs would distract it.
"cwd": str(self.scripts_dir),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve prompt paths before changing the Codex working directory

When a run uses a relative output directory such as --output-dir ., the directory helpers preserve relative paths, and the prompts embed them unchanged. Setting Codex's working directory to scripts/<run_id> therefore makes the supplied HAR path har/<run_id>/recording.har point inside that scripts directory rather than at the actual capture; the requested output directory similarly becomes a nested scripts/<run_id>/scripts/<run_id>. This can prevent engineering from reading the capture or leave generated files somewhere the sync watcher and returned script_path do not track. Normalize the HAR, scripts, and message-history paths against the caller's working directory before building the prompts and starting the thread.

Useful? React with 👍 / 👎.

Comment thread src/reverse_api/cli.py
Comment on lines +1541 to +1543
if sdk == "codex":
# --model first, as agent mode takes it; empty: Codex's default model.
return model or resume_model or config_manager.get("codex_model") or ""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow Codex model IDs through CLI option validation

With sdk set to codex, neither agent --model gpt-6.1-sol nor engineer --model gpt-6.1-sol can reach the new model-override handling: both commands still declare type=ModelChoice(), whose choices in cli.py and tui.py contain only Claude IDs. Exercising that option type produces exit code 2 with Invalid value for '--model' / '-m': 'gpt-6.1-sol' is not one of ...; its --help likewise lists only Claude models. Consequently, callers cannot select a Codex model per invocation and must change persistent settings instead. Make model validation SDK-aware or accept arbitrary backend model IDs before forwarding this override.

Useful? React with 👍 / 👎.

@kalil0321
kalil0321 merged commit 5c7721e into main Nov 15, 2026
14 checks passed
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.

1 participant