Repository navigation
feat(codex): Codex SDK backend for agent and engineer runs - #179
Conversation
# 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
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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)) |
There was a problem hiding this comment.
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.| 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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this 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
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!
There was a problem hiding this comment.
💡 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".
| 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 |
There was a problem hiding this comment.
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 👍 / 👎.
… list, document client_executed for Codex
There was a problem hiding this comment.
💡 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), |
There was a problem hiding this comment.
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 👍 / 👎.
| 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 "" |
There was a problem hiding this comment.
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 👍 / 👎.
…configured sdk's own model id
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-streamemits them;/resumereopens the run's Codex thread;agent --dry-runchecks the SDK and the sign-in.~/.reverse-api/codex) whoseauth.jsonlinks to the user's Codex sign-in, so the user's config, MCP servers, hooks, skills,AGENTS.mdand ChatGPT apps stay out of the agent.codex_homeruns in a Codex home as it is.codex_modelandcodex_effort, with/settingsand/effortlisting what the account and model offer.report_client_verifiedthrough a small stdio MCP server (verification_mcp.py), so its runs reach the verified step and the client card like Claude's.--modeltakes the configured sdk's own model id instead of only Claude's.Verification:
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.