Skip to content

Bug: downloaded media files deleted before async consumer reads them #619

@ex-takashima

Description

@ex-takashima

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

  1. Remove the premature defer os.Remove() from the four affected channel handlers.
  2. Introduce a background MediaCleaner that 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions