fix: remove premature media file cleanup in channel handlers#543
Open
DevEverything01 wants to merge 3 commits intosipeed:mainfrom
Open
fix: remove premature media file cleanup in channel handlers#543DevEverything01 wants to merge 3 commits intosipeed:mainfrom
DevEverything01 wants to merge 3 commits intosipeed:mainfrom
Conversation
Media files (photos, voice, audio, documents) downloaded by channel handlers were immediately deleted via defer when handleMessage returned. However, HandleMessage publishes to an async message bus, so the agent goroutine would attempt to access already-deleted files. Remove the eager defer cleanup from telegram, discord, slack, and line channels. Temp files in os.TempDir()/picoclaw_media/ are managed by the OS temp directory lifecycle. Fixes media/voice/document processing being non-functional across all affected channels.
- Remove defer cleanup of LocalFiles in onebot channel handler, same async race condition as the other channels. - Remove the now-unused LocalFiles field from parseMessageResult. - Add downloaded audio files to mediaPaths in discord channel so they are tracked (previously only tracked via the now-removed localFiles).
This was referenced Feb 22, 2026
Contributor
|
Thanks for identifying this race condition — the analysis in the PR description is spot on. 👍 I ran into the same issue and built on your findings in #620, which takes a slightly different approach: instead of only removing the Would love to hear your thoughts! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Media files (photos, voice messages, audio, documents) downloaded by channel handlers are immediately deleted via
deferwhenhandleMessagereturns. However,HandleMessagepublishes the message (including media file paths) to an async message bus (PublishInbound), and the agent consumes it in a separate goroutine.Result: By the time the agent goroutine tries to access the media files, they have already been deleted. Voice/image/document processing is effectively non-functional.
Root Cause
Fix
Remove the premature
defercleanup from all 4 affected channels:pkg/channels/telegram.gopkg/channels/discord.gopkg/channels/slack.gopkg/channels/line.goMedia files live in
os.TempDir()/picoclaw_media/with UUID-prefixed names, managed by the OS temp directory lifecycle.Verification
go build ./...✅go test ./pkg/channels/...✅go vet ./...✅