Skip to content

fix(slack): classify D-prefix DMs correctly when channel_type disagrees#10643

Closed
mcaxtr wants to merge 2 commits intoopenclaw:mainfrom
mcaxtr:fix/8421-slack-dm-classification-v2
Closed

fix(slack): classify D-prefix DMs correctly when channel_type disagrees#10643
mcaxtr wants to merge 2 commits intoopenclaw:mainfrom
mcaxtr:fix/8421-slack-dm-classification-v2

Conversation

@mcaxtr
Copy link
Contributor

@mcaxtr mcaxtr commented Feb 6, 2026

Fixes #8421

Problem

Slack sometimes sends events where the channel_type field contradicts the channel ID prefix. For example, a DM channel with ID D0ABC123 may arrive with channel_type: "channel" instead of "im". This causes the bot to misclassify DMs as public channels, leading to:

  • Wrong session key: messages route to agent:main:slack:channel:D0ABC123 instead of agent:main:main (when dmScope is "main")
  • Wrong ChatType: set to "channel" instead of "direct"
  • Policy bypass: DM policy checks are skipped because the message is treated as a channel message
  • Broken context: conversation history is isolated per-channel instead of unified in the DM session

Root Cause

normalizeSlackChannelType() in context.ts trusts the event's channel_type field when it's a recognized value ("im", "mpim", "channel", "group"), even when the channel ID prefix contradicts it. Since Slack channel IDs with D prefix are always DMs by Slack's own convention, the channel_type field should be overridden when it disagrees.

Fix

Added a cross-validation check in normalizeSlackChannelType(): when the channel ID starts with D (inferred as "im"), override any contradicting channel_type value. This is the canonical normalization function used across the entire Slack integration — all downstream callers (prepareSlackMessage, isChannelAllowed, resolveSlackSystemEventSessionKey, member events) are automatically protected.

Only D-prefix is overridden because it unambiguously identifies DMs. G-prefix is intentionally left alone since it's ambiguous (can be either a private channel or a group DM — Slack's API provides the correct channel_type in that case).

Test Plan

TDD approach — all 8 new tests were written first and confirmed failing before the fix:

  • normalizeSlackChannelType unit tests (3 cases):
    • Overrides wrong channel_type ("channel", "group", "mpim") for D-prefix channels → returns "im"
    • Preserves correct channel_type ("im") for D-prefix channels
    • Does not override G-prefix channels (ambiguous prefix)
  • prepareSlackMessage integration tests (2 cases):
    • D-prefix + wrong channel_type: "channel"isDirectMessage: true, session routes to agent:main:main, ChatType: "direct"
    • D-prefix + missing channel_type → correctly inferred as DM
  • All 5337 existing tests pass (no regressions)
  • Full CI gate: pnpm build && pnpm check && pnpm test

Greptile Overview

Greptile Summary

  • Updates normalizeSlackChannelType() to cross-check the channel ID prefix and override contradictory channel_type values for D* channels (treat as im).
  • Adds unit tests covering D-prefix overrides, preserving correct values, and leaving ambiguous G* channels unchanged.
  • Adds inbound prepareSlackMessage contract tests to ensure D-prefix DMs route to the main DM session and produce ChatType: direct even when Slack mislabels channel_type.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • Change is narrowly scoped to normalization logic, has clear test coverage for the regression scenario (D-prefix DM misclassified), and doesn’t affect ambiguous prefixes; no additional behavioral regressions were found in call sites using this normalization.
  • No files require special attention

@openclaw-barnacle openclaw-barnacle bot added the channel: slack Channel integration: slack label Feb 6, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@mcaxtr
Copy link
Contributor Author

mcaxtr commented Feb 7, 2026

@greptileai review

@mcaxtr mcaxtr force-pushed the fix/8421-slack-dm-classification-v2 branch 3 times, most recently from 63a9cef to 3aaedf8 Compare February 12, 2026 04:19
@mcaxtr mcaxtr force-pushed the fix/8421-slack-dm-classification-v2 branch from 3aaedf8 to 6f166b6 Compare February 13, 2026 02:30
@mcaxtr mcaxtr force-pushed the fix/8421-slack-dm-classification-v2 branch from 6f166b6 to 4e30a18 Compare February 13, 2026 14:45
@mcaxtr mcaxtr force-pushed the fix/8421-slack-dm-classification-v2 branch 8 times, most recently from 4ab4a4f to 49bcf8f Compare February 15, 2026 15:09
@mcaxtr mcaxtr force-pushed the fix/8421-slack-dm-classification-v2 branch 2 times, most recently from dfab4a8 to 78f4f13 Compare February 17, 2026 01:28
@mcaxtr mcaxtr force-pushed the fix/8421-slack-dm-classification-v2 branch from 78f4f13 to 9fb21fd Compare February 19, 2026 02:13
@steipete
Copy link
Contributor

Closing as AI-assisted stale-fix triage.

Linked issue #8421 ("Slack DMs Misclassified as Channels - dmScope 'main' Not Working") is currently CLOSED and was closed on 2026-02-24T04:24:48Z with state reason NOT_PLANNED.
Given that issue state, this fix PR is no longer needed in the active queue and is being closed as stale.

If the underlying bug is still reproducible on current main, please reopen this PR (or open a new focused fix PR) and reference both #8421 and #10643 for fast re-triage.

@steipete
Copy link
Contributor

Closed after AI-assisted stale-fix triage (closed issue duplicate/stale fix).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slack DMs Misclassified as Channels - dmScope 'main' Not Working

2 participants