Skip to content

fix(server): serialize Claude session start and recovery - #35

Closed
macodev00 wants to merge 16 commits into
mainfrom
cursor/claude-mcp-session-start-lock-8c9e
Closed

macodev00 wants to merge 16 commits into
mainfrom
cursor/claude-mcp-session-start-lock-8c9e

Conversation

@macodev00

Copy link
Copy Markdown
Owner

What Changed

Claude session start and session recovery for one thread now take the same lock, from the hasSession check through MCP credential settlement. resolveRoutableSession(..., { allowRecovery: true }) reaches recovery only through that lock, so it adopts a start that finished while it waited instead of minting a second bearer.

A replacement that is refused while child tasks are still running leaves the open Claude query and its MCP credential in place. An accepted start revokes every superseded credential for that thread. A failed start revokes and clears the thread credential when the previous provider adapter is already gone, or when hasSession fails after the old session has stopped.

Fixes pingdotgg#12694

Why

An ordinary turn could replace a live Claude session and stop its child tasks without a durable session boundary. Keeping that session up is only safe if the process that already spawned still holds a bearer that authorizes /mcp. A concurrent recovery could revoke the credential startSession had just issued, and a failed start could restore a bearer for a process that is no longer running.

UI Changes

No UI changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • No UI changes, so no screenshots or video
Open in Web Open in Cursor 

juliusmarminge and others added 16 commits September 23, 2026 15:01
…case screenshots (pingdotgg#13316)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: Exotic <118054752+extoci@users.noreply.github.com>
…otgg#11580)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>
…3355)

Co-authored-by: Yordis Prieto <yordis.prieto@gmail.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
A replacement start and a recovery start could mint MCP credentials for the
same thread at once, so the process that already spawned kept a bearer that
had just been revoked. Session start and recoverSessionForThread now share
one lock per thread. A failed start revokes a stale credential when the
previous adapter is gone or the session probe fails, and a live Claude
session is not replaced while child tasks are still running.

Co-authored-by: maco <macodev00@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL labels Sep 24, 2026
@macodev00 macodev00 closed this Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Claude session replacement suppresses exit and silently stops live subagent tasks

9 participants