fix(codex): ensure hcom DB is writable in sandbox mode#36
Conversation
Injects a configuration override for 'sandbox_workspace_write.writable_roots' alongside '--add-dir'. This addresses an issue in Codex (tracked as a known limitation in versions prior to 0.128.0) where one-off CLI flags like '--add-dir' could be dropped or ignored during configuration layer reconciliation, particularly when permission profiles are being resolved. By providing both the CLI flag and the direct configuration override, we ensure that the hcom directory remains writable across all session states and profile reconciliations. - Use robust CodexArgSpec parser for flag detection - Inject both --add-dir and -c config override - Escape hcom_dir using serde_json to handle special characters - Add regression tests for config injection and duplicate avoidance
|
Hey @khoant94 I can't verify. do you have more info? AI review: Review: aannoo/hcom PR #36 —
|
| Claim | File | Lines |
|---|---|---|
| Override semantics: replace at leaf | ../codex/codex-rs/utils/cli/src/config_override.rs |
79-89, 101-121 |
| Sandbox-mode override forces Legacy syntax | ../codex/codex-rs/core/src/config/mod.rs |
1687-1695 |
cfg.sandbox_workspace_write only used when implicit builtin |
../codex/codex-rs/core/src/config/mod.rs |
2278-2282 |
--add-dir merged additively (implicit builtin / WorkspaceWrite) |
../codex/codex-rs/core/src/config/mod.rs |
2311-2322 |
--add-dir merged additively (legacy fallback branch) |
../codex/codex-rs/core/src/config/mod.rs |
2421-2422 |
additional_writable_roots source |
../codex/codex-rs/cli/src/main.rs |
1372 |
Test: explicit :workspace does not inherit sandbox_workspace_write |
../codex/codex-rs/core/src/config/config_tests.rs |
1431-1437 |
Test: implicit builtin preserves sandbox_workspace_write.writable_roots |
../codex/codex-rs/core/src/config/config_tests.rs |
1498-1537 |
hcom ensure_hcom_writable (post-PR) |
src/tools/codex_preprocessing.rs |
65-122 (PR diff) |
hcom HCOM_DIR default |
src/paths.rs |
26-59 |
| hcom workspace-local mode docs | src/commands/help.rs |
(search HCOM_DIR) |
hcom join flow bypasses ensure_hcom_writable |
src/commands/start.rs |
~672 |
|
@aannoo it happened intermittently, there's no real pattern to reproduce yet. When it happened, codex can read from the db but failed to write. |
Problem Statement
In Codex versions prior to 0.128.0, one-off CLI flags like
--add-dircould be dropped or ignored during the reconciliation of configuration layers and permission profiles. Specifically, when a named profile or environment-level sandbox setting is resolved, it may supersede the filesystem permissions granted via the--add-dirlaunch flag without warning. This frequently resulted in "Operation not permitted" errors whenhcomattempted to write to its SQLite database, even though the flag appeared correctly in the process list. This is a known persistence bug tracked in openai/codex#11401.Solution
This PR implements a "defense-in-depth" approach to directory permissions. Instead of relying solely on the
--add-dirflag, we now explicitly inject a direct configuration override:-c sandbox_workspace_write.writable_roots=["/path/to/hcom"]By providing both the CLI flag and the config-level override, we ensure the
hcomdirectory survives the configuration reconciliation process across all session types.Key Changes:
ensure_hcom_writableto use theCodexArgSpecparser, ensuring we correctly detect existing-cand--add-dirvalues.serde_jsonto escape thehcom_dirpath, preventing injection vulnerabilities or parsing errors if the path contains quotes or special characters.Verification
test_ensure_hcom_writable_avoids_duplicate_configtest_ensure_hcom_writable_adds_config_overridecodex_preprocessingtests pass viacargo test codex_preprocessing.