Skip to content

fix(codex): preserve runtime config when system source is missing - #9127

Merged
brennanb2025 merged 5 commits into
stablyai:mainfrom
kin001:fix/codex-config-mirror-missing-source
Jul 24, 2026
Merged

brennanb2025 merged 5 commits into
stablyai:mainfrom
kin001:fix/codex-config-mirror-missing-source

Conversation

@kin001

@kin001 kin001 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stops a temporarily missing system Codex config from wiping an existing managed runtime config and stranding unpromoted changes.

ELI5

If Codex's settings file briefly disappeared, the app used to think you had no settings and erased the ones it was managing. Now it just waits for the file to come back and keeps your settings intact.

Root cause & fix

When ~/.codex/config.toml was temporarily absent, the mirror treated it as an authoritative empty config: it merged that emptiness into the existing managed runtime (erasing ordinary settings like model and hooks) and still advanced the baseline snapshot, so the lost runtime changes could never retry once the source returned. The fix makes syncSystemConfigIntoManagedCodexHomeUnsafe return a CodexConfigMirrorResult; a missing source with an existing runtime yields 'skipped-missing-source', and the caller returns early without advancing the baseline. This preserves the runtime config and allows a later retry once the source reappears.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23. Rebase was clean onto origin/main.

  • Focused suites pass on branch: 58 passed (58) across codex-config-mirror.test.ts and config-settings-promotion.test.ts.
  • Reverting the fix (git checkout origin/main -- codex-config-mirror.ts) fails exactly the two guard tests, proving they exercise the fix:
Test Files  2 failed (2)
Tests  2 failed | 56 passed (58)
- codex-config-mirror.test.ts:280 "preserves an existing runtime config when the
  system config is missing" -> runtime config was wiped (hooks/model removed).
- config-settings-promotion.test.ts:215 "retries a runtime change after a missing
  system config returns" -> AssertionError: expected '' to contain 'model = "o4"'.
  • Lint clean: oxlint src/main/codex/codex-config-mirror.ts -> 0 warnings, 0 errors. Typecheck passes.

Trade-offs

None — pure fix.

Regression risk

Zero-regression by construction: the new early-return path triggers only when the system config is absent and a runtime config already exists — the exact case that previously destroyed data. Fresh-mirror seeding, empty-baseline init, and normal merge paths are unchanged and remain covered by the other 56 passing tests.


Original fix by @kin001 (fixes #9073). Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

@coderabbitai

coderabbitai Bot commented Jul 17, 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 Plus

Run ID: a284338b-2690-4d18-a80e-a3a1e30c242a

📥 Commits

Reviewing files that changed from the base of the PR and between 90133526fcd4246fe9029eb2b44905b157555fbb and 0fb5ba1.

📒 Files selected for processing (1)
  • config/tsconfig.cli.json

📝 Walkthrough

Walkthrough

Updated Codex configuration mirroring to return early when the system config.toml is missing, preserve the runtime baseline during source loss, and distinguish mirror outcomes. Added tests covering unchanged runtime content during absence and successful promotion after the system configuration is restored. The CLI TypeScript compilation include list now contains two additional configuration source files.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks the required template sections like Screenshots, Testing, AI Review Report, Security Audit, and Notes. Rewrite it to match the template and add the missing sections, including the testing checklist, cross-platform review, security audit, screenshots note, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: preserving runtime config when the system source is missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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: c7aef3ca-a113-4426-99cb-e941840a5639

📥 Commits

Reviewing files that changed from the base of the PR and between cc1ad06 and 2c18dcdd7f31440e38bd7acfc8ae33bedd3e820a.

📒 Files selected for processing (2)
  • src/main/codex/codex-config-mirror.test.ts
  • src/main/codex/codex-config-mirror.ts

Comment thread src/main/codex/codex-config-mirror.ts Resolved
@brennanb2025

Copy link
Copy Markdown
Contributor

Taking a look!

@nwparker
nwparker force-pushed the fix/codex-config-mirror-missing-source branch from 9013352 to a7f4caf Compare July 23, 2026 11:48
@nwparker

Copy link
Copy Markdown
Contributor

@brennanb2025 please own

kin001 and others added 5 commits July 24, 2026 12:23
Why: codex-config-mirror.ts sat at the 300-line cap, so the missing-source
guard could not land without a max-lines disable.
Why: a runtime home seeded outside the mirror (WSL, per-account) never got a
baseline while the source was missing, so promotion stayed inert and silently
reverted the in-Codex change once the source returned.
…ings

Two routes still reached the stablyai#9073 data loss after the missing-source guard:

- Promotion runs before the guard and, with no ~/.codex/config.toml, created
  one holding only the promoted keys. The next mirror treated that skeleton as
  authoritative and deleted every other runtime setting. It needs no missing
  file: `codex mcp add` inside an Orca-launched Codex plus /model was enough to
  drop the MCP server for good. Promotion now seeds a brand-new system config
  from the runtime's ordinary settings, so the mirror round-trips them.
- A 0-byte source (half-written, or an unhydrated cloud-synced home) still read
  as an authoritative empty config and advanced the baseline, making the loss
  unrecoverable. A blank source is now treated like a missing one.

Moves the TOML section model out of codex-config-mirror.ts so promotion can
share it without a cycle.
@brennanb2025
brennanb2025 force-pushed the fix/codex-config-mirror-missing-source branch from a7f4caf to 0fb5ba1 Compare July 24, 2026 19:46
@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for this — the root cause is right and the guard is the correct shape.

I rebased onto latest main (the branch was well behind and conflicting) and adapted the fix to the promotion-plan signature the mirror uses now. While validating I found the guard alone doesn't fully close #9073, so I extended it in three places:

  • Promotion runs before the guard and could synthesize the source. With no ~/.codex/config.toml, promotion created one holding only the promoted keys, and the next mirror treated that skeleton as authoritative and deleted every other setting. This needs no missing file at all: codex mcp add … inside an Orca-launched Codex plus /model was enough to drop the MCP server permanently. Promotion now seeds a brand-new system config from the runtime's ordinary settings, so the mirror round-trips them.
  • A 0-byte source (half-written, or an unhydrated cloud-synced home) still read as an authoritative empty config and advanced the baseline, making the loss unrecoverable. A blank source is now treated like a missing one.
  • The skip path never bootstrapped a baseline. A runtime home seeded outside the mirror (WSL, per-account) had promotion disabled indefinitely, and the in-Codex change was silently overwritten when the source returned.

Each fix has a regression test that fails when that fix alone is reverted.

Two small structural changes were needed: normalizeDeprecatedCodexHookFeatureFlag and the TOML section model moved out of codex-config-mirror.ts into their own files — the first because the file sat at the max-lines cap so any fix tripped it, the second so promotion can share the section logic without a circular import. Both are literal moves, verified against main.

Two follow-ups I deliberately left out of scope: the skip is silent (worth transition-gated logging so a downed WSL distro is diagnosable), and it also pauses the runtime config's duplicate-[projects.*] self-heal.

@brennanb2025 brennanb2025 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.

Approving. Root cause is correct; extended to cover the remaining routes to the same data loss, each with a regression test. Validated on latest main.

@brennanb2025
brennanb2025 merged commit 6a72c8f into stablyai:main Jul 24, 2026
1 check failed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ablyai#9127)

* fix(codex): preserve runtime config without system source

* fix(codex): retain baseline when mirror is skipped

* refactor(codex): extract deprecated hook-flag normalization

Why: codex-config-mirror.ts sat at the 300-line cap, so the missing-source
guard could not land without a max-lines disable.

* fix(codex): bootstrap a baseline when the mirror is skipped

Why: a runtime home seeded outside the mirror (WSL, per-account) never got a
baseline while the source was missing, so promotion stayed inert and silently
reverted the in-Codex change once the source returned.

* fix(codex): stop a synthesized source config from wiping runtime settings

Two routes still reached the stablyai#9073 data loss after the missing-source guard:

- Promotion runs before the guard and, with no ~/.codex/config.toml, created
  one holding only the promoted keys. The next mirror treated that skeleton as
  authoritative and deleted every other runtime setting. It needs no missing
  file: `codex mcp add` inside an Orca-launched Codex plus /model was enough to
  drop the MCP server for good. Promotion now seeds a brand-new system config
  from the runtime's ordinary settings, so the mirror round-trips them.
- A 0-byte source (half-written, or an unhydrated cloud-synced home) still read
  as an authoritative empty config and advanced the baseline, making the loss
  unrecoverable. A blank source is now treated like a missing one.

Moves the TOML section model out of codex-config-mirror.ts so promotion can
share it without a cycle.

---------

Co-authored-by: Brennan Benson <[email protected]>
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.

Codex config mirror erases runtime settings when system config is missing

3 participants