Skip to content

fix(codex/oauth): resolve cache & credential paths under the real home on macOS (split 2 of #27) - #33

Open
kdegeek wants to merge 2 commits into
MarlBurroW:mainfrom
kdegeek:pr/codex-oauth-home-paths
Open

fix(codex/oauth): resolve cache & credential paths under the real home on macOS (split 2 of #27)#33
kdegeek wants to merge 2 commits into
MarlBurroW:mainfrom
kdegeek:pr/codex-oauth-home-paths

Conversation

@kdegeek

@kdegeek kdegeek commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Salvaged from #27 as a small standalone patch against current main, per @MarlBurroW's split suggestion. Blocker 3 (the getRealHome boot-crash) is already fixed on main, so this is purely the path-resolution improvement the review called out.

The bug: on macOS, getRealHome() returns /home/$USER (because USER is set and there's no snap path to strip) while the real home is /Users/$USER. A single REAL_HOME-derived path therefore misses the Codex CLI files entirely. The fix searches the plain env HOME first, then the snap-adjusted REAL_HOME:

  • openai-codex.tsmodels_cache.json is read from a candidate list, extracted as the pure, tested modelsCacheCandidates().
  • _codex-auth.ts~/.codex/auth.json searched under env HOME then REAL_HOME.
  • _anthropic-oauth-auth.ts — the three Claude credential filenames searched under env HOME then REAL_HOME.

Every home value is run through normalizeAbsoluteHome before use, so the builders never emit a relative candidate. When env HOME and REAL_HOME coincide (the common Linux case), the candidate lists collapse to the original single set — behavior there is unchanged.

Validation

  • bun run typecheck — PASS
  • bun run test — PASS (added modelsCacheCandidates unit tests: macOS ordering, dedup, relative-home rejection)
  • bun run build — PASS
  • git diff --check — PASS
  • CodeRabbit review — the two normalizeAbsoluteHome-consistency notes it raised are addressed in this branch.

🤖 Generated with Claude Code

…e (macOS)

Salvaged from PR #27 as a small standalone patch against current main (blocker 3,
the getRealHome boot-crash, is already fixed on main).

On macOS getRealHome() returns /home/$USER (USER is set, no snap match) while the
real home is /Users/$USER, so a single REAL_HOME-derived path misses the Codex CLI
files entirely. Search the plain env HOME first, then the snap-adjusted REAL_HOME:

- openai-codex.ts: models_cache.json is now read from a candidate list
  (extracted as the pure, tested modelsCacheCandidates()).
- _codex-auth.ts: ~/.codex/auth.json searched under env HOME then REAL_HOME.
- _anthropic-oauth-auth.ts: the three Claude credential filenames searched under
  env HOME then REAL_HOME.

When env HOME and REAL_HOME coincide (the common Linux case) the candidate lists
collapse to the original single set, so behavior there is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kdegeek
kdegeek requested a review from MarlBurroW as a code owner July 6, 2026 19:50
Copilot AI review requested due to automatic review settings July 6, 2026 19:50

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.

Pull request overview

This PR improves macOS (and nonstandard home) path resolution for Codex and Claude CLI cache/credential discovery by searching candidate paths under the plain env HOME first, then falling back to the snap-adjusted REAL_HOME, while ensuring only absolute home paths are used.

Changes:

  • Add modelsCacheCandidates() and use an ordered candidate list to read Codex models_cache.json from HOME then REAL_HOME.
  • Update Codex CLI auth and Claude Code credential discovery to search under HOME first, then REAL_HOME, with absolute-home validation.
  • Add unit tests covering modelsCacheCandidates() ordering, deduplication, and relative-home rejection.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/server/llm/llm/openai-codex.ts Reads Codex model cache from an ordered HOMEREAL_HOME candidate list with absolute-home normalization.
src/server/llm/llm/openai-codex.test.ts Adds unit tests for candidate ordering/dedup and rejecting relative homes.
src/server/llm/llm/_codex-auth.ts Searches for ~/.codex/auth.json under env HOME first, then REAL_HOME, with absolute-home validation.
src/server/llm/llm/_anthropic-oauth-auth.ts Searches for Claude credential files under env HOME first, then REAL_HOME, with absolute-home validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/server/llm/llm/openai-codex.ts Outdated
Comment thread src/server/llm/llm/_codex-auth.ts Outdated
Comment thread src/server/llm/llm/_anthropic-oauth-auth.ts Outdated
…ew on #33)

Copilot flagged normalizeAbsoluteHome being duplicated across the three
credential/cache path resolvers. Move it — plus the identical getRealHome and
the resolved REAL_HOME const — into a shared _home-paths.ts (underscore-prefixed,
so it's not mistaken for a provider) and import from it in openai-codex.ts,
_codex-auth.ts, and _anthropic-oauth-auth.ts. No behavior change; removes the
pre-existing getRealHome triplication too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kdegeek

kdegeek commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the Copilot note about normalizeAbsoluteHome being duplicated: extracted it (plus the identical getRealHome and the resolved REAL_HOME) into a shared src/server/llm/llm/_home-paths.ts and imported it from the three modules. Underscore-prefixed so it isn't picked up as a provider; no behavior change, and it removes the pre-existing getRealHome triplication too.

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