diff --git a/docs/plugins/runner-codex-app-server.md b/docs/plugins/runner-codex-app-server.md index c3d9e7b5..8287929a 100644 --- a/docs/plugins/runner-codex-app-server.md +++ b/docs/plugins/runner-codex-app-server.md @@ -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. @@ -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": ""}`, `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 `-`. Output read before it comes right after it. A run that ends before the turn started gets two UUIDs instead. @@ -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 starts a new one and resumes the thread `. 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 cannot start on thread ` 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 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 `, 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 `, 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. @@ -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: ...` 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 diff --git a/docs/spec-decisions.md b/docs/spec-decisions.md index 36eabf6c..325ae5a6 100644 --- a/docs/spec-decisions.md +++ b/docs/spec-decisions.md @@ -2380,7 +2380,7 @@ The guards, how each holds on Codex and what it cannot cover: - **`git push`, `gh` and history rewrites** (story 40). The denied commands are the claude-code runner's list, and since bl-135 `DeniedCommandsTest` fails when the two differ: `git push` and its force forms, `gh`, `git rebase`, the hard form of `git reset`, `git commit --amend`, `git filter-branch`, `git filter-repo`, `git reflog expire`, `git update-ref` and `git replace`, plus `loop approve` and `loop resume`, also through a launcher path (m2-24). A command is matched on its whole text, as Claude Code matches its deny rules: split into words at blanks, quotes and the shell's operators, a denied command matches as a run of whole words anywhere, so `cd x && git push`, `bash -lc 'gh pr create'` and a quoted script holding one are declined. They never run without a request: none of them is known safe to the pinned Codex, so under `untrusted` each comes as an approval request and is declined. Not covered, as on the claude-code runner: a command that dodges the words, such as a script file written first and run next. Since bl-135 a program by its path, git's own options, a backslash, a substitution as the git subcommand and a commit message are handled, and an execpolicy rule that allows a denied command stops the session before it starts, see [Codex guards after the m3-20 review](#codex-guards-after-the-m3-20-review-extension-bl-135). - **Holdout read and edit deny** (m2-14). The holdout folder reaches the runner through plugin loading, as the `holdoutDir` of `RunnerProvider.create`, which `loop run` always gives, with no `Host.kt` edit; the provider's refusal of m3-18 is lifted. A command approval is declined when the command names the folder, by its text, from `~` or `$HOME`, by a relative word read from the request's `cwd`, or by the path of one of its parsed read actions; a file change approval when it touches the folder, as above. Paths are compared by normalized and real path, ignoring case. Not covered: a read by a command Codex holds as known safe, such as `cat`, `sed -n` or `rg` on the folder, runs without a request, so nothing can refuse it. This gap is wider than the claude-code runner's, whose deny rules cover its file tools and miss only a shell read: a Codex agent reads files through the shell. What the [holdout checks](#holdout-checks-extension-m2-14) say holds: it is a guardrail, not a sandbox, the agent runs as the same OS user, and what keeps a holdout check honest is that its output never reaches the agent. -- **Strict MCP** (bl-72). `runners.codex.strict_mcp`, a boolean of the profile, `true` by default as bl-72 decided for both runners; any other value fails preflight with `runners.codex.strict_mcp must be a boolean`. With it the startup sends `config/read` with the workspace as `cwd` between `initialized` and `thread/start`, and `thread/start` carries `"config": {"mcp_servers": {"": {"enabled": false}, ...}, "features": {"apps": false}}`, one entry per server the answer lists. It is the first mechanism m3-02 found: no single override empties the table, but a server disabled by name never starts, and the `apps` feature off keeps `codex_apps` out, while the operator's login stays in use. Request ids become 1 (`initialize`), 2 (`config/read`), 3 (`thread/start`), 4 (`turn/start`), then 5 and on for continuation turns; without strict they stay 1, 2, 3, then 4 and on. A `config/read` error answer, or one that does not decode, fails the start with `response_error`, so a strict session never runs with the operator's servers. `strict_mcp: false` sends no `config/read`, and its `config` holds only `allow_login_shell: false`. Checked again on codex 0.167.0 in this issue, with a temporary `CODEX_HOME`, no login, no turn and no model call: `config/read` lists the user config's `mcp_servers` and, from a trusted workspace, the project's `.codex/config.toml` servers too; a thread started with them disabled and `apps` off started none, while a plain thread started both. The recorded `config/read` answer, scrubbed, is the fixture `src/test/resources/real/config_read.json`. Not covered: a server added to a config during the session, since each session reads the config once, at its start. +- **Strict MCP** (bl-72). `runners.codex.strict_mcp`, a boolean of the profile, `true` by default as bl-72 decided for both runners; any other value fails preflight with `runners.codex.strict_mcp must be a boolean`. With it the startup sends `config/read` with the workspace as `cwd` between `initialized` and `thread/start`, and `thread/start` carries `"config": {"mcp_servers": {"": {"enabled": false}, ...}, "features": {"apps": false}}`, one entry per server the answer lists. It is the first mechanism m3-02 found: no single override empties the table, but a server disabled by name never starts, and the `apps` feature off keeps `codex_apps` out, while the operator's login stays in use. Request ids become 1 (`initialize`), 2 (`config/read`), 3 (`thread/start`), 4 (`turn/start`), then 5 and on for continuation turns; without strict they stay 1, 2, 3, then 4 and on. A `config/read` error answer, or one that does not decode, fails the start with `response_error`, so a strict session never runs with the operator's servers. `strict_mcp: false` sends no `config/read`, and its `config` holds only `allow_login_shell: false`. Checked again on codex 0.167.0 in this issue, with a temporary `CODEX_HOME`, no login, no turn and no model call: `config/read` lists the user config's `mcp_servers` and, from a trusted workspace, the project's `.codex/config.toml` servers too; a thread started with them disabled and `apps` off started none, while a plain thread started both. The recorded `config/read` answer, scrubbed, is the fixture `src/test/resources/real/config_read.json`. Not covered: a server added to a config during the session, since each session reads the config once, at its start. Since bl-235 the strict `features` also turn `plugins` and `computer_use` off, since an enabled Codex plugin starts servers `config/read` does not list, see [strict MCP turns Codex plugins off](#strict-mcp-turns-codex-plugins-off-extension-bl-235). - **Observed on the pinned app server:** `thread/start` in a workspace inside a git repository wrote `[projects.""] trust_level = "trusted"` into `$CODEX_HOME/config.toml`. So after the first thread a workspace is a trusted project, and its `.codex/config.toml`, which the agent can write, loads in later sessions. Strict MCP covers its MCP servers, since `config/read` lists them; nothing in Loop covers the rest of that project config. Since bl-135 a `.codex/rules/` file that allows a denied command stops the next session before it starts, see [Codex guards after the m3-20 review](#codex-guards-after-the-m3-20-review-extension-bl-135). Not in m3-20: Loop's client tools (17.5 items 15 and 16), usage and rate limits (items 13 and 14), and a read deny that holds without an approval request, which would need a Codex sandbox that can deny reads under a folder. No model turn ran in this issue, so which commands the pinned Codex asks about under `untrusted`, and that a file change item starts before its approval request, come from the protocol's schema and documentation, not from a recorded session; the real integration profile (m3-24) checks them. @@ -2656,11 +2656,23 @@ Before bl-212 a Codex session ran every turn on one app server: once it exited, - **After a network hold.** `resumeSession(ctx, runtimeSessionId)` gives a session whose turn 1 resumes that thread on a new app server, after the stderr line `loop: turn 1 resumes the thread of an earlier attempt on a new app server`. Loop's own rule of m4-46, below the soft limit, decides when it is called; the runner only implements it. The runtime session id of `session_started` is the Codex thread id once Codex named it, null before. - **The thread id of a resumed session.** It stays the Codex thread id: the thread is the same one, and Loop's ids say so. The session id `-` is still new, through the turn id of the new `turn/start` answer. Nothing in the orchestrator keys on a thread id being new per attempt. - **Usage.** Right after `thread/resume` the pinned Codex replays the thread's latest `thread/tokenUsage/updated`, naming a turn of the earlier attempt, and its later totals include it. `Telemetry` takes a replayed total for a turn this session did not start, on the resumed thread, as the thread's baseline: no `usage` event, and the baseline is taken out of the thread's later totals, so the new attempt is not charged the held attempt's tokens again. After a respawn the replay names a turn of the same session, so it is an ordinary update that leaves the sum unchanged and counts once. Since bl-232 only a resume made before any turn of the session started, turn 1 of `resumeSession`, takes a baseline: a replay after a respawn that names a turn Loop never learned, because the old app server died between accepting its `turn/start` and answering it, is an ordinary update too, so the session's usage never drops. The same case can send a continuation prompt twice, which is harmless, as for the Claude Code respawn. Occupancy is unchanged: the replayed `last` is the input of the thread's latest request, its real occupancy. -- **Seen, not of this issue.** On both `thread/start` and `thread/resume`, codex 0.167.0 started an MCP server, `cua_repl`, that `config/read` did not list, so the strict config could not disable it by name. +- **Seen, not of this issue.** On both `thread/start` and `thread/resume`, codex 0.167.0 started an MCP server, `cua_repl`, that `config/read` did not list, so the strict config could not disable it by name. Fixed in bl-235, see [strict MCP turns Codex plugins off](#strict-mcp-turns-codex-plugins-off-extension-bl-235). - **Out of scope.** Updating the pinned Codex version or the schema, a resume by history or by path, and when Loop calls `resumeSession`. Tests: `plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexThreadResumeTest.kt` (a respawn after an exit between turns and after an exit mid turn, a session with no thread fails at once, `resumeSession` at turn 1 with the configured model, the strict MCP config and `dynamicTools` on the resume, an error answer, an answer of another type or another thread, the usage of a resumed and of a respawned thread, an exec policy rule before a respawn, and since bl-232 a replay of a turn Loop never learned after a started turn, a new app server that exits between its `thread/resume` answer and `turn/start`, and a later turn's respawn after `resumeSession`), `CodexAppServerRunnerContractTest.kt` (`AgentRunnerContract` with `resumeSession` overridden), `CodexAppServerRunnerTest.kt` (the `17_5` continuation tests and `m4-46 it resumes no session across attempts, ...`, which now checks that a session is returned). +### Strict MCP turns Codex plugins off (extension, bl-235) + +Seen in the real run of bl-212 (above): under `strict_mcp` a Codex thread, started or resumed, still started `cua_repl`, an MCP server `config/read` does not list, so the strict config could not disable it by name. Strict MCP means the agent gets no MCP server at all, so this weakened a guard. The decisions: + +- **Where `cua_repl` comes from.** Not from the `computer_use` feature, as triage guessed, but from a Codex plugin. The operator's `~/.codex/config.toml` enables plugins of the `openai-bundled` marketplace the ChatGPT app installs; `unified-computer-use@openai-bundled` declares `cua_repl` in its `.mcp.json`, and `codex-app-tools@openai-bundled` declares `codex_app` the same way. `config/read` lists neither: on the operator's machine it lists only `node_repl`, a server of the user config, which strict already disables by name. In a temporary `CODEX_HOME` with no plugin, a plain thread started no MCP server. +- **Probed on codex 0.167.0, 2026-11-26,** with the operator's Codex home, in a workspace outside any git repository so no trust entry was written, reading the `mcpServer/startupStatus/updated` notifications, the signal m3-02 settled on. A plain thread started `node_repl`, `codex_apps` and `cua_repl`. The strict config as built (`node_repl` disabled, `apps` off) still started `cua_repl`, on `thread/start` and on `thread/resume`. Adding `computer_use` off, `browser_use` off, or both, still started it. Adding `plugins` off started nothing. With `plugins` and `computer_use` off, a started thread ran one real turn and started nothing, and a new app server resumed that thread with the same config and started nothing; resumed with the config as built, it started `cua_repl` again. +- **The strict features.** Under `strict_mcp` the thread `config` of `thread/start` and `thread/resume` now turns off `apps`, `plugins` and `computer_use`. `plugins` is the switch that keeps the plugin servers out. `computer_use` goes off too as a precaution: it is the feature the issue named, and a strict session has no use for it, though alone it did not stop `cua_repl`. The pinned schema's `Config.computer_use` is a `ComputerUseConfig` with only app access settings and no switch, so the feature flag is the setting. Without `strict_mcp` the `config` is unchanged, `allow_login_shell: false` alone. +- **Other sources.** None left in the probe: `node_repl` is disabled by name, `codex_apps` by `apps`, and every plugin server by `plugins`, so a strict session needs no fallback that fails on an unknown server. A trusted project's `.codex/config.toml` servers are still listed by `config/read` and disabled by name (m3-20). +- **Not covered.** A later Codex that starts an MCP server from yet another source. The startup notifications would show it, as they showed `cua_repl`. + +Tests: `plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexServerRequestsTest.kt` (`bl-235 under strict MCP thread start turns plugins and computer_use off beside apps, and no feature without it`, and the m3-20 strict tests with the new features), `CodexThreadResumeTest.kt` (`bl-235 under strict MCP the resume turns plugins and computer_use off beside apps, and no feature without it`, and the bl-212 strict resume test). + ### Drain (extension, m4-10) Story 110, carrying bl-110. Loop had `loop run` and `loop stop`, nothing between. On the night of 2026-11-15 (run 284454f4), to let two running issues finish while starting nothing new, the operator removed the `ready-for-agent` label of the one issue they would unblock and restored it by hand later. A zero per state cap does not work, `max_concurrent_agents_by_state` ignores values below 1. The need comes back at each session end, before a reinstall and before a planned stop. The decisions: diff --git a/plugins/runner-codex-app-server/src/main/kotlin/loop/runner/codex/CodexAppServerRunner.kt b/plugins/runner-codex-app-server/src/main/kotlin/loop/runner/codex/CodexAppServerRunner.kt index cb3b6ea3..c1b4e8b4 100644 --- a/plugins/runner-codex-app-server/src/main/kotlin/loop/runner/codex/CodexAppServerRunner.kt +++ b/plugins/runner-codex-app-server/src/main/kotlin/loop/runner/codex/CodexAppServerRunner.kt @@ -55,9 +55,9 @@ import kotlin.time.TimeSource * run with no shell (m3-20). [readTimeout] (`read_timeout_ms`) is how long the runner waits for the answer to each * request it writes, [turnTimeout] (`turn_timeout_ms`) how long a started turn may go without a protocol message * (m3-19, spec 10.6). [strictMcp] (`strict_mcp`, m3-20 after bl-72) starts every thread with each MCP server of the - * Codex config disabled and the `apps` feature off, so the agent gets no MCP server. [holdoutDir] is Loop's holdout - * folder (m2-14), given by the host through plugin loading, whose reads and edits the approval rules refuse (m3-20); - * null refuses none. [model] (`model`, bl-141) is sent as the `model` of `thread/start`, so the thread runs the model + * Codex config disabled and the `apps`, `plugins` and `computer_use` features off, so the agent gets no MCP server. + * [holdoutDir] is Loop's holdout folder (m2-14), given by the host through plugin loading, whose reads and edits the + * approval rules refuse (m3-20); null refuses none. [model] (`model`, bl-141) is sent as the `model` of `thread/start`, so the thread runs the model * the workflow names rather than the one of the operator's Codex config; null sends none and keeps Codex's choice. * [readOnly] (bl-214, no profile key) is the posture of the merge risk reviewer, [CodexRiskReviewer]: the thread runs * on the `read-only` sandbox and every command and file change approval is declined, see [ServerRequestPolicy]. @@ -249,7 +249,8 @@ data class CodexAppServerSettings( * id of turn 1 and the turn id of their own answer, or one Loop minted. Exactly one terminal event comes last. * * Strict MCP (m3-20, bl-72): with [CodexAppServerSettings.strictMcp] the startup reads the Codex config with - * `config/read` and starts the thread with each MCP server it lists disabled and the `apps` feature off. + * `config/read` and starts the thread with each MCP server it lists disabled and the `apps`, `plugins` (bl-235) and + * `computer_use` features off. * * Exec policy rules (bl-135): before a session starts an app server, its first or a respawned one, [ExecPolicyRules] * reads the Codex rules files it would load; one that allows a denied command, or cannot be read, fails the turn with diff --git a/plugins/runner-codex-app-server/src/main/kotlin/loop/runner/codex/StartupHandshake.kt b/plugins/runner-codex-app-server/src/main/kotlin/loop/runner/codex/StartupHandshake.kt index a9d808ad..16119c54 100644 --- a/plugins/runner-codex-app-server/src/main/kotlin/loop/runner/codex/StartupHandshake.kt +++ b/plugins/runner-codex-app-server/src/main/kotlin/loop/runner/codex/StartupHandshake.kt @@ -97,7 +97,8 @@ sealed interface StartupFailure { * `thread/start`, and `thread/start` carries a `config` that disables each MCP server its answer lists, by name, and * turns the `apps` feature off, the mechanism m3-02 found on the pinned app server: no single override empties the * server table, but a server disabled by name never starts. The answer lists the servers of the user's config and of - * a trusted project's `.codex/config.toml`. An error answer or one that does not decode fails the start, so a strict + * a trusted project's `.codex/config.toml`, not those of the operator's Codex plugins, so the `plugins` feature goes + * off too, and `computer_use` with it (bl-235). An error answer or one that does not decode fails the start, so a strict * session never runs with the operator's servers. * * A resume (bl-212) is the same start with `thread/resume` of an existing thread in place of `thread/start`: [start] with @@ -424,13 +425,19 @@ internal class StartupHandshake( */ private fun baseConfig(): JsonObject = buildJsonObject { put(ALLOW_LOGIN_SHELL, false) } - /** The `config` of a strict thread: [baseConfig], each of [names] disabled, and the `apps` feature, `codex_apps`, off. */ + /** + * The `config` of a strict thread: [baseConfig], each of [names] disabled, and the features off that bring MCP + * servers `config/read` does not list: `apps`, which starts `codex_apps`, and `plugins` (bl-235), which starts the + * servers of the operator's enabled Codex plugins, such as `cua_repl` of `unified-computer-use`. `computer_use` goes + * off too, as a precaution. Probed on codex 0.167.0, on a started and on a resumed thread: `plugins` off kept + * `cua_repl` from starting, `computer_use` off alone did not. + */ private fun strictConfig(names: Set): JsonObject = JsonObject( baseConfig() + mapOf( MCP_SERVERS to JsonObject(names.sorted().associateWith { buildJsonObject { put("enabled", false) } }), - "features" to buildJsonObject { put("apps", false) }, + "features" to buildJsonObject { STRICT_FEATURES_OFF.forEach { put(it, false) } }, ), ) @@ -525,6 +532,9 @@ internal class StartupHandshake( /** The config table of the MCP servers. */ private const val MCP_SERVERS = "mcp_servers" + /** The Codex features a strict thread turns off, see [strictConfig]. */ + private val STRICT_FEATURES_OFF = listOf("apps", "plugins", "computer_use") + /** * The member of `thread/start` and `thread/resume` that declares the client tools (m3-22, bl-212), experimental * in the pinned protocol. diff --git a/plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexServerRequestsTest.kt b/plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexServerRequestsTest.kt index 0828b66c..1c33aaba 100644 --- a/plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexServerRequestsTest.kt +++ b/plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexServerRequestsTest.kt @@ -383,7 +383,7 @@ class CodexServerRequestsTest { val config = sent[3].obj("params").obj("config") assertEquals( CodexJson.format.parseToJsonElement( - """{"allow_login_shell":false,"mcp_servers":{"operator_server":{"enabled":false}},"features":{"apps":false}}""", + """{"allow_login_shell":false,"mcp_servers":{"operator_server":{"enabled":false}},"features":{"apps":false,"computer_use":false,"plugins":false}}""", ), config, ) @@ -409,11 +409,42 @@ class CodexServerRequestsTest { val config = received(server)[3].obj("params").obj("config") assertEquals( - CodexJson.format.parseToJsonElement("""{"allow_login_shell":false,"mcp_servers":{},"features":{"apps":false}}"""), + CodexJson.format.parseToJsonElement( + """{"allow_login_shell":false,"mcp_servers":{},"features":{"apps":false,"computer_use":false,"plugins":false}}""", + ), config, ) } + /** + * An enabled Codex plugin brings its own MCP servers, such as `cua_repl` of `unified-computer-use`, which + * `config/read` does not list, so they cannot be disabled by name. Probed on codex 0.167.0: `plugins` off keeps + * them from starting, `computer_use` off alone does not. + */ + @Test + fun `bl-235 under strict MCP thread start turns plugins and computer_use off beside apps, and no feature without it`() { + val features = + listOf(true, false).associateWith { strict -> + val server = + FakeAppServer.write(dir.resolve("strict-$strict")) { + if (strict) strictHandshake() else handshake() + turnCompleted() + } + + runAll(runner(server.command, strictMcp = strict)) + + val thread = received(server).single { it.string("method") == "thread/start" } + assertEquals(emptyList(), schema.problems("ClientRequest", thread), "$thread") + thread.obj("params").obj("config")["features"] + } + + assertEquals( + CodexJson.format.parseToJsonElement("""{"apps":false,"computer_use":false,"plugins":false}"""), + features.getValue(true), + ) + assertEquals(null, features.getValue(false), "without strict MCP the thread config turns no feature off") + } + @Test fun `m3-20 strict MCP refuses to start when config read fails, rather than run with the operator's servers`() { val server = diff --git a/plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexThreadResumeTest.kt b/plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexThreadResumeTest.kt index 63babcd8..0a60c6c6 100644 --- a/plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexThreadResumeTest.kt +++ b/plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/CodexThreadResumeTest.kt @@ -217,7 +217,11 @@ class CodexThreadResumeTest { buildJsonObject { put("allow_login_shell", false) putJsonObject("mcp_servers") { putJsonObject("operator_server") { put("enabled", false) } } - putJsonObject("features") { put("apps", false) } + putJsonObject("features") { + put("apps", false) + put("computer_use", false) + put("plugins", false) + } }, resume.obj("params").obj("config"), ) @@ -233,6 +237,40 @@ class CodexThreadResumeTest { assertEquals(emptyList(), schema.problems("ClientRequest", stable)) } + /** A plugin's MCP server, such as `cua_repl`, started on a resumed thread too on codex 0.167.0, until `plugins` was off. */ + @Test + fun `bl-235 under strict MCP the resume turns plugins and computer_use off beside apps, and no feature without it`() { + val features = + listOf(true, false).associateWith { strict -> + val server = + server("resume-$strict") { + resumeHandshake( + threadId = THREAD, + turnId = "turn-9", + config = if (strict) FakeAppServer.configReadResult() else null, + ) + turnCompleted(turnId = "turn-9", threadId = THREAD) + } + val session = assertNotNull(runner(server, strictMcp = strict).resumeSession(context(), THREAD)) + val (events) = runTurns(session, "Work on c-01 again") + + assertIs(events.last(), "$events") + val resume = received(server).single { it.string("method") == "thread/resume" } + assertEquals(emptyList(), schema.problems("ClientRequest", resume), "$resume") + resume.obj("params").obj("config")["features"] + } + + assertEquals( + buildJsonObject { + put("apps", false) + put("computer_use", false) + put("plugins", false) + }, + features.getValue(true), + ) + assertEquals(null, features.getValue(false), "without strict MCP the resumed thread config turns no feature off") + } + @Test fun `bl-212 a thread resume answered with an error fails the turn with response_error, stops the app server and starts no thread`() { val pidFile = dir.resolve("resume-error.pid").also { pidFiles.add(it) }