Skip to content

fix(mcp): serialize keepalive probes with the per-server RPC lock - #76691

Closed
686f6c61 wants to merge 1 commit into
NousResearch:mainfrom
686f6c61:fix/70218-mcp-keepalive-rpc-lock
Closed

fix(mcp): serialize keepalive probes with the per-server RPC lock#76691
686f6c61 wants to merge 1 commit into
NousResearch:mainfrom
686f6c61:fix/70218-mcp-keepalive-rpc-lock

Conversation

@686f6c61

@686f6c61 686f6c61 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Normal MCP tool RPCs are serialized on per-server _rpc_lock, but _keepalive_probe() sent ping / list_tools without the lock. A scheduled probe can interleave with a long-running tool call and wedge the session (#70218).

This PR:

  • Skips the probe when _rpc_lock is already held (active RPC proves liveness)
  • Otherwise acquires _rpc_lock for the whole probe
  • Pins the session reference for the probe duration
  • Adds regressions for skip-while-busy and serialize-user-RPC

Related work

Fixes #70218

Related open approaches: #62811 (same serialization idea; this branch is rebased on current main and linked to the issue). Happy for maintainers to pick either and close the other as superseded.

Test plan

pytest tests/tools/test_mcp_capability_gating.py -k "keepalive_skips or active_keepalive" -q

2/2 passed.

Keepalive ping/list_tools no longer interleave with in-flight tool calls on
the same ClientSession stream. If the lock is already held, skip the probe
(the active RPC is liveness). Otherwise acquire the lock for the probe.

Fixes NousResearch#70218

Co-authored-by: Diego Gomez <22959713+0xquinto@users.noreply.github.com>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/mcp MCP client and OAuth sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state duplicate This issue or pull request already exists labels Aug 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #62811. The current diffs use the same per-server _rpc_lock serialization and skip-while-busy behavior for the same keepalive-versus-RPC race; #62811 is the earlier open implementation.

@686f6c61

686f6c61 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Agreed — #62811 is the earlier open implementation of the same _rpc_lock serialize / skip-while-busy keepalive fix. Closing this one as a duplicate so maintainers have a single merge target. Thanks for the triage.

@686f6c61

686f6c61 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Duplicate of #62811 — earlier open PR for the same keepalive/RPC serialization fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP keepalive probe bypasses the per-server RPC lock and can interleave with an active tool call

2 participants