refactor(agent): remove deprecated model fetcher cache (#3433)
Co-authored-by: Kandev Agent <agent@kandev.dev>
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/kandev/kandev/internal/agent/managedruntime"
|
||||
"github.com/kandev/kandev/internal/agent/mcpconfig"
|
||||
"github.com/kandev/kandev/internal/agent/registry"
|
||||
"github.com/kandev/kandev/internal/agent/settings/modelfetcher"
|
||||
"github.com/kandev/kandev/internal/agent/settings/store"
|
||||
"github.com/kandev/kandev/internal/common/logger"
|
||||
"github.com/kandev/kandev/internal/secrets"
|
||||
@@ -71,7 +70,6 @@ type Controller struct {
|
||||
automationDeps AutomationDependencyChecker
|
||||
utilityDeps UtilityDependencyChecker
|
||||
mcpService *mcpconfig.Service
|
||||
modelCache *modelfetcher.Cache
|
||||
hostUtility hostUtilityProvider
|
||||
jobStore *JobStore
|
||||
updateJobStore *AgentUpdateJobStore
|
||||
@@ -256,7 +254,6 @@ func NewController(repo store.Repository, discoveryRegistry *discovery.Registry,
|
||||
agentRegistry: agentRegistry,
|
||||
sessionChecker: sessionChecker,
|
||||
mcpService: mcpconfig.NewService(repo),
|
||||
modelCache: modelfetcher.NewCache(),
|
||||
logger: log.WithFields(zap.String("component", "agent-settings-controller")),
|
||||
runtimeUpdateStatusCache: make(map[string]runtimeUpdateStatusCacheEntry),
|
||||
runtimeUpdateStatusNow: time.Now,
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/kandev/kandev/internal/agent/managedruntime"
|
||||
"github.com/kandev/kandev/internal/agent/registry"
|
||||
"github.com/kandev/kandev/internal/agent/settings/dto"
|
||||
"github.com/kandev/kandev/internal/agent/settings/modelfetcher"
|
||||
"github.com/kandev/kandev/internal/agent/usage"
|
||||
"github.com/kandev/kandev/internal/common/logger"
|
||||
)
|
||||
@@ -112,7 +111,6 @@ func newTestController(agentList map[string]agents.Agent) *Controller {
|
||||
}
|
||||
return &Controller{
|
||||
agentRegistry: reg,
|
||||
modelCache: modelfetcher.NewCache(),
|
||||
logger: log,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
package modelfetcher
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Model is a simple descriptor retained here so CacheEntry can remain typed.
|
||||
// Static agent model lists have been removed — models now come from the host
|
||||
// utility capability cache. This package is deprecated and kept only as a
|
||||
// shim for legacy callers until they migrate.
|
||||
type Model struct {
|
||||
ID string
|
||||
Name string
|
||||
Description string
|
||||
IsDefault bool
|
||||
}
|
||||
|
||||
const (
|
||||
defaultTTL = 10 * time.Second
|
||||
maxCacheAge = 1 * time.Minute
|
||||
)
|
||||
|
||||
// CacheEntry holds cached model data for an agent
|
||||
type CacheEntry struct {
|
||||
Models []Model
|
||||
CachedAt time.Time
|
||||
ExpiresAt time.Time
|
||||
Error error
|
||||
}
|
||||
|
||||
// IsValid returns true if the cache entry is still valid
|
||||
func (e *CacheEntry) IsValid() bool {
|
||||
return time.Now().Before(e.ExpiresAt) && e.Error == nil
|
||||
}
|
||||
|
||||
// IsStale returns true if the cache entry is stale but still usable
|
||||
func (e *CacheEntry) IsStale() bool {
|
||||
now := time.Now()
|
||||
return now.After(e.ExpiresAt) && now.Before(e.CachedAt.Add(maxCacheAge))
|
||||
}
|
||||
|
||||
// Cache provides thread-safe caching for dynamic models
|
||||
type Cache struct {
|
||||
entries map[string]*CacheEntry
|
||||
mu sync.RWMutex
|
||||
ttl time.Duration
|
||||
}
|
||||
|
||||
// NewCache creates a new model cache
|
||||
func NewCache() *Cache {
|
||||
return &Cache{
|
||||
entries: make(map[string]*CacheEntry),
|
||||
ttl: defaultTTL,
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns the cached models for an agent if available
|
||||
func (c *Cache) Get(agentName string) (*CacheEntry, bool) {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
entry, exists := c.entries[agentName]
|
||||
if !exists {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return entry, true
|
||||
}
|
||||
|
||||
// Set caches the models for an agent
|
||||
func (c *Cache) Set(agentName string, models []Model, err error) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
now := time.Now()
|
||||
c.entries[agentName] = &CacheEntry{
|
||||
Models: models,
|
||||
CachedAt: now,
|
||||
ExpiresAt: now.Add(c.ttl),
|
||||
Error: err,
|
||||
}
|
||||
}
|
||||
|
||||
// Invalidate removes the cache entry for an agent
|
||||
func (c *Cache) Invalidate(agentName string) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
delete(c.entries, agentName)
|
||||
}
|
||||
|
||||
// Clear removes all cache entries
|
||||
func (c *Cache) Clear() {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
c.entries = make(map[string]*CacheEntry)
|
||||
}
|
||||
@@ -13,18 +13,6 @@
|
||||
"removal_condition": "All callers import the owning agents package and no registry compatibility type alias remains.",
|
||||
"target_removal_date": "2027-02-01"
|
||||
},
|
||||
{
|
||||
"id": "agent-model-fetcher-shim",
|
||||
"locator": {
|
||||
"path": "apps/backend/internal/agent/settings/modelfetcher/cache.go",
|
||||
"marker": "// shim for legacy callers until they migrate."
|
||||
},
|
||||
"reason": "Legacy callers still require the old typed cache while model discovery moves to the host utility capability cache.",
|
||||
"owner": "backend agent-settings maintainers",
|
||||
"introduced_on": "2026-04-15",
|
||||
"removal_condition": "No production package imports internal/agent/settings/modelfetcher and the shim package can be deleted.",
|
||||
"target_removal_date": "2027-02-01"
|
||||
},
|
||||
{
|
||||
"id": "passthrough-stdin-writes-legacy-view",
|
||||
"locator": {
|
||||
|
||||
Reference in New Issue
Block a user