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
This commit is contained in:
Harshit Shrivastav 2026-03-26 12:55:46 +05:30 committed by GitHub
parent 9d6a445bb1
commit 3c2ecb2eda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -480,6 +480,8 @@ func restartServices(
}
fmt.Println(" ✓ Heartbeat service restarted")
if runningServices.MediaStore == nil {
runningServices.MediaStore = media.NewFileMediaStoreWithCleanup(media.MediaCleanerConfig{
Enabled: cfg.Tools.MediaCleanup.Enabled,
MaxAge: time.Duration(cfg.Tools.MediaCleanup.MaxAge) * time.Minute,
@ -488,6 +490,7 @@ func restartServices(
if fms, ok := runningServices.MediaStore.(*media.FileMediaStore); ok {
fms.Start()
}
}
al.SetMediaStore(runningServices.MediaStore)
runningServices.ChannelManager, err = channels.NewManager(cfg, msgBus, runningServices.MediaStore)