Skip to content

feat(codex): write in-Codex setting changes back to ~/.codex config - #7960

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/codex-settings-writeback
Jul 9, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/codex-settings-writeback

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Config flow between ~/.codex and Orca's managed runtime CODEX_HOME is one-way. The mirror (syncSystemConfigIntoManagedCodexHome) rewrites the runtime config.toml from ~/.codex on every launch and on background rate-limit fetches, preserving only [hooks.state.*] and [projects.*]. So a /model or /approvals change made inside Orca-launched Codex silently reverts — sometimes mid-session, when a rate-limit fetch re-mirrors while Codex is still running.

This is the settings half of the same one-way problem #7896 fixed for hook approvals, using the same design.

Fix

Three-way merge built into the mirror itself, so all call sites (launch prep, rate-limit fetch, hook install/refresh) get it for free:

  1. Baseline snapshot — after each successful mirror, record the promotable top-level settings Orca left in the runtime config (.orca-config-settings-baseline.json).
  2. Promotion before the mirror — any allowlisted top-level key whose runtime value differs from the baseline is a change Codex persisted for the user; write it into ~/.codex/config.toml (surgical line upsert, comments/format preserved) before the mirror pass, so the same pass mirrors it right back.
  3. ~/.codex stays source of truth — if the same key was also edited in ~/.codex since the baseline, the outside edit wins. Missing/corrupt baseline (first launch after upgrade) skips promotion for one pass, so stale pre-upgrade runtime values are never promoted.

Allowlist is exactly what the Codex TUI persists: model, model_reasoning_effort, approval_policy, sandbox_mode. Keys inside tables ([profiles.*]) and multiline values are never touched; key deletions are not promoted. Grow the list deliberately — every key on it gets silently written into the user's real config.

Verification

  • 17 new tests driving the real syncSystemConfigIntoManagedCodexHome: promote + steady-state byte-equality, multi-key promotion, no-baseline/corrupt-baseline upgrade passes, outside-edit-wins conflict, key insertion preserving comments, config creation for users with no ~/.codex/config.toml, deletion not promoted, allowlist/table/multiline exclusions, CRLF preservation.
  • Live e2e against real codex-cli 0.144.0 (sandboxed HOME + ORCA_USER_DATA_PATH, production mirror code via tsx): mirrored a system config → drove the real Codex TUI /model picker → Codex wrote top-level model = "gpt-5.5" + model_reasoning_effort = "medium" → next mirror pass promoted both into the sandboxed ~/.codex/config.toml, inserted cleanly into the preamble before [features] → third pass byte-identical (steady state). Real ~/.codex untouched (auth.json hash-verified).
  • Full src/main/codex + src/main/codex-accounts suites green (350 passed), pnpm typecheck, oxlint, max-lines ratchet all green.

Out of scope

Made with Orca 🐋

The runtime CODEX_HOME config mirror rewrites config.toml from ~/.codex on
every launch and background rate-limit fetch, so settings the user changes
inside Orca-launched Codex (/model, /approvals) silently revert. Diff the
runtime config against a baseline of what Orca last mirrored; any allowlisted
top-level key that changed is a value Codex persisted for the user and is
promoted into ~/.codex/config.toml before the mirror pass, so it survives.

- Baseline snapshot (.orca-config-settings-baseline.json) advances only after
  a successful mirror; missing/corrupt baseline skips promotion for one pass
  so stale pre-upgrade values are never promoted.
- ~/.codex stays source of truth: an outside edit to the same key since the
  baseline wins over the in-Codex change.
- Allowlist covers exactly what the Codex TUI persists: model,
  model_reasoning_effort, approval_policy, sandbox_mode. Keys inside tables
  ([profiles.*]) and multiline values are never touched.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 777c2c64-89c8-4669-bfb2-125c7db41856

📥 Commits

Reviewing files that changed from the base of the PR and between 81e4f0f and ac7eff8.

📒 Files selected for processing (4)
  • config/tsconfig.cli.json
  • src/main/codex/codex-config-mirror.ts
  • src/main/codex/config-settings-promotion.test.ts
  • src/main/codex/config-settings-promotion.ts

📝 Walkthrough

Walkthrough

This PR introduces a config settings promotion mechanism for Codex. A new module defines an allowlist of top-level scalar settings and implements baseline snapshotting, diff-based promotion of runtime changes into the system-level ~/.codex/config.toml, and a TOML content upsert helper that preserves formatting. The codex-config-mirror.ts sync flow is updated to promote runtime settings before mirroring and snapshot a baseline after a successful mirror. A comprehensive Vitest test suite covers promotion scenarios and the upsert helper. The CLI tsconfig include list is updated accordingly.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers problem, fix, and verification, but omits required template sections like Summary, Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections, including a concise Summary, Screenshots or 'No visual change', Testing checklist, AI Review Report, Security Audit, and Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: writing Codex setting changes back to ~/.codex.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jinwoo-H
Jinwoo-H merged commit 94662c8 into main Jul 9, 2026
2 checks passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/codex-settings-writeback branch July 9, 2026 19:17
Jinwoo-H added a commit that referenced this pull request Jul 9, 2026
Clean auto-merge, no conflicts. Brought in from main:
- feat(codex): write in-Codex setting changes back to ~/.codex config (#7960)
  — codex-config-mirror.ts, config-settings-promotion.ts
- Separate pane identity from liveness in the tab-agent resolver, fixes OMP
  tab flicker (#7860) — pane-agent-owner.ts, use-tab-agent.ts
- fix(sidebar): only show projects scrollbar when the list overflows (#7845)

Perf-branch structure preserved (clean auto-merge; pty-connection.ts auto-merged
without conflict). Gates: typecheck 0 errors; lint 0 errors; ipc/pty + daemon +
codex + terminal-pane + lib + runtime + shared + pane-manager suites all pass
(9015 + 2120 tests, 0 failed).

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant