#11990: Fix media understanding file path suppression + image tool bare-ID validation
channel: voice-call
gateway
commands
agents
stale
size: M
Cluster:
Media Handling Improvements
## Summary
- **Problem:** When media understanding pre-analyzes an image, `buildInboundMediaNote` fully strips the suppressed entry, removing the file path from the agent's context. If the LLM later needs the original image for follow-up analysis, it has no way to reference the file. It may then try using a message ID as an image reference, causing a noisy ENOENT error.
- **Why it matters:** Agents lose the ability to do follow-up image analysis on pre-processed attachments, and bare numeric inputs cause confusing filesystem errors.
- **What changed:** Suppressed media entries now render as `[media source: /path/to/file]` instead of being fully filtered. The image tool now validates bare numeric strings and returns a graceful error.
- **What did NOT change (scope boundary):** No changes to media understanding itself, transcription flow, or any other channel-specific logic.
## Change Type (select all)
- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Docs
- [ ] Security hardening
- [ ] Chore/infra
## Scope (select all touched areas)
- [ ] Gateway / orchestration
- [x] Skills / tool execution
- [ ] Auth / tokens
- [ ] Memory / storage
- [ ] Integrations
- [ ] API / contracts
- [ ] UI / DX
- [ ] CI/CD / infra
## Linked Issue/PR
- Closes #11989
## User-visible / Behavior Changes
- Suppressed media attachments now appear as `[media source: /path/to/file]` in the agent context instead of being fully removed, allowing follow-up image tool calls.
- The image tool now returns a clear validation error when given a bare numeric string (e.g., a Discord message ID) instead of an ENOENT filesystem error.
## Security Impact (required)
- New permissions/capabilities? No
- Secrets/tokens handling changed? No
- New/changed network calls? No
- Command/tool execution surface changed? No — the image tool already validated inputs; this adds an earlier guard for a specific invalid input pattern.
- Data access scope changed? No
## Repro + Verification
### Environment
- OS: Windows 11
- Runtime/container: Node.js
- Model/provider: Any
- Integration/channel (if any): Discord (or any channel with media understanding)
- Relevant config (redacted): Default media understanding enabled
### Steps
1. Send an image via Discord that triggers media understanding
2. Media understanding pre-analyzes the image and suppresses the attachment
3. Ask the agent a follow-up question that requires re-examining the original image
### Expected
- The agent context includes `[media source: /path/to/file]` so the image tool can reference the original file
- Bare numeric strings passed to the image tool return a clear validation error
### Actual (before fix)
- `buildInboundMediaNote` fully filters out suppressed entries, removing the file path entirely
- The image tool attempts `fs.readFile` on bare numeric strings, producing a noisy ENOENT error
## Evidence
- [x] Failing test/log before + passing after
- [ ] Trace/log snippets
- [ ] Screenshot/recording
- [ ] Perf numbers (if relevant)
Tests added/updated:
- `src/auto-reply/media-note.test.ts` — updated 2 existing tests, added 1 new test for all-suppressed case
- `src/agents/tools/image-tool.e2e.test.ts` — added test for bare numeric string validation
## Human Verification (required)
- Verified scenarios: Ran `vitest run src/auto-reply/media-note.test.ts` (6 passing) and `vitest run src/agents/tools/image-tool.e2e.test.ts` (15 passing). Typecheck passes.
- Edge cases checked: All attachments suppressed (no unsuppressed entries), mixed suppressed/unsuppressed, transcribed audio not emitting media source lines, single unsuppressed entry formatting.
- What you did **not** verify: Live end-to-end test with an actual Discord channel and media understanding provider.
## Compatibility / Migration
- Backward compatible? Yes
- Config/env changes? No
- Migration needed? No
## Failure Recovery (if this breaks)
- How to disable/revert this change quickly: Revert this PR
- Files/config to restore: `src/auto-reply/media-note.ts`, `src/agents/tools/image-tool.ts`
- Known bad symptoms reviewers should watch for: Media source lines appearing unexpectedly in agent context, or image tool rejecting valid numeric file names (unlikely — real image files have extensions)
## Risks and Mitigations
None
Most Similar PRs
#23249: fix(message): pass agentId through gateway RPC for media root resol...
by SidQin-cyber · 2026-02-22
75.3%
#23272: fix(whatsapp): forward mediaLocalRoots in extension plugin sendMedi...
by SidQin-cyber · 2026-02-22
73.3%
#20488: fix(discord): pass mediaLocalRoots to sendMessageDiscord
by olyashok · 2026-02-19
72.9%
#20186: fix(discord): thread mediaLocalRoots through reply delivery path
by pvoo · 2026-02-18
72.0%
#22088: fix(web): sanitize media errors to prevent PII leak
by ashiabbott · 2026-02-20
71.6%
#20735: fix: skip auto-attaching tool MEDIA: paths already sent via message t…
by anillBhoi · 2026-02-19
71.4%
#19868: fix: prevent media token regex from matching markdown bold text
by sanketgautam · 2026-02-18
71.2%
#23627: fix(telegram,feishu): pass mediaLocalRoots through channel action a...
by rockkoca · 2026-02-22
71.0%
#18811: fix(media): require file extension for ambiguous MEDIA: path detection
by aldoeliacim · 2026-02-17
71.0%
#19399: telegram: fix MEDIA false positives and partial final drop
by HOYALIM · 2026-02-17
70.9%