#10470: Fix: iMessage real-time delivery via imsg watch
channel: imessage
size: S
Cluster:
TUI and Tool Execution Fixes
Fixes #6775 — iMessage messages not delivered in real-time to agent
**Root cause:** The gateway relies on `imsg rpc` and `watch.subscribe` for real-time delivery. On some environments (e.g. macOS 25.2, imsg v0.4.0), the RPC process does not emit `method: "message"` when new messages are stored, so the agent only sees messages when manually running `imsg history`.
**Approach:** Keep RPC watch as the primary path. Add an optional history-polling fallback so delivery works even when watch does not push:
- New config: `channels.imessage.pollIntervalMs` (optional, number, default `0`). When > 0, the monitor runs a loop that calls RPC `chats.list` and then `imsg history --chat-id <id> --limit 5 --json` per chat at the given interval.
- All inbound messages (from watch or poll) go through the same handler. A bounded `InboundMessageDeduper` (by chat + message id) ensures each message is delivered at most once.
- Docs: gateway configuration and iMessage channel docs updated with `pollIntervalMs` and when to use it.
**How to use:** If the agent does not receive iMessages in real time, set e.g. `channels.imessage.pollIntervalMs: 5000` and restart the gateway. Messages will be delivered within the chosen interval; real-time delivery continues to work when the RPC watch pushes.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
- Adds an optional `channels.imessage.pollIntervalMs` config to enable periodic `imsg history` polling as a fallback when `watch.subscribe` does not emit real-time inbound message events.
- Introduces a bounded inbound message deduper so watch- and poll-sourced messages are delivered at most once.
- Updates iMessage and gateway configuration docs to describe the new polling fallback.
- PR also adds a new PR template file that appears unrelated to this change set.
<h3>Confidence Score: 4/5</h3>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#7353: fix: prevent silent message drops after config.patch restart
by 18-RAJAT · 2026-02-02
77.9%
#12974: fix: intermittent (no output) reported by users
by vincentkoc · 2026-02-10
75.1%
#2799: fix(imessage): prevent self-chat and outbound echo loops (#2585)
by Tfh-Yqf · 2026-01-27
74.7%
#15564: fix: webchat messages disappear during concurrent session activity
by Automatedcapitalist · 2026-02-13
73.9%
#3300: changed chat session selection logic in iMessage
by KimEJ · 2026-01-28
73.8%
#3182: fix(gateway): use canonical session key in chat.send
by chrisherold · 2026-01-28
73.7%
#5561: fix(telegram): auto-restart on timeout + lower API timeout to 60s
by jesseproudman · 2026-01-31
72.7%
#7127: fix(webchat): add regenerate flag to prevent context leak on response…
by craihub · 2026-02-02
72.6%
#14309: fix(ui): resolve chat event session key mismatch
by justonlyforyou · 2026-02-11
72.0%
#7218: fix(telegram): skip empty text messages in threaded mode
by ArsalanShakil · 2026-02-02
71.9%