-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Bug: downloaded media files deleted before async consumer reads them #619
Description
Description
Channel handlers (telegram.go, line.go, slack.go, onebot.go) download media files to a local temp directory and then call HandleMessage, which publishes the message (including local file paths) to an async message bus via PublishInbound. However, each handler also has a defer os.Remove() that deletes those files when the handler function returns — before the agent loop goroutine has a chance to read them.
This race condition was originally identified by @DevEverything01 in #543.
Impact
Voice transcription, image analysis, and document processing via the agent loop silently fail because the files no longer exist by the time they are accessed.
Proposed Fix
- Remove the premature
defer os.Remove()from the four affected channel handlers. - Introduce a background
MediaCleanerthat periodically scans the temp media directory and removes files older than 30 minutes, preventing unbounded temp file accumulation.
Note: discord.go is not affected — it processes voice files synchronously before returning, so there is no race condition.