fix(slack): honor replyToModeByChatType when ThreadLabel exists (#26251)

* fix(slack): honor direct replyToMode when thread label exists

ThreadLabel is a session/conversation label, not a reliable indicator
of an actual Slack thread reply. Using it to force replyToMode="all"
overrides replyToModeByChatType.direct="off" in DMs.

Switch to MessageThreadId which indicates a real thread target is
available, preserving expected behavior: thread replies stay threaded,
normal DMs respect the configured mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Slack: add changelog for threading tool context fix

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
dan bachelder
2026-03-01 09:02:06 -08:00
committed by GitHub
parent a28a4b1b61
commit 46da76e267
3 changed files with 50 additions and 4 deletions

View File

@@ -243,6 +243,7 @@ Docs: https://docs.openclaw.ai
- Slack/Identity: thread agent outbound identity (`chat:write.customize` overrides) through the channel reply delivery path so per-agent username, icon URL, and icon emoji are applied to all Slack replies including media messages. (#27134) Thanks @hou-rong.
- Slack/Threading: resolve `replyToMode` per incoming message using chat-type-aware account config (`replyToModeByChatType` and legacy `dm.replyToMode`) so DM/channel reply threading honors overrides instead of always using monitor startup defaults. (#24717) Thanks @dbachelder.
- Slack/Threading: track bot participation in message threads (per account/channel/thread) so follow-up messages in those threads can be handled without requiring repeated @mentions, while preserving mention-gating behavior for unrelated threads. (#29165) Thanks @luijoc.
- Slack/Threading: stop forcing tool-call reply mode to `all` based on `ThreadLabel` alone; now force thread reply mode only when an explicit thread target exists (`MessageThreadId`/`ReplyToId`), so DM `replyToModeByChatType.direct` overrides are honored outside real thread replies. (#26251) Thanks @dbachelder.
- Agents/Subagents delivery: refactor subagent completion announce dispatch into an explicit queue/direct/fallback state machine, recover outbound channel-plugin resolution in cold/stale plugin-registry states across announce/message/gateway send paths, finalize cleanup bookkeeping when announce flow rejects, and treat Telegram sends without `message_id` as delivery failures (instead of false-success `"unknown"` IDs). (#26867, #25961, #26803, #25069, #26741) Thanks @SmithLabsLLC and @docaohieu2808.
- Telegram/Webhook: pre-initialize webhook bots, switch webhook processing to callback-mode JSON handling, and preserve full near-limit payload reads under delayed handlers to prevent webhook request hangs and dropped updates. (#26156)
- Slack/Session threads: prevent oversized parent-session inheritance from silently bricking new thread sessions, surface embedded context-overflow empty-result failures to users, and add configurable `session.parentForkMaxTokens` (default `100000`, `0` disables). (#26912) Thanks @markshields-tl.

View File

@@ -86,20 +86,64 @@ describe("buildSlackThreadingToolContext", () => {
expect(result.replyToMode).toBe("all");
});
it("uses all mode when ThreadLabel is present", () => {
it("uses all mode when MessageThreadId is present", () => {
const cfg = {
channels: {
slack: { replyToMode: "off" },
slack: {
replyToMode: "all",
replyToModeByChatType: { direct: "off" },
},
},
} as OpenClawConfig;
const result = buildSlackThreadingToolContext({
cfg,
accountId: null,
context: { ChatType: "channel", ThreadLabel: "some-thread" },
context: {
ChatType: "direct",
ThreadLabel: "thread-label",
MessageThreadId: "1771999998.834199",
},
});
expect(result.replyToMode).toBe("all");
});
it("does not force all mode from ThreadLabel alone", () => {
const cfg = {
channels: {
slack: {
replyToMode: "all",
replyToModeByChatType: { direct: "off" },
},
},
} as OpenClawConfig;
const result = buildSlackThreadingToolContext({
cfg,
accountId: null,
context: {
ChatType: "direct",
ThreadLabel: "label-without-real-thread",
},
});
expect(result.replyToMode).toBe("off");
});
it("keeps configured channel behavior when not in a thread", () => {
const cfg = {
channels: {
slack: {
replyToMode: "off",
replyToModeByChatType: { channel: "first" },
},
},
} as OpenClawConfig;
const result = buildSlackThreadingToolContext({
cfg,
accountId: null,
context: { ChatType: "channel", ThreadLabel: "label-only" },
});
expect(result.replyToMode).toBe("first");
});
it("defaults to off when no replyToMode is configured", () => {
const result = buildSlackThreadingToolContext({
cfg: emptyCfg,

View File

@@ -16,7 +16,8 @@ export function buildSlackThreadingToolContext(params: {
accountId: params.accountId,
});
const configuredReplyToMode = resolveSlackReplyToMode(account, params.context.ChatType);
const effectiveReplyToMode = params.context.ThreadLabel ? "all" : configuredReplyToMode;
const hasExplicitThreadTarget = params.context.MessageThreadId != null;
const effectiveReplyToMode = hasExplicitThreadTarget ? "all" : configuredReplyToMode;
const threadId = params.context.MessageThreadId ?? params.context.ReplyToId;
return {
currentChannelId: params.context.To?.startsWith("channel:")