fix: create scratch CODEX_HOME before login#120
Conversation
The isolated login flow correctly avoids exposing the real active auth.json to upstream codex login, but current Codex rejects a CODEX_HOME override when the target directory does not already exist. Create the temporary login home before spawning codex login, keep the existing cleanup behavior, and add a strict integration fake that fails unless the scratch CODEX_HOME exists before launch. Validation: zig build run -- list; zig build test --summary all
Greptile SummaryThis PR fixes a runtime failure where upstream
Confidence Score: 5/5Safe to merge — the change is a targeted one-liner that creates the scratch directory before the child process starts, with no regressions to the surrounding cleanup logic. The defer deleteTree is registered on the line immediately before the new try ensurePrivateDir, so the cleanup is already on the stack if directory creation or permission-hardening fails. The new integration test faithfully models the stricter real-world behavior and the assertions cover isolation, naming, and post-login cleanup. No existing logic is altered. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant H as handleLogin
participant R as registry
participant C as codex login
H->>R: loadRegistry / syncActiveAccount
H->>R: ensureAccountsDir
H->>H: loginScratchCodexHomeAlloc
H->>H: defer deleteTree registered
H->>R: ensurePrivateDir (NEW)
note over H,R: scratch dir now exists on disk
H->>C: runCodexLogin
C-->>H: writes auth.json into scratch dir
H->>R: copyManagedFile to real CODEX_HOME
H->>R: upsertAccount / saveRegistry
H->>H: defer fires - deleteTree scratch dir
Reviews (3): Last reviewed commit: "style: remove login scratch comment" | Re-trigger Greptile |
@loongphy/codex-auth-darwin-arm64
@loongphy/codex-auth-darwin-x64
@loongphy/codex-auth-linux-arm64
@loongphy/codex-auth-linux-x64
@loongphy/codex-auth-win32-arm64
@loongphy/codex-auth-win32-x64
@loongphy/codex-auth
commit: |
|
Addressed the cleanup-order review point in 23f8ca7. The scratch login CODEX_HOME cleanup is now registered before the ensurePrivateDir call, so if directory creation succeeds but permission hardening fails, the scratch directory is still removed. Validation rerun locally with isolated HOME/Zig caches:
|
|
LGTM! It seems the GPT-5.5 downgrade caused it to miss some test cases, and the PR got auto-merged before I could catch it. |
Summary
This keeps the isolated-login behavior intact, but creates the temporary login
CODEX_HOMEdirectory before spawning upstreamcodex login.The isolated-login fix is the right direction for the account-revocation issue: it prevents upstream
codex loginfrom seeing the real activeauth.jsonwhile a new account is being added. While testing that flow locally, I hit a follow-up failure from current Codex:What happened
codex-auth logincomputed an isolated scratch home underCODEX_HOME/accounts/login-<timestamp>and passed it to upstreamcodex login, but the scratch directory was not created before the child process started. Current Codex validates thatCODEX_HOMEexists, so login failed before the isolated auth file could be created.Why tests missed it
The existing fake
codexused by the integration tests created the targetCODEX_HOMEitself withmkdir -p, so it tolerated a missing scratch directory. Real Codex is stricter and fails when the override path does not already exist.Fix
codex login.CODEX_HOMEexists before launch, so this behavior is covered by tests.Validation
zig build run -- listzig build test --summary all(383/383 tests passed)I also verified this manually with the local
codex-authbinary by restoring previously invalid accounts while checking that the previously active account stayed valid after login.