Skip to content

Give session recovery one owner - #500

Merged
lynnswap merged 2 commits into
mainfrom
claude/session-recovery
Nov 20, 2026
Merged

lynnswap merged 2 commits into
mainfrom
claude/session-recovery

Conversation

@lynnswap

Copy link
Copy Markdown
Owner

Summary

Session recovery in MCPClientSessionAuthority now has one owner, and a recovery continues after its last waiting caller is cancelled or times out. Before, that recovery was abandoned and the connection stayed .unavailable until reconnect(timeout:), so cancelling one call during a recovery made every later call fail.

Details

  • A Recovery holds its attempt task, a deadline task, the replacement connection, and the continuations of waiting callers. Waiters are only notified; they no longer keep the recovery alive.
  • A recovery ends when the replacement is initialized, when requestTimeout passes (30 seconds when it is nil, as for the first connection), or when the session closes. A caller with a longer or disabled timeout no longer extends a recovery past that bound.
  • The deadline fails a recovery at whichever step it has reached. Work that is still running, such as a transport factory that ignores cancellation, moves to a cleanup that close() waits for. A later reconnect(timeout:) starts at once, and a transport that arrives late is closed without being initialized.
  • The recovery handshake reuses performManagedHandshake from the first connection. The detached handshake with its per-step authorization, the background lease, and the table of retired recoveries are removed. The file goes from 1,686 to 1,093 lines.
  • Ten tests of the abandoned-recovery behavior are replaced by six that cover the current contract: a cancelled waiter leaves the recovery running, the deadline fails waiters and allows a fresh reconnect, the deadline during transport creation allows a fresh reconnect, close() waits for a transport that is being created and for an event stream that is starting, and the bound without a default timeout.

Review focus

The local Codex review left two findings that this PR does not change.

  • A recovery that finishes its handshake just after the deadline, but before the deadline task runs, becomes .ready. I kept this: the connection works, and failing it would discard a usable connection.
  • The attempt holds the session while it runs the handshake. A transport whose startEventStream never returns after cancellation would keep a session alive after its client dropped it without close(). The shipped transports return from startEventStream at once (HTTP starts a task; the process transport does nothing), so I did not restore the detached handshake to cover it.

Testing

  • swift build --build-tests: succeeded.
  • swift test --no-parallel --filter XcodeMCPKitTests: 63 tests passed in 12 consecutive runs.
  • swift test --no-parallel --filter 'XcodeMCPKitTestingTests|ProxyToolVerifierTests|ProxyIntegrationTests': 133 tests passed.
  • PublicProductContractTests passed before the second commit, which did not change public API.

🤖 Generated with Claude Code

lynnswap and others added 2 commits November 20, 2026 09:19
A recovery is one task that the session owns. Callers wait for it
without owning it, so cancelling a waiting call no longer abandons the
recovery and leaves the connection unavailable. A recovery ends when the
replacement is initialized, when its deadline passes, or on close.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
The deadline now fails a recovery whichever step it has reached, so a
transport that is still being created cannot keep the session
recovering. Leftover work moves to a cleanup that close() waits for,
and a later reconnect starts at once.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T00:26:56.913084Z 495406a PR opened
🔒 Security Review ✅ Completed 2026-11-20T00:29:42.181167Z 495406a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lynnswap
lynnswap merged commit 25c0d61 into main Nov 20, 2026
7 checks passed
@lynnswap
lynnswap deleted the claude/session-recovery branch November 20, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Give session recovery one owner

1 participant