fix(mcp): retry after missing session id errors - #1355
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of the MCP client by introducing an automatic retry mechanism for transient session expiry errors. It centralizes the session reinitialization logic into a dedicated function and updates the request sending process to detect and recover from specific session-related HTTP 400 errors, thereby improving the client's resilience against server-side session invalidations. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request successfully implements a retry mechanism for MCP session expiry errors. The new reinitialize_session and is_session_expiry_error functions are well-defined and modular, enhancing code readability and maintainability. The integration into send_request correctly handles the retry logic, and the initialize function is refactored to leverage the new reinitialization logic. A comprehensive test case, test_http_session_error_triggers_reinitialize_and_retry, has been added, which effectively validates the new retry mechanism using a custom mock transport. Overall, the changes improve the robustness of the MCP client and are well-implemented.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3034c71f5a
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
henrypark133
left a comment
There was a problem hiding this comment.
Review: Retry MCP requests after session expiry errors
Clean refactor + new capability. Extracts reinitialize_session() from inline code in ensure_initialized() and wires it into the send_request() retry loop for recoverable 400/missing-session-ID errors.
Positives:
reinitialize_session()correctly usesself.transport.send()directly (avoiding recursive retry) and properly sequences: terminate → get_or_create → handshake → mark_initialized → notificationis_session_expiry_error()heuristic is conservative (requires both "session" AND one of "400"/"missing session id"/"no valid session id")- Only triggers on
attempt == 0withsession_manager.is_some()— no infinite loops, no retry on non-HTTP transports RetryMockTransporttest helper andtest_http_session_error_triggers_reinitialize_and_retryprovide good end-to-end coverage of the recovery path- No
.unwrap()in production code
LGTM.
Retry a single time after a recoverable MCP session-expiry 400 by forcing a fresh initialize handshake.
Fixes #1315.