Skip to content

fix(codex): reconcile marketplace and plugin tables through the config mirror - #20150

Merged
nwparker merged 3 commits into
mainfrom
fix/codex-mirror
Sep 12, 2026
Merged

nwparker merged 3 commits into
mainfrom
fix/codex-mirror

Conversation

@nwparker

@nwparker nwparker commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​691 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​687
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​797 $\color{#cf222e}{\Huge{\mathbf{−}}}$​187 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​610

What this fixes (plain language)

If you added a Codex plugin or plugin marketplace while working inside Orca, it kept disappearing. You would install it, it would work, and then the next time Orca started it was simply gone — you had to add it again. The same thing quietly happened to the bookkeeping Codex keeps about where a marketplace came from and when it last updated, so Codex could also lose track of having refreshed it.

The cause was that Orca keeps its own copy of your Codex settings and re-syncs it from your real config file on startup. That sync knew how to carry ordinary settings back and forth, but it did not know about plugins and marketplaces at all, so anything you installed from inside Orca was wiped out when the two copies were reconciled.

Now the sync understands them. Something you install inside Orca is copied back into your real config so it survives, while a marketplace or plugin you deliberately remove from your own config stays removed instead of coming back. Both copies end up agreeing, and repeated startups no longer change the file.

Scalar promotion omitted the marketplace and plugin tables, and the mirror rebuilt ordinary config from canonical while only trust sections survived. A new managed-account registration and refreshed provider metadata were therefore destroyed at the same boundary.

Fixes #10489
Fixes #11770

Policy

Identity key is <root>:<parsed header segment>, so [plugins."a@b"] and [plugins.'a@b'] are one registration. R = runtime tables, S = canonical, B = registration baseline.

Condition Policy
in R, not in S, not in B runtime-only addition → promote
in R, not in S, in B canonical removal since last mirror → honor it
in R∩S, identity fields differ canonical source change → canonical wins
in R∩S, marketplace, runtime last_updated valid and strictly newer promote it + paired last_revision
in R∩S, marketplace, missing/malformed/rolled-over/older/equal, or no runtime last_revision to pair skip
in R∩S, plugin, enabled changed only in R vs B promote enabled
in R∩S, plugin, changed both sides or no B entry canonical wins
in S, not in R canonical owns presence; mirror restores it
promotion write fails throws → plan null → mirror skipped → runtime bytes and baseline intact

Registrations are promoted into ~/.codex/config.toml before the mirror runs, so they return through the ordinary canonical→runtime copy rather than needing a second preservation path.

Baseline v3 migration

The baseline gains an optional registrations map. Absent ≡ never mirrored, which is what makes the upgrade lossless: an existing v2 user's registrations read as additions on the first pass and heal into canonical, instead of reading as removals and being dropped. isStoredSettingsBaseline accepts 1 | 2 | 3, so no rewrite or migration step is needed.

Downgrade is a safe degrade: an older build accepts only version === 1 | 2, so it rejects a v3 file, treats it as absent, and bootstraps a fresh baseline. One pass of scalar promotion is skipped, exactly as on a fresh install. No corruption, no data loss.

Residual risk: baseline loss

The baseline is the only guard against re-promoting a registration the user removed canonically. Reproduced on real files, three cases:

Situation Result
Baseline lost, no canonical removal pending (ordinary upgrade/corruption) config byte-identical; nothing happens
Baseline lost and a canonical removal has not yet been mirrored the registration is re-promoted
Baseline intact, same removal removal honored

The damaging window requires the removal and the loss to coincide. The consequence is un-removal, not data loss, and it is recoverable — removing it again with the rebuilt baseline in place sticks. Covered by re-promotes a canonically removed registration when the baseline is lost first as a characterization test so the behavior cannot change silently.

Real-file evidence

Run against real config.toml files under /tmp with a real managed-account home and canonical system home, driving the actual mirror entry point (no test framework, no mocks).

Registration survives and is idempotent. Runtime after Codex registers a marketplace and a quoted plugin, then after each of three mirrors — all four states sha256:edef2f198aec692b, both files identical:

model = "gpt-5"
approval_policy = "on-request"

[mcp_servers.docs]
command = "docs-server"

[marketplaces.ponytail]
source_type = "git"
source = "https://github.com/DietrichGebert/ponytail.git"
ref_name = "main"
last_updated = "2026-01-05T10:00:00Z"
last_revision = "aaaa111"

[plugins."ponytail@ponytail"]
enabled = true
version = "4.8.4"

Resulting baseline:

{
  "version": 3,
  "settings": { "model": "\"gpt-5\"", "approval_policy": "\"on-request\"", ... },
  "registrations": {
    "marketplaces:ponytail": {},
    "plugins:ponytail@ponytail": { "enabled": "true" }
  }
}

#10489 discriminator. Canonical holds [marketplaces.other]; the runtime-only [marketplaces.ponytail] has perfectly valid timestamps. A metadata-only policy (what #11770 proposed) only reconciles entries present on both sides, so it drops ponytail entirely. This implementation promotes it, and both marketplaces end up in canonical and runtime.

Canonical removal honored. After the registration is promoted, the user deletes both tables from ~/.codex outside Orca. Two further mirrors leave canonical and runtime at model = "gpt-5"\n — not resurrected.

Refresh metadata. Seeded at 2026-01-05T10:00:00Z / aaaa111; runtime refresh to 2026-02-01T09:30:00Z / bbbb222 promotes the pair and leaves the user comment, ref_name, source, and [mcp_servers.docs] untouched. A subsequent stale (2020-01-01) and then malformed (not-a-timestamp) runtime value each leave canonical byte-identical at sha256:e49510fa49452136.

Atomic-write failure. ~/.codex chmod 0500 produces a real EACCES on the temp write. Checksums before and after the failed pass: canonical 85e4f46739de75eb, runtime 2c73775d8fc457a9, baseline dbc5ebcc91ccf853 — all three unchanged, runtime registration intact. Restoring permission lets the next pass complete.

Account isolation. Two managed accounts sharing one canonical home, mirrored alternately: each promotes its own marketplace, both converge on the same canonical file, and neither baseline is polluted by the other's pending state.

v2 → v3. Baseline downgraded on disk to { "version": 2, "settings": {...} } with no registrations key; the runtime then holds the registration the old mirror was about to destroy. After two passes it is healed into canonical and the baseline is rewritten as v3 with both entries.

Mutation discriminators

Against the 34 tests in config-plugin-registration-promotion.test.ts:

Mutation Failures
Fix disabled (planCodexRegistrationPromotion returns []) 15
Metadata-only policy (#11770's proposal) 11, including the explicit #10489 discriminator
Blind runtime preservation, ignoring the baseline 4
Registration block re-extended to the next table header 1

Review fixes in the second commit

  • Block boundary. entry.block ran to the next table header, so a comment introducing the following table was copied into canonical detached from what it described. Now trimmed using the existing TOML line-scan state, so a # inside a multiline string is never mistaken for a trailing comment.
  • Untested policy rows. Removing the plugin-enabled baseline three-way guard entirely passed all 27 original tests — the "both sides changed" test was actually discriminating on disabled_reason, not enabled. Added the two rows that exercise it (enabled is three-valued in practice: true, false, absent), taking that mutation from 1 failure to 4.
  • v2 → v3 upgrade had no test (only v1 → v3); added.
  • Append ordering now partitions on the typed entry.root instead of re-deriving it with key.startsWith('marketplaces:').

End-to-end with a real Codex binary

The evidence below is not a simulation of Codex: codex-cli 0.154.0 wrote the registration and read the result, with CODEX_HOME pointed at scratch homes throughout.

Real Codex was launched against the managed runtime home (what Orca does), and ran codex plugin marketplace add + codex plugin add against a real local marketplace. It wrote:

model = "gpt-5"
approval_policy = "on-request"

[marketplaces.ponytail]
source_type = "local"
source = "/private/tmp/.../mkt"

[plugins."ponytail@ponytail"]
enabled = true

Note this is real Codex choosing the quoted [plugins."<plugin>@<marketplace>"] form the identity key is built to handle. Two mirror passes then ran, and real Codex was asked to list what it could see.

Before (registration promotion disabled), canonical and runtime both collapse to:

model = "gpt-5"
approval_policy = "on-request"
$ codex plugin marketplace list
No plugin marketplaces in scope.

$ codex plugin list
No marketplace plugins found.

After (this PR), both homes keep the full table shown above, and real Codex reports:

$ codex plugin marketplace list
MARKETPLACE  ROOT
ponytail     /private/tmp/.../mkt

$ codex plugin list
PLUGIN             STATUS              VERSION  SOURCE
ponytail@ponytail  installed, enabled  4.8.4    /private/tmp/.../mkt/ponytail-plugin

That No marketplace plugins found. → installed, enabled transition is the user-visible bug in #10489 and #11770, reproduced and fixed against the real tool.

Why no screenshots

There is no Orca UI for this. Codex's marketplace and plugin registrations live only in config.toml and are surfaced by the codex CLI inside a terminal pane. Orca's own Settings → Plugins pane is a separate plugin host (src/main/plugins/, window.api.plugins) that never reads these tables, so a screenshot of it would show an unrelated feature that this PR does not change. The real before/after config bytes and real Codex CLI output above are the honest equivalent.

Relationship to #10494 and #11861

Two open community PRs each solved one half of this, and both were on the right track. Both authors are credited as co-authors.

#10494 (@Bongseop-Kim) — the #10489 half. Reaches the same central conclusion this PR does: a runtime-only registration must be promoted, but a registration the canonical config removed must not be resurrected, and the baseline is what tells them apart. Their guard (runtimeRaw !== baselineRaw && systemRaw === baselineRaw) is the same three-way as the baseline rows in the table above, and they reused the existing conflict machinery rather than adding a parallel path. Their real-binary sandboxed regression against Codex CLI 0.145 covered removal-without-resurrection too. It does not close #11770: it compares whole normalised table blocks, so a marketplace metadata refresh makes the entire block "changed" and there is no field-level last_updated/last_revision rule to merge it.

Where they went further: for a baseline with no registration ancestry they anchor a conflict instead of promoting, which sidesteps the baseline-loss resurrection documented above. This PR deliberately promotes instead, so a v2 upgrade heals the user's install into canonical rather than parking it in a conflict — a real trade-off, chosen because the install reaching ~/.codex is the outcome #10489 asks for.

#11861 (@rodboev) — the #11770 half. Implements substantively the same marketplace rule: identity match on the source fields, then promote only on a strictly newer timestamp, with stale and malformed values skipped. It handles more than the happy path, and its array-aware sparse_paths comparison is more precise than the raw-text comparison used here (this PR is merely conservative there — a formatting difference reads as an identity change and skips). It does not close #10489: it only rewrites last_updated/last_revision inside marketplaces that already exist on both sides, so a runtime-only registration is never promoted and still vanishes. That case is the discriminator test in this PR.

Neither PR caught the Date.parse('2025-02-30') rollover; #11861 shares it, since plain Date.parse rolls the day forward instead of rejecting it.

Verification

pnpm tc clean · oxlint clean · oxfmt --check clean · vitest run src/main/codex — 1853 passed, 10 skipped, 173 files.

…g mirror

Scalar promotion omitted marketplace/plugin tables and the mirror rebuilt
ordinary config from canonical, so managed-account registrations and refreshed
provider metadata were both lost.

Fixes #10489
Fixes #11770
… baseline rows

The block ran to the next table header, so that table's leading comment was
copied into the canonical config detached from what it described. Adds the
policy rows no test discriminated: canonical wins when enablement changed on
both sides or has no mirrored ancestor, the v2 baseline upgrade path, and the
baseline-loss resurrection as a characterization test.

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

✅ No new issues found.

Reviewed changes

  • Registration-table reconciliation — planCodexRegistrationPromotion / applyCodexRegistrationPromotions reconcile [marketplaces.*] and [plugins.*] tables across the destructive managed-home mirror via a baseline-aware three-way (runtime vs canonical vs mirrored baseline), with distinct rules for marketplace refresh metadata and the plugin enabled toggle.
  • TOML table parsing — config-toml-plugin-registration-tables.ts keys registrations by parsed-header identity (so [plugins."a@b"] and [plugins.'a@b'] are one registration), captures whole blocks including [root.name.*] subtables, and trims trailing comments through the existing line-scan state rather than text heuristics.
  • Baseline v3 — config-settings-baseline.ts gains an optional registrations map (version: 3); absent ≡ never-mirrored makes the v2→v3 upgrade lossless and downgrade a safe degrade.
  • Mirror integration — config-settings-promotion.ts and codex-config-mirror.ts promote registrations into canonical before the canonical→runtime copy and set mirroredRegistrations: true only after a successful mirror, so a bootstrap baseline never records tables Orca didn't mirror.
  • Extraction refactor — promoted-key constants and readPromotedSettingValues move into config-toml-promoted-setting-values.ts, and the EOL helpers into config-toml-line-scan.ts, removing the duplicate definitions.

I read the full diff end-to-end and traced the mirror flow through codex-config-mirror.ts, config-settings-promotion.ts, config-settings-baseline.ts, and the runtime-owned-section merge. The three-way reconciliation is internally consistent, the EOL/CRLF handling is correct, and the tests carry exact (toBe) rather than loose assertions — including characterization tests for the documented baseline-loss residual risk and the #10489 metadata-only discriminator. The author's mutation analysis and real-file evidence align with what the code actually does.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c9b1de5a-4305-4358-95fe-31d6d361b573

📥 Commits

Reviewing files that changed from the base of the PR and between c78c394 and ce2780e.

📒 Files selected for processing (3)
  • src/main/codex/config-plugin-registration-promotion.test.ts
  • src/main/codex/config-plugin-registration-promotion.ts
  • src/main/codex/config-toml-plugin-registration-tables.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/codex/config-plugin-registration-promotion.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The change adds TOML readers for promoted settings and Codex registration tables. Baselines now persist normalized registration fields under schema version 3. Runtime marketplace metadata and plugin enablement changes are reconciled with canonical configuration. The mirror passes registration state through snapshot and promotion flows. Shared line-ending helpers preserve CRLF and trailing-newline behavior. New tests cover parsing, reconciliation, persistence, failures, formatting, and account isolation.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to ce278

A failed baseline write can cause a later sync to restore a registration that was intentionally removed from canonical configuration. Resolve the failure handling before merge to preserve removal semantics.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements the linked objectives in [#10489] and [#11770] for registration persistence, baseline-aware removals, plugin enablement conflicts, matching marketplace identity, newer valid timestam… Require a non-multiline runtime last_revision before any marketplace metadata promotion, regardless of canonical revision presence. Skip the complete promotion when the runtime pair is incomplete. Add a regression test where the canonical…
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 52 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changed source, baseline schema, shared TOML line-ending helpers, TypeScript include updates, and regression tests support the registration reconciliation and marketplace metadata objectives in [#…
Title check ✅ Passed The title clearly identifies the main change: reconciling Codex marketplace and plugin tables through the configuration mirror.
Description check ✅ Passed The description provides a clear problem statement, detailed changes, rationale, linked issues, behavior evidence, testing results, visual-proof rationale, compatibility considerations, and residual r…
Full details: Linked Issues check

Explanation

The PR implements the linked objectives in [#10489] and [#11770] for registration persistence, baseline-aware removals, plugin enablement conflicts, matching marketplace identity, newer valid timestamps, paired metadata in the covered case, formatting preservation, atomic failure handling, account isolation, and regression coverage. One [#11770] requirement remains unmet. planMarketplaceRefreshPromotion rejects a missing runtime last_revision only when the canonical entry already has last_revision. If both entries lack last_revision, a newer runtime last_updated is still promoted alone. This violates the required complete last_updated/last_revision pair and the stated incomplete-pair behavior.

Resolution

Require a non-multiline runtime last_revision before any marketplace metadata promotion, regardless of canonical revision presence. Skip the complete promotion when the runtime pair is incomplete. Add a regression test where the canonical marketplace also lacks last_revision and the runtime has only a newer last_updated.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 530b1c1a-d925-47c2-900c-882eefbb83f9

📥 Commits

Reviewing files that changed from the base of the PR and between 7294915 and c78c394.

📒 Files selected for processing (13)
  • config/tsconfig.cli.json
  • src/main/codex/codex-config-mirror.ts
  • src/main/codex/codex-config-settings-upsert.ts
  • src/main/codex/config-plugin-registration-promotion.test.ts
  • src/main/codex/config-plugin-registration-promotion.ts
  • src/main/codex/config-settings-baseline-upgrade.test.ts
  • src/main/codex/config-settings-baseline.ts
  • src/main/codex/config-settings-promotion.test.ts
  • src/main/codex/config-settings-promotion.ts
  • src/main/codex/config-toml-line-scan.ts
  • src/main/codex/config-toml-plugin-registration-tables.ts
  • src/main/codex/config-toml-promoted-setting-values.ts
  • src/main/codex/sta-4823-shared-state-survives-a-failed-read.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comment on lines +72 to +74
registrations: options.mirroredRegistrations
? readCodexRegistrationBaseline(runtimeConfig)
: new Map()

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not report a successful mirror when the registration baseline write fails

snapshotCodexRuntimeSettingsBaseline catches writeCodexSettingsBaseline failures and returns void, so the mirror continues with the runtime registration reachable but absent from the durable baseline. If canonical configuration later removes that registration, planCodexRegistrationPromotion sees a runtime-only entry and promotes it again. Propagate the snapshot failure or persist a pending state, and block baseline-free registration promotion until the baseline write succeeds.

…airs

Date.parse rolls `2025-02-30` forward to March 2 rather than rejecting it, so a
malformed runtime timestamp read as NEWER and won against canonical. Promoting a
newer timestamp while the runtime had no last_revision also cleared the canonical
revision, publishing the mismatched pair the pairing rule exists to prevent.

Co-authored-by: BsTiger <[email protected]>
Co-authored-by: Rod Boev <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor Author

Both findings on this review were real and are fixed in ce2780e.

Impossible calendar dates — confirmed and fixed. Date.parse('2025-02-30T00:00:00Z') returns 1740873600000, i.e. it silently rolls forward to March 2 rather than rejecting. That is worse than a parse failure here: a malformed runtime timestamp read as newer than canonical and won the comparison. The RFC 3339 regex now captures Y/M/D and validates the day against the real month length before Date.parse runs, so 2025-02-30 returns null and is skipped. 2025-13-01 and hour 25 were already rejected by V8; only day-overflow within a valid month slipped through. Covered by rejects an impossible calendar date instead of rolling it forward, which fails if the validation is reverted.

Incomplete last_revision pair — agreed, and fixed as the pre-merge check suggested. Previously a newer runtime last_updated with no runtime last_revision promoted the timestamp and emitted a deletion for the canonical revision, publishing exactly the pair-that-never-existed the pairing rule is meant to prevent. The refresh is now skipped entirely when the runtime cannot supply a revision the canonical table has. Note the reverse case is unaffected: when neither side has a revision, both normalise to absent and no field promotion is produced, so source_type = "local" marketplaces (which real Codex writes without either field) are untouched. Covered by skips the refresh when the runtime cannot supply the paired last_revision.

Baseline write failure — I am not making the snapshot failure fatal, deliberately. You have correctly identified a real window, and it is the same residual risk the PR body documents under "Residual risk: baseline loss", reached by a different trigger (failed write rather than lost file). Two reasons not to take the suggested fix:

  1. A failed writeCodexSettingsBaseline leaves the previous baseline on disk, not an empty one. For the common sequences that is strictly better than absent — a registration mirrored on an earlier pass still has its baseline entry, so a later canonical removal is still honoured. The harmful case is narrow: a newly promoted registration, plus a failed baseline write, plus a canonical removal before any later pass writes a baseline successfully.
  2. Propagating the failure would make an unwritable baseline path block config mirroring entirely. That trades a narrow, recoverable un-removal for a hard stall on the whole Codex config sync, including ordinary settings — a worse outcome, and a behaviour regression against today's mirror.

This is a pre-existing property of the baseline mechanism that this PR extends to registrations rather than introduces: a failed baseline write already causes scalar settings to be re-promoted the same way. It is characterised by a test (re-promotes a canonically removed registration when the baseline is lost first) so it cannot change silently, and the companion test proves a settled config stays byte-identical when the baseline is lost with no removal pending.

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

✅ No new issues found.

Reviewed changes

This run re-reviewed the delta since the prior Pullfrog review at c78c394 — commit ce2780e, which tightens two edge cases in marketplace refresh promotion.

  • Impossible-date rejection — parseCodexRegistrationTimestamp now validates the day against the real length of the month before calling Date.parse, so values like 2026-02-30 (which V8 rolls forward to March 2 and would otherwise read as newer) become malformed and are skipped. Checked the adjacent cases too: non-leap 2023-02-29 is rejected the same way, while invalid time components and out-of-range offsets already yield NaN from Date.parse, so the date guard is the only gap.
  • Unpaired refresh guard — planMarketplaceRefreshPromotion returns early when the runtime supplies a newer last_updated but no last_revision while canonical already carries one, so the refresh can no longer clear the canonical revision and publish a mismatched pair.
  • Regression tests — two exact-assertion tests cover both cases; the full file passes 36/36 locally (pnpm test src/main/codex/config-plugin-registration-promotion.test.ts).

Pullfrog  | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant