Skip to content

DynamicRegistry with version-based cache invalidation #2999

Closed

Description

@jhrozek

Summary

Create a mutable DynamicRegistry implementation that supports thread-safe backend updates with version-based cache invalidation for the discovery manager.

Background

Part of the vMCP K8s-aware refactor (THV-2884). The current immutableRegistry discovers backends once at startup and never changes. For dynamic discovery mode, we need a mutable registry that supports real-time updates when backends change in K8s.

Proposed Design

Interface

type DynamicRegistry interface {
    BackendRegistry  // Embed existing interface (Get, List, Count)

    // Upsert adds or updates a backend atomically.
    // Idempotent - calling with the same backend multiple times is safe.
    // Increments Version() on every call.
    Upsert(backend *Backend) error

    // Remove deletes a backend by ID.
    // Idempotent - removing non-existent backends returns nil.
    // Increments Version() on every call.
    Remove(backendID string) error

    // Version returns the current registry version.
    // Increments on every mutation (Upsert/Remove).
    // Used for cache invalidation in discovery manager.
    Version() uint64
}

Implementation

type dynamicRegistry struct {
    mu       sync.RWMutex
    backends map[string]*Backend
    version  uint64
}

Cache Invalidation

The discovery manager maintains per-user cache entries tagged with the registry version:

type cacheEntry struct {
    capabilities    *AggregatedCapabilities
    expiresAt       time.Time
    registryVersion uint64  // Version when this entry was computed
}

Cache hit is valid only if not expired AND registryVersion == currentVersion. This provides lazy invalidation without thundering herd problems.

Files to Modify

  • pkg/vmcp/registry.go - Add DynamicRegistry interface and dynamicRegistry implementation
  • pkg/vmcp/discovery/manager.go - Add registryVersion field to cache entries and version check on lookup

Acceptance Criteria

  • DynamicRegistry interface extending BackendRegistry
  • Upsert(backend *Backend) error - idempotent add/update
  • Remove(backendID string) error - idempotent delete
  • Version() uint64 - monotonic counter, increments on mutation
  • Thread-safe with RWMutex
  • Cache entries tagged with registryVersion
  • Stale entries (version mismatch) trigger recomputation
  • Lazy invalidation (no thundering herd)
  • Unit tests for all operations

Notes

  • No event callbacks needed - reconciler pattern handles "what changed" logic
  • In static mode, the existing immutableRegistry continues to be used

Activity

  1. added
    enhancement
    go
    vmcp
    on Dec 11, 2025
  2. slyt3 commented on Dec 16, 2025

    @slyt3
    Contributor

    Hey. I’d like to take this issue if it’s still available. The design looks clear and I’m comfortable working on it.
    Please let me know if I can get assigned.

  3. self-assigned this
    on Jan 5, 2026
  4. added 9 commits that reference this issue on Jan 5, 2026
    6b7c539
    62dc596
    da23ff2
    d77cf60
    64efa89
    345fd47
    d07754e
    ce5d28f
    60c614b
  5. added a commit that references this issue on Jan 5, 2026
    674e321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgovmcp

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions