← Back to PRs

#22168: fix(imessage): resolve group sessions without chat identifiers

by AIflow-Labs open 2026-02-20 20:26 View on GitHub →
channel: imessage size: S
## 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