Repository navigation
feat(#212): 默认允许 Codex 联网工具(default-on toggle + section-form 注入) - #213
Merged
Merged
Conversation
Codex 默认 sandbox_workspace_write.network_access = false 让模型用 curl 被拦截, 小白撞 "Codex 看似挂了" 不知所措。 方案: - `Settings.codex_network_access: bool`(默认 true, serde default=true 兼容老配置) - apply 时把 `[sandbox_workspace_write] network_access = true|false` 写入 `~/.codex/config.toml`(section table 形式, Codex docs / exec 输出标准) - UI 设置页加 toggle + 中英 i18n + help 文字 - 专业用户可关 toggle, 写入 false; 不变 Codex 内置 web_search 缓存 - restore 时按快照恢复(快照有就回原值, 没有就 strip 我们的 key 保留 section) 新 `crates/codex_integration/src/toml_sync.rs::sync_table_field` helper **不用 root-level dotted key**: TOML 1.0 spec 禁止 dotted root key 跟 同名 [section] 并存(pre-push code-reviewer 抓到的 BLOCKER —— dotted `sandbox_workspace_write.foo = …` 隐式创建 table, 后面 `[sandbox_workspace_write]` 触发 duplicate table parse error, Codex CLI 无法加载 config.toml)。 `apply.rs` 新 `MANAGED_TOML_TABLE_FIELDS` 表跟 root-key 表平行管理 table 字段的 strip / restore 路径。`snapshot.rs` 新 `snapshot_table_field_literal` 按 section 边界查 key, restore 时不跟 root level 同名 key 撞车。 Tests: - `apply_with_network_access_false_writes_false` —— 显式 false 写入 + 唯一性 invariant - `apply_output_parses_with_pre_existing_sandbox_section` —— **关键防回归**: 用户已有 `[sandbox_workspace_write]` 段时 apply output 必须可被 `toml` crate parse(防 BLOCKER 回归) - `restore_strips_managed_network_access_keeps_user_section` —— restore 后 strip 我们的 key, 保留 section + 用户其它 key - `restore_brings_back_user_network_access_value` —— 快照有 false 时 restore 恢复 false - 6 个 `sync_table_field_*` 单测覆盖 insert/replace/append/delete/section absent - 1 个 toml parse round-trip invariant test `toml = "0.8"` 加 dev-dep 用于 parse 验证。 frontend: index.html 新 toggle row + app.js 3 处(load/save/handler) + i18n.js 中英 strings。README FAQ 加一条 "Codex 模型不能用 curl" entry。 Refs #212
xtask gen-fixtures 把 Settings 新加的 codexNetworkAccess=true 字段填进 default_config.json / with_provider.json fixtures。CI "Verify fixtures regenerable from Rust" 步骤会 diff 这两个文件,本地补 gen 即可绿。
chatgpt-codex review 抓到 2 个 P2 真实 corner case(都会让 Codex CLI 加载 config.toml 失败): 1. **section header 带尾注释** `[sandbox_workspace_write] # comment` 是 TOML spec 合法形式, 但 exact `l.trim() == header` 比较 miss → append 第二份 [section] 触发 duplicate table。改成 `matches_section_header` 兼容尾部空白 + `#` 注释。 2. **用户已用 root-level dotted-key 形式** `sandbox_workspace_write.network_access = false`(等价合法 TOML) 我们识别不到 [section] 直接 append → 跟 dotted key 隐式定义的同名 table 撞 duplicate。新加 `has_root_key_line` 检测,优先走 `sync_root_value_in_memory` 替换原 dotted 行,**尊重用户原格式** 不破坏。 新加 2 个对应 regression test, 都用 toml crate parse 验证不破 TOML spec。所有 18 toml_sync test pass。
…-only 下无效) 真机 verify 发现单写 `[sandbox_workspace_write] network_access = true` 并不能让 curl 联网 —— Codex CLI 默认 `sandbox_mode = "read-only"` (`config_types.rs::SandboxMode` 的 `#[default] ReadOnly`),read-only 下 整个 workspace_write section 被完全忽略。 修法 (双 key 一体): - toggle on: 同时写 `sandbox_mode = "workspace-write"` (root) + `[sandbox_workspace_write] network_access = true` (section) - toggle off: strip 两条, 让 Codex 回 default read-only 沙箱 - MANAGED_TOML_KEYS 加 sandbox_mode, restore 跟其它 root key 同路径 自动 cover UI / README 文案纠正: 关闭后 Codex 走 read-only 沙箱 + 仅能用模型自带 web_search 能力 (若所选模型不支持 web_search 则完全无网络搜索)。 开启后注明同时获得 workspace-write 权限 (Codex 设计为一体档位)。
Devin BLOCKER 抓到的真问题: write path `sync_table_field_in_memory` (toml_sync.rs:117-119) 识别 root-level dotted-key 形式 (`sandbox_workspace_write.network_access = false`), 但 read path `snapshot_table_field_literal` 只匹配 `[section]` header → snapshot 含 dotted form 时返 None → caller 误以为"没有", 传 None 给 sync_table_field → has_root_key_line 找到 dotted key → sync_root_value_in_memory(.., None) **删行** → 用户原 security 设置(`= false`)永久丢失。 修法: snapshot_table_field_literal 跟 sync_table_field_in_memory 对称识别 两种 TOML 合法形式(root-level dotted key 优先 / `[section]` table fallback)。 section header 匹配也兼容尾部 `# comment`(同步 chatgpt-codex 之前 P2 fix 的对称性)。 新加 `restore_preserves_user_dotted_root_form_network_access` 回归测试 覆盖完整 round-trip: 用户原 dotted false → apply 覆盖成 dotted true → restore 恢复用户原 dotted false(不删行)。72 test pass。
调研 OpenAI 官方 issue [openai/codex#10390](openai/codex#10390) 确认: macOS seatbelt sandbox 静默忽略 config.toml 里的 `network_access`, 我们写得对但 macOS 上不生效。issue 状态仍 Open, 无修复进度。 PR #213 主体仍 land: Linux / Windows 用户 toggle 完全 work。macOS 用户 通过本 commit: - UI 设置页 toggle hint 加⚠️ 警告 + workaround CLI flag - README FAQ 加上游 issue 引用 + workaround 完整命令 - docs/followup-tracker.md 加 #38 active 条目 - docs/followup/38-codex-macos-seatbelt-network-access-bug.md 详情文件 (上游修后转 resolved 流程已写好) macOS workaround: codex --sandbox danger-full-access "..." # 或永久 alias alias codex='CODEX_SANDBOX_NETWORK_DISABLED=0 codex --sandbox danger-full-access' 不主动包装 Codex 启动器 (改 alias / wrap CLI 入参) —— 跨 shell / Codex Desktop Electron 启动路径不一致, 代价远高于"等上游修"。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #212
背景
Codex 默认 sandbox_mode=workspace-write 下
network_access = false,小白用户撞 "Codex 看似挂了 / curl 全部被拦截" 不知所措。
方案
Settings.codex_network_access: bool(默认true)[sandbox_workspace_write] network_access = true|false写入~/.codex/config.toml(section table 形式,Codex docs / exec 输出标准)web_search缓存(走 OpenAI cache 不需 network_access)关键技术点
不用 root-level dotted key —— pre-push code-reviewer 抓到的 BLOCKER:
TOML 1.0 spec 禁止 dotted root key 跟同名
[section]并存(
sandbox_workspace_write.foo = ...隐式创建 table → 后面[sandbox_workspace_write]触发 duplicate table parse error → Codex CLI 无法加载 config.toml)。改用
sync_table_fieldhelper 在 section body 内 insert/replace。apply.rs新增MANAGED_TOML_TABLE_FIELDS表跟 root-key 表平行管理 table字段的 apply / strip / restore 路径。
测试
新增 8 个 unit/integration test:
sync_table_field_*6 个:insert / replace / append / delete / section absentapply_output_parses_with_pre_existing_sandbox_section关键防回归:模拟用户已有[sandbox_workspace_write]section,apply output 必须可被tomlcrate parseapply_with_network_access_false_writes_false+ 唯一性 invariantrestore_strips_managed_network_access_keeps_user_sectionrestore_brings_back_user_network_access_value新加
toml = "0.8"作为 codex-integration dev-dep。Test plan
[sandbox_workspace_write]\nnetwork_access = true,Codex CLI 可正常加载