fix(codex/oauth): resolve cache & credential paths under the real home on macOS (split 2 of #27) - #33
fix(codex/oauth): resolve cache & credential paths under the real home on macOS (split 2 of #27)#33kdegeek wants to merge 2 commits into
Conversation
…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>
There was a problem hiding this comment.
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 Codexmodels_cache.jsonfromHOMEthenREAL_HOME. - Update Codex CLI auth and Claude Code credential discovery to search under
HOMEfirst, thenREAL_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 HOME→REAL_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.
…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>
|
Addressed the Copilot note about |
Summary
Salvaged from #27 as a small standalone patch against current
main, per @MarlBurroW's split suggestion. Blocker 3 (thegetRealHomeboot-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(becauseUSERis set and there's no snap path to strip) while the real home is/Users/$USER. A singleREAL_HOME-derived path therefore misses the Codex CLI files entirely. The fix searches the plain envHOMEfirst, then the snap-adjustedREAL_HOME:openai-codex.ts—models_cache.jsonis read from a candidate list, extracted as the pure, testedmodelsCacheCandidates()._codex-auth.ts—~/.codex/auth.jsonsearched 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
normalizeAbsoluteHomebefore 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— PASSbun run test— PASS (addedmodelsCacheCandidatesunit tests: macOS ordering, dedup, relative-home rejection)bun run build— PASSgit diff --check— PASSnormalizeAbsoluteHome-consistency notes it raised are addressed in this branch.🤖 Generated with Claude Code