Skip to content

fix(matrix): download non-image MXC files and recover text MIME type - #3495

Closed
dlkakbs wants to merge 1 commit into
NousResearch:mainfrom
dlkakbs:fix/matrix-gateway-runtime-issues
Closed

fix(matrix): download non-image MXC files and recover text MIME type #3495
dlkakbs wants to merge 1 commit into
NousResearch:mainfrom
dlkakbs:fix/matrix-gateway-runtime-issues

Conversation

@dlkakbs

@dlkakbs dlkakbs commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes two runtime bugs in the Matrix gateway that occur after a successful setup.

  1. Non-image MXC downloads failing — the download block in gateway/platforms/matrix.py was gated on msg_type == MessageType.PHOTO, so PDFs, text files, and other non-image uploads were only passed as an
    authenticated MXC HTTP URL that the agent cannot access. All file types are now downloaded via self._client.download() and cached locally.
  2. Text files not injected into agent context — gateway/run.py only detected text files when the MIME type was already text/*. When MIME detection returned application/octet-stream (common for Matrix
    uploads), the file fell through to the generic "document saved at" branch and its content was never injected. A fallback now uses file extension and mimetypes.guess_type to recover the correct type.

NOT: The third (missing "matrix" entry in PLATFORMS) was already resolved upstream.

Related Issue

Fixes #3487

Type of Change

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

Changes Made

  • gateway/platforms/matrix.py — extended MXC download block to cover all file types; non-image files cached via cache_document_from_bytes
  • gateway/run.py — added extension-based and mimetypes.guess_type fallback when media_type is empty or application/octet-stream

Checklist

…allback

- Add "matrix" entry to PLATFORMS dict (hermes_cli/tools_config.py) — missing
  key caused KeyError at runtime whenever the Matrix platform was referenced
- Extend MXC download logic to cover all file types, not just images; non-image
  files are now cached via cache_document_from_bytes so the agent can read them
  (gateway/platforms/matrix.py)
- Add extension/mimetypes fallback when media_type is empty or
  application/octet-stream so text files (.txt, .md, .csv …) are correctly
  injected into agent context instead of silently falling through to the generic
  "document saved at" branch (gateway/run.py)

Fixes NousResearch#3487
@dlkakbs
dlkakbs force-pushed the fix/matrix-gateway-runtime-issues branch from 050661d to b56d27a Compare March 28, 2026 06:45
@dlkakbs dlkakbs changed the title fix/matrix-gateway-runtime-issue fix(matrix): download non-image MXC files and recover text MIME type Mar 28, 2026
teknium1 pushed a commit that referenced this pull request Apr 5, 2026
Cherry-picked run.py portion from PR #3495 by dlkakbs.
When Matrix sends non-image files (text, YAML, JSON, etc.), the MIME
type may be empty or application/octet-stream. Falls back to
extension-based detection so text files are properly injected into
agent context.
@teknium1

teknium1 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

The gateway/run.py MIME fallback fix from your PR was cherry-picked into PR #5271 with your authorship preserved. The matrix.py portion was covered by #3140's more comprehensive encrypted media handling. Thanks!

@teknium1 teknium1 closed this Apr 5, 2026
teknium1 pushed a commit that referenced this pull request Apr 5, 2026
Cherry-picked run.py portion from PR #3495 by dlkakbs.
When Matrix sends non-image files (text, YAML, JSON, etc.), the MIME
type may be empty or application/octet-stream. Falls back to
extension-based detection so text files are properly injected into
agent context.
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
Cherry-picked run.py portion from PR NousResearch#3495 by dlkakbs.
When Matrix sends non-image files (text, YAML, JSON, etc.), the MIME
type may be empty or application/octet-stream. Falls back to
extension-based detection so text files are properly injected into
agent context.
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
Cherry-picked run.py portion from PR NousResearch#3495 by dlkakbs.
When Matrix sends non-image files (text, YAML, JSON, etc.), the MIME
type may be empty or application/octet-stream. Falls back to
extension-based detection so text files are properly injected into
agent context.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
Cherry-picked run.py portion from PR NousResearch#3495 by dlkakbs.
When Matrix sends non-image files (text, YAML, JSON, etc.), the MIME
type may be empty or application/octet-stream. Falls back to
extension-based detection so text files are properly injected into
agent context.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Cherry-picked run.py portion from PR NousResearch#3495 by dlkakbs.
When Matrix sends non-image files (text, YAML, JSON, etc.), the MIME
type may be empty or application/octet-stream. Falls back to
extension-based detection so text files are properly injected into
agent context.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Cherry-picked run.py portion from PR NousResearch#3495 by dlkakbs.
When Matrix sends non-image files (text, YAML, JSON, etc.), the MIME
type may be empty or application/octet-stream. Falls back to
extension-based detection so text files are properly injected into
agent context.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Matrix gateway runtime issues after setup (missing PLATFORMS entry, non-image file downloads, text-file enrichment)

2 participants