mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-20 02:17:24 +00:00
fix: invalidate ContextFileInterceptor cache on agents.files.set (#29)
* fix: invalidate ContextFileInterceptor cache on agents.files.set When agents.files.set (or agents.update) wrote context files to agent_context_files in Postgres, only the agent router cache was invalidated via agents.InvalidateAgent(). The ContextFileInterceptor maintains its own separate in-memory cache with a 5-minute TTL which was never cleared, causing the agent to serve stale file content (e.g. wizard-written SOUL.md/IDENTITY.md) for up to 5 minutes. Fix: inject *tools.ContextFileInterceptor into AgentsMethods and call intc.InvalidateAgent(ag.ID) immediately after each successful DB write in handleFilesSet and handleUpdate. Wire path: wireManagedExtras now returns the interceptor it creates; gateway.go captures it and passes it through registerAllMethods → NewAgentsMethods. The interceptor is nil in standalone mode so all nil guards are in place. * test: add unit tests for ContextFileInterceptor cache invalidation Covers: - Cache hit: second read does not call store again - InvalidateAgent clears agent cache → fresh content served from store - InvalidateAgent clears user cache for that agent - InvalidateAgent does not affect other agents' cache entries - TTL expiry causes re-fetch from store
This commit is contained in:
1 parent
82ce20a029
commit
8d513763f2
6 files changed
+288
-14
No files matched your search
@@ -12,12 +12,12 @@ import (
|
||||
"github.com/nextlevelbuilder/goclaw/internal/tools"
|
||||
)
|
||||
|
||||
func registerAllMethods(server *gateway.Server, agents *agent.Router, sessStore store.SessionStore, cronStore store.CronStore, pairingStore store.PairingStore, cfg *config.Config, cfgPath, workspace, dataDir string, msgBus *bus.MessageBus, execApprovalMgr *tools.ExecApprovalManager, agentStore store.AgentStore, isManaged bool, skillStore store.SkillStore, configSecretsStore store.ConfigSecretsStore, teamStore store.TeamStore) *methods.PairingMethods {
|
||||
func registerAllMethods(server *gateway.Server, agents *agent.Router, sessStore store.SessionStore, cronStore store.CronStore, pairingStore store.PairingStore, cfg *config.Config, cfgPath, workspace, dataDir string, msgBus *bus.MessageBus, execApprovalMgr *tools.ExecApprovalManager, agentStore store.AgentStore, isManaged bool, skillStore store.SkillStore, configSecretsStore store.ConfigSecretsStore, teamStore store.TeamStore, contextFileInterceptor *tools.ContextFileInterceptor) *methods.PairingMethods {
|
||||
router := server.Router()
|
||||
|
||||
// Phase 1: Core methods
|
||||
methods.NewChatMethods(agents, sessStore, isManaged, server.RateLimiter()).Register(router)
|
||||
methods.NewAgentsMethods(agents, cfg, cfgPath, workspace, agentStore, isManaged).Register(router)
|
||||
methods.NewAgentsMethods(agents, cfg, cfgPath, workspace, agentStore, isManaged, contextFileInterceptor).Register(router)
|
||||
methods.NewSessionsMethods(sessStore).Register(router)
|
||||
methods.NewConfigMethods(cfg, cfgPath, isManaged, configSecretsStore).Register(router)
|
||||
|
||||
|
||||
Reference in new issue
Block a user