Skip to content

Remove Remove() from ValidatingCache API and replace eager-cleanup with a background sweep #4727

Closed

Description

@yrobla

Context

Raised as a suggestion during review (discussed with @JAORMX).

ValidatingCache.Remove was added to support two call sites:

  1. Terminate Phase 2 — evicts the entry after session teardown
  2. DecorateSession's !updated path — evicts a stale entry after a failed update

Both are prompt-cleanup optimizations. In both cases the cache self-heals on the next Get via checkSession, so the explicit Remove calls are not correctness-critical.

Problem

Exposing Remove invites callers to manage cache state imperatively rather than relying on the liveness invariant, which is the whole point of the ValidatingCache design. Widening the API surface in this way makes it easier for future contributors to bypass the invariant by manually evicting entries instead of trusting the check function.

Suggestion

  • Remove Remove() from the ValidatingCache API
  • Remove the two call sites that use it (Terminate Phase 2, DecorateSession's !updated path)
  • Add a background sweep that proactively runs the cache's built-in checkSession function to evict invalid entries, addressing the eager-cleanup concern without widening the API surface

The background sweep is a small addition and achieves the same eager-eviction goal while keeping cache lifecycle management internal to the cache itself.

References

  • PR where Remove was introduced and discussed with @JAORMX

Activity

  1. added
    scalability
    on Apr 10, 2026
  2. added
    enhancement
    go
    vmcp
    and removed
    scalability
    on Apr 10, 2026
  3. yrobla commented on Apr 13, 2026

    @yrobla
    ContributorAuthor

    implemented on same patch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgotech-debtvmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions