Skip to content

fix(simplex): classify inbound documents as MessageType.DOCUMENT - #35490

Closed
lambertian wants to merge 1 commit into
NousResearch:mainfrom
lambertian:fix/simplex-inbound-document-type
Closed

fix(simplex): classify inbound documents as MessageType.DOCUMENT#35490
lambertian wants to merge 1 commit into
NousResearch:mainfrom
lambertian:fix/simplex-inbound-document-type

Conversation

@lambertian

@lambertian lambertian commented May 30, 2026

Copy link
Copy Markdown

Summary

Documents received over SimpleX (PDF / office / zip / .txt / etc.) currently arrive as MessageType.TEXT and are silently dropped. In _handle_new_chat_item, any non-image/non-audio attachment is tagged application/octet-stream and the msg_type block only promotes audio/* -> VOICE and image/* -> PHOTO, while the gateway's document-attachment block (gateway/run.py) forwards attachments only when message_type == MessageType.DOCUMENT. So received documents reach the agent as a text note, not a file.

This adds inbound document classification, mirroring the existing image/voice handling:

  • _doc_mime_for() maps common document extensions (pdf/txt/md/csv/json/docx/xlsx/pptx/zip/…) to real MIME types. For anything else it uses mimetypes.guess_type, but collapses any non-application/*/text/* guess to application/octet-stream so a stray image/* or audio/* guess (e.g. .heic, .flac) cannot re-route the file into the vision/STT pipelines.
  • the non-image/non-audio branch records that MIME instead of a hard-coded application/octet-stream.
  • a new msg_type branch promotes application/* or text/* -> MessageType.DOCUMENT.

Net effect: any attachment that isn't an allowlisted image/audio type is delivered to the agent as a document attachment instead of being dropped.

Tests (tests/gateway/test_simplex_plugin.py)

  • test_inbound_document_classified_as_document — a received .pdf dispatches a MessageEvent typed DOCUMENT with application/pdf in media_types. Fails on main (arrives as TEXT), passes with this change.
  • test_inbound_unallowlisted_media_routes_to_document_not_photo_or_voice.heic / .svg / .flac / .mp4 classify as DOCUMENT, never PHOTO/VOICE.
  • test_doc_mime_for_maps_known_and_unknown_extensions — extension → MIME mapping, including the collapse and the unknown-extension fallback.

Notes

Received documents (PDF/office/zip/etc.) arrived as MessageType.TEXT and were
silently dropped by the gateway's DOCUMENT-gated attachment block. Classify
non-image/non-audio attachments by a real MIME and promote application/* or
text/* to MessageType.DOCUMENT, mirroring the existing image/voice handling.
_doc_mime_for collapses any non-application/text guess to
application/octet-stream so stray image/audio/video extensions don't re-route
into the vision/STT pipelines.

Relates to NousResearch#30150.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins comp/gateway Gateway runner, session dispatch, delivery labels May 30, 2026
@lambertian

Copy link
Copy Markdown
Author

Closing — superseded upstream. The inbound-document classification this PR adds (and the MIME-precision _doc_mime_for helper) both landed on main in v0.17:

Verified against current origin/main: the inbound classify branch emits MessageType.DOCUMENT for documents, and the gateway remaps the residual octet-stream MIME. Nothing here remains unaddressed upstream, so this branch is no longer needed. Thanks.

@lambertian lambertian closed this Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants