Skip to content

fix(matrix): return SendResult instead of sending error to main room on missing file#41891

Open
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/matrix-file-not-found-thread-routing
Open

fix(matrix): return SendResult instead of sending error to main room on missing file#41891
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/matrix-file-not-found-thread-routing

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes _send_local_file() in the Matrix adapter to return SendResult(success=False) instead of sending an error message to the main room when a file is not found. Previously, the error message bypassed thread routing (missing metadata parameter), causing confusing messages in the wrong room.

Related Issue

Fixes #32503

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/platforms/matrix.py: Replace self.send() call in file-not-found path with logger.warning() + SendResult(success=False, error=...), matching Slack's pattern for missing files
  • tests/gateway/test_matrix.py: Add TestSendLocalFileNotFound with 3 tests — missing file returns failure, no message leaked to any room, existing file still uploads correctly

How to Test

  1. Run pytest tests/gateway/test_matrix.py::TestSendLocalFileNotFound -v — all 3 tests pass
  2. Configure Matrix gateway, send a message with MEDIA:/nonexistent/path/file.png in a thread — verify no error message appears in the main room
  3. Check gateway logs for Matrix: MEDIA file not found, skipping: /nonexistent/path/file.png warning

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: gateway/platforms/matrix.py::_send_local_file (callers: 4 within same adapter, flows: media delivery)
  • Blast radius: LOW — single method in Matrix adapter only; Slack adapter already uses this pattern
  • Related patterns: Slack returns SendResult(success=False, error=...) for missing files at lines 1725/1823/1848; this PR aligns Matrix with that convention

…on missing file

When _send_local_file() encounters a missing file, it currently calls
self.send() without the metadata parameter, causing the error message
to appear in the main room instead of the intended thread.

Replace the error-message send with a logger.warning + SendResult(success=False),
matching Slack's pattern for missing files. This avoids confusing user-visible
errors in the wrong room while still surfacing the issue in logs and the
return value.

Fixes NousResearch#32503
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/matrix Matrix adapter (E2EE) labels Jun 8, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Analysis

Correctness

  • The old code called self.send() recursively with an error message when a file was not found, which could leak error messages to the wrong room and cause confusion.
  • The fix returns SendResult(success=False, error=...) which properly propagates the error without side effects.
  • The logger.warning provides visibility for debugging without sending to a room.

Testing

  • Two tests verify: (1) SendResult(success=False) is returned and send() is NOT called, (2) same behavior without metadata.

Recommendation
Approve — clean fix with good test coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists platform/matrix Matrix adapter (E2EE) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MEDIA file not found sends message to main room instead of thread

3 participants