omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(slack-app): voice-dictated messages can be sent to the wrong channel on an ambiguous fuzzy match

Open Abhist17 opened this issue 2 months ago • 5 comments

Description

In plugins/omi-slack-app/message_detector.py, ai_extract_message_and_channel resolves the spoken channel name the AI extracted against the workspace's channel list. After the exact-match check, the fallback is:

for name, id in channel_map.items():
    if channel_name.lower() in name.lower() or name.lower() in channel_name.lower():
        channel_id = id
        channel_name = name
        break

channel_map is built from list_channels() (Slack API order), and the loop takes the first channel satisfying a bidirectional substring match — not the closest one. A spoken name like "dev" with both dev-ops and dev-secrets in the workspace (neither an exact match) resolves to whichever one Slack happened to list first, arbitrarily.

The consequence is not cosmetic: all three call sites in main.py (the realtime-timeout auto-send, and the two chat_tool/session-based send paths) call slack_client.send_message immediately once a channel is resolved, with no confirmation step. A wrong guess here silently sends the user's voice-dictated message to a channel they never named.

ai_match_channel, an AI-based fuzzy matcher already defined lower in the same file, is dead code for this path — nothing calls it (grep -rn "ai_match_channel" plugins/omi-slack-app finds only its own definition).

Proposed Fix

Replace the inline loop with a small, pure resolve_channel(spoken_name, channel_map) helper:

  1. Exact (case-insensitive) match still wins outright.
  2. Otherwise, score every substring-matching candidate by difflib.SequenceMatcher ratio against the spoken name and take the single closest one.
  3. A genuine tie between two equally-close candidates resolves to "not found" (the existing fallback path) instead of an arbitrary pick.
  4. Hermetic regression tests for the four cases above, loading message_detector.py directly with openai/dotenv stubbed (same pattern as test_slack_search.py/test_segments.py), registered in .github/checks-manifest.yaml.

Same shape as #13976 (hive-app update_task_status matching the first search hit) — a fuzzy match with no confirmation step, just with a worse failure mode here (the wrong channel, rather than the wrong task, receives content).


Proposed Bounty Reward: $50.00 USD Bounty Payout Destination (PayPal): [email protected]

cc @josancamon19 @kodjima33

Abhist17 avatar Sep 15 '26 15:09 Abhist17

PR up: https://github.com/BasedHardware/omi/pull/14113

Happy to adjust anything — I'll turn review comments around the same day.

Abhist17 avatar Sep 15 '26 15:09 Abhist17

I have implemented and submitted the fix for this issue in PR #14124:

  • Added resolve_channel(spoken_name, channel_map) with exact-match precedence, difflib.SequenceMatcher.ratio() scoring, and ambiguous tie rejection returning (None, None).
  • Updated MessageDetector.ai_extract_message_and_channel to use resolve_channel and exposed it as a static method.
  • Added hermetic regression tests in plugins/omi-slack-app/test_channel_resolution.py and registered the check in .github/checks-manifest.yaml.
  • All tests pass cleanly.

Evos09 avatar Sep 15 '26 19:09 Evos09

PR #14140 submitted addressing the fuzzy match ambiguity and length guards.

  • Replaced arbitrary bidirectional substring fallback with similarity ratio ranking via difflib.
  • Rejects ties / ambiguous candidate matches to prevent misdelivery.
  • Added short-token threshold to eliminate false positives on common words.
  • Hermetically tested with 4/4 passing unit tests.

PINYOPATTANAWASANPORN avatar Sep 16 '26 00:09 PINYOPATTANAWASANPORN

Implemented the fix and hermetic unit test suite in PR #14180.

  • Implemented resolve_channel(spoken_name, channel_map) with exact match priority, difflib.SequenceMatcher.ratio() scoring for partial matches, and safe tie rejection.
  • Updated ai_extract_message_and_channel to use resolve_channel.
  • Added hermetic test suite plugins/omi-slack-app/test_resolve_channel.py covering all 6 cases, registered in .github/checks-manifest.yaml.

USDC Address (Base / Polygon EVM): 0xa709768e0B597df11b2B81AB7ea54EEacd2532D0

arawnslab-hash avatar Sep 16 '26 07:09 arawnslab-hash

Closing as already fixed on current main.

Current main message_detector.resolve_channel rejects ambiguous substring matches instead of first-hit send

aryanorastar avatar Sep 20 '26 16:09 aryanorastar