Skip to content

fix(matrix): Add file size to file upload, otherwise Synapse refuses media uploads (voice messages, etc.) - #4343

Closed
pjay-io wants to merge 2 commits into
NousResearch:mainfrom
pjay-io:main
Closed

fix(matrix): Add file size to file upload, otherwise Synapse refuses media uploads (voice messages, etc.)#4343
pjay-io wants to merge 2 commits into
NousResearch:mainfrom
pjay-io:main

Conversation

@pjay-io

@pjay-io pjay-io commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes media uploads to Synapse homeservers by passing filesize to nio.upload().

Matrix Synapse requires a Content-Length header on media uploads. The nio library only sets this header when filesize is explicitly passed to upload(). Without it, nio uses chunked transfer encoding which Synapse rejects, causing all media uploads (images, audio, video, files) to fail with "Request must specify a Content-Length". This also prevents voice message replies from working, since TTS audio files cannot be uploaded to Matrix.

Related Issue

Fixes #4339

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Security fix
  • Documentation update
  • Tests (adding or improving test coverage)
  • Refactor (no behavior change)
  • New skill (bundled or hub)

Changes Made

  • gateway/platforms/matrix.py: Added filesize=len(data) to the nio.upload() call in _upload_and_send(). This ensures the Content-Length header is set on uploads, which Synapse requires.

How to Test

  1. Configure Hermes with a Synapse homeserver
  2. Send an image or file via the Matrix channel — verify it uploads and sends without error
  3. Send a voice message — verify Hermes can reply with a TTS audio file uploaded as a native voice bubble (MSC3245)

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: Linux (Synapse homeserver)

Documentation & Housekeeping

  • N/A — no documentation changes required
  • N/A — no config key changes
  • N/A — no architecture changes

Screenshots / Logs

# Before (errors.log):
2026-03-30 22:34:51,939 WARNING nio.responses: Error validating response: 'content_uri' is a required property
2026-03-30 22:34:51,939 ERROR gateway.platforms.matrix: Matrix: upload failed: Request must specify a Content-Length

# After: uploads succeed with correct Content-Length header

teknium1 pushed a commit that referenced this pull request Apr 5, 2026
Cherry-picked from PR #4343 by pjay-io.
Synapse rejects chunked uploads without Content-Length. Adding
filesize=len(data) ensures the upload includes proper sizing.
@teknium1

teknium1 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #5271. Your commit was cherry-picked with authorship preserved. Thanks for the Synapse fix!

@teknium1 teknium1 closed this Apr 5, 2026
teknium1 pushed a commit that referenced this pull request Apr 5, 2026
Cherry-picked from PR #4343 by pjay-io.
Synapse rejects chunked uploads without Content-Length. Adding
filesize=len(data) ensures the upload includes proper sizing.
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
Cherry-picked from PR NousResearch#4343 by pjay-io.
Synapse rejects chunked uploads without Content-Length. Adding
filesize=len(data) ensures the upload includes proper sizing.
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
Cherry-picked from PR NousResearch#4343 by pjay-io.
Synapse rejects chunked uploads without Content-Length. Adding
filesize=len(data) ensures the upload includes proper sizing.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
Cherry-picked from PR NousResearch#4343 by pjay-io.
Synapse rejects chunked uploads without Content-Length. Adding
filesize=len(data) ensures the upload includes proper sizing.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Cherry-picked from PR NousResearch#4343 by pjay-io.
Synapse rejects chunked uploads without Content-Length. Adding
filesize=len(data) ensures the upload includes proper sizing.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Cherry-picked from PR NousResearch#4343 by pjay-io.
Synapse rejects chunked uploads without Content-Length. Adding
filesize=len(data) ensures the upload includes proper sizing.
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]: TTS doesn't work with Matrix (Synapse) because of missing Content-Length

2 participants