Skip to content

Enable Codex account-authenticated runs - #253

Merged
itsHabib merged 5 commits into
mainfrom
codex/codex-account-auth
Aug 27, 2026
Merged

Enable Codex account-authenticated runs#253
itsHabib merged 5 commits into
mainfrom
codex/codex-account-auth

Conversation

@itsHabib

@itsHabib itsHabib commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Summary

Ship could not use an existing Codex ChatGPT login and its workspace-write sandbox could not commit from linked worktrees because their Git metadata lives outside the checkout. This change admits file- and keyring-backed Codex account auth, moves the default to gpt-5.6-sol, updates the bundled SDK, and grants only the linked-worktree Git stores required for a bounded repair commit.

What this adds

Signed-in Codex execution:

  • omit the SDK apiKey option when CODEX_API_KEY and OPENAI_API_KEY are absent or blank, allowing the CLI to use its isolated CODEX_HOME login
  • recognize account auth through the SDK-bundled native codex login status, so the CLI's active file or keyring store remains authoritative
  • skip the login-status subprocess when an API key is already present

Bounded linked-worktree commits:

  • keep Codex in workspace-write
  • add only the validated per-worktree Git admin directory plus shared objects, every active ref store (refs and/or reftable), and optional reflogs as writable roots
  • accept valid repositories with reflogs disabled and reftable-backed linked worktrees while rejecting malformed or unrelated Git-directory layouts

Current Codex runtime:

  • default local Codex runs to gpt-5.6-sol
  • update @openai/codex-sdk from 0.142.3 to 0.149.1

Regression coverage:

  • prove API-key and account-auth option shapes remain distinct, including whitespace-only keys
  • prove file- and keyring-backed profiles satisfy driver preflight and suppress false fallback warnings
  • prove stale auth files cannot overrule the CLI's active credential store
  • prove the bundled native CLI resolves on supported macOS, Linux, and Windows targets
  • prove linked-worktree Git roots are narrowly derived and forwarded to the SDK, including files-ref, no-reflog, and reftable layouts

Validation

  • make check at exact head ba053967f3e35da3ecac13e85bdd433a35d09c72
  • Ubuntu CI and Windows CI passed at the exact head
  • Exact-head Codex review: no major issues
  • Installed SDK-native Codex executable resolved without relying on PATH
  • RoxIQ live provider contract passed: workflow wf_01M0YF167MMAFH0TNJPD6YR2EP, provider codex, runtime local, model gpt-5.6-sol, duration 94,883 ms
  • Full RoxIQ controller dress rehearsal passed: run gnt_20260826T082017Z_61c7a053866efc1f, Ship workflow wf_01M0YJJ0MYN9B30KJGSXT1ADJ4, all required stages through audit, clean candidate 5d85f6430de9ad129af1d7b6bd30d0ac14ec5c53
  • Live Codex repair passed 612 web tests plus lint; Workbench Tracelens returned pass/T0
  • Dress-rehearsal Ship trace SHA-256: d89223937dbc7414f1a664299acf9232c4568be4ba87c27d8adf51959866c04b
  • Run-owned Codex auth.json was removed before trace grading and evidence retention

Residual review judgment

Copilot's final exact-head summary generated no new inline comments and repeated one suppressed P2 suggestion: expose malformed linked-worktree metadata with a more specific top-level error than Codex construction failed. The underlying cause is preserved, malformed layouts are still rejected, and the concern does not alter auth, sandbox, or commit correctness. Per the repository's two-fix-round ceiling, this residual diagnosability improvement is deferred to Gate's judge rather than creating another review head.

Claude and Cursor review requests did not produce completed reviews because those seats are unavailable. They are not represented here as completed review evidence; Gate must evaluate the missing-panel condition within the operator's grant ceiling.

@itsHabib
itsHabib requested a lite review from Copilot August 26, 2026 07:06
@itsHabib

Copy link
Copy Markdown
Owner Author

@codex review

@itsHabib

Copy link
Copy Markdown
Owner Author

@claude review

@itsHabib

Copy link
Copy Markdown
Owner Author

@cursor review

@cursor

cursor Bot commented Aug 26, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_2f400543-7d33-49a8-adfa-0abef6ba4572)

@claude

claude Bot commented Aug 26, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Copilot AI 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.

🟡 Changes recommended

There’s a verified edge-case bug around whitespace-only API keys preventing the intended account-auth fallback, plus a test assertion that can pass even if apiKey is inadvertently included as undefined.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Enables running Codex locally using an existing signed-in Codex CLI profile (when no API key env vars are set), updates viability/preflight checks to recognize that profile, bumps the bundled Codex SDK to a version that can run the new default model, and sets the default local Codex model accordingly.

Changes:

  • Allow Codex local runs to omit apiKey so the Codex CLI can use account-auth (CODEX_HOME profile), and teach driver viability checks to detect auth.json.
  • Update default Codex model to gpt-5.6-sol.
  • Bump @openai/codex-sdk to 0.149.1 and update tests/docs for the new credential shape.
File summaries
File Description
pnpm-lock.yaml Updates lockfile entries for the newer @openai/codex(-sdk) versions.
packages/driver/src/viability.ts Adds Codex account-auth detection to viability checks via auth.json.
packages/driver/src/viability.test.ts Adds regression coverage for Codex account-auth viability and deps wiring.
packages/driver/src/fallback-hop.test.ts Updates viability deps stubs to include the new codexAccountAuthExists port.
packages/driver/src/assign.test.ts Updates viability deps stubs to include the new codexAccountAuthExists port.
packages/core/src/default-wiring.ts Changes the default Codex model id to gpt-5.6-sol.
packages/codex-runner/src/local-runner.ts Conditionally supplies apiKey only when present, enabling account-auth fallback.
packages/codex-runner/src/local-runner.test.ts Adjusts tests to validate the account-auth/no-apiKey option shape.
packages/codex-runner/README.md Documents the new behavior and SDK version/capability gaps reference.
packages/codex-runner/package.json Bumps @openai/codex-sdk dependency to 0.149.1.
Review details

Files not reviewed (1)

  • pnpm-lock.yaml: Generated file
  • Files reviewed: 9/10 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/codex-runner/src/local-runner.ts
Comment thread packages/codex-runner/src/local-runner.test.ts Outdated

@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: 401150fadc

ℹ️ 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".

Comment thread packages/driver/src/viability.ts Outdated
Comment thread packages/driver/src/viability.ts
@itsHabib

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI 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.

🟡 Changes recommended

Codex account-auth detection may fail on Windows because the executable resolver doesn’t consider common .cmd/.bat PATH shims, leading to false “not signed in” results.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Files not reviewed (1)

  • pnpm-lock.yaml: Generated file
  • Files reviewed: 17/18 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread packages/driver/src/codex-auth.ts Outdated

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

ℹ️ 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".

Comment thread packages/codex-runner/src/linked-worktree-writes.ts Outdated
Comment thread packages/driver/src/codex-auth.ts Outdated
Comment thread packages/driver/src/import.ts Outdated
@itsHabib

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI 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.

🔵 Needs a closer look

It modifies authentication behavior and expands sandbox write roots for Git metadata, which warrants final human review for security and operational correctness.

Review details

Files not reviewed (1)

  • pnpm-lock.yaml: Generated file

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

packages/codex-runner/src/local-runner.ts:166

  • linkedWorktreeWriteDirectories(input.cwd) can throw for malformed or unexpected .git pointer layouts, but that exception is currently caught and rethrown as AgentRunFailedError("Codex construction failed"), which obscures the real failure mode (worktree/Git metadata validation). Consider catching around the directory-derivation call and throwing a more specific AgentRunFailedError so users get an actionable message while still rejecting unsafe layouts.
function buildThreadOptions(
  input: AgentRunInput,
): NonNullable<Parameters<Codex["startThread"]>[0]> {
  return {
    additionalDirectories: linkedWorktreeWriteDirectories(input.cwd),
    approvalPolicy: "never",
    sandboxMode: resolveSandboxMode(),
    skipGitRepoCheck: false,
    workingDirectory: input.cwd,
    ...(input.model.id.length > 0 && { model: input.model.id }),
  };
  • Files reviewed: 21/22 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@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: 07a4e1e84d

ℹ️ 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".

Comment thread packages/driver/src/codex-auth.ts Outdated
@itsHabib

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI 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.

🟢 Approval recommended

The changes are consistent with the PR’s stated goals and include targeted regression tests covering the new auth and linked-worktree behaviors.

Review details

Files not reviewed (1)

  • pnpm-lock.yaml: Generated file
  • Files reviewed: 21/22 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@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: 34205a11af

ℹ️ 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".

Comment thread packages/codex-runner/src/linked-worktree-writes.ts Outdated
@itsHabib

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: ba053967f3

ℹ️ 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".

Copilot AI 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.

🔵 Needs a closer look

A new failure mode from linked-worktree detection can currently surface as a generic “Codex construction failed” message, which is likely to be confusing and should be made more specific.

Review details

Files not reviewed (1)

  • pnpm-lock.yaml: Generated file

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

packages/codex-runner/src/local-runner.ts:160

  • linkedWorktreeWriteDirectories() can throw (e.g., malformed .git pointer), but because it’s called inside buildThreadOptions() and that’s executed within the try that wraps Codex construction, the user-facing error becomes a generic "Codex construction failed" with the real cause only in .cause. Consider catching and rethrowing with a more specific message so failures are diagnosable without inspecting nested causes.
function buildThreadOptions(
  input: AgentRunInput,
): NonNullable<Parameters<Codex["startThread"]>[0]> {
  return {
    additionalDirectories: linkedWorktreeWriteDirectories(input.cwd),
  • Files reviewed: 21/22 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@itsHabib

Copy link
Copy Markdown
Owner Author

@claude review

@itsHabib

Copy link
Copy Markdown
Owner Author

@cursor review

@cursor

cursor Bot commented Aug 27, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_d666e9b3-1a19-487c-a3dc-70f8a9561f02)

@claude

claude Bot commented Aug 27, 2026

Copy link
Copy Markdown

Claude finished @itsHabib's task in 2m 53s —— View job


Claude's Review

  • Gather context and understand the PR
  • Read key changed files
  • Review auth flow changes (codex-auth.ts, viability.ts, import.ts)
  • Review linked worktree write logic (linked-worktree-writes.ts)
  • Review local runner changes (local-runner.ts, login-status.ts)
  • Review test coverage
  • Post comprehensive review

Summary

This is a well-structured PR with correct security decisions throughout. The iterative review process was effective — the stale auth.json trust issue (fixed in 34205a1) and reftable support (fixed in ba05396) were real bugs; the final commit state is solid. My review covers the full diff at ba05396.

Auth flow: correct

codex-auth.ts / login-status.ts

The final design is correct: hasCodexAccountAuth delegates entirely to codexLoginStatus, which runs the bundled codex login status subprocess as the authoritative check. File-backed and keyring-backed profiles both go through this single path. No more auth.json existence short-circuit means a stale file from an earlier session can't bypass the actual credential store.

resolveBundledCodexExecutable is the cleanest way to solve the PATH shim problem. The resolution chain (@ship/codex-runner@openai/codex-sdk@openai/codex → platform package) mirrors the SDK's own install-time layout. The codex-package.json sentinel and the validExecutable absolute-path + executable-bit guard are belt-and-suspenders checks that prevent resolution of arbitrary or partially-installed paths.

One note: codexLoginStatus calls spawnSync, which blocks the Node.js event loop for up to 5 seconds. This is acceptable here — it's called only at viability check / import time, not during a run, and the memoization in createViabilityDeps (line 129–132) ensures it runs at most once per preflight. Worth keeping in mind if the viability deps ever get held across async boundaries.

viability.ts — memoization

The codexAccountAuth ??= hasCodexAccountAuth(...) pattern on line 130 is correct and important. Without it, every codex member in a long fallback chain would spawn a fresh subprocess. The memoization is per-createViabilityDeps instance, which is fine as long as instances are not reused across multiple import/preflight calls that could see different auth state — consistent with current usage.

import.ts — probe gating

collectFallbackEnvWarnings (line 569) gates the codexLoginStatus probe correctly: it only fires when keyMissing !== undefined for a codex entry (i.e., no API key) and codexAccountAuth hasn't been probed yet. The import.test.ts assertion at line 777 (expect(codexLoginStatus).not.toHaveBeenCalled()) closes this.

One style observation: missingCredentialEnv is called twice per entry — first without codexAccountAuth to decide whether to probe, then with it to get the final verdict. The logic is correct but slightly redundant. A small refactor would be to check hasValue(env['CODEX_API_KEY']) || hasValue(env['OPENAI_API_KEY']) directly to gate the probe, avoiding the double call. Not a bug.

Linked worktree sandbox: tight

linked-worktree-writes.ts

The path validation is thorough:

  • isStrictDescendant rejects "", "..", ..${sep}*, and absolute paths — no path traversal possible.
  • realpathSync resolves symlinks before all comparisons, so a symlink inside worktrees/ pointing outside cannot fool the containment check.
  • The two-layer check (isStrictDescendant(worktreesDir, gitDir) && dirname(gitDir) === worktreesDir) is belt-and-suspenders: the first bounds the admin dir to anywhere under worktrees/, the second requires it to be a direct child (not a nested grandchild). Together they prevent a compromised or crafted .git pointer from widening access beyond one named worktree's admin dir.
  • requireRefStores correctly accepts refs OR reftable OR both, and throws if neither exists — the reftable fix is correct.
  • logs is optional via optionalDirectory — the no-reflog fix is correct.

Lines 55–57 make two separate statSync calls on the same path. This is a TOCTOU-safe pattern given that the Codex sandbox operates on the resulting directory list, not the original marker path, but it could be simplified with a single stat capture. Not a correctness issue.

local-runner.ts: correct

readApiKey() on line 77 trims and treats whitespace-only values as absent. buildCodexOptions only sets apiKey when non-undefined. The Copilot finding from the first review cycle is fully addressed.

The acknowledged suppressed P2 (linkedWorktreeWriteDirectories throwing inside buildThreadOptions, wrapped as generic "Codex construction failed"): the cause IS preserved in the { cause: err } chain (line 266), so it's inspectable via .cause. The PR's rationale — correct invariants, malformed layouts still rejected, pure diagnosability gap — is sound for a deferred judgment.

Test coverage: comprehensive

All edge cases identified across four review cycles are covered:

  • Auth: file-backed ✓, keyring-backed ✓, stale file + active store failure → rejected ✓, no auth ✓
  • API key: present ✓, whitespace-only → no apiKey property on Codex options ✓, OPENAI_API_KEY fallback ✓
  • SDK binary: darwin arm64 ✓, win32 x64 (codex.exe) ✓, unsupported platform ✓, missing optional dep ✓
  • Import probe: skipped when CODEX_API_KEY is set ✓
  • Linked worktree: files-ref ✓, reftable ✓, no-reflog ✓, separate-git-dir → no expansion ✓, outside worktrees dir → throws ✓, malformed pointer → throws ✓
  • SHIP_CODEX_CLI relative path → rejected without spawning ✓

The Object.hasOwn(options, "apiKey") assertion pattern (instead of expect.anything()) correctly proves the property is truly absent, not just set to undefined. The change from the first review cycle is meaningful.

Nothing blocking

No correctness bugs, no security gaps in the final diff. The suppressed P2 is correctly characterized in the PR description and is a reasonable deferral given the two-fix-round ceiling.

@github-actions

Copy link
Copy Markdown

Reviewer: claude
Reviewed commit: ba053967f3e35da3ecac13e85bdd433a35d09c72

@itsHabib
itsHabib merged commit f5376fb into main Aug 27, 2026
7 checks passed
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.

2 participants