← Back to PRs

#8782: fix: resolve relative paths in MEDIA: directive

by phuctm97 open 2026-02-04 11:32 View on GitHub →
agents stale
## 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