Skip to content

fix(gateway): SMS session-per-send + Matrix bare media types break downstream processing#1736

Merged
teknium1 merged 1 commit intomainfrom
fix/gateway-platform-hardening
Mar 17, 2026
Merged

fix(gateway): SMS session-per-send + Matrix bare media types break downstream processing#1736
teknium1 merged 1 commit intomainfrom
fix/gateway-platform-hardening

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

1. SMS adapter: persistent HTTP session (sms.py)

Each outbound SMS created and destroyed a new aiohttp.ClientSession, paying TCP+TLS handshake costs every time. Now uses a persistent session created in connect() and closed in disconnect(), matching the pattern used by Mattermost and HomeAssistant adapters.

2. Matrix adapter: MIME-type media types (matrix.py)

Media types were set to bare category words ("image", "audio", "video") instead of proper MIME types. The gateway's media processing in run.py checks mtype.startswith("image/") and mtype.startswith("audio/"), so bare words caused:

  • Matrix images to skip vision enrichment (the MessageType.PHOTO fallback saved it, but only for the image path)
  • Matrix audio to skip transcription entirely

Now extracts the actual MIME type from the nio event's content.info.mimetype field when available, falling back to sensible defaults (image/png, audio/ogg, video/mp4).

Test plan

  • python -m pytest tests/gateway/test_sms.py tests/gateway/test_matrix.py -n0 -q → 61 passed ✔
1. sms.py: Replace per-send aiohttp.ClientSession with a persistent
   session created in connect() and closed in disconnect(). Each
   outbound SMS no longer pays the TCP+TLS handshake cost. Falls back
   to a temporary session if the persistent one isn't available.

2. matrix.py: Use proper MIME types (image/png, audio/ogg, video/mp4)
   instead of bare category words (image, audio, video). The gateway's
   media processing checks startswith('image/') and startswith('audio/')
   so bare words caused Matrix images to skip vision enrichment and
   Matrix audio to skip transcription. Now extracts the actual MIME
   type from the nio event's content info when available.
@teknium1 teknium1 merged commit aea39ee into main Mar 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant