Skip to content

Remove redundant storage.Load from NotifyBackendExpired#4779

Merged
yrobla merged 1 commit intomainfrom
issue-4667
Apr 14, 2026
Merged

Remove redundant storage.Load from NotifyBackendExpired#4779
yrobla merged 1 commit intomainfrom
issue-4667

Conversation

@yrobla
Copy link
Copy Markdown
Contributor

@yrobla yrobla commented Apr 13, 2026

Summary

Accept the caller's metadata map directly rather than re-loading it from storage. Any caller that detects a backend expiry already holds the session metadata (e.g. from MultiSession.GetMetadata), so the extra round-trip is unnecessary. Passing nil is treated as a silent no-op. Safety is preserved: updateMetadata uses SET XX, so a concurrently terminated (deleted) session is never resurrected.

Fixes #4667

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Changes

File Change

Does this introduce a user-facing change?

Implementation plan

Approved implementation plan

Special notes for reviewers

@yrobla yrobla requested a review from Copilot April 13, 2026 14:47
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Apr 13, 2026
Copy link
Copy Markdown
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

Refactors NotifyBackendExpired to avoid an unnecessary storage read by having callers pass the session metadata they already have when detecting backend expiry (per issue #4667), while keeping the operation best-effort and relying on SET XX semantics to avoid resurrection.

Changes:

  • Update NotifyBackendExpired to accept a caller-supplied metadata map and treat nil as a silent no-op.
  • Simplify timeout documentation now that the internal Load call is removed.
  • Update unit tests and the SessionManager interface to match the new signature.

Reviewed changes

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

File Description
pkg/vmcp/server/sessionmanager/session_manager.go Changes NotifyBackendExpired to take metadata directly and removes the internal storage Load.
pkg/vmcp/server/sessionmanager/session_manager_test.go Updates tests to pass metadata into NotifyBackendExpired.
pkg/vmcp/server/session_manager_interface.go Updates the SessionManager interface and docstring for the new NotifyBackendExpired signature.

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.98%. Comparing base (40aea59) to head (e764b5f).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
pkg/vmcp/server/sessionmanager/session_manager.go 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4779      +/-   ##
==========================================
+ Coverage   68.89%   68.98%   +0.08%     
==========================================
  Files         518      517       -1     
  Lines       54921    54736     -185     
==========================================
- Hits        37840    37759      -81     
+ Misses      14170    14074      -96     
+ Partials     2911     2903       -8     

☔ 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.

Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

LGTM — clean refactoring that removes an unnecessary storage round-trip with no behavior change.

Extended reasoning...

Overview

The PR modifies three files in the vMCP session manager package: the SessionManager interface, its implementation, and the corresponding tests. The core change is to NotifyBackendExpired's signature — the function previously loaded session metadata from storage itself; now the caller supplies the metadata it already holds, eliminating a redundant Redis round-trip.

Security risks

None. The storage update uses SET XX (conditional update), enforced by updateMetadata, so a concurrently deleted session key cannot be resurrected. No auth, crypto, or permissions logic is touched.

Level of scrutiny

Low-to-medium. This is a refactoring with no user-facing behavior change. The interface signature change is technically breaking, but a search of the codebase confirms there are no production callers outside the implementation and its tests, so the risk surface is limited. The map mutation in NotifyBackendExpired (delete + reassign on the caller-supplied map) is a subtle API contract worth noting, but it poses no immediate risk given current usage patterns. Tests comprehensively cover nil, empty, terminated, same-pod, and cross-pod scenarios.

Other factors

Unit tests are thorough and were updated in lock-step with the implementation. The PR was linted and unit-tested. No CODEOWNER-owned files are touched.

Accept the caller's metadata map directly rather than re-loading it
from storage. Any caller that detects a backend expiry already holds
the session metadata (e.g. from MultiSession.GetMetadata), so the
extra round-trip is unnecessary. Passing nil is treated as a silent
no-op. Safety is preserved: updateMetadata uses SET XX, so a
concurrently terminated (deleted) session is never resurrected.

Closes #4667
@github-actions github-actions bot added size/S Small PR: 100-299 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Apr 13, 2026
@yrobla yrobla merged commit 08e4b52 into main Apr 14, 2026
41 checks passed
@yrobla yrobla deleted the issue-4667 branch April 14, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-up: refactor NotifyBackendExpired to accept metadata and use lazy expiry handling

4 participants