You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Codex authentication gets invalidated when using WSL Ubuntu #13697
token_invalidated is the exact failure Orca already has a guard for, and in the WSL configuration the two lanes that guard is meant to serialize compute different lock keys for the same credential home, so they don't serialize. Verified on upstream/main at 20848169e0.
// Why: Codex OAuth uses rotating refresh tokens stored in each home's auth.json.// Two Orca-spawned codex processes refreshing the same home concurrently can// consume one rotation twice and permanently invalidate the stored credential,// so Orca's own spawns (quota probes, commit-message runs) serialize per home.// User terminal panes are intentionally not serialized here.
"consume one rotation twice and permanently invalidate the stored credential" is your 401 Unauthorized / token_invalidated followed by forced re-auth. The serialization exists precisely to prevent it; the question is whether it engages under WSL.
Why it doesn't engage under WSL
There are two key derivations, and they disagree.
Probe lane — codex-fetcher.ts:1270 calls resolveCodexHomeProcessLockKey(options?.codexHomePath), which is (codex-home-process-lock.ts:13-16):
For a WSL probe, codexHomePath is the \\wsl$\<distro>\home\<user>\.codex UNC path — buildWslCodexCommand (codex-fetcher.ts:164-193) only takes the WSL branch when parseWslUncPath(codexHomePath) succeeds. So the probe's key normalizes to roughly //wsl$/<distro>/home/<user>/.codex.
Spawn lane — resolveCodexHomeProcessLockKeyForSpawnEnv (:18-37), used by commit-message generation at commit-message-text-generation.ts:493 and :881. Its WSL branch:
if(wslDistro){constcodexHome=env?.CODEX_HOME!==process.env.CODEX_HOME ? (env?.CODEX_HOME??null) : null// Why: WSL spawns carry a Linux CODEX_HOME; key it through the same UNC// normalization the probe's \\wsl$ home path uses so both lanes collide.// Without an explicit home the distro default is unknowable from the host;// a sentinel still serializes same-distro default spawns with each other.returnnormalizeRuntimePathForComparison(`//wsl$/${wslDistro}${codexHome??'/.orca-default-codex-home'}`)}
The stated goal is "so both lanes collide". They collide only when the spawn env carries an explicitCODEX_HOME. Without one — the default WSL setup, where Codex uses the distro user's ~/.codex — the key falls back to the sentinel:
Lane
Key under default WSL
probe (resolveCodexHomeProcessLockKey)
//wsl$/<distro>/home/<user>/.codex
spawn (…ForSpawnEnv, no explicit CODEX_HOME)
//wsl$/<distro>/.orca-default-codex-home
Two different strings, so withCodexHomeProcessLock takes two different entries in the lockTails map and the two lanes run concurrently against oneauth.json. The comment is candid that this is best-effort — "the distro default is unknowable from the host; a sentinel still serializes same-distro default spawns with each other" — i.e. sentinel-vs-sentinel only. Sentinel-vs-probe is exactly the pair that must not overlap, and it's the pair the sentinel cannot match.
On native Windows the same two derivations both land on join(homedir(), '.codex'), they collide, the lock holds — which matches your observation that Windows-direct is unaffected while WSL is not.
Why re-authenticating in the CLI doesn't stick
The last line of that header comment — // User terminal panes are intentionally not serialized here. — means your codex login in a pane is outside the lock by design. So after re-auth, the next probe + commit-message overlap can consume the fresh rotation twice again. That fits "I have to authenticate Codex again through the CLI" recurring rather than resolving.
Discriminating check
If this is the mechanism, the invalidation should correlate with two Orca-initiated codex touches close together, not with the usage fetch alone. Two ways to separate it:
Set an explicit CODEX_HOME for the WSL environment (matching the distro user's real ~/.codex). That makes env?.CODEX_HOME non-null, so the spawn lane keys on the real path and both lanes collide again. If invalidation stops, the key mismatch is confirmed.
Disable commit-message generation (or avoid committing) for a session while leaving usage polling on. If the token survives, the second lane is required to reproduce — consistent with a rotation race rather than a bad token being sent.
Worth noting which, because the fix differs: (1) points at the sentinel in …ForSpawnEnv, (2) would point somewhere else entirely.
One thing I could not check from outside: whether your setup actually exercises the commit-message lane, or whether some third Orca-spawned codex process is the second participant. The key-mismatch mechanism holds for any two lanes where one keys by sentinel and the other by real path, but naming the specific second process would need a log.
Happy to send a PR for the sentinel if maintainers agree that's the right level — the honest fix is probably to resolve the distro's real default home once (it's knowable from the host via wsl.exe -d <distro> -- sh -c 'echo $HOME', which buildWslCodexCommand already demonstrates the mechanics for) rather than to key on a placeholder that can never equal the probe's path.
Thanks for reporting this! This looks like it comes from Orca's older WSL integration, which reaches into the distro from Windows through \\wsl.localhost paths and wsl.exe. We've since shipped a new WSL bridge, WSL hosts, where Orca's server runs inside the distro itself, so this part of the old path isn't involved.
Could you give it a try?
Open Settings → Experimental and turn on WSL hosts.
Click Add a project → Add remote host → Add WSL distro and pick your distro.
Open your project on that WSL host and try the same steps again.
If it still happens there, please let us know here with your Orca version. That helps us a lot.
Activity
manuaudio commentedon Aug 11, 2026
token_invalidatedis the exact failure Orca already has a guard for, and in the WSL configuration the two lanes that guard is meant to serialize compute different lock keys for the same credential home, so they don't serialize. Verified onupstream/mainat20848169e0.The invariant, stated in-tree
src/main/codex-cli/codex-home-process-lock.ts:5-9:"consume one rotation twice and permanently invalidate the stored credential" is your
401 Unauthorized / token_invalidatedfollowed by forced re-auth. The serialization exists precisely to prevent it; the question is whether it engages under WSL.Why it doesn't engage under WSL
There are two key derivations, and they disagree.
Probe lane —
codex-fetcher.ts:1270callsresolveCodexHomeProcessLockKey(options?.codexHomePath), which is (codex-home-process-lock.ts:13-16):For a WSL probe,
codexHomePathis the\\wsl$\<distro>\home\<user>\.codexUNC path —buildWslCodexCommand(codex-fetcher.ts:164-193) only takes the WSL branch whenparseWslUncPath(codexHomePath)succeeds. So the probe's key normalizes to roughly//wsl$/<distro>/home/<user>/.codex.Spawn lane —
resolveCodexHomeProcessLockKeyForSpawnEnv(:18-37), used by commit-message generation atcommit-message-text-generation.ts:493and:881. Its WSL branch:The stated goal is "so both lanes collide". They collide only when the spawn env carries an explicit
CODEX_HOME. Without one — the default WSL setup, where Codex uses the distro user's~/.codex— the key falls back to the sentinel:resolveCodexHomeProcessLockKey)//wsl$/<distro>/home/<user>/.codex…ForSpawnEnv, no explicitCODEX_HOME)//wsl$/<distro>/.orca-default-codex-homeTwo different strings, so
withCodexHomeProcessLocktakes two different entries in thelockTailsmap and the two lanes run concurrently against oneauth.json. The comment is candid that this is best-effort — "the distro default is unknowable from the host; a sentinel still serializes same-distro default spawns with each other" — i.e. sentinel-vs-sentinel only. Sentinel-vs-probe is exactly the pair that must not overlap, and it's the pair the sentinel cannot match.On native Windows the same two derivations both land on
join(homedir(), '.codex'), they collide, the lock holds — which matches your observation that Windows-direct is unaffected while WSL is not.Why re-authenticating in the CLI doesn't stick
The last line of that header comment —
// User terminal panes are intentionally not serialized here.— means yourcodex loginin a pane is outside the lock by design. So after re-auth, the next probe + commit-message overlap can consume the fresh rotation twice again. That fits "I have to authenticate Codex again through the CLI" recurring rather than resolving.Discriminating check
If this is the mechanism, the invalidation should correlate with two Orca-initiated codex touches close together, not with the usage fetch alone. Two ways to separate it:
CODEX_HOMEfor the WSL environment (matching the distro user's real~/.codex). That makesenv?.CODEX_HOMEnon-null, so the spawn lane keys on the real path and both lanes collide again. If invalidation stops, the key mismatch is confirmed.Worth noting which, because the fix differs: (1) points at the sentinel in
…ForSpawnEnv, (2) would point somewhere else entirely.One thing I could not check from outside: whether your setup actually exercises the commit-message lane, or whether some third Orca-spawned codex process is the second participant. The key-mismatch mechanism holds for any two lanes where one keys by sentinel and the other by real path, but naming the specific second process would need a log.
Happy to send a PR for the sentinel if maintainers agree that's the right level — the honest fix is probably to resolve the distro's real default home once (it's knowable from the host via
wsl.exe -d <distro> -- sh -c 'echo $HOME', whichbuildWslCodexCommandalready demonstrates the mechanics for) rather than to key on a placeholder that can never equal the probe's path.nwparker commentedon Nov 17, 2026
Thanks for reporting this! This looks like it comes from Orca's older WSL integration, which reaches into the distro from Windows through
\\wsl.localhostpaths andwsl.exe. We've since shipped a new WSL bridge, WSL hosts, where Orca's server runs inside the distro itself, so this part of the old path isn't involved.Could you give it a try?
If it still happens there, please let us know here with your Orca version. That helps us a lot.