Skip to content

Use maps.Equal for full metadata staleness detection in checkSession instead of per-key comparison #4728

@yrobla

Description

@yrobla

Context

Raised as a suggestion on the session manager's checkSession implementation.

Currently, the cache liveness check in checkSession compares only MetadataKeyBackendIDs to detect cross-pod metadata drift:

if cachedIDs, present := sess.GetMetadata()[vmcpsession.MetadataKeyBackendIDs]; present {
    if cachedIDs != metadata[vmcpsession.MetadataKeyBackendIDs] {
        return cache.ErrExpired
    }
}

Problem

This approach requires checkSession to know which specific metadata key to inspect. If new metadata keys are introduced in the future, staleness detection won't cover them unless checkSession is explicitly updated. The session manager doesn't need to care about which key drifted — if in-memory state doesn't match storage, it should evict and let the next restore pick up current state.

Suggestion

Replace the per-key comparison with maps.Equal over the full metadata maps:

if !maps.Equal(sess.GetMetadata(), metadata) {
    return cache.ErrExpired
}

Both sides are map[string]string, so maps.Equal works directly with no reflection overhead. This gives all present and future metadata keys staleness detection for free without any further changes to checkSession.

Acceptance Criteria

  • checkSession uses maps.Equal to compare the full metadata maps
  • The per-key MetadataKeyBackendIDs comparison is removed
  • Existing tests continue to pass; no new metadata-key-specific logic needed in checkSession

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgoPull requests that update go codescalabilityItems related to scalabilitytech-debtvmcpVirtual MCP Server related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions