Skip to content

Mark sessions as expired when authentication fails#40

Merged
jancurn merged 5 commits intomainfrom
claude/fix-session-expiration-HZcDv
Mar 8, 2026
Merged

Mark sessions as expired when authentication fails#40
jancurn merged 5 commits intomainfrom
claude/fix-session-expiration-HZcDv

Conversation

@jancurn
Copy link
Member

@jancurn jancurn commented Mar 8, 2026

Summary

This PR ensures that sessions are correctly marked as expired when the server rejects authentication, rather than remaining in a live state. This improves the user experience by accurately reflecting the session status in the session list.

Key Changes

  • bridge-manager.ts: Added session expiration marking in ensureBridgeReady() when authentication errors are detected during MCP connection attempts (two locations: initial connection and post-restart health checks)
  • bridge/index.ts: Extended the session expiration logic to handle both session ID rejection and authentication failures, with improved error message logging
  • CHANGELOG.md: Documented the fix for users

Implementation Details

  • When an authentication error is detected, the session is marked with status: 'expired' before throwing the auth error
  • Error handling includes graceful fallback with warning logs if the session update fails
  • The fix covers both initial connection failures and failures after bridge restart attempts
  • Authentication error detection reuses the existing isAuthenticationError() utility function for consistency

https://claude.ai/code/session_01Vz55QPzBXfNxd34dRQZxHL

claude added 5 commits March 7, 2026 22:35
When a server rejects an unauthenticated connection, the session was
still showing as 'live' because the session status was never updated
to 'expired'. This fix marks the session as expired in three places:

1. Bridge startup: auth errors now trigger expired status (previously
   only session ID rejection did)
2. ensureBridgeReady: marks session expired before throwing auth error
   (both on initial check and after restart attempt)

https://claude.ai/code/session_01Vz55QPzBXfNxd34dRQZxHL
The run_xmcpc invariant check compares --json and --json --verbose
outputs for equality. The lastSeenAt field can change between calls
due to bridge keepalive pings, causing spurious failures. Normalize
this field before comparison.

https://claude.ai/code/session_01Vz55QPzBXfNxd34dRQZxHL
Now that lastSeenAt is normalized in the invariant comparison,
restore run_xmcpc (with full --json/--verbose invariant checks)
in session tests that were previously downgraded to run_mcpc
to avoid lastSeenAt timestamp drift between the 4 variant calls.

https://claude.ai/code/session_01Vz55QPzBXfNxd34dRQZxHL
Shared-home tests cannot use run_xmcpc because parallel tests modify
the session list (adding/removing sessions, changing status) between
the 4 invariant-check variant calls. The lastSeenAt normalization only
fixes timestamp drift — it doesn't help when the session list itself
changes due to concurrent test execution.

https://claude.ai/code/session_01Vz55QPzBXfNxd34dRQZxHL
The bridge IPC serializes MCP auth failures (e.g. 401 from server) as
NetworkError (code 3). Previously, ensureBridgeReady treated all
NetworkErrors as "socket not responding" and fell through to restart,
only checking for auth patterns after restart. This caused connect to
silently succeed in Bun when the second check path behaved differently.

Now check isAuthenticationError() on the error message before falling
through to restart, so auth failures are detected immediately on the
first health check regardless of runtime.

https://claude.ai/code/session_01Vz55QPzBXfNxd34dRQZxHL
@jancurn jancurn merged commit c29d034 into main Mar 8, 2026
6 checks passed
@jancurn jancurn deleted the claude/fix-session-expiration-HZcDv branch March 12, 2026 14:17
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.

3 participants