Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions docs/plugins/runner-codex-app-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ runners:
- `turn_timeout_ms`: how long a started turn may go without a protocol message on stdout before Loop kills the app server and fails the turn with `turn_timeout`. Each protocol message restarts it, so it is a silence limit, not a cap on the turn. The spec's default, 1 hour. A real agent can be silent for long stretches (a cold build, a long test run), so set it above the longest silence the project's work has.
- `read_timeout_ms`: how long Loop waits for the answer to each request it writes, `initialize`, `thread/start` and every `turn/start`, before it kills the app server and fails the turn with `response_timeout`. The spec's default, 5 seconds.

- `strict_mcp`: `true` or `false`, `true` by default. With it every thread starts with each MCP server of the Codex config disabled and the `apps` feature off, so the agent gets no MCP server, see [guards](#guards). `false` lets Codex start every server its config lists.
- `strict_mcp`: `true` or `false`, `true` by default. With it every thread starts with each MCP server of the Codex config disabled and the `apps`, `plugins` and `computer_use` features off, so the agent gets no MCP server, see [guards](#guards). `false` lets Codex start every server its config lists.
- `model`: the model the thread runs, sent as `model` on `thread/start` (bl-141). Without it, or blank, Loop sends none and the thread takes the `model` of `$CODEX_HOME/config.toml`, else Codex's default. Set it to the model the workflow was checked with, one of those `model/list` returns for the Codex login: a ChatGPT login refuses some models, such as `gpt-5.1-codex-max`, that an operator's config may name, see [a refused model](#a-refused-model).

All are read from `runners.codex`, beside `command`, with the same names as the claude-code runner's. The top level `codex` block of the spec is not read by this runner.
Expand Down Expand Up @@ -92,7 +92,7 @@ The startup of spec 10.2 on the pinned protocol (m3-18), each request written on
| 1 | `initialize` (id 1) | `clientInfo` `{"name": "loop", "version": "<Loop's version>"}`, `capabilities` `{"experimentalApi": false}`, or `true` when the thread declares [Loop's tools](#loops-tools) |
| 2 | `initialized` | after the `initialize` answer |
| 3 | `config/read` (id 2), with `strict_mcp` only | `cwd` the workspace's absolute path; the answer lists the MCP servers of the Codex config |
| 4 | `thread/start` (id 3, or 2 without `strict_mcp`) | `approvalPolicy` `untrusted`, `sandbox` `danger-full-access`, `cwd` the workspace's absolute path, `model` when `runners.codex.model` is set, and a `config` with `allow_login_shell: false`, plus, with `strict_mcp`, each server `config/read` listed disabled and the `apps` feature off, plus, in an attempt Loop started, [Loop's tools](#loops-tools) as `dynamicTools` |
| 4 | `thread/start` (id 3, or 2 without `strict_mcp`) | `approvalPolicy` `untrusted`, `sandbox` `danger-full-access`, `cwd` the workspace's absolute path, `model` when `runners.codex.model` is set, and a `config` with `allow_login_shell: false`, plus, with `strict_mcp`, each server `config/read` listed disabled and the `apps`, `plugins` and `computer_use` features off, plus, in an attempt Loop started, [Loop's tools](#loops-tools) as `dynamicTools` |
| 5 | `turn/start` (id 4, or 3 without `strict_mcp`) | `threadId` from the `thread/start` answer, the prompt as one `text` input, `approvalPolicy` `untrusted`, `sandboxPolicy` `{"type": "dangerFullAccess"}`, `cwd` the workspace |

- **Ids:** `session_started` carries `thread.id` of the `thread/start` answer and `turn.id` of the `turn/start` answer, with the session id `<thread_id>-<turn_id>`. Output read before it comes right after it. A run that ends before the turn started gets two UUIDs instead.
Expand All @@ -111,7 +111,7 @@ How a turn ends, the timeouts and the turns after the first (m3-19). The decisio
- **Exit:** an app server that exits during a turn fails it at once with `port_exit`, whatever the timeouts. The session goes on: the next turn respawns it, see below.
- **Respawn** (bl-212): a continuation turn whose app server is gone, because it exited during an earlier turn or between turns, before it answered this turn's `turn/start`, or an earlier turn's failure killed it, starts a new app server and resumes the session's thread, after the stderr line `loop: the app server of this session is gone, turn <n> starts a new one and resumes the thread <id>`. The new app server gets the same startup, `initialize`, `initialized` and `config/read` under `strict_mcp`, with request ids from 1 again, then `thread/resume` with the thread id in place of `thread/start`, then the turn's `turn/start`. A turn respawns at most once: a new app server that exits too fails the turn with `port_exit`, and the next turn tries again. A session whose thread Codex never named, because turn 1 failed before its `turn/start` answer, has nothing to resume: a later turn fails at once with `port_exit: the app server of this session is gone, turn <n> cannot start on thread <id>` after its `turn_started`, and no app server starts. The workspace check and the [exec policy rules](#guards) run before every new app server, so a rules file the agent wrote during a turn stops the respawn with `exec_policy_rule`. A continuation prompt can reach Codex twice: when the old app server persisted this turn's `turn/start` and died before it answered, the new one gets the same input again on the resumed thread. This is harmless, as for the Claude Code respawn, whose process can die after its input was written.
- **Resume after a network hold** (bl-212, m4-46): `resumeSession` gives a session whose turn 1 starts a new app server and resumes the thread of the held attempt the same way, after the stderr line `loop: turn 1 resumes the thread <id> of an earlier attempt on a new app server`. The runtime session id of `session_started` is the Codex thread id, so Loop's own rule, below the soft limit, decides when it is used. The resumed session keeps that thread id, the thread is the same one, and its session id is new through the turn id of its answer.
- **The resume request:** `thread/resume` carries what `thread/start` carries, the approval policy, the sandbox, the workspace as `cwd`, `runners.codex.model`, the `config` (login shell off, and under `strict_mcp` every MCP server of `config/read` disabled and `apps` off) and Loop's tools as `dynamicTools`, so the guards, the strict MCP settings and the tools hold on a resumed thread as on a started one. It also sets `excludeTurns`, since Loop never reads the history and a long one could pass the launcher's line bound. An error answer, such as `no rollout found for thread id <id>`, an answer that is not the pinned `ThreadResumeResponse` or one that names another thread fails the turn with `response_error: thread/resume ...` and kills the app server. Loop never starts a new, empty thread in its place.
- **The resume request:** `thread/resume` carries what `thread/start` carries, the approval policy, the sandbox, the workspace as `cwd`, `runners.codex.model`, the `config` (login shell off, and under `strict_mcp` every MCP server of `config/read` disabled and the `apps`, `plugins` and `computer_use` features off) and Loop's tools as `dynamicTools`, so the guards, the strict MCP settings and the tools hold on a resumed thread as on a started one. It also sets `excludeTurns`, since Loop never reads the history and a long one could pass the launcher's line bound. An error answer, such as `no rollout found for thread id <id>`, an answer that is not the pinned `ThreadResumeResponse` or one that names another thread fails the turn with `response_error: thread/resume ...` and kills the app server. Loop never starts a new, empty thread in its place.
- **Usage of a resumed thread:** right after `thread/resume`, codex 0.167.0 replays the thread's latest `thread/tokenUsage/updated`, for a turn of the earlier attempt, and its later totals include it. A replayed total for a turn the session did not start is the thread's baseline: it gives no `usage` event and is taken out of the thread's later totals, so a resumed attempt is not charged the held attempt's tokens again. Only a resume made before any turn of the session started, turn 1 of `resumeSession`, takes that baseline. After a respawn the replay is an ordinary update and counts once, whether it names a turn of the session itself or one Loop never learned because the old app server died between accepting its `turn/start` and answering it (bl-232), so the session's usage never drops.
- **Stop:** stopping the session, or the end of a single turn run, closes stdin, gives the app server 5 seconds to exit, then kills its group.
- **Network loss:** a `failed` turn whose error is a transport failure with no HTTP answer is `runner_unavailable` (m4-08): it takes no `retries.max_attempts` slot and holds the run until a probe succeeds.
Expand Down Expand Up @@ -163,7 +163,12 @@ The guards Loop mode puts on the claude-code runner, on Codex (m3-20). Each is a
- **`git push`, `gh` and history rewrites:** the claude-code runner's deny list, `loop approve` and `loop resume` included, matched as whole words anywhere in a command's text, and a test fails when the two lists differ. A program run by its path (`/usr/bin/git push`), git's own options before the subcommand (`git -c x=y push`, `git -C . push`), a backslash a shell drops (`g\h`) and a git subcommand from a substitution or a variable (`git $(echo push)`) are caught too, and the message of a `git commit -m` is left out, so a message that names `gh` is not a denied command (bl-135). None of them is known safe to Codex, so each comes as an approval request and is declined. A command that dodges the words, such as a script file written first and run next, is not caught.
- **Exec policy rules:** a Codex `prefix_rule` with the decision `allow` runs a matching command with no approval request. So before each session starts its app server, the runner reads each `*.rules` file of `$CODEX_HOME/rules`, `/etc/codex/rules` and the `.codex/rules` folders from the workspace up to its project root. One that allows a denied command, or that Loop cannot read as literal rules, fails the first turn with `exec_policy_rule: <file> ...` and nothing starts (bl-135). Not covered: a rule that allows another program that runs a denied command for it, such as an interpreter.
- **Holdout folder:** a command that names the folder, by path, from `~`, by a relative path or by a parsed read action, and a file change under it, are declined. A read by a known safe command, such as `cat` on the folder, runs without a request and is not refused.
- **Strict MCP:** with `strict_mcp`, the default, `config/read` lists the MCP servers of the user's config and of a trusted project's `.codex/config.toml`, and `thread/start` disables each by name and turns the `apps` feature off, so the agent gets no MCP server while the operator's login stays in use. A `config/read` that fails stops the start with `response_error` rather than run with the operator's servers.
- **Strict MCP:** with `strict_mcp`, the default, `config/read` lists the MCP servers of the user's config and of a trusted project's `.codex/config.toml`, and `thread/start` and `thread/resume` disable each by name, so the agent gets no MCP server while the operator's login stays in use. A `config/read` that fails stops the start with `response_error` rather than run with the operator's servers. Some servers come from elsewhere and are not listed, so strict MCP also turns these Codex features off, and no other:
- `apps`: keeps out `codex_apps`, the ChatGPT apps server of a ChatGPT login.
- `plugins` (bl-235): keeps out the MCP servers of the operator's enabled Codex plugins, such as `cua_repl` of the `unified-computer-use` plugin the ChatGPT app installs. `config/read` does not list them.
- `computer_use` (bl-235): Codex's computer use, off as a precaution. Alone it did not keep `cua_repl` out; `plugins` does.

Checked on codex 0.167.0 with the operator's Codex home, on a started and on a resumed thread: with these off, no `mcpServer/startupStatus/updated` came; with `apps` alone off, `cua_repl` started on both.

## Usage, rate limits and cost

Expand Down
Loading