Skip to content

Comments

Add SessionManager behind sessionManagementV2 flag (Phase 2)#3906

Open
yrobla wants to merge 1 commit intoissue-3865-v1from
issue-3866
Open

Add SessionManager behind sessionManagementV2 flag (Phase 2)#3906
yrobla wants to merge 1 commit intoissue-3865-v1from
issue-3866

Conversation

@yrobla
Copy link
Contributor

@yrobla yrobla commented Feb 20, 2026

Implement RFC THV-0038 Phase 2: a vmcpSessionManager that bridges the MultiSession/MultiSessionFactory domain logic to the MCP SDK's SessionIdManager interface. The feature is gated behind a sessionManagementV2 config flag (default false), leaving the existing code path completely unchanged when disabled.

Key changes:

  • pkg/vmcp/server/session_manager.go: new vmcpSessionManager with two-phase creation — Generate() stores a placeholder, CreateSession() (called from OnRegisterSession hook) replaces it with a fully-formed MultiSession via MakeSessionWithID(). Terminate() calls Close() before deleting to release backend connections. GetAdaptedTools() returns SDK tools with session-scoped handlers delegating to CallTool().
  • pkg/vmcp/session/factory.go: add MakeSessionWithID() to the MultiSessionFactory interface; refactor MakeSession to share a private makeSession() implementation.
  • pkg/transport/session/manager.go: add ReplaceSession() upsert to swap a placeholder with a fully-formed MultiSession.
  • pkg/vmcp/config/config.go: add SessionManagementV2 bool field.
  • pkg/vmcp/server/server.go: wire vmcpSessionManager when flag+factory are set; add handleSessionRegistrationV2() hook handler.
  • pkg/vmcp/discovery/middleware.go: skip Phase 1 routing-table reconstruction for Phase 2 MultiSession sessions.
  • Tests: unit tests for all new methods, ReplaceSession coverage in transport/session, and an end-to-end integration test covering initialize, tool call routing, and the old-path-unaffected case.

Closes: #3866

Large PR Justification

This is an atomic PR that covers an isolated functionality, and includes complete tests. Cannot be split.

@github-actions github-actions bot added the size/XL Extra large PR: 1000+ lines changed label Feb 20, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Large PR Detected

This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.

How to unblock this PR:

Add a section to your PR description with the following format:

## Large PR Justification

[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformation

Alternative:

Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.

See our Contributing Guidelines for more details.


This review will be automatically dismissed once you add the justification section.

@yrobla yrobla requested a review from Copilot February 20, 2026 11:14
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 20, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements RFC THV-0038 Phase 2 by introducing a feature-flagged vmcpSessionManager that bridges MultiSession/MultiSessionFactory to the MCP SDK SessionIdManager, enabling session-scoped backend client lifecycle while keeping the existing path unchanged when disabled.

Changes:

  • Add vmcpSessionManager behind SessionManagementV2 to generate/validate/terminate sessions and register per-session tools.
  • Extend MultiSessionFactory with MakeSessionWithID() and add transportsession.Manager.ReplaceSession() to support two-phase session creation.
  • Update discovery middleware to bypass Phase 1 routing-table reconstruction for Phase 2 MultiSession sessions; add unit + integration tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
pkg/vmcp/server/session_manager.go New Phase 2 session manager (Generate/CreateSession/Validate/Terminate + tool adaptation).
pkg/vmcp/server/server.go Wires Phase 2 manager behind SessionManagementV2 and registers session tools in OnRegisterSession.
pkg/vmcp/session/factory.go Adds MakeSessionWithID() and refactors shared makeSession() implementation.
pkg/transport/session/manager.go Adds ReplaceSession() upsert for swapping placeholder → real session.
pkg/vmcp/discovery/middleware.go Skips Phase 1 routing-table reconstruction when the stored session is a MultiSession.
pkg/vmcp/config/config.go Adds sessionManagementV2 operational config flag.
pkg/vmcp/server/session_manager_test.go Unit tests for Phase 2 session manager behavior.
pkg/transport/session/manager_test.go Unit tests for ReplaceSession() behavior.
pkg/vmcp/server/session_management_v2_integration_test.go End-to-end tests for v2 initialize + tool routing and “old path unaffected” case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 20, 2026
@github-actions github-actions bot dismissed their stale review February 20, 2026 11:22

Large PR justification has been provided. Thank you!

@github-actions
Copy link
Contributor

✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review.

@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 80.84291% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.29%. Comparing base (dee5c2c) to head (54e893e).

Files with missing lines Patch % Lines
pkg/vmcp/server/server.go 52.63% 24 Missing and 3 partials ⚠️
pkg/vmcp/server/session_manager.go 85.27% 13 Missing and 6 partials ⚠️
pkg/vmcp/discovery/middleware.go 84.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           issue-3865-v1    #3906      +/-   ##
=================================================
+ Coverage          67.21%   67.29%   +0.08%     
=================================================
  Files                449      450       +1     
  Lines              45220    45447     +227     
=================================================
+ Hits               30393    30582     +189     
- Misses             12459    12490      +31     
- Partials            2368     2375       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 20, 2026
@yrobla yrobla requested a review from Copilot February 20, 2026 12:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 20, 2026
@yrobla yrobla requested a review from Copilot February 20, 2026 12:59
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 20, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 20, 2026
Implement RFC THV-0038 Phase 2: a vmcpSessionManager that bridges
the MultiSession/MultiSessionFactory domain logic to the MCP SDK's
SessionIdManager interface. The feature is gated behind a
sessionManagementV2 config flag (default false), leaving the
existing code path completely unchanged when disabled.

Key changes:
  - pkg/vmcp/server/session_manager.go: new vmcpSessionManager with
    two-phase creation — Generate() stores a placeholder, CreateSession()
    (called from OnRegisterSession hook) replaces it with a fully-formed
    MultiSession via MakeSessionWithID(). Terminate() calls Close() before
    deleting to release backend connections. GetAdaptedTools() returns
    SDK tools with session-scoped handlers delegating to CallTool().
  - pkg/vmcp/session/factory.go: add MakeSessionWithID() to the
    MultiSessionFactory interface; refactor MakeSession to share a private
    makeSession() implementation.
  - pkg/transport/session/manager.go: add ReplaceSession() upsert to
    swap a placeholder with a fully-formed MultiSession.
  - pkg/vmcp/config/config.go: add SessionManagementV2 bool field.
  - pkg/vmcp/server/server.go: wire vmcpSessionManager when flag+factory
    are set; add handleSessionRegistrationV2() hook handler.
  - pkg/vmcp/discovery/middleware.go: skip Phase 1 routing-table
    reconstruction for Phase 2 MultiSession sessions.
  - Tests: unit tests for all new methods, ReplaceSession coverage in
    transport/session, and an end-to-end integration test covering
    initialize, tool call routing, and the old-path-unaffected case.

Closes: #3866
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 20, 2026
@yrobla yrobla requested a review from Copilot February 20, 2026 15:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants