From 3c2ecb2eda37c30b1a7a549b62f1ad49caf2d566 Mon Sep 17 00:00:00 2001 From: Harshit Shrivastav Date: Thu, 26 Mar 2026 12:55:46 +0530 Subject: [PATCH] preserve media store across config reloads ## Bug Fix Prevents loss of uploaded file references when using `/reload` command. ## Problem When calling `/reload`, a new `FileMediaStore` was created with an empty `refs` map, causing all previously uploaded files to become inaccessible with error: media store: unknown ref: media://... ## Solution Reuse the existing `MediaStore` instance instead of recreating it on every reload. The media store is now only created once on initial startup. ## Changes - `pkg/gateway/gateway.go` (line 468): Wrap media store creation in `if runningServices.MediaStore == nil` ## Testing 1. Start picoclaw with Telegram enabled 2. Upload a file to the bot 3. Run `/reload` command 4. Ask bot to read the previously uploaded file 5. File should now be accessible (previously would fail with "unknown ref" error) ## Impact - Users can now safely use `/reload` without breaking file uploads - No breaking changes - Backward compatible --- pkg/gateway/gateway.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index 03d7dfe0c..13e68cec0 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -480,14 +480,17 @@ func restartServices( } fmt.Println(" ✓ Heartbeat service restarted") - runningServices.MediaStore = media.NewFileMediaStoreWithCleanup(media.MediaCleanerConfig{ - Enabled: cfg.Tools.MediaCleanup.Enabled, - MaxAge: time.Duration(cfg.Tools.MediaCleanup.MaxAge) * time.Minute, - Interval: time.Duration(cfg.Tools.MediaCleanup.Interval) * time.Minute, - }) - if fms, ok := runningServices.MediaStore.(*media.FileMediaStore); ok { - fms.Start() - } + + if runningServices.MediaStore == nil { + runningServices.MediaStore = media.NewFileMediaStoreWithCleanup(media.MediaCleanerConfig{ + Enabled: cfg.Tools.MediaCleanup.Enabled, + MaxAge: time.Duration(cfg.Tools.MediaCleanup.MaxAge) * time.Minute, + Interval: time.Duration(cfg.Tools.MediaCleanup.Interval) * time.Minute, + }) + if fms, ok := runningServices.MediaStore.(*media.FileMediaStore); ok { + fms.Start() + } +} al.SetMediaStore(runningServices.MediaStore) runningServices.ChannelManager, err = channels.NewManager(cfg, msgBus, runningServices.MediaStore)