Skip to content

fix: preserve slack mention source metadata#79046

Closed
zeus1959 wants to merge 1 commit into
openclaw:mainfrom
zeus1959:fix/slack-mention-source-metadata
Closed

fix: preserve slack mention source metadata#79046
zeus1959 wants to merge 1 commit into
openclaw:mainfrom
zeus1959:fix/slack-mention-source-metadata

Conversation

@zeus1959

@zeus1959 zeus1959 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Preserve Slack explicit user and user-group mention targets in inbound context instead of only exposing the collapsed WasMentioned boolean.
  • Add prompt-visible mention metadata for Slack implicit thread wakes: explicitly_mentioned_bot, mentioned_user_ids, mentioned_subteam_ids, implicit_mention_kinds, and mention_source.
  • Keep existing Slack mention-gating and wake behavior unchanged.

Linked Issue/PR

Fixes #79025

Real behavior proof

Behavior or issue addressed: Slack thread messages that implicitly wake OpenClaw can now show whether the bot was explicitly mentioned or another Slack user was mentioned, instead of exposing only was_mentioned: true.

Real environment tested: Local OpenClaw checkout on Node 22 with the production inbound prompt metadata renderer.

Exact steps or command run after this patch:

pnpm exec tsx --eval 'import { buildInboundUserContextPrefix } from "./src/auto-reply/reply/inbound-meta.ts"; const text = buildInboundUserContextPrefix({ ChatType: "channel", OriginatingChannel: "slack", Provider: "slack", Surface: "slack", OriginatingTo: "channel:C0AHZFCAS1K", MessageSid: "1777244714.000100", SenderId: "U_BEK", WasMentioned: true, ExplicitlyMentionedBot: false, MentionedUserIds: ["UOTHER"], ImplicitMentionKinds: ["reply_to_bot"], MentionSource: "implicit_thread" } as any); const match = text.match(/Conversation info \(untrusted metadata\):\n```json\n([\s\S]*?)\n```/); console.log(match ? match[1] : "missing conversation info");'

Evidence after fix:

{
  "chat_id": "channel:C0AHZFCAS1K",
  "message_id": "1777244714.000100",
  "sender_id": "U_BEK",
  "sender": "U_BEK",
  "is_group_chat": true,
  "was_mentioned": true,
  "explicitly_mentioned_bot": false,
  "mentioned_user_ids": [
    "UOTHER"
  ],
  "implicit_mention_kinds": [
    "reply_to_bot"
  ],
  "mention_source": "implicit_thread"
}

Observed result after fix: The conversation metadata keeps was_mentioned: true while also exposing explicitly_mentioned_bot: false, the explicit Slack user target UOTHER, the implicit thread wake kind reply_to_bot, and mention_source: "implicit_thread".

What was not tested: A live Slack workspace Socket Mode event was not sent in this local validation; the Slack prepare path is covered by the added regression test.

Root Cause

Slack computed explicit mention and implicit thread wake facts during message preparation, but only wrote the final collapsed WasMentioned value into the inbound context and prompt metadata.

Regression Test Plan

  • pnpm test extensions/slack/src/monitor/message-handler/prepare.test.ts src/auto-reply/reply/inbound-meta.test.ts
  • pnpm lint:extensions -- extensions/slack/src/monitor/message-handler/prepare.ts
  • git diff --check

User-visible / Behavior Changes

Slack agents can distinguish direct bot mentions, user-group mentions, mention-pattern wakes, and implicit thread wakes from the inbound prompt metadata. Existing mention-gating behavior is unchanged.

Security Impact

No new permissions or auth bypass. The new fields are provider metadata derived by OpenClaw and rendered as untrusted conversation metadata alongside existing Slack ids.

Human Verification

Verified locally with targeted tests, extension lint, git diff --check, and a real OpenClaw prompt metadata rendering command.

Review Conversations

None.

Compatibility / Migration

Additive context fields only; existing WasMentioned behavior remains intact.

Risks and Mitigations

Risk is limited to additional Slack mention metadata in prompts. Tests cover the implicit thread wake with another-user mention, user-group mention metadata, and prompt rendering.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: slack Channel integration: slack size: S proof: supplied External PR includes structured after-fix real behavior proof. labels May 7, 2026
@clawsweeper

clawsweeper Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

Summary
The PR propagates Slack mention-source details from Slack message preparation into finalized inbound context, prompt metadata, docs, changelog, and regression tests.

Reproducibility: yes. source-level: current main computes explicit Slack mention and implicit thread wake facts but prompt-visible context only receives was_mentioned. The linked issue at #79025 also includes a concrete Slack incident from version 2026.5.5.

Real behavior proof
Sufficient (terminal): The PR body includes terminal output from a post-patch local OpenClaw command showing the production inbound prompt metadata renderer emits the new fields; no live Slack event was shown.

Next step before merge
A narrow automated repair can remove the unrelated generated Canvas hash from the PR branch while leaving the substantive Slack fix intact.

Security
Cleared: No concrete security or supply-chain issue found; the diff adds provider-native Slack ids to existing untrusted prompt metadata and does not touch secrets, dependencies, workflows, permissions, or auth paths.

Review findings

  • [P2] Drop the unrelated A2UI bundle hash change — extensions/canvas/src/host/a2ui/.bundle.hash:1
Review details

Best possible solution:

Land the additive Slack metadata carry-through after removing the unrelated Canvas hash drift and keeping the targeted Slack and prompt metadata checks green.

Do we have a high-confidence way to reproduce the issue?

Yes, source-level: current main computes explicit Slack mention and implicit thread wake facts but prompt-visible context only receives was_mentioned. The linked issue at #79025 also includes a concrete Slack incident from version 2026.5.5.

Is this the best way to solve the issue?

Yes for the Slack code path: additive carry-through preserves existing WasMentioned and mention-gating behavior while exposing the missing source metadata. The branch is not merge-ready as-is because the unrelated Canvas generated hash should be removed.

Full review comments:

  • [P2] Drop the unrelated A2UI bundle hash change — extensions/canvas/src/host/a2ui/.bundle.hash:1
    This Slack-only PR changes the generated A2UI bundle hash without changing the A2UI bundle or its inputs. The bundle script uses this hash to decide whether the prebuilt Canvas asset is current, so the stale unrelated value can force regeneration or generated-file drift in package/build checks; please revert this file from the branch.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.86

Acceptance criteria:

  • git diff --check
  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md docs/channels/slack.md extensions/slack/src/monitor/message-handler/prepare.ts extensions/slack/src/monitor/message-handler/prepare.test.ts src/auto-reply/reply/inbound-meta.ts src/auto-reply/reply/inbound-meta.test.ts src/auto-reply/templating.ts
  • pnpm test extensions/slack/src/monitor/message-handler/prepare.test.ts src/auto-reply/reply/inbound-meta.test.ts
  • pnpm lint:extensions -- extensions/slack/src/monitor/message-handler/prepare.ts

What I checked:

  • Current main collapses Slack mention detail: Slack message preparation computes explicit mention state and implicit thread wake kinds, then current main only writes the effective WasMentioned boolean into ctxPayload. (extensions/slack/src/monitor/message-handler/prepare.ts:794, 56fe64e8e369)
  • Current prompt metadata exposes only was_mentioned: The current inbound prompt metadata conversation block renders was_mentioned without mention target ids, implicit wake kinds, or mention source. (src/auto-reply/reply/inbound-meta.ts:229, 56fe64e8e369)
  • Slack docs describe distinct mention sources: The Slack docs already distinguish explicit app mentions, Slack user-group mentions, mention regex patterns, and implicit reply-to-bot thread behavior. Public docs: docs/channels/slack.md. (docs/channels/slack.md:901, 56fe64e8e369)
  • PR carries the metadata through the intended path: The PR diff adds Slack mention id collection, mention source resolution, ctxPayload fields, prompt rendering fields, docs, changelog, and targeted tests. (extensions/slack/src/monitor/message-handler/prepare.ts:843, d6783d5b975b)
  • Unrelated generated hash is included: The diff changes extensions/canvas/src/host/a2ui/.bundle.hash even though the PR is a Slack prompt metadata change and no A2UI bundle/input change is part of the patch. (extensions/canvas/src/host/a2ui/.bundle.hash:1, d6783d5b975b)
  • Related duplicate implementation exists: A later open PR also targets the same linked Slack metadata bug, but there is no maintainer signal in the provided context that it supersedes this PR.

Likely related people:

  • steipete: Current blame for Slack explicit/implicit mention handling points to Peter Steinberger, and recent commits show Slack user-group mention and inbound mention policy work; the unrelated A2UI hash also traces to a recent generated-hash maintenance commit. (role: recent Slack mention-gating maintainer and adjacent generated-asset maintainer; confidence: high; commits: f2bf925a38, 5b1c2ee25f0f, 625fd5b3e3e2; files: extensions/slack/src/monitor/message-handler/prepare.ts, src/channels/mention-gating.ts, docs/channels/slack.md)
  • vincentkoc: Recent commit metadata shows Slack prepare hot-path work and inbound metadata hardening adjacent to the PR's Slack and prompt-rendering surfaces. (role: recent Slack and inbound metadata maintainer; confidence: high; commits: ac74a928456d, c0302512d4dd, 6437aa8532f6; files: extensions/slack/src/monitor/message-handler/prepare.ts, src/auto-reply/reply/inbound-meta.ts, docs/channels/slack.md)

Remaining risk / open question:

  • The branch includes an unrelated generated Canvas A2UI hash change that can cause generated-asset drift and should be reverted before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 56fe64e8e369.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 7, 2026
@zeus1959
zeus1959 force-pushed the fix/slack-mention-source-metadata branch from e935cdc to d6783d5 Compare May 7, 2026 20:49
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed size: S proof: sufficient ClawSweeper judged the real behavior proof convincing. labels May 7, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 7, 2026
@bek91

bek91 commented May 8, 2026

Copy link
Copy Markdown
Contributor

@hera8939 Thanks for the PR. The overall direction looks right butI think this needs a couple changes before merge:

  1. Please adjust the mention-source/addressed-to-bot logic so explicit agent invocations do not get treated as purely implicit thread wakes. In resolveSlackMentionSource(), matchedImplicitMentionKinds is checked before wasMentioned.

After explicit bot/subteam handling, wasMentioned is the remaining signal for configured mention-pattern wakes. Thread message that both implicitly wakes the bot and explicitly matches a mention pattern (Bill …), can get mention_source: "implicit_thread" and receive the selective-reply nudge, even though the user explicitly invoked the agent by pattern.

I think the guidance should apply when the turn is not addressed to the bot, such as when mention_source=implicit_thread and explicitly_mentioned_bot=false. But mention-pattern invocations should count as addressed to the bot.

I'd prioritize mention_pattern / command bypass ahead of implicit_thread, or expose both primary and secondary sources and key the guidance off an addressed_to_bot-style boolean.

  1. Please revert the unrelated Canvas hash change: extensions/canvas/src/host/a2ui/.bundle.hash This PR is Slack prompt metadata only, and the hash drift is unrelated.

  2. Please rebase/update after the above fixes.

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

Labels

channel: slack Channel integration: slack docs Improvements or additions to documentation proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slack: preserve explicit mention targets and distinguish implicit thread wakes from bot mentions

2 participants