#8782: fix: resolve relative paths in MEDIA: directive
agents
stale
Cluster:
Media Handling Improvements
## Summary
Fix `MEDIA:` directives with relative paths (e.g., `MEDIA:./image.jpg`) failing silently on Telegram and other channels.
## Root Cause
The agent runner in `attempt.ts` temporarily changes `process.cwd()` to the workspace during execution:
```typescript
process.chdir(effectiveWorkspace);
try {
// agent runs here, produces output with MEDIA:./image.jpg
} finally {
process.chdir(prevCwd); // cwd restored BEFORE delivery
}
```
However, reply delivery is **asynchronous** — it happens via a promise chain in `reply-dispatcher.ts`:
```typescript
sendChain = sendChain.then(async () => {
await options.deliver(normalized, { kind }); // runs LATER
});
```
So by the time `loadWebMedia("./image.jpg")` is called, `process.cwd()` has already been restored to its original value, causing ENOENT:
```
telegram final reply failed: Error: ENOENT: no such file or directory, open './avatars/default.jpg'
```
## Solution
Resolve relative paths to absolute paths **immediately during directive parsing**, while `process.cwd()` is still the workspace directory.
```typescript
function resolveMediaPath(mediaUrl: string): string {
if (mediaUrl.startsWith("./")) {
return path.resolve(mediaUrl); // resolve NOW while cwd is correct
}
return mediaUrl;
}
```
## Changes
- `src/auto-reply/reply/streaming-directives.ts`: Resolve relative paths in `parseChunk()` before returning
- `src/auto-reply/reply/reply-directives.ts`: Resolve relative paths in `parseReplyDirectives()` before returning
Fixes #8759
Most Similar PRs
#9817: fix(media): resolve relative paths before reading local files (#8759)
by lailoo · 2026-02-05
76.3%
#22401: fix: resolve relative media paths against workspace and fix /tmp on...
by derrickburns · 2026-02-21
72.5%
#20488: fix(discord): pass mediaLocalRoots to sendMessageDiscord
by olyashok · 2026-02-19
71.1%
#20186: fix(discord): thread mediaLocalRoots through reply delivery path
by pvoo · 2026-02-18
70.5%
#19171: fix(feishu): pass mediaLocalRoots to sendMediaFeishu for agent-scop...
by whiskyboy · 2026-02-17
69.9%
#20294: fix(message): thread mediaLocalRoots through channel plugin dispatch
by odrobnik · 2026-02-18
69.7%
#23627: fix(telegram,feishu): pass mediaLocalRoots through channel action a...
by rockkoca · 2026-02-22
68.2%
#14794: fix: parse inline MEDIA: tokens in agent replies
by explainanalyze · 2026-02-12
68.1%
#18811: fix(media): require file extension for ambiguous MEDIA: path detection
by aldoeliacim · 2026-02-17
67.5%
#11990: Fix media understanding file path suppression + image tool bare-ID ...
by robertbergman2 · 2026-02-08
66.5%