Skip to content

CLI degrades after stale streamable-http MCP session; subsequent tool calls fail #12869

@adam-r-kowalski

Description

@adam-r-kowalski

What version of Codex CLI is running?

codex-cli 0.104.0

What subscription do you have?

ChatGPT Pro

Which model were you using?

gpt-5.3-codex

What platform is your computer?

macOS 26.3 (Build 25D125), Darwin 25.3.0, arm64

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

Ghostty 1.2.3

What issue are you seeing?

When using streamable HTTP MCP connectors, Codex CLI can degrade after a stale MCP session response.

In this failure mode, the server returns 401 Unauthorized with a body like Unauthorized: Session not found for a stale or invalid mcp-session-id. After that failure, follow-up MCP calls in the same Codex session can keep failing instead of transparently recovering.

Observed impact:

  • Initial MCP calls can succeed (for example list_tools).
  • A later call fails on stale session.
  • Subsequent calls in the same session fail until restart/reconnect.

What steps can reproduce the bug?

  1. Start a stateful streamable HTTP MCP server.
  2. Connect to it from Codex CLI as an MCP connector.
  3. Make at least one successful MCP call (for example a tools list call).
  4. Invalidate/expire the MCP session (or force stale session behavior on server side).
  5. Make another MCP call.
  6. Observe stale-session failure and lack of automatic recovery for subsequent calls in the same session.

Concrete local repro setup used:

  • Test server path in this repo: codex-rs/rmcp-client/src/bin/test_streamable_http_server.rs
  • Force stale session on Nth POST with:
    • MCP_FORCE_STALE_SESSION_AT_POST_NUMBER=3

What is the expected behavior?

Codex CLI should recover automatically from stale streamable HTTP MCP sessions:

  1. Detect stale-session failure.
  2. Reconnect/reinitialize the MCP transport.
  3. Retry the failed request once.
  4. Keep the connector usable for subsequent calls.

If retry still fails, Codex should return a clear, status-aware error message (including HTTP status/body context) rather than leaving the connector in a degraded state.

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmcpIssues related to the use of model context protocol (MCP) servers

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions