Skip to content

fix(gateway): add Signal message type classification for documents#12851

Closed
kdunn926 wants to merge 3 commits into
NousResearch:mainfrom
kdunn926:fix-gateway-signal-doc-attachments
Closed

fix(gateway): add Signal message type classification for documents#12851
kdunn926 wants to merge 3 commits into
NousResearch:mainfrom
kdunn926:fix-gateway-signal-doc-attachments

Conversation

@kdunn926

@kdunn926 kdunn926 commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Add missing Signal adapter DOCUMENT message type for non-image/non-audio attachments.

Related Issue

Fixes #12845

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

  • Changed src/gateway/platforms/signal.py to include support for application/* and text/* MIME types.

How to Test

  1. Send a PDF via Note-to-Self
  2. Document context injection is triggered
  3. Agent correctly reads and summarizes the file

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:

Documentation & Housekeeping

  • [N/A] I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • [N/A] I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • [N/A] I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • [N/A] I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • [N/A] I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

DEBUG gateway.platforms.signal: Signal: Note to Self attachments: [{'contentType': 'application/pdf', 'filename': '1-s2.0-S0090429520315314-main.pdf', 'id': '6zLO3b-6Yf3zVWeLDctA.pdf', 'size': 508237, ...}]
DEBUG gateway.platforms.signal: Signal: message from +1********** in +1**********: What's this?
INFO  gateway.run: inbound message: platform=signal user=####### chat=+1********** msg="What's this?"
DEBUG gateway.run: run_agent resolved: model=claude-sonnet-4.6 provider=copilot
DEBUG gateway.run: Created new agent for session agent:main:signal:dm:+1**********
DEBUG gateway.platforms.signal: Signal: message from +1********** in +1**********: /approve
INFO  gateway.run: User approved 1 dangerous command(s) via /approve
INFO  gateway.run: response ready: platform=signal chat=+1********** time=27.2s api_calls=3 response=234 chars
INFO  gateway.platforms.base: [Signal] Sending response (234 chars) to +1**********

@ether-btc ether-btc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hermes Agent Code Review — PR #12851

Verdict: Request Changes

Clean fix with good test coverage. One gap: no tests for the document message-type classification logic.


🔴 Critical — No Tests for Document Message-Type Classification

File: gateway/platforms/signal.py:509

The fix adds application/* and text/* MIME type handling to classify attachments as MessageType.DOCUMENT. However, the test suite does not include a test case for this specific classification.

The existing tests in TestSignalInboundMessageTypeClassification (test_pdf_attachment_sets_document_type) test application/pdf, which is covered. But text/* is a broader type — text/plain, text/csv, text/html — and no test verifies these are classified as DOCUMENT.

This matters because MessageType.DOCUMENT is the gate for run.py's document-context injection. If a future regression narrows the MIME type check, or if text/* behaves differently than application/*, there is no test to catch it.

Suggested fix:

  • Add a test with contentType: "text/plain" (e.g., a .txt attachment) and verify it is classified as DOCUMENT
  • Add a test with contentType: "text/html" to cover the full text/* wildcard

✅ Looks Good

  • Correctly extends the existing MIME type chain with elif — maintains the priority order (voice → photo → document)
  • Good test structure using _make_dm_envelope helper with AsyncMock for _fetch_attachment
  • Clear docstring explaining the bug: documents misclassified as TEXT caused silent file drops

Reviewed by Hermes Agent

@kdunn926 kdunn926 requested a review from ether-btc April 20, 2026 15:41
@ether-btc

Copy link
Copy Markdown
Contributor

Hermes Agent Code Review — PR #12851

Verdict: APPROVE

Clean, minimal fix with good test coverage. Solves a real user-facing bug (PDFs silently dropped) with surgical precision.


🟢 Nit — Add Type Hint to _dispatch_single_attachment

File: tests/gateway/test_signal.py:672

The helper method _dispatch_single_attachment returns dispatched[0] which is an InboundEvent, but lacks a return type annotation.

# Current:
async def _dispatch_single_attachment(self, monkeypatch, content_type: str,
                                      att_id: str, fetch_path: str, fetch_ext: str):
    ...

# Suggested:
async def _dispatch_single_attachment(self, monkeypatch, content_type: str,
                                      att_id: str, fetch_path: str, fetch_ext: str) -> InboundEvent:
    ...

Impact: Low - IDE/type-checker doesn't know the return type. Adding -> InboundEvent improves static analysis.


🟢 Nit — Import InboundEvent at Module Level

File: tests/gateway/test_signal.py

Each test imports from gateway.platforms.base import MessageType inline (lines 709, 731, 753). This works but is slightly inconsistent with Python style.

# Add at top of file with other imports:
from gateway.platforms.base import MessageType, InboundEvent

Then remove the inline imports from each test method.

Impact: Low - current code works fine. This is purely style.


What Works Well

  1. Surgical fix — Only 2 lines changed in production code, exactly where needed
  2. Good test coverage — 3 tests cover PDF, text/plain, text/html (the key MIME types)
  3. Clear intent — Comment in test docstring explains the bug and fix
  4. Proper ordering — elif chain correctly prioritizes audio → image → document → text
  5. Edge case handling — Tests verify the wildcards work for various text/* subtypes

Code Quality Assessment

Area Score Notes
Code organization Helper method keeps tests DRY
Naming Clear, descriptive names
Test coverage Covers key MIME types
Error handling N/A N/A for this change

Security Assessment

No security concerns. This change only affects message type classification. The media_types list comes from Signal-CLI's validated envelope data. No new attack surface.


Performance Assessment

No performance concerns. The any() calls are O(n) on attachment count (typically 1-5). String prefix checks are negligible.


Bug Detection

Logic is sound. The elif chain correctly handles the priority order:

  • audio/ → VOICE
  • image/ → PHOTO
  • application/ or text/ → DOCUMENT (new)
  • fallback → TEXT

Tests verify the new DOCUMENT classification for key MIME types.


Recommendation

APPROVE — This is a solid fix. The two nits above are minor style improvements that could be addressed in a follow-up, but they don't block merge.

The PR resolves issue #12845 cleanly: users can now send PDFs and other document attachments via Signal and the agent will receive them properly.

@ether-btc ether-btc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits noted. Clean fix, good test coverage.

@ether-btc ether-btc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hermes Agent Code Review — PR #12851

Verdict: APPROVE

Clean, minimal fix with good test coverage. Solves a real user-facing bug (PDFs silently dropped) with surgical precision.


🟢 Nit — Add Type Hint to _dispatch_single_attachment

File: tests/gateway/test_signal.py:672

The helper method _dispatch_single_attachment returns dispatched[0] which is an InboundEvent, but lacks a return type annotation.

Impact: Low - IDE/type-checker doesn't know the return type. Adding -> InboundEvent improves static analysis.


🟢 Nit — Import InboundEvent at Module Level

File: tests/gateway/test_signal.py

Each test imports from gateway.platforms.base import MessageType inline (lines 709, 731, 753). This works but is slightly inconsistent with Python style.

Impact: Low - current code works fine. This is purely style.


What Works Well

  1. Surgical fix — Only 2 lines changed in production code, exactly where needed
  2. Good test coverage — 3 tests cover PDF, text/plain, text/html (the key MIME types)
  3. Clear intent — Comment in test docstring explains the bug and fix
  4. Proper ordering — elif chain correctly prioritizes audio → image → document → text
  5. Edge case handling — Tests verify that wildcards work for various text/* subtypes

Code Quality Assessment

Area Score Notes
Code organization Helper method keeps tests DRY
Naming Clear, descriptive names
Test coverage Covers key MIME types
Error handling N/A N/A for this change

Security Assessment

No security concerns. This change only affects message type classification. The media_types list comes from Signal-CLI's validated envelope data. No new attack surface.


Performance Assessment

No performance concerns. The any() calls are O(n) on attachment count (typically 1-5). String prefix checks are negligible.


Bug Detection

Logic is sound. The elif chain correctly handles the priority order:

  • audio/ → VOICE
  • image/ → PHOTO
  • application/ or text/ → DOCUMENT (new)
  • fallback → TEXT

Tests verify that the new DOCUMENT classification works for key MIME types.


Recommendation

APPROVE — This is a solid fix. The two nits above are minor style improvements that could be addressed in a follow-up, but they don't block merge.

The PR resolves issue #12845 cleanly: users can now send PDFs and other document attachments via Signal and the agent will receive them properly.

@alt-glitch alt-glitch added type/bug Something isn't working platform/signal Signal CLI adapter comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Apr 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #13512 — both fix Signal document MIME type classification for #12845.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #13512 — both fix Signal document MIME type classification for #12845.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Superseded by #20347 which centralizes inbound attachment classification logic and adds broader MIME coverage (DOCUMENT + VIDEO).

teknium1 added a commit that referenced this pull request Jun 12, 2026
…fallback

Widen the salvaged #12851 fix to match the established classification
pattern (WhatsApp/Slack/BlueBubbles/Mattermost): video/* -> VIDEO, and
any remaining MIME type falls through to DOCUMENT instead of TEXT, so
exotic types still trigger run.py's document-context injection.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #44695 with your authorship preserved via cherry-pick + rebase-merge (commits 8207ae8, ffef9da, 8e821cd on main). Thanks for the fix and the thorough tests! We also widened the fix to the same bug class on Email and SimpleX during salvage.

@teknium1 teknium1 closed this Jun 12, 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 duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists 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

4 participants