#17630: Fix LINE media temp files accumulating in os.tmpdir
commands
agents
stale
size: S
trusted-contributor
Cluster:
Media File Management Fixes
## Description
`downloadLineMedia` writes received media to `os.tmpdir()` but never cleans up the files. On a busy LINE bot, this causes unbounded temp file growth until the OS reboots or tmpdir is manually purged.
## Fix
Schedule a best-effort `unlink` 5 minutes after download — enough time for the media pipeline to process the file. The timer is `unref`'d so it doesn't keep the process alive.
## Tests
Added `src/line/download-cleanup.test.ts` verifying:
- Temp files are created with correct prefix
- Cleanup removes the file
- Cleanup handles non-existent files gracefully
## AI Transparency
- **Assisted by**: OpenClaw Agent (Claude 3.5 Sonnet / Opus)
- **Testing level**: Fully tested with new unit tests (`src/line/download-cleanup.test.ts`)
- **Prompt strategy**: Self-correction loop based on codebase analysis
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added automatic cleanup of temporary LINE media files to prevent unbounded accumulation in `os.tmpdir()`. Files are scheduled for deletion 5 minutes after download using an unref'd timer that won't block process exit.
The implementation addresses the core issue of temp file accumulation, but the previous comment about timing risks remains valid — the fixed 5-minute delay could delete files mid-processing if media understanding operations (vision models, audio transcription) exceed this window.
<h3>Confidence Score: 3/5</h3>
- Safe to merge with acceptable risk, but the timing issue noted in previous comments should be considered for follow-up
- The cleanup mechanism is correctly implemented with proper error handling and unref'd timers. However, the fixed 5-minute delay introduces a race condition risk already identified in previous review threads. The PR solves the immediate problem (unbounded temp file growth) but may create intermittent failures under heavy load or slow processing.
- No additional files require special attention beyond what was already flagged in previous threads
<sub>Last reviewed commit: 61f490b</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#20022: Fix temp file leak on media download failure
by Clawborn · 2026-02-18
79.9%
#17816: Fix media store cleanup ignoring subdirectories (e.g. inbound)
by Clawborn · 2026-02-16
77.9%
#17456: fix(test): stabilize media root guard test against tmpdir HOME overlap
by widingmarcus-cyber · 2026-02-15
74.0%
#11443: LINE: fix buffer guards in detectContentType + add tests
by MdRahmatUllah · 2026-02-07
73.2%
#7400: media: allow temp-dir MEDIA paths for tool outputs
by grammakov · 2026-02-02
73.0%
#14794: fix: parse inline MEDIA: tokens in agent replies
by explainanalyze · 2026-02-12
70.6%
#18811: fix(media): require file extension for ambiguous MEDIA: path detection
by aldoeliacim · 2026-02-17
70.1%
#6827: fix: cron scheduler cleanup orphaned .tmp files on startup
by fatelei · 2026-02-02
69.8%
#22401: fix: resolve relative media paths against workspace and fix /tmp on...
by derrickburns · 2026-02-21
69.6%
#23621: fix(LINE): keep startAccount promise alive to prevent auto-restart ...
by ttakanawa · 2026-02-22
69.3%