Skip to content

Slack mention causes "Cannot read properties of undefined (reading 'includes')" error #31851

@ogulcansarioglu

Description

@ogulcansarioglu

Bug Description

When the Bot is mentioned in Slack, it throws: Cannot read properties of undefined (reading 'includes'). This happens when processing Slack message events with mentions.

Reproduction Steps

  1. Mention @bot in any Slack channel
  2. Error appears - Bot responds with the error message instead of processing normally

Environment

  • OpenClaw version: 2026.3.1
  • Platform: macOS
  • Channel: Slack

Root Cause Analysis

After extensive investigation, the bug is in multiple locations in the bundled channel-web.js:

  1. isBotMentionedFromTargets function - targets.normalizedMentions.includes() called without null check
  2. stripMessageIdHints in chat-envelope.js - text.includes() without null check
  3. Various uses of msg.body without null checks

The bug is intermittent - shorter messages like "hey" may work while longer ones crash. This suggests timing/async issues in how Slack delivers message payloads.

Patches Applied (but not persisting)

Multiple patches were attempted on dist files but they get overwritten on restart:

  • channel-web-*.js: msg.body ?? ""
  • chat-envelope-*.js: text || text.includes(...)

Recommended Fix

This needs to be fixed in the OpenClaw source code with proper null guards:

  • Add optional chaining (?.) to all .includes() calls
  • Add null coalescing (??) to message body accesses
  • The fix should be in the TypeScript source, not the bundled JS

Workaround

None found - bug is in core framework code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions