Skip to content

[Bug] Codex authentication gets invalidated when using WSL Ubuntu #13697

Open

Description

@orca-discord-issues

RIchard Manzoli RIchard Manzoli via Discord

Codex authentication appears to be invalidated specifically when Orca is configured to use WSL Ubuntu.

The issue does NOT occur when Orca uses Windows directly.

When using WSL Ubuntu, Orca attempts to fetch Codex usage/rate limits and receives:

401 Unauthorized - token_invalidated

After that, I have to authenticate Codex again through the CLI.

Switching Orca back to Windows avoids the issue.

Steps to reproduce

  1. Authenticate Codex CLI normally.
  2. Configure Orca to use WSL Ubuntu.
  3. Open/restart Orca.
  4. Orca attempts to fetch Codex usage/rate limits.
  5. The request to /backend-api/wham/usage returns 401 Unauthorized.
  6. Orca reports token_invalidated.
  7. Re-authentication is required.

Expected behavior

Orca should correctly reuse the Codex authentication available inside WSL and should not invalidate the session.

Actual behavior

Codex authentication/rate-limit fetching fails when Orca uses WSL Ubuntu.

The same setup works correctly when Orca is configured to use Windows directly.

Environment

  • Host OS: Windows
  • Orca execution mode with issue: WSL Ubuntu
  • Orca execution mode without issue: Windows
  • Agent: Codex
  • Error: 401 Unauthorized / token_invalidated

Activity

  1. added
    bug
    on Aug 10, 2026
  2. manuaudio commented on Aug 11, 2026

    @manuaudio
    Contributor

    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.

    The invariant, stated in-tree

    src/main/codex-cli/codex-home-process-lock.ts:5-9:

    // 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):

    const home = codexHomePath ?? process.env.CODEX_HOME ?? join(homedir(), '.codex')
    return normalizeRuntimePathForComparison(home)

    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) {
      const codexHome = 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.
      return normalizeRuntimePathForComparison(
        `//wsl$/${wslDistro}${codexHome ?? '/.orca-default-codex-home'}`
      )
    }

    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:

    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 one auth.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:

    1. 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.
    2. 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.

  3. nwparker commented on Nov 17, 2026

    @nwparker
    Contributor

    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?

    1. Open Settings → Experimental and turn on WSL hosts.
    2. Click Add a project → Add remote host → Add WSL distro and pick your distro.
    3. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions