Skip to content

Preserve Codex [tui] settings across managed CODEX_HOME remirrors - #9475

Merged
brennanb2025 merged 8 commits into
mainfrom
brennanb2025/fix-9168-codex-tui-settings-remirror
Jul 23, 2026
Merged

brennanb2025 merged 8 commits into
mainfrom
brennanb2025/fix-9168-codex-tui-settings-remirror

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9168

Problem

Codex TUI preferences changed inside an Orca-launched session (/statusline, theme, terminal title) are written by Codex into the [tui] table of the managed runtime config.toml — but Orca's write-back promotion allowlist only covered four top-level scalars (model, model_reasoning_effort, approval_policy, sandbox_mode). On the next mirror pass the runtime config is rewritten from ~/.codex, silently discarding the [tui] changes: a custom status line works in the current session and is gone in the next one.

Fix

  • Extend promotion to the [tui] keys the Codex TUI persists: status_line, status_line_use_colors, terminal_title, theme. They flow through the same three-way merge (runtime vs baseline vs ~/.codex): in-Codex changes are promoted into ~/.codex before the mirror so the very pass that used to erase them now preserves them, while an outside edit to ~/.codex still wins over a stale runtime value.
  • Promotion state is keyed by structured path (tui.<key>) so [tui] entries can never collide with a top-level key of the same name. Old baseline files stay valid — a missing tui.* baseline entry degrades safely (analyzed for both upgrade and downgrade).
  • The byte-preserving upsert moves to codex-config-settings-upsert.ts (max-lines) and learns [tui] placement with a total rule: replace an existing bare or dotted key in place (keeping its form), else insert bare into the first [tui] body (before any [tui.*] subtable), else insert dotted beside existing dotted tui.* preamble keys, else create exactly one [tui] table at EOF. It never defines tui twice — including the corner where ~/.codex holds an inline tui = {...} table, where the update is dropped instead of corrupting the config.
  • Reading recognizes both shapes Codex/users produce: the bare [tui] table body and hand-authored dotted tui.<key> preamble form. Keys under [tui.*] subtables and multiline values are excluded (line-wise editing can't handle them safely), matching the existing top-level behavior.

Testing

  • New end-to-end test reproducing the issue's exact repro: a runtime [tui] block (the shape codex 0.144.6 writes via config/batchWrite) survives a system→managed remirror and reaches a steady state.
  • 14 more tests covering: in-place replacement next to non-promoted [tui] neighbors, dotted-form preservation, mixed top-level + tui batches, single [tui] table creation (incl. after a [tui.*] subtable), outside-edit-wins conflicts, deletion non-promotion, CRLF preservation, subtable exclusion, and the inline-table guard.
  • src/main/codex suite: 11 files, 282 passed / 5 skipped. typecheck:node and oxlint clean.

Trade-offs / user-visible changes

None beyond the fix itself. Non-allowlisted [tui] keys, [tui.*] subtable keys, and inline-table configs keep today's behavior (not promoted, fail-safe).

Review validation

  • Hardened the TOML placement scan so a nested tui.* key under an array-of-tables is never mistaken for a root key, and a root [[tui]] can never gain an invalid duplicate [tui] table.
  • Focused config promotion tests: 52 passed. Full src/main/codex suite: 463 passed / 5 skipped. Node + CLI typechecks, changed-file lint/format, and max-lines ratchet passed.
  • Promotion/upsert cost remains linear and off the unchanged hot path: measured ~0.2 ms at 14 KB and ~8.4 ms at 158 KB in the test runtime.

Live Electron smoke

The dev Electron build launched with a ready runtime graph; Settings navigation rendered normally and Codex was detected and enabled. A fresh Codex terminal could not be included because this host had exhausted its OS PTY pool (posix_openpt failed); no existing user terminal sessions were closed. The filesystem end-to-end test above exercises the exact remirror behavior.

Agents settings loaded

Agents settings loaded

Codex detected and enabled

Codex detected and enabled

…emirror

Codex TUI preferences (/statusline, theme, terminal title) are written into
the [tui] table of the managed runtime config.toml, but the write-back
promotion allowlist only covered four top-level scalars — so the next mirror
pass rewrote the runtime config from ~/.codex and silently discarded them.

Extend promotion to the [tui] keys the Codex TUI persists (status_line,
status_line_use_colors, terminal_title, theme), keyed as structured tui.*
paths so the same three-way merge (runtime vs baseline vs ~/.codex) applies:
in-Codex changes promote into ~/.codex before the mirror, and outside edits
to ~/.codex still win over stale runtime values.

The byte-preserving upsert moves to codex-config-settings-upsert.ts (max-lines)
and learns [tui] placement: replace an existing bare or dotted key in place,
insert into the first [tui] body, insert dotted beside existing dotted tui.*
keys, or create one [tui] table at EOF — never defining tui twice, including
when the system config holds an inline tui = {...} table.
@coderabbitai

coderabbitai Bot commented Jul 19, 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: e5318320-d51d-421b-900d-46ce63d0426d

📥 Commits

Reviewing files that changed from the base of the PR and between ff91239 and dc16062.

📒 Files selected for processing (1)
  • config/tsconfig.cli.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/tsconfig.cli.json

📝 Walkthrough

Walkthrough

Adds structured TOML upsert utilities for top-level and [tui] settings, including placement-aware insertion, replacement, table handling, and line-ending preservation. Updates promotion logic to snapshot and propagate structured [tui] settings. Expands integration and unit tests for write-back scenarios, conflicts, inline tables, array tables, nested keys, and CRLF content. Extends the CLI TypeScript compilation includes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it does not follow the required template sections like Summary, Screenshots, AI Review Report, Security Audit, and Notes. Rewrite the PR description using the repository template and include all required sections, or explicitly mark Screenshots as no visual change.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preserving Codex [tui] settings during managed CODEX_HOME remirrors.
Linked Issues check ✅ Passed The changes appear to implement the linked issue by promoting [tui] settings, preventing duplicate tables, preserving formatting, and adding regression tests.
Out of Scope Changes check ✅ Passed The added helper file, test updates, and tsconfig include changes are all directly related to the TUI settings promotion fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
config/tsconfig.cli.json

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 627d1d87-cabe-4d1c-bbbc-b693ea364680

📥 Commits

Reviewing files that changed from the base of the PR and between 624c8d4 and 3ae6313.

📒 Files selected for processing (4)
  • src/main/codex/codex-config-settings-upsert.ts
  • src/main/codex/config-settings-promotion.test.ts
  • src/main/codex/config-settings-promotion.ts
  • src/main/codex/config-toml-line-scan.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/codex/codex-config-settings-upsert.ts (1)

173-205: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Appending [tui] after [tui.*] sub-tables creates invalid TOML.

If the file already contains a sub-table like [tui.something], appending a [tui] super-table at the end of the file will result in an unparseable configuration. The TOML specification prohibits defining a super-table after one of its sub-tables.

To prevent creating an invalid config, blocksNewTuiTable should also be set to true if a [tui.*] table header is encountered.

🛠️ Proposed fix to block new `[tui]` table on sub-tables
         const tableName = getTomlTableName(header)
         if (tableName === 'tui' && !tuiTableSeen) {
           tuiTableSeen = true
           tuiBodyActive = true
           tuiBodyHeaderIndex = index
+        } else if (tableName && tableName.startsWith('tui.')) {
+          blocksNewTuiTable = true
         }
         // Why: a root [[tui]] is already an array, so appending [tui] would
         // redefine it and make an otherwise valid config unparseable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 68021262-30e4-41c7-aa93-dd38b7a39a04

📥 Commits

Reviewing files that changed from the base of the PR and between 397a491 and ff91239.

📒 Files selected for processing (2)
  • src/main/codex/codex-config-settings-upsert.ts
  • src/main/codex/config-settings-promotion.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/codex/config-settings-promotion.test.ts

@brennanb2025
brennanb2025 merged commit c8381f3 into main Jul 23, 2026
1 of 2 checks passed
AmethystLiang added a commit that referenced this pull request Jul 23, 2026
brennanb2025 added a commit that referenced this pull request Jul 23, 2026
…0213)

* Reapply "Preserve Codex [tui] settings across managed CODEX_HOME remirrors (#9475)" (#10085)

This reverts commit 09756df.

* fix(codex): anchor settings baseline migration
gal064 pushed a commit to gal064/orca that referenced this pull request Jul 25, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ablyai#9475)

* fix(codex): promote [tui] settings so they survive the managed-home remirror

Codex TUI preferences (/statusline, theme, terminal title) are written into
the [tui] table of the managed runtime config.toml, but the write-back
promotion allowlist only covered four top-level scalars — so the next mirror
pass rewrote the runtime config from ~/.codex and silently discarded them.

Extend promotion to the [tui] keys the Codex TUI persists (status_line,
status_line_use_colors, terminal_title, theme), keyed as structured tui.*
paths so the same three-way merge (runtime vs baseline vs ~/.codex) applies:
in-Codex changes promote into ~/.codex before the mirror, and outside edits
to ~/.codex still win over stale runtime values.

The byte-preserving upsert moves to codex-config-settings-upsert.ts (max-lines)
and learns [tui] placement: replace an existing bare or dotted key in place,
insert into the first [tui] body, insert dotted beside existing dotted tui.*
keys, or create one [tui] table at EOF — never defining tui twice, including
when the system config holds an inline tui = {...} table.

* Add codex-config-settings-upsert to the CLI tsconfig file list

* fix(codex): keep tui upserts out of array tables

* fix(codex): handle quoted tui config paths during promotion

* fix(codex): harden tui promotion writes
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ablyai#10213)

* Reapply "Preserve Codex [tui] settings across managed CODEX_HOME remirrors (stablyai#9475)" (stablyai#10085)

This reverts commit f86e28f.

* fix(codex): anchor settings baseline migration
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.

[Bug] Codex TUI settings are discarded when Orca remirrors managed CODEX_HOME

1 participant