Add test reproducing MCP session invalidation on server restart and implement partial fix#26
Add test reproducing MCP session invalidation on server restart and implement partial fix#26
Conversation
g3force
left a comment
There was a problem hiding this comment.
- Simplify the test to only use streaming-http, not sse.
- Solve the mypi lint issue
Done in commit 998c832:
The test still successfully reproduces the issue (task fails with "Failed to create MCP session" error after simulated server restart). |
g3force
left a comment
There was a problem hiding this comment.
Ok, now analyse the bug and look for a fix.
I've analyzed the bug and implemented a partial fix in commit 3e33dff. Root Cause: Fix Implemented:
Status: Next Step: |
083c0ae to
85f632a
Compare
Co-authored-by: g3force <779094+g3force@users.noreply.github.com>
…mplement partial fix Co-authored-by: g3force <779094+g3force@users.noreply.github.com>
85f632a to
e704b33
Compare
g3force
left a comment
There was a problem hiding this comment.
Fix the linting issues in failing workflow
- Removed unused type: ignore comments on lines 70 and 75 - Fixed variable naming conflict: used read_stream and write_stream instead of reusing 'stream' variable - Fixed incorrect reference to session._write_stream instead of write_stream variable on line 101 - Applied ruff formatting fixes to test_agent_integration.py All linting checks now pass (ruff, mypy, bandit). Co-authored-by: g3force <779094+g3force@users.noreply.github.com>
Fixed in commit 3b32d7c. All linting issues resolved:
All checks now pass: ruff ✓, mypy ✓, bandit ✓ |
Summary
Successfully created a test that reproduces the MCP server restart communication failure issue, analyzed the root cause, and implemented a partial fix via monkey-patching.
Completed Tasks
Test Details
Test Name:
test_mcp_server_restart_causes_communication_failureLocation:
adk/tests/test_agent_integration.pyWhat it does:
/messages/SESSION_IDURLsCurrent Behavior (Bug):
failedFailed to create MCP session:Expected Behavior (After Fix):
Root Cause Analysis
The bug is in the Google ADK's
MCPSessionManager:self._sessionskeyed by headers_is_session_disconnected()only checks if client-side streams are closed@retry_on_errorsdecorator retries, butcreate_session()reuses the same bad cached sessionFix Implementation
Created a monkey-patch in
adk/agenticlayer/mcp_session_patch.py:retry_on_errorsdecorator to detect MCP operation failures_is_session_disconnected()return True on retryStatus: Partial fix implemented. The patch is being applied and detecting errors correctly, but requires further refinement to fully resolve all edge cases.
Files Changed
adk/agenticlayer/mcp_session_patch.py- Monkey-patch implementationadk/agenticlayer/agent.py- Applies patch on module importadk/tests/test_agent_integration.py- Reproduction test (simplified to streaming-http only)Changes Made
/messages/URL pathsNext Steps
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.