Skip to content

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

@yrobla

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgoPull requests that update go codetech-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