Files
codex/codex-rs
teddywyly-oai 3d5a786a20 Clean up abandoned MCP sessions during HTTP recovery (#64011)
## Why

A Streamable HTTP server can assign a replacement session ID before the
initialization handshake finishes. If recovery fails or times out at
that point, the abandoned session can occupy server capacity needed by
the next attempt.

## What changed

- Track replacement sessions as soon as the server returns
  `Mcp-Session-Id`. Coordinate a single `DELETE` between handshake cleanup
  and SDK teardown, leaving successfully initialized sessions active.
- Let cleanup finish in the background when the caller's deadline
  expires. Coordinate cleanup with OAuth refresh so the deletion can use
  updated credentials.
- Keep the service, OAuth state, and expiry signal together for each
  connection. Keep recovery scoped to the failed connection and
  recheck client state before returning a replacement so shutdown can
  take precedence.

## Testing

Cover interrupted JSON and SSE handshakes, cleanup before retry on a
server with limited session capacity, OAuth refresh during cleanup,
concurrent calls on expired sessions, and recovery racing with shutdown.

GitOrigin-RevId: 0caa1b1271f4e7ae667f90f15bfa86b1bdfe7d0b
2026-11-25 22:52:27 +00:00
..
…
…
…