Repository navigation
Description
What version of Codex CLI is running?
codex-cli 0.172.0
What subscription do you have?
ChatGPT Plus
Which model were you using?
Whatever codex exec selects by default on Plus (the model was not pinned). The failure is in MCP auth / tool exposure, not in model reasoning: the same prompt works again immediately after codex mcp login.
What platform is your computer?
macOS 27.0.1 (Build 26A434), arm64 (darwin-arm64)
What terminal emulator and version are you using (if applicable)?
The scored runs used codex exec (non-interactive). codex mcp list was used only to read auth_status after each run.
Codex doctor report
Omitted from this draft so it cannot leak account details. Happy to attach a trimmed codex doctor dump if a maintainer wants it.
What issue are you seeing?
If an MCP authorization server issues a short-lived access token and no refresh token, Codex does not treat that as “you will need to sign in again when the access token dies.”
After the access token expires:
- A tool call in
codex execdoes not run. The reply says the tool is missing from the session, for example:- “The call couldn’t run because this session exposes no
ssi-trialMCP tool namedrecommendation_log.” - “The
ssi-trialMCP toolrecommendation_logis unavailable because it isn’t registered in this session.”
- “The call couldn’t run because this session exposes no
- That reply never mentions authorization, login, or signing in again.
codex mcp list --jsonreportsauth_status=not_logged_inon the 3 scored runs (so the CLI does know the session is no longer logged in), but that fact is not surfaced in the exec reply or as a re-auth prompt.- One
codex mcp loginfixes it immediately, and the tool works again.
This is legal server behavior. The MCP authorization spec, 2026-07-28, Refresh Tokens says clients that want refresh tokens MUST NOT assume refresh tokens will be issued; the authorization server retains discretion.
We ran this 3 times on 0.172.0. All 3 failed in the same way. Claude Code 2.1.334 (and 2.1.335 on a rerun) against the same server, same night, passed 3/3: it replied that the server needs authorization and to run /mcp, and claude mcp list said “Needs authentication.”
Extra variant (1 run, not part of the 3/3): the server advertised expires_in=600 but rejected the access token after 60 seconds. Codex still failed (same “tool isn’t exposed” reply), and this time codex mcp list reported auth_status=o_auth (still logged in) even though the server had returned 401 invalid_token. A fresh codex mcp login fixed it. That status mismatch is closer to the “empty tools + authStatus oAuth” shape in #39054.
Same symptom, second trigger (3/3, same night, 0.172.0): on the same test server with normal rotating refresh tokens, we had the authorization server revoke the token family (what OAuth 2.1 / RFC 9700 servers do after refresh-token reuse). Codex's next refresh got 400 invalid_grant. The exec reply was again “the ssi-trial MCP tool isn’t available in this session” (wording varied slightly), with no sign-in prompt. codex mcp list still said auth_status=o_auth (logged in) on all 3 runs. One codex mcp login fixed it. Claude Code passed the same case 3/3 (“Needs authentication”). Third and fourth triggers (3/3 each, 0.172.0, rerun at 12:36 to 1:23 AM ET): (a) after a global revoke on the test server (every token dead, 400 invalid_grant/401 revoked), and (b) when the server returns HTTP 403 instead of 401 for an expired access token (the spec says 401; this is a misbehaving-server case). Both ended the same way: “tool isn’t available in this session,” no sign-in wording, and auth_status=o_auth afterward. Claude Code 2.1.335 told the user to authenticate in the revoke case. The no-refresh-token case above also failed 3/3 again in the rerun.
This second trigger overlaps #39054 (rejected refresh token leaves status oAuth), so it may be best mentioned there as well; the no-refresh-token trigger above is the new part.
On the server side, for each scored run: after expiry Codex presented no bearer (two 401s with reason no_token). It never requested a refresh token (there was none to send) and never started a new authorization.
What steps can reproduce the bug?
Public test server only (a local reference MCP server with fake data). It is not a production service.
-
Use the
trial/failure-casesbranch of mandalarules/still-signed-in (commitab4ff53was the first published trial; commita7df4f5adds more failure-case switches and the 3x results; theSSI_NO_REFRESH=1command below works on both).git clone https://github.com/mandalarules/still-signed-in.git cd still-signed-in git checkout trial/failure-cases cd horizons-test SSI_PORT=8789 SSI_NO_REFRESH=1 SSI_ACCESS_TTL=60 SSI_ADVERTISED_TTL=60 \ node --disable-warning=ExperimentalWarning --import ./register-ts.mjs server.mjs
The token endpoint returns an access token only (
refresh_tokenis omitted, andgrant_types_supporteddoes not includerefresh_token). The server auto-approves the authorize redirect, so a browser sign-in does not need a person to click anything. It binds127.0.0.1only. -
In another terminal, add the server and complete the first sign-in (this part works):
codex mcp add ssi-trial --url http://127.0.0.1:8789/mcp # first login should succeed codex mcp list --json # auth_status should be logged in / o_auth
-
Confirm a tool call works while the access token is still valid:
codex exec --skip-git-repo-check "Call the ssi-trial MCP tool recommendation_log with action=read, then tell me how many entries it returned. If the tool is unavailable or errors, say exactly why."
-
Wait past the access-token lifetime (60 seconds, plus a few seconds of padding):
sleep 75
-
Repeat the same
codex execprompt, then inspect status:codex mcp list --json
-
Recover (optional, to confirm the grant is not permanently broken):
codex mcp login ssi-trial # repeat the exec prompt — the tool should work again
What is the expected behavior?
When the access token is dead and the server issued no refresh token, Codex should treat that as “authorization required,” not as “this tool is not in the session.”
Concretely:
- The exec / session reply should say that the MCP server needs sign-in again (or automatically open the existing login flow), not that the tool is unregistered or unavailable.
- Any status API (
codex mcp list, app-servermcpServerStatus/list) should agree with that, and should offer a re-auth path. It should not be possible to be “logged in” (o_auth) with zero tools after a 401, as in the early-expiry variant. - A missing refresh token is not an error; it is allowed by the spec. The client should still fail clearly.
Additional information
Result: Codex 0.172.0 FAIL 3/3 (outcome: tool missing, no sign-in wording in the exec reply, auth_status=not_logged_in). One sign-in recovered every run. Claude Code 2.1.334 PASS 3/3 on the same server the same night.
Scrubbed evidence from the three scored runs (America/New_York, 2026-12-02, roughly 8:46–8:51 PM). Tokens were never stored in these logs. Server events are counts and reason codes only:
| Run | codex exec after expiry (exact reply) |
codex mcp list |
Server after expiry | After codex mcp login |
|---|---|---|---|---|
| 1 | “The call couldn’t run because this session exposes no ssi-trial MCP tool named recommendation_log.” |
auth_status=not_logged_in |
2× 401 no_token; 0 refresh requests; 0 new sign-ins |
tool call returned 0 entries |
| 2 | “The ssi-trial MCP tool recommendation_log is unavailable because it isn’t registered in this session.” |
auth_status=not_logged_in |
same | same |
| 3 | “The ssi-trial MCP tool recommendation_log is unavailable because it isn’t registered in this session.” |
auth_status=not_logged_in |
same | same |
Related issues (same neighborhood, not the same trigger):
- MCP OAuth: a rejected refresh token stays "usable", so Codex retries it forever and never surfaces re-authentication #39054 — a rejected refresh token (
400 invalid_grant) is retried forever; status can stayoAuthwith an empty tool list and no re-auth prompt. Closest user-visible symptom. Different trigger: we never issued a refresh token, so there was nothing to retry. The early-expiry variant of this report (status left ato_authafter 401s) may share the “usable because something is stored” status bug described there. - Codex MCP OAuth sessions expire and require application restart #32590 — Codex desktop: after a session expires, tools disappear and a successful
codex mcp logindoes not fix the already-running app until a full restart. We only tested the CLI, and a newcodex execafter login recovered immediately. - Codex does not auto-refresh routed MCP OAuth tokens even when a refresh token is stored #17265 — Codex does not auto-refresh even when a refresh token is stored. Opposite setup. On 0.172.0, against this same test server with rotating refresh tokens, Codex does refresh and recover (early expiry 3/3, concurrent refresh 3/3).
- MCP tools disappear or become unsupported in existing long-running threads #26196 — MCP tools disappear in long-running desktop threads (sleep/wake, “unsupported call”) while
codex mcp liststill shows OAuth. Different lifetime (hours, thread-local tools), not a no-refresh-token expiry of about a minute.
Happy to add a trimmed server event log or a codex doctor dump if useful. We have not posted this anywhere else.
Activity