← Back to PRs

#9757: fix(signal): exclude "unknown" media kind from placeholder generation

by leszekszpunar open 2026-02-05 16:51 View on GitHub →
channel: imessage channel: signal stale
Fixes #9706 ## Problem `mediaKindFromMime(mime?: string | null)` returns `"unknown"` (a truthy string) when MIME type is undefined/null/empty. Code checking `if (kind)` incorrectly treats `"unknown"` as valid, generating `<media:unknown>` placeholder. ### Root cause from issue #9706 Two separate problems: 1. **Zombie signal-cli processes** - compete for SSE events, causing corrupted/empty envelopes (process management issue - not addressed in this PR) 2. **Truthy "unknown" check** - `"unknown"` string passes `if (kind)` check → **this PR fixes this** ## Solution Added `kind !== "unknown"` guard to all 4 locations that generate `<media:${kind}>` placeholder: ### Inbound (receiving messages from users) | File | Line | Before | After | |------|------|--------|-------| | `src/signal/monitor/event-handler.ts` | 526 | `if (kind)` | `if (kind && kind !== "unknown")` | | `src/imessage/monitor/monitor-provider.ts` | 417 | `if (kind)` | `if (kind && kind !== "unknown")` | **Behavior change:** Corrupted envelopes (empty `messageText`, no attachments, unknown MIME) are now **ignored** instead of processed as `<media:unknown>`. When attachments exist but MIME is unknown, fallback is `<media:attachment>`. ### Outbound (bot sending messages) | File | Line | Before | After | |------|------|--------|-------| | `src/signal/send.ts` | 167 | `if (!message && kind)` | `if (!message && kind && kind !== "unknown")` | | `src/imessage/send.ts` | 88 | `if (kind)` | `if (kind && kind !== "unknown")` | **Behavior change:** Attachments with unknown MIME type are sent **without** ugly `<media:unknown>` caption. Signal/iMessage display attachment cleanly without text. ## Testing - Unit tests added for `mediaKindFromMime` covering the truthy `"unknown"` edge case - Verified Signal API accepts attachments without message body (caption is optional) - Checked other channels: Mattermost already handles `"unknown"` → `"document"`, Matrix uses switch with default case ## Architectural note A cleaner long-term fix would be changing `mediaKindFromMime` to return `undefined` instead of `"unknown"`, fixing all call sites at once. However, this PR takes a surgical approach with minimal blast radius. The refactor can be done separately if desired. ## Not addressed The **zombie signal-cli process** issue mentioned in #9706 is a separate process management problem. This PR only fixes the placeholder logic. If zombie processes still cause empty envelopes, they will now be **silently ignored** (correct behavior) instead of generating `<media:unknown>` responses. lobster-biscuit

Most Similar PRs