Repository navigation
fix(codex): use profile Codex home for app-server workers #57792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,20 +17,48 @@ | |
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import logging | ||
| import os | ||
| import queue | ||
| import subprocess | ||
| import threading | ||
| import time | ||
| import tomllib | ||
| from dataclasses import dataclass, field | ||
| from typing import Any, Optional | ||
|
|
||
| from tools.environments.local import hermes_subprocess_env | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # Default minimum codex version we test against. The PR sets this from the | ||
| # `codex --version` parsed at install time; bumping is a one-line change here. | ||
| MIN_CODEX_VERSION = (0, 125, 0) | ||
|
|
||
| _DANGER_DEFAULT_PERMISSIONS = ":danger-full-access" | ||
|
|
||
|
|
||
| def _codex_home_default_permissions(codex_home: Optional[str]) -> Optional[str]: | ||
| """Read Codex's top-level ``default_permissions`` from CODEX_HOME.""" | ||
| if not codex_home: | ||
| return None | ||
| config_path = os.path.join(codex_home, "config.toml") | ||
| try: | ||
| with open(config_path, "rb") as handle: | ||
| config = tomllib.load(handle) | ||
| except FileNotFoundError: | ||
| return None | ||
| except Exception: | ||
| logger.debug( | ||
| "codex app-server: failed to read Codex config %s", | ||
| config_path, | ||
| exc_info=True, | ||
| ) | ||
| return None | ||
|
|
||
| value = config.get("default_permissions") | ||
| return value if isinstance(value, str) else None | ||
|
|
||
|
|
||
| @dataclass | ||
| class CodexAppServerError(RuntimeError): | ||
|
|
@@ -112,16 +140,26 @@ def __init__( | |
| ), | ||
| ) | ||
| ) | ||
| app_server_args.extend( | ||
| [ | ||
| "-c", | ||
| 'sandbox_mode="workspace-write"', | ||
| "-c", | ||
| f'sandbox_workspace_write.writable_roots=["{kanban_root}"]', | ||
| "-c", | ||
| "sandbox_workspace_write.network_access=false", | ||
| ] | ||
| default_permissions = _codex_home_default_permissions( | ||
| spawn_env.get("CODEX_HOME") | ||
| ) | ||
| if default_permissions == _DANGER_DEFAULT_PERMISSIONS: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| logger.info( | ||
| "codex app-server: using profile default_permissions for " | ||
| "kanban worker (CODEX_HOME=%s)", | ||
| spawn_env.get("CODEX_HOME"), | ||
| ) | ||
| else: | ||
| app_server_args.extend( | ||
| [ | ||
| "-c", | ||
| 'sandbox_mode="workspace-write"', | ||
| "-c", | ||
| f'sandbox_workspace_write.writable_roots=["{kanban_root}"]', | ||
| "-c", | ||
| "sandbox_workspace_write.network_access=false", | ||
| ] | ||
| ) | ||
|
|
||
| cmd = [codex_bin, "app-server"] + app_server_args | ||
| # Codex emits tracing to stderr; default WARN keeps it quiet for users. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds implicit profile Codex-home discovery, but current documentation deliberately keeps Codex state shared by default and requires explicit
CODEX_HOMEfor profile isolation (website/docs/user-guide/features/codex-app-server-runtime.md:296-309). Please resolve that precedence/design contract and document setup/auth behavior before introducing this convention.