#3300: changed chat session selection logic in iMessage
channel: imessage
Cluster:
Messaging Platform Improvements
I modified it to work based on chat-id because group chat doesn't work normally if you choose by number.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adjusts iMessage inbound session/target selection to key off `chat_id` when available (so group chats can be addressed reliably), and tweaks inbound envelope formatting to include the chat type in the channel header for non-direct messages.
The iMessage change feeds `To`/`OriginatingTo` as `chat_id:<id>` (fallbacking to `imessage:<sender>`), which aligns with existing target parsing/normalization utilities used by outbound routing and tests. The envelope change affects a shared formatter used across multiple providers, so it will change headers beyond iMessage as well.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge; changes are small and aligned with existing target formats, with minor concerns about shared formatting impact.
- The iMessage change uses an established `chat_id:` prefix already supported by parsing/normalization and existing tests. The main risk is the envelope formatter change being globally applied, which could create noisy headers across other channels.
- src/auto-reply/envelope.ts (shared formatting behavior)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</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
#2799: fix(imessage): prevent self-chat and outbound echo loops (#2585)
by Tfh-Yqf · 2026-01-27
81.1%
#22168: fix(imessage): resolve group sessions without chat identifiers
by AIflow-Labs · 2026-02-20
79.9%
#7353: fix: prevent silent message drops after config.patch restart
by 18-RAJAT · 2026-02-02
78.5%
#6521: fix: addressed style issue for chat compose and thread on mobile
by spencer-rafada · 2026-02-01
78.2%
#18664: fix(imessage): honor groupConfig regardless of allowlistEnabled
by brandonwise · 2026-02-16
77.0%
#7127: fix(webchat): add regenerate flag to prevent context leak on response…
by craihub · 2026-02-02
76.0%
#14309: fix(ui): resolve chat event session key mismatch
by justonlyforyou · 2026-02-11
76.0%
#3182: fix(gateway): use canonical session key in chat.send
by chrisherold · 2026-01-28
75.7%
#11123: Fix webchat→external channel cross-delivery
by jingkang0822 · 2026-02-07
74.9%
#22798: feat(webchat): ChatGPT-style multi-chat threads with generated titles
by opnsec · 2026-02-21
74.8%