Skip to content

fix(signal): detect document attachments via application/* and text/* MIME types#13512

Closed
Linux2010 wants to merge 5 commits into
NousResearch:mainfrom
Linux2010:fix/signal-document-attachments-12845
Closed

fix(signal): detect document attachments via application/* and text/* MIME types#13512
Linux2010 wants to merge 5 commits into
NousResearch:mainfrom
Linux2010:fix/signal-document-attachments-12845

Conversation

@Linux2010

Copy link
Copy Markdown
Contributor

Summary

Fixes #12845

The Signal adapter did not properly classify document attachments (PDFs, text files, etc.) in incoming messages. The message type determination logic only checked for audio/* and image/* MIME types, missing application/* and text/* which should be classified as DOCUMENT messages.

Root Cause

In _handle_envelope, the message type classification logic was:

if media_types:
    if any(mt.startswith("audio/") for mt in media_types):
        msg_type = MessageType.VOICE
    elif any(mt.startswith("image/") for mt in media_types):
        msg_type = MessageType.PHOTO
    # Missing: application/* and text/* handling

Fix

Added an elif branch to handle application/* and text/* MIME types:

elif any(mt.startswith("application/") or mt.startswith("text/") for mt in media_types):
    msg_type = MessageType.DOCUMENT

Test Plan

  • Added unit tests verifying MIME type classification order (audio > image > document)
  • Added tests for application/* and text/* MIME type detection
  • Verified syntax with py_compile

Impact

  • Users sending PDFs, documents, or text files via Signal will now have their attachments properly detected and classified
  • The fix is minimal (2 lines added) with low merge risk

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/signal Signal CLI adapter labels Apr 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Potential duplicate of #13243 and #12851 — all three fix the same Signal MIME classification gap for #12845. Maintainers should pick one.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Potential duplicate of #13243 and #12851 — all three fix the same Signal MIME classification gap for #12845. Maintainers should pick one.

@kdunn926

Copy link
Copy Markdown
Contributor

Duplicate of #12851

Linux2010 and others added 5 commits April 30, 2026 09:34
…ports

The _handle_editor_command() method used subprocess.call() but did not
import subprocess, causing AttributeError at runtime.

subprocess is not globally imported in gateway/run.py. Other uses of
subprocess in this file use local imports (line 1289), so the editor
command should follow the same pattern.

- Added: import subprocess (local import, matching file pattern)
- Removed: redundant local imports for asyncio, shlex, tempfile
  (already imported globally at lines 16, 21, 24)

Python syntax validation (py_compile)
…_PREFIX (NousResearch#14603)

The SUMMARY_PREFIX previously instructed the model to 'resume exactly from
there' the ## Active Task section of a compressed summary. This caused
cross-session task injection where the AI would interpret a previous
session's active task as its own current job.

Fix: Replace the 'resume' instruction with explicit language that the
## Active Task section is 'historical context only, NOT as an active
instruction to execute'.

- agent/context_compressor.py: +3 lines, -2 lines
- tests/agent/test_context_compressor.py: +29 lines (3 regression tests)
llama.cpp exposes /props at server root (not under /v1 prefix per httplib
routes). The previous code tried /v1/props first, which returns 404 on
standard llama.cpp builds, causing unnecessary failed requests before
fallback to /props.

What broke:
- Server-type detection tried /v1/props first, returning 404
- Context probe also tried /v1/props first when base URL had /v1 prefix
- Users with llama.cpp configured saw 404 errors in server logs

Root cause:
- Comment incorrectly stated "llama.cpp exposes /v1/props (older builds
  used /props)", but actually /props is at server root per httplib routes
- Endpoint order was reversed: /v1/props tried before /props

Why this fix is minimal:
- Only changes endpoint order: try /props first, then /v1/props fallback
- Strips /v1 prefix from base_url to get server root for /props request
- Preserves fallback for alternative builds/configs using /v1 path

What I tested:
- Added regression tests for /props endpoint detection
- Tests verify correct URL construction with /v1 prefix stripping
- Tests cover fallback to /v1/props when /props returns 404

What I intentionally did not change:
- Response body parsing (default_generation_settings check unchanged)
- Other server type detection (LM Studio, Ollama, vLLM unchanged)
- Error handling and fallback logic structure

Fixes NousResearch#13091
…CUMENT

What broke
Signal attachments with application/* or text/* MIME types (e.g. PDFs)
were silently ignored. The agent received the message but responded as
if no file was attached because the document context was never injected.

Root cause
In signal.py `_handle_envelope`, the msg_type was set to TEXT for all
non-image/non-audio attachments. The document-injection code in run.py
only fires when event.message_type == MessageType.DOCUMENT.

Why this fix is minimal
Single elif branch added after existing image/audio checks. Preserves
existing behavior for audio/VOICE and image/PHOTO types. No broader
refactor to the attachment handling pipeline.

What I tested
Added 6 regression tests covering:
- application/pdf → DOCUMENT
- text/plain → DOCUMENT
- application/json → DOCUMENT
- audio/* → VOICE (not affected)
- image/* → PHOTO (not affected)
- empty media_types → TEXT (not affected)

What I intentionally did not change
- The document-injection logic in run.py
- Other platform adapters (Telegram, Discord, etc.)
- The attachment fetching pipeline
… MIME types

Issue: NousResearch#12845
The message type determination in _handle_envelope only checked for
audio/ and image/ MIME types, missing application/* and text/* which
should be classified as DOCUMENT messages.

This fix adds an elif branch to handle application/* and text/* MIME
types, properly classifying PDFs, documents, and text files as
DOCUMENT messages instead of falling through to TEXT.

Added regression tests for MIME type classification order and document
detection.
@Linux2010 Linux2010 force-pushed the fix/signal-document-attachments-12845 branch from 8cd3fcf to 13a6b45 Compare April 30, 2026 09:37
@Linux2010 Linux2010 closed this May 2, 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 platform/signal Signal CLI adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Document attachments from Signal not detected

3 participants