#11774: fix: add guards for undefined mentionRegexes arrays
channel: whatsapp-web
stale
Cluster:
WhatsApp and Google Chat Fixes
Prevents `Cannot read properties of undefined (reading some)` errors when `mentionRegexes` is undefined in group chat mention detection.
## Fixes
- `matchesMentionPatterns`: add `!mentionRegexes` check before `.length`
- `matchesMentionWithExplicit`: extract regexes with `?? []` fallback
- `isBotMentionedFromTargets`: add `?? []` fallback for `.some()` call
## Context
Observed intermittent crashes in group chat sessions with error:
```
Cannot read properties of undefined (reading 'some')
```
The issue occurs when `params.mentionRegexes` is undefined during mention detection, likely due to race conditions or edge cases in config resolution.
## Changes
- `src/auto-reply/reply/mentions.ts` - 2 functions fixed
- `src/web/auto-reply/mentions.ts` - 1 function fixed
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR hardens group-chat mention detection against cases where `mentionRegexes` is unexpectedly `undefined`, preventing runtime crashes like `Cannot read properties of undefined (reading 'some')`.
Changes are localized to mention-matching helpers used by auto-reply and the web/WhatsApp inbound path: the core mention matcher now short-circuits when no regexes are available, and callers use `?? []` when iterating regex arrays so `.some()` is always safe.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge, but the type contract mismatch around `mentionRegexes` should be resolved to avoid future regressions.
- The runtime guard additions appear correct and directly address the reported crash. The main remaining issue is that `matchesMentionPatterns` now accepts `undefined` at runtime but is still typed as `RegExp[]`, which can hide incorrect call sites and undermines type safety.
- src/auto-reply/reply/mentions.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#12069: fix(whatsapp): handle native group @mentions with requireMention
by abhishek0450 · 2026-02-08
79.5%
#17256: fix: allow text regex fallback when bot JID not in mentionedJids
by DarlingtonDeveloper · 2026-02-15
79.5%
#13829: fix(googlechat): detect bot @mentions via user.type when botUser no...
by mcaxtr · 2026-02-11
76.8%
#15786: fix: strip device suffix from selfJid in WhatsApp mention matching
by kenken64 · 2026-02-13
76.4%
#13430: fix(discord): properly handle bot-sent @everyone mentions
by wassimbensalem · 2026-02-10
76.2%
#7719: fix(slack): thread replies with @mentions dropped in requireMention...
by SocialNerd42069 · 2026-02-03
75.8%
#11166: fix(whatsapp): detect LID @mentions in self-chat mode
by mcaxtr · 2026-02-07
75.5%
#17081: fix(telegram): suppress file-size error replies in groups when bot ...
by p697 · 2026-02-15
74.4%
#18647: fix(agents): guard against undefined paths in injectedFiles
by kleinpanic · 2026-02-16
74.3%
#15999: fix: handle null/undefined in activity feed filters
by pamnlambert · 2026-02-14
73.9%