Skip to content

Distributed sessions (rebased)#2

Open
jerenkrantz wants to merge 2 commits into
mainfrom
jerenkrantz/rebase-distributed-sessions
Open

Distributed sessions (rebased)#2
jerenkrantz wants to merge 2 commits into
mainfrom
jerenkrantz/rebase-distributed-sessions

Conversation

@jerenkrantz
Copy link
Copy Markdown

@jerenkrantz jerenkrantz commented Mar 31, 2026

Summary

  • Rebase of distributed sesions #1 onto latest main
  • Adds SessionBackend interface for distributed session management across multiple server replicas
  • Includes in-memory implementation (MemorySessionBackend) for development/testing
  • Integrates session backend into StreamableHTTPHandler for session persistence and cross-pod message routing

Changes from original PR

  • Fixed build: updated randText()rand.Text() to match upstream API change
  • Fixed race condition: replaced read-modify-write cycle in updateSessionStateInBackend with direct Update using reconstructed SessionData, eliminating concurrent state clobber between pods/goroutines
  • Fixed unbounded context: added 10s timeout to context.Background() used for backend session deletion in onClose callback
  • Moved userID extraction earlier so OnStateChange callbacks can capture it without a second TokenInfoFromContext call

Test plan

  • go build ./mcp/... passes
  • go test ./mcp/... passes
  • go test -race ./mcp/... passes
  • Review new distributed session tests in mcp/distributed_test.go
  • Review session backend integration in mcp/session_backend_integration.go

🤖 Generated with Claude Code

pquerna and others added 2 commits March 30, 2026 22:07
- Eliminate read-modify-write race in updateSessionStateInBackend by
  reconstructing SessionData directly instead of Get+mutate+Update
- Extract userID earlier so OnStateChange callbacks can capture it
- Add 10s timeout to context.Background() used for backend session deletion

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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