Skip to content

Add --auto-restart option to automatically recover expired sessions#79

Open
jancurn wants to merge 5 commits intomainfrom
claude/add-auto-restart-option-qS9kS
Open

Add --auto-restart option to automatically recover expired sessions#79
jancurn wants to merge 5 commits intomainfrom
claude/add-auto-restart-option-qS9kS

Conversation

@jancurn
Copy link
Member

@jancurn jancurn commented Mar 16, 2026

Summary

This PR adds an --auto-restart option to the connect command that enables automatic recovery when MCP server sessions expire, eliminating the need for manual mcpc @session restart commands.

Key Changes

  • New CLI option: Added --auto-restart flag to the connect command that persists the setting in session configuration
  • Session expiry handling: Modified classifyAndThrowSessionError() to return 'expired' when autoRestart is enabled, allowing callers to handle recovery instead of throwing immediately
  • Auto-recovery logic: Enhanced ensureBridgeReady() to detect expired sessions and automatically:
    • Stop the existing bridge process
    • Restart the bridge
    • Verify health after restart
    • Fall back to error handling if restart fails
  • Dual recovery paths: Implemented auto-restart handling both for:
    • Sessions already marked as expired (checked at start of ensureBridgeReady())
    • Sessions that expire during health checks (detected via return value from classifyAndThrowSessionError())
  • Error prevention: When auto-restart fails, the code avoids infinite loops by passing autoRestart=false equivalent to error classification on retry
  • User guidance: Updated error messages to inform users about the --auto-restart option for enabling automatic recovery

Implementation Details

  • The autoRestart flag is stored in SessionData and passed through the session configuration
  • Auto-restart is only attempted once per health check cycle to prevent infinite retry loops
  • Failed auto-restarts still provide detailed error messages with log file paths for debugging
  • The feature gracefully degrades — if auto-restart fails, users get clear instructions on manual recovery options

https://claude.ai/code/session_01JguVLhdg3mmrejPXf9RehX

claude and others added 5 commits March 16, 2026 23:15
Allow users to disable automatic bridge restart on crash via
`mcpc connect --no-auto-restart <server> @session`. When set, crashed
bridges require manual restart with `mcpc @session restart`.

The flag is stored in session data and checked in both ensureBridgeReady()
(initial health check) and SessionClient.withRetry() (mid-operation crash).

https://claude.ai/code/session_01JguVLhdg3mmrejPXf9RehX
Auto-restart can silently lose session state (MCP session ID,
subscriptions, in-flight requests), which is confusing. Flip the
default so crashed bridges stay crashed with a clear error message,
and users opt in with `mcpc connect --auto-restart` when they
explicitly accept potential state loss.

https://claude.ai/code/session_01JguVLhdg3mmrejPXf9RehX
Auto-restart should only handle expired sessions (server rejected
session ID), not crashed bridges. Crashed bridges already have their
own recovery logic that always restarts on next command.

Move auto-restart logic into ensureBridgeReady's expired-session
handling and classifyAndThrowSessionError, revert all changes to
SessionClient (crash recovery stays unchanged).

https://claude.ai/code/session_01JguVLhdg3mmrejPXf9RehX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants