feat: add Codex permission env fallback
Summary
- Add
CLOUDCLI_CODEX_PERMISSION_MODEas a server-side fallback for Codex chat requests that do not includepermissionMode. - Preserve explicit request permission modes and validate values against
default,acceptEdits, andbypassPermissions. - Document the fallback and the safety implications of
bypassPermissions.
Why
Self-hosted and containerized CloudCLI deployments sometimes need a process-level Codex permission default for clients that do not send permissionMode. This keeps upstream defaults unchanged (default) while allowing trusted deployments to opt into acceptEdits or bypassPermissions explicitly.
Testing
node --check server/openai-codex.jsgit diff --check
Summary by CodeRabbit
-
Documentation
- Added "Codex Permission Defaults" section explaining the three permission modes and showing example commands for configuring a server-side default and its fallback behavior.
-
New Features
- Server-side configuration for Codex permission mode via an environment variable, with validation and automatic fallback to the default mode when unset or invalid.
📝 Walkthrough
Walkthrough
This PR adds server-side environment-driven fallback for Codex permission modes. A new module validates and resolves permission mode by choosing between explicit request values and environment-configured defaults (CLOUDCLI_CODEX_PERMISSION_MODE). The resolver warns on invalid modes and falls back to default. Updates queryCodex to use the resolver when determining sandboxMode and approvalPolicy. Includes comprehensive tests and documentation.
Changes
Codex Permission Mode Environment Configuration
| Layer / File(s) | Summary |
|---|---|
Permission mode resolution implementation and tests server/codex-permission-mode.js, server/codex-permission-mode.test.js |
New module exports CODEX_PERMISSION_MODE_ENV, getConfiguredCodexPermissionMode, and resolveCodexPermissionMode. Helpers read and validate CLOUDCLI_CODEX_PERMISSION_MODE against allowed modes (default, acceptEdits, bypassPermissions), warn on invalid config, and resolve effective permission mode by choosing between request-provided or environment-configured values. Test suite validates explicit mode preservation, environment fallbacks, omitted mode defaults, and invalid value handling. |
QueryCodex permission mode resolution server/openai-codex.js |
Imports resolveCodexPermissionMode, removes hardcoded permissionMode default, detects whether mode was explicitly provided in options, computes effective permission mode via the resolver, and derives sandboxMode and approvalPolicy from the resolved value before starting/resuming Codex thread. |
Permission defaults documentation README.md |
New "Codex Permission Defaults" section describes the three available permission modes, explains that the UI sends the selected mode per Codex request, documents server-side fallback via CLOUDCLI_CODEX_PERMISSION_MODE environment variable with default as the fallback when unset or invalid, and provides example environment commands for each mode. |
Sequence Diagram
sequenceDiagram
participant Request as Client Request
participant QueryCodex as queryCodex
participant Resolver as resolveCodexPermissionMode
participant Env as Environment Config
Request->>QueryCodex: options with optional permissionMode
QueryCodex->>QueryCodex: detect if permissionMode explicit
QueryCodex->>Resolver: call resolver(mode, hasExplicit, env)
alt Has Explicit Permission Mode
Resolver->>Resolver: validate request mode
Resolver-->>QueryCodex: return validated mode
else Omitted Permission Mode
Resolver->>Env: read CLOUDCLI_CODEX_PERMISSION_MODE
Resolver->>Resolver: validate env value
Resolver-->>QueryCodex: return env default or 'default'
end
QueryCodex->>QueryCodex: derive sandboxMode and approvalPolicy
QueryCodex->>QueryCodex: start/resume Codex thread
Suggested Reviewers
- viper151
Poem
A rabbit reads the config file so clear,
With permissions that the server holds dear,
When the request forgets to say,
The env var shows the default way,
Fallback wisdom, permission care! 🐰
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title accurately captures the main change: adding a server-side environment variable fallback for Codex permission modes, which is the primary feature introduced across the modified files. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Hey @CoderLuii, thanks for the PR. Can u resolve the merge conflict and I'll review it.
Hey @CoderLuii, on the pr description it says "Self-hosted and containerized CloudCLI deployments sometimes need a process-level Codex permission default for clients that do not send permissionMode". When would you need this? When is the 'sometimes'?
@blackmammoth thanks for calling that out. You were right that sometimes was too vague.
The concrete use case came from HolyClaude: CoderLuii/HolyClaude#18. HolyClaude ships CloudCLI inside a trusted self-hosted Docker image where users run multiple coding agents against the same mounted workspace. The current CloudCLI browser chat submit path sends permissionMode, but deployment owners still need a server-side fallback for direct WebSocket clients or custom frontends that omit it.
Concrete examples:
- A cautious or shared deployment can leave the env var unset, so omitted-mode Codex requests stay on
default. - A trusted self-hosted workspace can set
CLOUDCLI_CODEX_PERMISSION_MODE=acceptEdits, so Codex can apply file edits without repeated prompts while still using theworkspace-writesandbox. - A single-user local container can intentionally set
CLOUDCLI_CODEX_PERMISSION_MODE=bypassPermissionswhen they want Codex to have full access inside the container and mounted workspace. That is powerful, so it should only be used where the operator trusts the workspace and prompts.
That is why this PR keeps explicit request values first, and only uses CLOUDCLI_CODEX_PERMISSION_MODE when the request omits permissionMode. It also keeps upstream CloudCLI's default unchanged: if the env var is unset or invalid, Codex still uses default.
I also cleaned the generated noise out of the PR description. Sorry about that; it made the PR harder to review than it needed to be.
I refreshed the branch against current main, resolved the conflicts, and kept the newer Codex model-resolution path intact. The PR is now intended as the upstream version of that small server-side fallback, so downstream images do not need to patch CloudCLI just to set a deployment-level Codex default.