Skip to content

fix(codex): persist plugin registrations across managed-home remirrors - #10494

Closed
Bongseop-Kim wants to merge 2 commits into
stablyai:mainfrom
Bongseop-Kim:agent/fix-codex-plugin-persistence
Closed

Bongseop-Kim wants to merge 2 commits into
stablyai:mainfrom
Bongseop-Kim:agent/fix-codex-plugin-persistence

Conversation

@Bongseop-Kim

@Bongseop-Kim Bongseop-Kim commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Persist Codex marketplace and plugin registrations made inside an Orca-managed CODEX_HOME across config remirrors.
  • Root cause: the existing baseline-based promotion tracked top-level and [tui] settings, but not the dynamic [marketplaces.<name>] and [plugins."<plugin>@<marketplace>"] tables, so the next system-config mirror replaced them.
  • Extend the same baseline/reconciliation path to generalized marketplace and plugin table blocks, preserving quoted headers, comments, CRLF, table order, and byte stability.
  • Treat registration removal as a managed-home change and never infer installation from cache contents.

Reconciliation policy

  • If only the managed runtime changed from a known baseline, promote its add, edit, disable, or removal to the system config.
  • If the system config changed the same registration, keep the system value, matching the existing three-way policy.
  • For legacy baselines without registration ancestry, use the existing anchored-conflict behavior rather than guessing a winner.
  • Do not unconditionally preserve runtime plugin tables, so external removals cannot be resurrected.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions

Additional coverage:

  • 9 related Codex config/mirror/account test files: 300 tests passed.
  • Full suite: 3,396 test files and 36,011 tests passed; 7 files and 60 tests skipped.
  • oxfmt --check passed for all changed files.
  • Sandboxed HOME/CODEX_HOME regression with Codex CLI 0.145.0: marketplace add, plugin add/list, repeated real mirror byte stability, plugin/marketplace removal, and no resurrection after remirror.

AI Review Report

  • Reviewed the real mirror call path and all callers before changing the shared promotion layer.
  • Checked TOML parsing and rewriting risks: quoted/literal headers, comments, CRLF, ordering, duplicate tables, legacy baselines, concurrent system edits, deletion/disable behavior, and cache-only state.
  • Checked macOS, Linux, Windows, WSL, and SSH behavior. The change uses existing Node path/file primitives and explicit runtime/system home paths; it adds no shortcuts, labels, shell commands, or Electron platform branches.
  • Checked folder workspaces and supported Git providers; this is isolated to Codex config mirroring and adds no git-worktree or GitHub-specific assumptions.
  • Performance remains linear in the small config file per mirror, with no new polling, dependencies, or cache scans.

Security Audit

  • No new command execution, IPC, network access, dependencies, auth handling, or secret logging.
  • Config writes continue through the existing atomic/symlink-aware promotion path and existing explicit home boundaries.
  • Baseline registration payloads are validated as strings before use, and cache directories are never trusted as installation state.
  • No follow-up security work identified.

Notes

  • This intentionally does not change system-default CODEX_HOME routing or authentication isolation; those remain separate from this managed-account persistence fix.
  • pnpm build exited successfully with the existing bundle warnings and local /usr/local/bin/orca-dev symlink permission notice.
  • X handle: not provided.

Fixes #10489

ELI5

Codex marketplace and plugin registrations inside Orca-managed CODEX_HOME were wiped on the next config remirror. Those plugin tables are preserved across remirrors so installed plugins stick.

@Bongseop-Kim
Bongseop-Kim marked this pull request as ready for review July 25, 2026 05:03
@coderabbitai

coderabbitai Bot commented Jul 25, 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: db7afe8d-76f0-4027-bd57-85bd22cedb11

📥 Commits

Reviewing files that changed from the base of the PR and between d297a6c and 5477e7e.

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

📝 Walkthrough

Walkthrough

Codex configuration synchronization now tracks plugin registration tables in persisted baselines, reads and updates registration blocks in TOML, and applies registration-specific promotion and conflict-preservation logic. Scalar setting promotion uses shared value and conflict-resolution helpers. Runtime snapshots include registrations, and generated system configuration preserves formatting and line endings. Integration tests cover promotion, conflicts, removal, legacy baselines, idempotence, and cache-file handling.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: persisting Codex plugin registrations across managed-home remirrors.
Description check ✅ Passed The description matches the required template and includes summary, screenshots, testing, AI review, security audit, and notes sections.
Linked Issues check ✅ Passed The changes implement persistence for marketplace/plugin registrations, preserve conflict precedence, and add tests for remirrors, removals, and cache-only state.
Out of Scope Changes check ✅ Passed The only non-feature changes are supporting tsconfig and tests, which are directly tied to the registration persistence work.

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.

🧹 Nitpick comments (2)
src/main/codex/config-plugin-registration-promotion.test.ts (1)

71-84: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the exact first-pass output bytes.

The second mirror only proves idempotence of its own output. A regression that reformats the original preamble, [features] block, or blank lines still passes these toContain checks. Compare system with an exact CRLF expected string after the first promotion.

As per PR objectives, registration reconciliation must preserve byte stability.

src/main/codex/config-settings-baseline.ts (1)

63-74: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

pluginRegistrations is always serialized, unlike conflicts, breaking null/untracked round-trip fidelity.

writeCodexSettingsBaseline unconditionally sets pluginRegistrations: Object.fromEntries(baseline.pluginRegistrations ?? []), coercing a null (untracked/legacy) baseline into a tracked-but-empty {} on write. Contrast with conflicts, which is only added if (baseline.conflicts.size > 0). Since readCodexSettingsBaseline uses Object.hasOwn(parsed, 'pluginRegistrations') to distinguish "untracked" (null) from "tracked" (a Map, even empty), any future call site that writes a baseline object while intentionally preserving pluginRegistrations: null would silently have it promoted to tracked-empty on the next read, defeating the untracked-conflict semantics that collectCodexPluginRegistrationChanges relies on (context.baseline.pluginRegistrations === null). Today's only caller (snapshotCodexRuntimeSettingsBaseline) always passes a real Map, so this isn't exercised yet, but the write/read contract itself is inconsistent.

♻️ Mirror the conditional pattern used for `conflicts`
   const file: StoredSettingsBaseline = {
     version: 2,
-    settings: Object.fromEntries(baseline.settings),
-    pluginRegistrations: Object.fromEntries(baseline.pluginRegistrations ?? [])
+    settings: Object.fromEntries(baseline.settings)
   }
+  if (baseline.pluginRegistrations !== null) {
+    file.pluginRegistrations = Object.fromEntries(baseline.pluginRegistrations)
+  }
   if (baseline.conflicts.size > 0) {
     file.conflicts = Object.fromEntries(baseline.conflicts)
   }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e8c8933c-8942-4aea-aa58-2059dd8fc64c

📥 Commits

Reviewing files that changed from the base of the PR and between 6592c01 and d297a6c.

📒 Files selected for processing (7)
  • config/tsconfig.cli.json
  • src/main/codex/codex-config-settings-preservation.ts
  • src/main/codex/codex-plugin-registration-config.ts
  • src/main/codex/config-plugin-registration-promotion.test.ts
  • src/main/codex/config-settings-baseline.ts
  • src/main/codex/config-settings-conflict-resolution.ts
  • src/main/codex/config-settings-promotion.ts

@nwparker

Copy link
Copy Markdown
Contributor

Thank you for this — it was genuinely good work, and you are credited as a co-author on the commit that landed.

You reached the central conclusion independently and correctly: a runtime-only registration has to be promoted, but a registration the canonical config removed must not be resurrected, and the mirrored baseline is the only thing that can tell those two apart. Your guard — runtimeRaw !== baselineRaw && systemRaw === baselineRaw — is the same three-way the merged fix uses for its baseline rows. You also reused the existing conflict-resolution machinery instead of adding a parallel path, which was the better instinct, and your sandboxed CODEX_HOME regression against Codex CLI 0.145 covered removal-without-resurrection rather than just the happy path.

One thing your PR does that the merged fix deliberately does not, and it is a place your design is better than ours: for a baseline with no registration ancestry you anchor a conflict rather than promoting. That sidesteps a residual risk the merged version accepts (if the baseline is lost at the same moment a canonical removal is pending, the removal can be undone). The merged fix promotes instead, so that a v2→v3 upgrade heals an existing install into ~/.codex rather than parking it in a conflict — the outcome #10489 asks for. It is a real trade-off and your side of it is defensible; it is written up in the merged PR body so the choice is on the record.

Closing as superseded by #20150, which covers this plus the #11770 half. Your PR compares whole normalised table blocks, so a marketplace metadata refresh reads as a wholesale block change with no field-level last_updated/last_revision rule to merge it — that was the remaining gap, and the merged policy handles both halves in one baseline-aware pass. If you think something in yours is still uncovered, please say so and I will reopen.

@nwparker nwparker closed this Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex plugin installs disappear after Orca restarts while cache remains

4 participants