From af40578d5baffb5460101b0a3381a035089930ab Mon Sep 17 00:00:00 2001 From: ZanzyTHEbar Date: Sun, 22 Feb 2026 22:51:49 +0000 Subject: [PATCH] feat(agent): add InvalidateBootstrapCache for IdentitySync file changes ContextBuilder.InvalidateBootstrapCache allows IdentitySync to force reload of bootstrap files when identity docs change on disk. --- pkg/agent/context.go | 8 ++++++++ pkg/sync/identity.go | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/agent/context.go b/pkg/agent/context.go index 171d50cb0..92ab75483 100644 --- a/pkg/agent/context.go +++ b/pkg/agent/context.go @@ -404,6 +404,14 @@ func (cb *ContextBuilder) cachedBootstrapFiles() string { return cb.bootstrapCache } +// InvalidateBootstrapCache forces the next BuildSystemPrompt to reload +// bootstrap files from the delegate. Called by IdentitySync when files change. +func (cb *ContextBuilder) InvalidateBootstrapCache() { + cb.cacheMu.Lock() + cb.bootstrapCache = "" + cb.cacheMu.Unlock() +} + func (cb *ContextBuilder) LoadBootstrapFiles() string { if cb.delegate == nil { return "" diff --git a/pkg/sync/identity.go b/pkg/sync/identity.go index 7d89ab230..6c8cd4867 100644 --- a/pkg/sync/identity.go +++ b/pkg/sync/identity.go @@ -49,6 +49,10 @@ type IdentitySync struct { agentID string store DocumentStore + // OnChange is called after CheckAndSync detects and persists file changes. + // Use it to invalidate downstream caches (e.g., bootstrap prompt cache). + OnChange func() + watcher *fsnotify.Watcher cancel context.CancelFunc wg sync.WaitGroup @@ -128,6 +132,9 @@ func (s *IdentitySync) CheckAndSync(ctx context.Context) error { now := time.Now() s.lastSync.Store(now.UnixNano()) _ = s.store.UpsertKV(ctx, s.agentID, kvLastSyncKey, now.Format(time.RFC3339Nano)) + if s.OnChange != nil { + s.OnChange() + } } return nil }