Skip to content

fix(codex): promote only newer marketplace metadata (#11770) - #11861

Closed
rodboev wants to merge 3 commits into
stablyai:mainfrom
rodboev:pr/marketplace-metadata-promotion
Closed

rodboev wants to merge 3 commits into
stablyai:mainfrom
rodboev:pr/marketplace-metadata-promotion

Conversation

@rodboev

@rodboev rodboev commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Promote Codex marketplace refresh metadata only when the canonical and managed tables have the same source identity and the managed timestamp is newer.
  • Preserve canonical marketplace settings, unrelated configuration, and existing non-marketplace promotion behavior.

Closes #11770.

Screenshots

No visual change

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused validation run in this session:

  • pnpm exec vitest run --config config/vitest.config.ts src/main/codex/codex-config-mirror.test.ts src/main/codex/config-settings-promotion.test.ts src/main/codex/config-marketplace-refresh-promotion.test.ts
  • pnpm typecheck:node
  • pnpm exec oxlint src/main/codex/config-marketplace-refresh-promotion.ts src/main/codex/config-marketplace-refresh-promotion.test.ts src/main/codex/config-settings-promotion.ts
  • pnpm exec oxfmt --check src/main/codex/config-marketplace-refresh-promotion.ts src/main/codex/config-marketplace-refresh-promotion.test.ts src/main/codex/config-settings-promotion.ts
  • git diff --check

The base reproduction failed before the fix, and the focused head suite passed with 97 tests and 4 intentional skips. Full lint, test, and build remain CI-gated.

AI Review Report

The final diff is limited to Codex config promotion and its production-composed tests. It compares marketplace source identity and strict timestamp ordering, preserves canonical fields and unrelated settings, and leaves the existing managed-home mirror path in place. No UI, provider, local/remote transport, or new filesystem authority changed.

Security Audit

The change only copies two already-parsed metadata values from a matching managed table into the canonical config. It accepts no new URL, credential, command, or filesystem authority.

Notes

Related config PRs #6577, #9501, and #10221 do not own this marketplace freshness slice.

@coderabbitai

coderabbitai Bot commented Aug 1, 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: 0e2e80eb-273f-43ed-a45e-f9c5b3a88858

📥 Commits

Reviewing files that changed from the base of the PR and between 33142db and 0b453b7.

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

📝 Walkthrough

Walkthrough

The change adds TOML parsing and marketplace metadata promotion for matching marketplaces with newer valid runtime timestamps. It preserves formatting and unrelated configuration, removes runtime-only marketplace sections during canonical configuration creation, and applies optional revision updates. Configuration synchronization now uses the complete runtime configuration and writes only when prepared content changes. New Vitest coverage verifies promotion, idempotency, timestamp validation, identity matching, and marketplace retention behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes promoting only newer Codex marketplace metadata.
Description check ✅ Passed The description includes all required sections and documents the change, focused validation, AI review, security audit, and lack of visual changes.
Linked Issues check ✅ Passed The changes address issue #11770 by matching marketplace identities, promoting only newer valid metadata, preserving canonical settings, and covering exclusion and idempotency cases.
Out of Scope Changes check ✅ Passed The changed production files and tests are limited to Codex configuration promotion and directly support issue #11770.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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-settings-promotion.ts (1)

235-237: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Avoid reading runtimeTomlPath twice per promotion pass.

readPromotedSettingValues(runtimeTomlPath) (line 235) already reads the file internally. Line 237 reads the same path again to get the raw string. This doubles I/O on runtimeTomlPath on every promotion pass. It can also let runtimeValues and runtimeConfig reflect two different snapshots of the file if a concurrent write happens between the two reads, since the runtime config.toml can be modified by a running Codex CLI process.

Read the file once and derive both the structured values and the raw content from the same read.

♻️ Proposed refactor to read the runtime file once
-  const runtimeValues = readPromotedSettingValues(runtimeTomlPath)
-  const systemValues = readPromotedSettingValues(systemTomlPath)
-  const runtimeConfig = readAgentStateFileSync(runtimeTomlPath)
+  const runtimeConfig = readAgentStateFileSync(runtimeTomlPath)
+  const runtimeValues = readPromotedSettingValuesFromContent(runtimeConfig)
+  const systemValues = readPromotedSettingValues(systemTomlPath)

This requires extracting the line-scanning body of readPromotedSettingValues into a readPromotedSettingValuesFromContent(content: string) helper, with readPromotedSettingValues(configPath) calling it after its own read.

src/main/codex/config-marketplace-refresh-promotion.test.ts (1)

128-207: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a regression test for promoting multiple marketplaces independently.

The PR objectives call for covering "multiple marketplaces" alongside idempotency and identity matching. All tests here exercise a single [marketplaces.demo] table. Add a case with two marketplace tables in the same config where only one has a newer, matching runtime timestamp, and assert that only the eligible one is promoted while the other's canonical metadata stays untouched. This also exercises the bottom-up line-splice ordering in promoteMarketplaceRefreshMetadata when both tables need a last_revision line inserted.

Do you want me to draft this test case?


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ebf93f4-466b-42b3-bbc4-ebb067699fa5

📥 Commits

Reviewing files that changed from the base of the PR and between 5738d61 and 33142db.

📒 Files selected for processing (3)
  • src/main/codex/config-marketplace-refresh-promotion.test.ts
  • src/main/codex/config-marketplace-refresh-promotion.ts
  • src/main/codex/config-settings-promotion.ts

@greptile-apps

greptile-apps Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR introduces config-marketplace-refresh-promotion.ts to selectively promote Codex marketplace refresh metadata (last_updated, last_revision) from the managed runtime config back into the canonical ~/.codex/config.toml, gated on matching source identity and a strictly newer timestamp. config-settings-promotion.ts is updated to delegate through prepareSystemConfigForPromotion, which composes the new marketplace refresh with the existing settings-upsert path.

  • New promotion module: Parses marketplace TOML sections from both configs, compares identity fields (source_type, source, ref, sparse_paths) and timestamp strictly, then updates the canonical lines in place — or splices in last_revision when it is absent — using a descending-index sort so multi-table splices don't corrupt earlier line indices.
  • config-settings-promotion.ts refactor: The mkdirSync calls are correctly moved to just before the write (after the nextContent === null / unchanged early-return), so a no-op promotion no longer touches the filesystem unnecessarily.
  • Tests: Integration tests cover promotion, idempotency, equal/older/malformed/missing timestamps, identity-change preservation, last_revision splice insertion with CRLF ordering, and runtime-only marketplace exclusion.

Confidence Score: 5/5

Safe to merge — the change is self-contained to the Codex config promotion path and introduces no new filesystem authority, credentials, or network access.

The identity gate, timestamp comparison, CRLF handling, and multi-table splice ordering are all correct. The fail-closed behavior for unparseable multi-line arrays is intentional and documented. The mkdirSync relocation is a clean fix to a prior review finding, and the test suite covers the key scenarios including idempotency and the last_revision splice path.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/main/codex/config-marketplace-refresh-promotion.ts New module: parses marketplace TOML sections, gates promotion on identity equality and strict timestamp ordering, handles CRLF, and inserts last_revision when absent. Logic is sound with correct descending-sort guard for multi-table splices.
src/main/codex/config-settings-promotion.ts Refactored to delegate to prepareSystemConfigForPromotion; mkdirSync calls correctly moved below the nextContent === null / unchanged early-return; no existing semantics broken.
src/main/codex/config-marketplace-refresh-promotion.test.ts Integration tests cover promotion (with idempotency), equal/older/malformed/missing timestamps, identity-change preservation, last_revision splice insertion (with CRLF pin), and runtime-only marketplace exclusion.

Reviews (2): Last reviewed commit: "docs(codex): note why an unparsed sparse..." | Re-trigger Greptile

@rodboev

rodboev commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nwparker

Copy link
Copy Markdown
Contributor

Thank you for this — you are credited as a co-author on the commit that landed.

Your marketplace rule is substantively the one that merged: match the source identity first, then promote only on a strictly newer timestamp. You handled more than the happy path — stale and malformed values both skip, and gating on identity so a marketplace whose source moved keeps canonical in control is exactly right. Your array-aware sparse_paths comparison is actually more precise than what merged, which compares the raw text and therefore treats a pure formatting difference as an identity change and conservatively skips.

Two notes for the record. The merged version differs on one edge: when canonical has no parseable last_updated at all but the runtime does, yours skips (both must parse) and the merged version promotes, on the grounds that the runtime holds real information and canonical holds none. And neither of us caught that Date.parse('2025-02-30T00:00:00Z') does not fail — it rolls forward to March 2, so an impossible date read as newer and won the comparison. The merged fix now validates the day against the real month length before parsing; your implementation shares the original behaviour, which is worth knowing if you carry this logic elsewhere.

Closing as superseded by #20150. The reason it needed to be one change rather than two: a metadata-only policy only rewrites fields inside marketplaces that already exist on both sides, so a marketplace registered from inside Orca is never promoted and still disappears — that is #10489, and it is now an explicit discriminator test in the merged suite. The merged policy handles both halves in a single baseline-aware pass. If you think anything in yours is still uncovered, 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Orca overwrites refreshed Codex marketplace metadata with stale metadata from ~/.codex/config.toml

4 participants