Skip to content

MCP OAuth: long-lived clients reuse rotated refresh tokens; refresh coordination prevents reproduction #46028

Open

Description

@matCzelusniak

What version of Codex CLI is running?

0.154.0-alpha.6.2

What subscription do you have?

PRO

Which model were you using?

Not applicable - reproduced via MCP calls without model turns.

What platform is your computer?

Windows NT 10.0.26200.0 x64

What terminal emulator and version are you using (if applicable)?

Originally observed in the Codex desktop app. Reproduced using Node.js spawning codex app-server over stdio; no terminal emulator involved.

Codex doctor report

{
  "schemaVersion": 1,
  "generatedAt": "1789592535s since unix epoch",
  "overallStatus": "fail",
  "codexVersion": "0.154.0-alpha.6.2",
  "checks": {
    "app_server.status": {
      "id": "app_server.status",
      "category": "app-server",
      "status": "ok",
      "summary": "background server is not running",
      "details": {
        "control socket": "<USER_HOME>\\.codex\\app-server-control\\app-server-control.sock",
        "daemon state dir": "<USER_HOME>\\.codex\\app-server-daemon",
        "mode": "ephemeral",
        "pid file": "<USER_HOME>\\.codex\\app-server-daemon\\app-server.pid (missing)",
        "settings": "<USER_HOME>\\.codex\\app-server-daemon\\settings.json (missing)",
        "status": "not running",
        "update-loop pid file": "<USER_HOME>\\.codex\\app-server-daemon\\app-server-updater.pid (missing)"
      },
      "remediation": null,
      "durationMs": 0
    },
    "auth.credentials": {
      "id": "auth.credentials",
      "category": "auth",
      "status": "ok",
      "summary": "auth is configured",
      "details": {
        "auth file": "<USER_HOME>\\.codex\\auth.json",
        "auth storage mode": "File",
        "stored API key": "false",
        "stored ChatGPT tokens": "true",
        "stored agent identity": "false",
        "stored auth mode": "chatgpt"
      },
      "remediation": null,
      "durationMs": 0
    },
    "config.load": {
      "id": "config.load",
      "category": "config",
      "status": "ok",
      "summary": "config loaded",
      "details": {
        "CODEX_HOME": "<USER_HOME>\\.codex",
        "active thread overrides": "not inspected",
        "config.toml": "<USER_HOME>\\.codex\\config.toml",
        "config.toml parse": "ok",
        "configuration load ms": "8",
        "configuration scope": "invocation config, including cloud-managed policy",
        "cwd": "<USER_HOME>\\Desktop\\<PROJECT>",
        "enabled feature flags": "<redacted>",
        "feature flag overrides": "mcp_oauth_refresh_coordination=true",
        "feature flags enabled": "50",
        "log dir": "<USER_HOME>\\.codex\\log",
        "mcp servers": "3",
        "model": "gpt-6-astra",
        "model provider": "openai",
        "sqlite home": "<USER_HOME>\\.codex"
      },
      "remediation": null,
      "durationMs": 0
    },
    "desktop.app.version": {
      "id": "desktop.app.version",
      "category": "desktop",
      "status": "ok",
      "summary": "the desktop application is installed",
      "details": {
        "log directory": "$HOME\\AppData\\Local\\Codex/Logs",
        "running": "true",
        "version": "26.908.4834.0"
      },
      "remediation": null,
      "durationMs": 0
    },
    "desktop.app_server.handshake": {
      "id": "desktop.app_server.handshake",
      "category": "desktop",
      "status": "ok",
      "summary": "no desktop app-server handshake was recorded",
      "details": {},
      "remediation": null,
      "durationMs": 0
    },
    "desktop.security.enforcement": {
      "id": "desktop.security.enforcement",
      "category": "desktop",
      "status": "ok",
      "summary": "no locally visible recent Codex security enforcement was found",
      "details": {},
      "remediation": null,
      "durationMs": 0
    },
    "git.environment": {
      "id": "git.environment",
      "category": "git",
      "status": "ok",
      "summary": "git executable found; execution not verified",
      "details": {
        ".git entry": "directory",
        "PATH git #1": "C:\\Program Files\\Git\\cmd\\git.exe",
        "PATH git #2": "<USER_HOME>\\.cache\\codex-runtimes\\codex-primary-runtime\\dependencies\\native\\git\\cmd\\git.exe",
        "PATH git entries": "2",
        "git execution": "not inspected (PATH helpers are not executed)",
        "repo detected": "true",
        "repo root": "<USER_HOME>\\Desktop\\<PROJECT>",
        "selected git": "C:\\Program Files\\Git\\cmd\\git.exe"
      },
      "remediation": null,
      "durationMs": 15
    },
    "git.worktree.dev_drive": {
      "id": "git.worktree.dev_drive",
      "category": "git",
      "status": "warning",
      "summary": "this worktree is not on a Windows Dev Drive; moving it to a trusted Dev Drive can significantly improve repository and filesystem performance",
      "details": {},
      "remediation": "create a trusted Windows Dev Drive for source repositories: https://learn.microsoft.com/en-us/<redacted>",
      "durationMs": 0
    },
    "installation": {
      "id": "installation",
      "category": "install",
      "status": "ok",
      "summary": "installation looks consistent",
      "details": {
        "PATH codex #1": "<USER_HOME>\\AppData\\Local\\OpenAI\\Codex\\bin\\bffc5354119c8421\\codex.exe",
        "current executable": "<USER_HOME>\\AppData\\Local\\OpenAI\\Codex\\bin\\bffc5354119c8421\\codex.exe",
        "install context": "other",
        "managed by Vite+": "false",
        "managed by bun": "false",
        "managed by npm": "false",
        "managed by pnpm": "false",
        "managed package root": "not set"
      },
      "remediation": null,
      "durationMs": 14
    },
    "mcp.config": {
      "id": "mcp.config",
      "category": "mcp",
      "status": "ok",
      "summary": "MCP configuration is locally consistent",
      "details": {
        "configured servers": "3",
        "disabled servers": "1",
        "stdio servers": "2",
        "streamable_http servers": "1"
      },
      "remediation": null,
      "durationMs": 275
    },
    "network.env": {
      "id": "network.env",
      "category": "network",
      "status": "ok",
      "summary": "network-related environment looks readable",
      "details": {
        "managed proxy": "not configured",
        "proxy env vars": "none",
        "respect system proxy": "disabled"
      },
      "remediation": null,
      "durationMs": 0
    },
    "network.provider_reachability": {
      "id": "network.provider_reachability",
      "category": "reachability",
      "status": "ok",
      "summary": "active provider endpoints are reachable over HTTP",
      "details": {
        "ChatGPT inference URL": "https://chatgpt.com/backend-api/<redacted> reachable (HTTP 405)",
        "desktop assets CDN": "https://persistent.oaistatic.com/codex-app-prod/<redacted> reachable (HTTP 200)",
        "reachability mode": "ChatGPT auth"
      },
      "remediation": null,
      "durationMs": 124
    },
    "network.websocket_reachability": {
      "id": "network.websocket_reachability",
      "category": "websocket",
      "status": "ok",
      "summary": "Responses WebSocket handshake succeeded",
      "details": {
        "DNS": "2 IPv4, 0 IPv6, first IPv4",
        "auth mode": "chatgpt",
        "connect timeout": "15000 ms",
        "endpoint": "wss://chatgpt.com/backend-api/<redacted>",
        "handshake result": "HTTP 101 Switching Protocols",
        "model provider": "openai",
        "provider name": "OpenAI",
        "proxy env vars": "none",
        "reasoning header": "false",
        "server model present": "false",
        "supports websockets": "true",
        "wire API": "responses"
      },
      "remediation": null,
      "durationMs": 955
    },
    "runtime.provenance": {
      "id": "runtime.provenance",
      "category": "runtime",
      "status": "ok",
      "summary": "running local build on windows-x86_64",
      "details": {
        "commit": "unknown",
        "current executable": "<USER_HOME>\\AppData\\Local\\OpenAI\\Codex\\bin\\bffc5354119c8421\\codex.exe",
        "install method": "other",
        "platform": "windows-x86_64",
        "version": "0.154.0-alpha.6.2"
      },
      "remediation": null,
      "durationMs": 0
    },
    "runtime.search": {
      "id": "runtime.search",
      "category": "search",
      "status": "ok",
      "summary": "search command found (system); execution not verified",
      "details": {
        "search command": "rg.exe",
        "search command path": "<USER_HOME>\\AppData\\Local\\OpenAI\\Codex\\bin\\116cfc4fd47f015a\\rg.exe",
        "search command readiness": "found; execution not verified",
        "search provider": "system"
      },
      "remediation": null,
      "durationMs": 1
    },
    "sandbox.helpers": {
      "id": "sandbox.helpers",
      "category": "sandbox",
      "status": "ok",
      "summary": "sandbox configuration is readable",
      "details": {
        "approval policy": "OnRequest",
        "codex-linux-sandbox helper": "none",
        "denied-read glob rules": "0",
        "denied-read restrictions": "false",
        "denied-read rules": "0",
        "execve wrapper helper": "none",
        "filesystem sandbox": "restricted",
        "glob scan max depth": "unbounded",
        "managed filesystem source": "none",
        "network sandbox": "restricted",
        "sandbox backend": "elevated",
        "sandbox provisioning": "complete"
      },
      "remediation": null,
      "durationMs": 2
    },
    "security.endpoint": {
      "id": "security.endpoint",
      "category": "security",
      "status": "warning",
      "summary": "endpoint protection detected; Codex exclusions are unverified",
      "details": {
        "Codex exclusions": "not verified",
        "endpoint products": "Microsoft Defender",
        "exclusion targets": "signed Codex app; codex.exe; codex-windows-sandbox-setup.exe; codex-command-runner.exe; codex-code-mode-host.exe"
      },
      "issues": [
        {
          "severity": "warning",
          "cause": "Microsoft Defender can interfere with Codex. Verify Codex exclusions.",
          "measured": "not verified",
          "expected": "Codex application and helper exclusions",
          "remedy": "Microsoft Defender: Add a certificate or executable-path exclusion for Codex and its helpers. If Attack Surface Reduction blocks Codex, add a rule exclusion. If Controlled Folder Access blocks Codex, allow the app.",
          "fields": [
            "Codex exclusions"
          ]
        }
      ],
      "remediation": "ask your security administrator to verify Codex exclusions and required helper allowances",
      "durationMs": 33
    },
    "state.paths": {
      "id": "state.paths",
      "category": "state",
      "status": "ok",
      "summary": "state paths and databases are inspectable",
      "details": {
        "CODEX_HOME": "<USER_HOME>\\.codex (dir)",
        "active rollout files": "176 files, 833549131 total bytes, 4736074 average bytes",
        "archived rollout files": "3 files, 2812397 total bytes, 937465 average bytes",
        "goals DB": "<USER_HOME>\\.codex\\goals_1.sqlite (file)",
        "goals DB <PROJECT>ty": "ok",
        "log DB": "<USER_HOME>\\.codex\\logs_2.sqlite (file)",
        "log DB <PROJECT>ty": "ok",
        "log dir": "<USER_HOME>\\.codex\\log (missing)",
        "memories DB": "<USER_HOME>\\.codex\\memories_1.sqlite (file)",
        "memories DB <PROJECT>ty": "ok",
        "queue DB": "<USER_HOME>\\.codex\\queue_1.sqlite (file)",
        "queue DB <PROJECT>ty": "ok",
        "sqlite home": "<USER_HOME>\\.codex (dir)",
        "state DB": "<USER_HOME>\\.codex\\state_5.sqlite (file)",
        "state DB <PROJECT>ty": "ok",
        "thread history DB": "<USER_HOME>\\.codex\\thread_history_1.sqlite (file)",
        "thread history DB <PROJECT>ty": "ok"
      },
      "remediation": null,
      "durationMs": 7913
    },
    "state.rollout_db_parity": {
      "id": "state.rollout_db_parity",
      "category": "threads",
      "status": "warning",
      "summary": "rollout files and state DB thread inventory differ",
      "details": {
        "default model provider": "openai",
        "rollout DB active files": "176",
        "rollout DB active rows": "175",
        "rollout DB archive mismatches": "0",
        "rollout DB archived files": "3",
        "rollout DB archived rows": "3",
        "rollout DB duplicate DB paths": "0",
        "rollout DB duplicate rollout thread id sample": "<REDACTED_THREAD_ID>",
        "rollout DB duplicate rollout thread ids": "1",
        "rollout DB malformed file names": "0",
        "rollout DB missing active rows": "1",
        "rollout DB missing active sample": "<USER_HOME>\\.codex\\sessions\\2026\\09\\07\\rollout-2026-09-07T20-53-11-<REDACTED_THREAD_ID>.jsonl",
        "rollout DB missing archived rows": "0",
        "rollout DB model providers": "openai=178",
        "rollout DB rows": "178",
        "rollout DB scan cap reached": "false",
        "rollout DB scan errors": "0",
        "rollout DB sources": "subagent:other=144, vscode=34",
        "rollout DB stale rows": "0"
      },
      "issues": [
        {
          "severity": "warning",
          "cause": "rollout files are missing from the state DB",
          "measured": "1 active, 0 archived",
          "expected": "every rollout file has a matching threads row",
          "remedy": null,
          "fields": []
        },
        {
          "severity": "warning",
          "cause": "duplicate thread inventory entries found",
          "measured": "1 duplicate rollout thread ids, 0 duplicate DB paths",
          "expected": "one rollout path and thread id per thread",
          "remedy": "Attach the doctor report to a bug report so support can inspect samples.",
          "fields": []
        }
      ],
      "remediation": null,
      "durationMs": 199
    },
    "system.disk": {
      "id": "system.disk",
      "category": "disk",
      "status": "ok",
      "summary": "sufficient free disk space (22.2 GiB)",
      "details": {
        "CODEX_HOME available": "22.2 GiB",
        "failure threshold": "1.0 GiB",
        "warning threshold": "5.0 GiB",
        "worktree available": "22.2 GiB"
      },
      "remediation": null,
      "durationMs": 0
    },
    "system.environment": {
      "id": "system.environment",
      "category": "system",
      "status": "ok",
      "summary": "OS language en-US",
      "details": {
        "EDITOR": "not set",
        "GH_PAGER": "set",
        "GIT_PAGER": "set",
        "LANG": "C.UTF-8",
        "LC_ALL": "C.UTF-8",
        "LC_CTYPE": "C.UTF-8",
        "PAGER": "set",
        "VISUAL": "not set",
        "os": "Windows 10.0.26200 (Windows 11 Core) [64-bit]",
        "os language": "en-US",
        "os type": "Windows",
        "os version": "10.0.26200"
      },
      "remediation": null,
      "durationMs": 0
    },
    "terminal.env": {
      "id": "terminal.env",
      "category": "terminal",
      "status": "fail",
      "summary": "TERM=dumb - colors and cursor control are disabled",
      "details": {
        "COLORTERM": "present",
        "NO_COLOR": "1",
        "TERM": "dumb",
        "color output": "disabled (NO_COLOR)",
        "console input code page": "437",
        "console output code page": "65001",
        "effective locale": "C.UTF-8",
        "stderr console mode": "unavailable",
        "stderr is terminal": "false",
        "stdin is terminal": "false",
        "stdout console mode": "unavailable",
        "stdout is terminal": "false",
        "terminal": "dumb",
        "terminal size": "120x30"
      },
      "issues": [
        {
          "severity": "fail",
          "cause": "TERM=dumb - colors and cursor control are disabled",
          "measured": "TERM=dumb",
          "expected": "TERM=xterm-256color or another real terminal type",
          "remedy": "set TERM to a real value, for example xterm-256color",
          "fields": [
            "TERM"
          ]
        }
      ],
      "remediation": null,
      "durationMs": 0
    },
    "terminal.title": {
      "id": "terminal.title",
      "category": "title",
      "status": "ok",
      "summary": "terminal title default",
      "details": {
        "terminal title activity": "true",
        "terminal title items": "activity, project-name",
        "terminal title project source": "git repo root",
        "terminal title project value": "<PROJECT>",
        "terminal title source": "default"
      },
      "remediation": null,
      "durationMs": 0
    },
    "updates.status": {
      "id": "updates.status",
      "category": "updates",
      "status": "ok",
      "summary": "update configuration is locally consistent",
      "details": {
        "check for update on startup": "true",
        "desktop application": "OpenAI.Codex",
        "desktop latest build": "26.908.9136.0",
        "desktop update status": "available",
        "latest version": "0.154.0",
        "latest version status": "current version is not older",
        "update action": "manual or unknown",
        "version cache": [
          "<USER_HOME>\\.codex\\version.json",
          "missing"
        ]
      },
      "remediation": null,
      "durationMs": 403
    }
  }
}

What issue are you seeing?

Codex loses access to an OAuth-authenticated MCP server because long-lived clients sharing the same OAuth grant can reuse an already-consumed refresh token.

Originally observed in the Codex desktop app on Windows. Independently reproduced using Codex 0.154.0-alpha.6.2 app-server processes with a localhost OAuth/MCP server and fake credentials, without running model turns.

Observed behavior:

  1. OAuth authorization succeeds.
  2. One client refreshes successfully and receives a new access token and refresh token.
  3. Another long-lived client submits the previous refresh token.
  4. The OAuth server detects reuse and revokes the token family.
  5. MCP requests fail with “Auth required”; subsequent refresh attempts return:
    invalid_grant: Refresh token revoked

In the production incident, the old refresh token was reused approximately 59 minutes after the successful rotation, outside the server’s 30-second retry grace period.

The local reproducer failed with refresh coordination disabled. With mcp_oauth_refresh_coordination enabled, a test involving 3 processes and 14 refreshes completed with zero stale-token reuses.

Users consequently need to reconnect their MCP integration despite having successfully authorized it earlier. Enabling the experimental flag is a local workaround, but ordinary users should not need to configure it manually.

What steps can reproduce the bug?

An isolated Node.js reproducer is attached. It uses a localhost OAuth/MCP server, fake credentials, an isolated CODEX_HOME, and ephemeral threads. It does not require an Omrela account or run model turns.

  1. Save the attached codex-mcp-oauth-reproducer.txt as verify-codex-mcp-oauth.mjs.

  2. Ensure Node.js and Codex 0.154.0-alpha.6.2 are available on PATH. Alternatively, set CODEX_BINARY to the Codex executable path.

  3. Run with refresh coordination explicitly disabled:

    node verify-codex-mcp-oauth.mjs secrets long legacy

    The reproducer starts app-server processes sharing one OAuth grant, creates long-lived threads, and makes thread-bound MCP tool calls. It forces an HTTP 401 to trigger a refresh, then calls the MCP tool from another existing client.

    The legacy path reproduces reuse of a spent refresh token and an authentication failure.

  4. Repeat with refresh coordination enabled:

    node verify-codex-mcp-oauth.mjs secrets long coordinated

    This also starts a third process and exercises repeated concurrent calls. Our test completed with 14 refreshes and zero stale-token reuses.

The failure was reproduced with both the encrypted Secrets backend and direct Windows keyring. Global resource reads alone did not reproduce it; thread-bound MCP tool calls did.

codex-mcp-oauth-reproducer.txt

What is the expected behavior?

Long-lived MCP clients sharing an OAuth grant should coordinate token refreshes and use the latest stored credentials.

After one client rotates the refresh token, other clients should reload the updated credentials before attempting another refresh, rather than submitting a spent token.

Concurrent calls, multiple open conversations, and process restarts should not cause token-family revocation or require users to sign in again while the authorization remains valid.

This should work with the default configuration, without requiring users to enable an experimental feature flag. Explicit revocation and genuine token expiry should still be respected.

Additional information

Related umbrella issue: #35006, particularly sections 2 and 7
on refresh-path coverage and shared credential lifecycle.

This report provides a concrete reproduction on Windows with
Codex 0.154.0-alpha.6.2: long-lived app-server clients reuse a
spent refresh token when coordination is disabled.

With

codex-mcp-oauth-reproducer.txt

enabled, our isolated test
completed 14 refreshes across 3 processes with zero stale-token
reuses.

Activity

  1. added
    bug
    on Sep 16, 2026
  2. added
    app
    mcp
    auth
    app-server
    windows-os
    on Sep 16, 2026
  3. github-actions commented on Sep 16, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. aaldere1 commented on Sep 18, 2026

    @aaldere1

    Confirming from the server side, on macOS (the issue is labelled windows-os), with the CLI rather than the desktop app — and with production timings rather than a reproducer.

    Setup. A private remote MCP server (Streamable HTTP, OAuth 2.1, rotating refresh tokens, family revocation on reuse, 60 s reuse grace measured from each token's retirement). One user, one client_id, one machine, several Codex instances off the same credential store. User agents seen: codex-mcp-client/0.153.4, 0.154.0, 0.155.0-alpha.9.

    What the server logged (UTC, 2026-09-11):

    • 22:15:38 — the same refresh token presented five times within one second. The first rotated it; the server honoured the other four as retries ("retired 0s ago") and handed each the new head.
    • 22:23:23 — the same old token presented a sixth time, 7 m 45 s after rotation — a further instance that had been idle and evidently never re-read the store, since it would otherwise have held the new head. Outside the grace window → reuse detected → family revoked.
    • Afterwards, 189 further refresh attempts with tokens from the revoked family from the same client over the following days, across all three builds above, with no re-auth prompt surfacing (that half looks like MCP OAuth: a rejected refresh token stays "usable", so Codex retries it forever and never surfaces re-authentication #39054).

    The same shape had hit us three times earlier with Hermes, so it is not Codex-specific, but the five-in-one-second burst followed by a straggler minutes later is a distinctive fingerprint of per-instance in-memory refresh tokens with on-401 refresh.

    Workarounds in place: mcp_oauth_refresh_coordination = true on the affected machine (thanks — this issue is how we found the flag), and the server now honours a retired token for the life of the access token issued beside it, which covers instances that renew while their access token is still valid but not one idle longer than that. +1 for making coordination the default.

  5. shotishu commented on Sep 21, 2026

    @shotishu

    Another production data point for this issue, from the operator side (we run the OAuth authorization server behind a remote MCP server). It also touches #41133 and #39054.

    Setup. Spring Authorization Server. Codex connects as a public client (CIMD https://chatgpt.com/oauth/codex/client.json, PKCE, no DPoP). Refresh tokens rotate on every use. We allow a 30-second grace window where a racing request with the previous token gets the winner's tokens back.

    What we see (prod, 2026-09-18 to 2026-09-21, UTC).

    • Codex refresh requests: 3 succeeded and 403 failed with invalid_grant, across 4 machines and 3 versions (0.153.4, 0.154.0-alpha.6.2, 0.155.0-alpha.9.2). Over the same period, Claude and ChatGPT connectors against the same server refreshed with no failures.
    • The failures are not a race on one token. In one burst, two requests fail at 10:47:19.631 and the third succeeds at 10:47:19.803. The failures finish first, so their token was already gone before this burst began. The previous success for that client was 11.3 hours earlier, so that is when the failing token was rotated. For comparison, three concurrent requests that DID carry the same token (another burst) all got 200 within 5 ms.
    • One client had a successful refresh at 15:07:04.371 and sent DELETE /v1/mcp at 15:07:04.524, 150 ms later. Every refresh from that machine after that failed. This matches MCP shutdown can lose a rotated refresh token during session cleanup #41133: a rotated token lost at shutdown.
    • After the first invalid_grant, Codex does not start a new authorization. One installation retried the same dead token about 200 times a day for 5 days, and upgrading Codex did not change that (MCP OAuth: a rejected refresh token stays "usable", so Codex retries it forever and never surfaces re-authentication #39054).

    What we did. We turned off refresh-token rotation for the Codex client only. That is a security trade-off we would rather not keep, because RFC 9700 §4.14.2 wants rotation or sender-constrained tokens for public clients. We will turn rotation back on once Codex keeps one shared copy of the latest refresh token across its MCP client processes, and saves it before shutdown.

    Happy to share more timing data if it helps.

  6. Hatcherthekid commented on Oct 1, 2026

    @Hatcherthekid

    Additional macOS data for this issue, using the desktop-bundled codex-cli 0.155.0-alpha.16.4 and a remote OAuth MCP server with rotating refresh tokens. The current configuration requests mcp_oauth_refresh_coordination=true, but the incident connection's effective mode was not recorded, so this is not proof that coordination failed in production.

    In one production window (2026-09-30 UTC), the authorization server recorded a successful rotation at 05:39:24, then reuse of the preceding token generation from the same family at 05:39:53. The relevant MCP gateway logs had 26 HTTP 401s, all on requests without a bearer token; there were zero bearer-token 401s and zero 5xx responses. This rules out the "bearer 401 -> refresh -> MCP retry 500" path for this window, but the provider and Host logs have no shared request ID. The Keychain item's last observed modification was before the successful rotation; that is suggestive, not enough to attribute the Auth0 exchange to this Mac or process.

    I also reproduced a separate, narrower failure with the same bundled app-server binary, an isolated file credential store, a localhost fake OAuth/MCP server, fake rotating tokens, and coordination explicitly enabled. With an expired access token, connection initialization proactively refreshed; the fake provider consumed the old refresh token and dropped the HTTP response. No MCP POST or bearer 401 occurred. The Host retained the old durable token, and a subsequent connection was rejected for reuse. This shows that a provider-success/response-loss window can produce the same rotation/reuse pattern even when coordinated locking works. It does not establish that response loss caused the production incident.

    The remaining evidence gap is per-transaction Host telemetry linking: process/connection and effective refresh mode -> refresh HTTP outcome -> pinned credential store save outcome. The current source has storage telemetry, but the available desktop logs do not provide this end-to-end correlation. Safe fields would be an anonymous connection/attempt ID, trigger, HTTP status versus transport error, and save success/failure/store kind, without token values or OAuth bodies. That would distinguish response loss, persistence failure, and another stale process on the next occurrence. A definitive invalid_grant should also stop repeated reuse attempts and surface reauthorization (related: #39054).

  7. agcty commented on Oct 4, 2026

    @agcty

    Server-side numbers from Oddlynew (https://mcp.oddlynew.com/mcp), for comparison. Codex connects with protocol 2025-06-18; our logs show codex-mcp-client 0.155 to 0.160. We rotate refresh tokens on every use and issue 1 hour access tokens.

    In the 7 days to 2026-10-04, Codex made 265 successful requests to our token endpoint. In the 14 days to the same date, our grace path for a second refresh of an already rotated token fired once for a Codex client (6 times across all clients), and no refresh chain was revoked after any of them. So on our server this pattern is rare for Codex: one event in 14 days. Its shape is the one described here: one refresh token presented twice by the same client.

    Our grace path has a flaw that can turn such a race into a full sign-out: it revokes the token the first refresh just received. We are replacing it with a short reuse window in which the previous token returns a valid successor and nothing is revoked.

    That does not cover an instance that holds a spent token for minutes, as in the comments above, so refresh coordination by default would still help every server.

  8. ElmoJones3 commented on Oct 18, 2026

    @ElmoJones3

    Additional confirmation with codex-cli 0.163.0 on macOS, using file-based MCP OAuth credential storage.

    We reproduced the reported failure in the default refresh mode: a successful rotation was followed by stale saved credentials and a later authentication failure. With features.mcp_oauth_refresh_coordination=true, repeated refreshes, subsequent MCP calls and process restarts succeeded without another consent.

    The installed CLI still labels the option “under development.” This confirms a working opt-in configuration for our test, not a fix to the default path or a claim that every historical incident has the same cause.

    Agent-authored: Codex, posted at the maintainer's explicit request. No credentials, private endpoints, identifiers or internal logs are included.

  9. pleish commented on Oct 21, 2026

    @pleish

    Additional independent reproduction on macOS with the desktop-bundled codex-cli 0.163.0-alpha.10.2, tested on 2026-10-21. The default refresh path fails; explicitly enabling features.mcp_oauth_refresh_coordination=true makes the same test pass.

    Impact

    Our remote OAuth MCP integration repeatedly requires manual reauthorization. In the live incident, Codex was retrying credentials from an already-revoked authorization family, received invalid_grant, and failed to expose the server's tools. A fresh MCP OAuth login restored access. The initiating production revocation event is no longer retained, so the controlled reproduction below establishes a matching failure mechanism, not the proven original trigger.

    Controlled reproduction

    The fixture uses two actual bundled Codex app-server processes, one isolated CODEX_HOME, mcp_oauth_credentials_store = "file", ephemeral threads, and a localhost OAuth/MCP server with synthetic credentials. No model turns or production credentials are involved.

    1. Complete OAuth login in process A. Start threads in A and B sharing the same grant, and confirm a thread-bound MCP tool call succeeds in each.
    2. Make the server reject the access token with HTTP 401 while the client's advertised token lifetime remains valid.
    3. Call the tool from A. A refreshes successfully, rotating R0 to R1.
    4. Move the server fixture's R0 consumption timestamp beyond its 30-second reuse grace, then reject the current access token again. This advances test state without waiting or changing real server state.
    5. Call the tool from the existing thread in B.

    Default mode: B presents consumed R0 rather than using the current grant. The server detects refresh-token reuse and revokes the family. B's tool call returns isError: true; server counters show one replay and zero remaining access or refresh tokens.

    Coordination enabled in both processes: the same sequence succeeds in B and in a subsequent call from A. Final server counters show zero replays and a surviving refresh grant.

    Sanitized test excerpts:

    Default:
      BASELINE       exchanges=1 refresh=1 replays=0
      FIRST_REFRESH  exchanges=2 refresh=1 replays=0
      CALL second    isError=true
      STATS_AT_ERROR exchanges=3 access=0 refresh=0 replays=1
    
    features.mcp_oauth_refresh_coordination=true:
      BASELINE       exchanges=1 refresh=1 replays=0
      FIRST_REFRESH  exchanges=2 refresh=1 replays=0
      SECOND_REFRESH exchanges=3 refresh=1 replays=0
      CALL first     succeeds
      FINAL          exchanges=4 refresh=1 replays=0
    

    An ordinary advertised-expiry control also passed without forcing a server-side 401. Server-side tests covering refresh persistence across restart, concurrent refreshes within the grace window, and replay revocation passed separately.

    Limits and requested behavior

    The production connection uses macOS Keychain/auto storage; this reproduction uses file storage. We have not reproduced the initiating production incident against Keychain, and the desktop's effective refresh mode during that incident was not established. The bundled binary currently lists mcp_oauth_refresh_coordination as under development / false when queried with features list on this machine.

    This supports the request to make safe shared-credential refresh coordination the default, including the HTTP 401 recovery path. Please retain server-side refresh replay protection. An actionable reauthorization state after definitive invalid_grant would also help with recovery.

    Posted by Codex at the user's explicit request. Credential values, private endpoints, employee information, and raw production logs are omitted.

  10. Brianwones commented on Nov 5, 2026

    @Brianwones

    Another production data point from the operator side. We run the OAuth server behind a remote MCP server (app.collimer.com, Elixir). Codex connects as the CIMD public client with PKCE, refresh tokens rotate on every use, and a replayed rotated token revokes the family. No grace window until today.

    What we saw on 2026-11-05, one user, one macOS machine, codex-cli 0.154.0:

    • The stored credential had last been rotated on 2026-09-24 and was never written again, so a later refresh replayed a rotated token and the family was revoked.
    • Codex then retried the dead refresh token every few seconds, across sessions, until it hit our 30/hour token-endpoint limit, and kept going against the 429s. No re-auth prompt surfaced on the client. Our on-call noticed the 429 volume first.
    • The instances sharing the credential were the CLI plus codex exec runs launched by other tooling, each loading the same remote MCP server at startup.

    Clearing the credential and re-adding the server fixed it, and we have set features.mcp_oauth_refresh_coordination = true on the machine.

    Same two asks as the thread: make coordination the default, and treat invalid_grant on refresh as terminal (drop the credential and surface a re-login) instead of retrying. We're adding a short reuse grace window server side, but the retry loop against a 400 or 429 is the part only the client can fix.

  11. burak-bayir commented on Nov 30, 2026

    @burak-bayir

    We see the same thing from the server side. Our MCP server issues single-use refresh tokens and follows RFC 9700 section 4.14.2 reuse detection. So when a Codex client sends a refresh token that an earlier successful refresh already rotated, the server treats it as theft and revokes the token family, and the user has to reconnect. We can't tell whether the client didn't store the new token or the answer never arrived.

    The coordination this issue describes would prevent it. Store the new refresh token before using the new access token, and let only 1 process refresh a sign-in at a time. Our guidance for clients is at https://docs.xquik.com/oauth/overview#refresh-tokens.

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

    appapp-serverauthbugmcpwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions