#22168: fix(imessage): resolve group sessions without chat identifiers
channel: imessage
size: S
Cluster:
Messaging Platform Improvements
## Summary
- Fix iMessage inbound routing to support group messages when `chat_id` is missing in runtime payloads.
- Derive group identity from `chat_id`, `chat_guid`, or `chat_identifier` and keep routing/group history keys consistent.
- Preserve chat target formatting for group delivery so replies continue correctly for guid-based threads.
- Add regression coverage for group dispatch with `chat_guid` payloads in inbound decision/context logic.
## Testing
- `pnpm vitest run src/imessage/monitor.gating.test.ts`
- `pnpm vitest run src/imessage/monitor.shutdown.unhandled-rejection.test.ts src/imessage/monitor/deliver.test.ts src/imessage/targets.test.ts`
- `pnpm vitest run src/imessage/monitor.gating.test.ts src/imessage/monitor.shutdown.unhandled-rejection.test.ts src/imessage/monitor/deliver.test.ts`
- `pnpm vitest run src/imessage`
Closes #22163
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Extended iMessage inbound routing to support group messages without `chat_id` by adding fallback resolution to `chat_guid` and `chat_identifier`.
- Added `normalizeIMessageNumericId` to safely normalize numeric chat IDs
- Added `resolveIMessageGroupId` to derive group identity from `chat_id`, `chat_guid`, or `chat_identifier` in priority order
- Added `resolveIMessageGroupTarget` to format group targets with appropriate prefixes (`chat_id:`, `chat_guid:`, or `chat_identifier:`)
- Changed `chatId` type from `number` to `string` in dispatch decision to support all identifier types
- Added `groupTarget` field to track formatted group target strings for delivery
- Updated session key generation and echo scope logic to use resolved group identifiers
- Removed unused import of `formatIMessageChatTarget` from targets module
- Test coverage verifies group dispatch with `chat_guid` when `chat_id` is absent
<h3>Confidence Score: 5/5</h3>
- Safe to merge - well-tested fix with proper fallback logic
- The changes are well-structured with clear fallback logic, comprehensive test coverage, and proper handling of edge cases (null checks, type conversions, trimming). The implementation correctly preserves backward compatibility with `chat_id` while adding support for alternative identifiers.
- No files require special attention
<sub>Last reviewed commit: bf5a7bb</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#18664: fix(imessage): honor groupConfig regardless of allowlistEnabled
by brandonwise · 2026-02-16
84.3%
#3300: changed chat session selection logic in iMessage
by KimEJ · 2026-01-28
79.9%
#17380: fix(imessage): reject non-numeric chat_id values to prevent silent ...
by aldoeliacim · 2026-02-15
76.1%
#10309: fix: use group ID for peer.id in Feishu group messages
by ParsifalC · 2026-02-06
74.9%
#19435: fix(slack): properly handle group DM (MPIM) events
by Utkarshbhimte · 2026-02-17
73.0%
#17527: fix(gateway): allow WebChat to attach to main session regardless of...
by Glucksberg · 2026-02-15
72.9%
#21693: feat(gateway): expose session entry id on chat history messages
by tlxue · 2026-02-20
72.7%
#14966: fix(webchat): preserve user message visibility after chat.send
by BenediktSchackenberg · 2026-02-12
72.6%
#16105: fix: handle message_reaction updates in group polling mode
by claw-sylphx · 2026-02-14
72.6%
#3368: fix: sessions navigation, DM thread display, and DM thread delivery...
by Lukavyi · 2026-01-28
72.4%