Skip to content

[WRONG BRANCH] fix(codex): fence entitlement credential refreshes - #393

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-auth.json-refresh-issue
Draft

[WRONG BRANCH] fix(codex): fence entitlement credential refreshes#393
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-auth.json-refresh-issue

Conversation

@luvs01

@luvs01 luvs01 commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent background/data-plane callers (e.g. GET /v1/models and catalog sync) from causing the native auth.json to be refreshed or rewritten while native-main lifecycle, recovery, or profile-switch drains intend the physical native identity to be untouchable.
  • Ensure entitlement collection honors the native-main lifecycle boundary and the cross-process shared claim so credential reads and any refreshes are performed only while proper ownership is held.

Description

  • Add a lifecycle-aware admission wrapper resolveAdmittedCodexModelEntitlements that acquires the process-local native-main lease, uses a cross-process shared claim for the credential read (so refreshes are fenced), and excludes MAIN_CODEX_ACCOUNT_ID when lifecycle admission cannot be obtained or the shared claim is unavailable (file: src/codex/model-entitlement-admission.ts).
  • Route model discovery in the data-plane GET /v1/models handler to use the admitted/fenced resolver instead of calling the refresh-capable resolver directly (file: src/server/index.ts).
  • Apply the same fenced resolver to retained catalog synchronization and convergence code paths that previously called the entitlement resolver directly (files: src/codex/catalog/sync.ts, src/codex/convergence.ts).
  • Add focused regression tests covering lifecycle-blocked exclusion, correct ordering of lifecycle lease vs shared claim during discovery, and fallback to Pool-only discovery when the shared claim is unavailable (file: tests/codex-model-entitlement-admission.test.ts).
  • Handle claim-unavailability errors from the shared-claim path by falling back to Pool-only entitlement resolution rather than failing the overall operation.

Testing

  • Ran the focused entitlement tests: bun test tests/codex-model-entitlement-admission.test.ts tests/codex-model-entitlements.test.ts, which reported 23 passing tests and 0 failures across those files.
  • Performed type checking with bun run typecheck, which succeeded (no emits reported).
  • Ran the repository privacy scan bun run privacy:scan, which passed.
  • Attempted the scoped change selection check bun run test:changed but it could not run due to the local branch not resolving the upstream comparison ref; focused tests above were used instead as recommended by repo guidance.

Codex Task

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-31T01:06:59.612887Z 620f3c8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 673e99be-1b8e-4192-853b-7d3788da5dc4


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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 620f3c8db0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

): Promise<CodexModelEntitlementSnapshot> {
const resolve = deps.resolve ?? resolveCodexModelEntitlements;
const lease = (deps.acquireNativeMain ?? tryAcquireNativeMainProfileClaim)();
if (!lease) return resolve(config, excludeNativeMain(options));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retry catalog sync after startup admission opens

When startup ownership acquisition or journal recovery is still pending, startNativeMainStartupLifecycle reports native-main traffic as blocked, but the startup flow in src/cli/index.ts proceeds from startServer to syncCodexOnStartIfEnabled without awaiting that lifecycle. This branch therefore lets syncCatalogModels commit a Pool-only entitlement snapshot, removing main-only account-gated models from the on-disk Codex catalog; when recovery later succeeds, nothing automatically reconverges that catalog, so the models remain absent until a separate sync occurs. Treat this as a non-committable/retryable snapshot for catalog writers, or schedule convergence when the startup gate opens.

Useful? React with 👍 / 👎.

// A foreign exclusive holder or an unsupported claim filesystem makes
// main unavailable; it must not suppress independent Pool discovery.
if (!(error instanceof NativeProfileError)) throw error;
return await resolve(config, excludeNativeMain(options));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Release the main lease before Pool-only fallback

When the cross-process claim is busy or unavailable, this fallback performs the entire Pool-only resolution before the finally releases the process-local native-main lease. A concurrent local profile switch therefore sees a native-main request in progress and waits for unrelated Pool credential refreshes/model fetches; those can outlast the switch's 10-second drain deadline and make the switch fail with MAIN_REQUESTS_ACTIVE even though the fallback never reads main. Release the lease before starting the independent Pool-only resolution.

Useful? React with 👍 / 👎.

@github-actions github-actions Bot added the bug Something isn't working label Aug 31, 2026
@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot changed the title fix(codex): fence entitlement credential refreshes [WRONG BRANCH] fix(codex): fence entitlement credential refreshes Aug 31, 2026
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions
github-actions Bot marked this pull request as draft August 31, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant