fix(mcp): enforce session pool capacity during promotion - #4962
Open
XIIRUAN wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
MCPSessionPoolchecks its LRU capacity before starting session creation. Because initialization awaits, different keys can all observe spare capacity and enter_inflight, then each promote into_entrieswithout another capacity check. This can leave the persistent-session registry aboveMAX_SESSIONS, retaining extra subprocesses and connections.What changed
Surface area
frontend/backend/applanggraph.json, or prompt changedocker/or sandboxed executionskills/backend/pyproject.tomlorfrontend/package.jsonScreenshots / Recording
N/A — backend-only concurrency fix.
Bug fix verification
backend/tests/test_mcp_session_pool.py::test_concurrent_distinct_sessions_respect_capacitymain, green on this branch: yes.main, two distinct concurrent initializations withMAX_SESSIONS = 1leave two registered sessions. This branch keeps one registered session and closes the evicted owner session.Validation
cd backend && uv run pytest tests/test_mcp_session_pool.py::test_concurrent_distinct_sessions_respect_capacity -qcd backend && uv run pytest tests/test_mcp_session_pool.py -q -k "not test_session_pool_tool_pins_cwd_and_temp_env and not test_session_pool_tool_does_not_override_explicit_tmpdir"— 40 passed, 2 deselected (existing Windows path/permission assertions)cd backend && uv run ruff check .cd backend && uv run ruff format --check .python scripts/check_agent_guidance.pyAI assistance
Tool(s) used: Codex
How you used it: Used to inspect the concurrency path, draft the regression test and implementation, and run validation. I reviewed and verified the final diff.