Skip to content

fix(slack): route DM thread replies to main session instead of thread-scoped session - #82418

Merged
steipete merged 8 commits into
openclaw:mainfrom
kagura-chen:fix/slack-dm-thread-reply-routing
May 16, 2026
Merged

steipete merged 8 commits into
openclaw:mainfrom
kagura-chen:fix/slack-dm-thread-reply-routing

Conversation

@kagura-chen

@kagura-chen kagura-chen commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Slack DM thread replies now stay on the main direct-message session instead of creating invisible :thread:<thread_ts> sessions.
  • Explicit runtime conversation bindings for Slack DM threads still win, so ACP/subagent-bound conversations keep routing to their bound session.
  • Slack UI thread delivery is preserved through ReplyToId/TransportThreadId, last-route metadata, routed replies, ACP delivery, queued follow-ups, and Slack tool context.
  • Scope boundary: this does not fully fix assistant message_changed dispatch. Refs [Bug] Slack DM inbound silently dropped for thread replies + assistant_app_thread message_changed events #82390.

Verification

Behavior addressed: Slack DM thread replies no longer route to thread-scoped sessions by default; explicit runtime DM thread bindings remain honored; routed/ACP/tool/follow-up deliveries keep the Slack UI thread target.
Real environment tested: local OpenClaw source checkout with Slack routing, prepare, dispatch, session, routed reply, ACP delivery, follow-up, and tool-context tests after rebasing onto origin/main.
Exact steps or command run after this patch:

  • git rebase origin/main
  • git diff --check
  • /Users/steipete/Projects/agent-scripts/skills/codex-review/scripts/codex-review --parallel-tests 'pnpm test extensions/slack/src/threading-tool-context.test.ts && pnpm test src/auto-reply/reply/dispatch-from-config.test.ts -t "Slack DM TransportThreadId|thread-scoped session key|cleared route thread" && pnpm test src/auto-reply/reply/dispatch-acp-delivery.test.ts -t "Slack DM TransportThreadId|mirrors routed ACP replies" && pnpm test src/auto-reply/reply/get-reply-run.media-only.test.ts -t "transport thread metadata" && pnpm test src/auto-reply/reply/session.test.ts -t "transport thread routing" && pnpm test extensions/slack/src/monitor/message-handler/dispatch.preview-fallback.test.ts -t "transport thread metadata|non-main DM last-route|main-scope DM last-route" && pnpm test extensions/slack/src/monitor/message-handler/prepare.test.ts -t "DM thread replies|parent_user_id replies|open DMs|preserves Slack thread history"'
  • pnpm test extensions/slack/src/threading-tool-context.test.ts && pnpm test src/auto-reply/reply/dispatch-from-config.test.ts -t "Slack DM TransportThreadId|thread-scoped session key|cleared route thread" && pnpm test src/auto-reply/reply/dispatch-acp-delivery.test.ts -t "Slack DM TransportThreadId|mirrors routed ACP replies" && pnpm test src/auto-reply/reply/get-reply-run.media-only.test.ts -t "transport thread metadata" && pnpm test src/auto-reply/reply/session.test.ts -t "transport thread routing" && pnpm test extensions/slack/src/monitor/message-handler/dispatch.preview-fallback.test.ts -t "transport thread metadata|non-main DM last-route|main-scope DM last-route" && pnpm test extensions/slack/src/monitor/message-handler/prepare.test.ts -t "DM thread replies|parent_user_id replies|open DMs|preserves Slack thread history"
    Evidence after fix: codex-review reported no actionable findings; the focused rebased proof passed 16 Slack tool-context tests, 3 dispatch-from-config routing tests, 2 ACP delivery tests, 1 follow-up delivery test, 1 session routing test, 3 Slack dispatch tests, and 5 Slack prepare tests.
    Observed result after fix: unbound Slack DM thread replies route to the direct/main DM session without MessageThreadId or a :thread: session suffix; TransportThreadId/ReplyToId preserve Slack UI thread delivery; explicit runtime bindings still route to the bound session; legacy thread-session store entries do not suppress Slack thread history.
    What was not tested: live Slack DM roundtrip; full assistant message_changed dispatch recovery. A broad reviewer-triggered prepare.test.ts run still hits unrelated existing media-history assertions around skipped no-mention images.

@openclaw-barnacle openclaw-barnacle Bot added channel: slack Channel integration: slack size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 16, 2026
@clawsweeper

clawsweeper Bot commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
This PR flattens unbound Slack DM thread replies to the main direct-message session, preserves explicit runtime thread bindings, adds a verbose Assistant message_changed diagnostic, updates focused tests, and adds a changelog entry.

Reproducibility: yes. at source level: current main maps direct-message thread replies to threadTs and current tests assert thread-suffixed DM session keys. I did not establish a live Slack workspace reproduction in this read-only review.

Real behavior proof
Needs real behavior proof before merge: Needs real behavior proof before merge: the PR body provides only local Vitest/source checks and explicitly says no live Slack workspace roundtrip was run; add redacted Slack Socket Mode evidence or a maintainer proof override, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.

Next step before merge
Human handling is needed for real Slack proof or maintainer override, plus acceptance and documentation of the DM thread-routing contract.

Security
Cleared: The diff is limited to Slack TypeScript routing/logging, tests, and changelog text with no dependency, workflow, install, secret, or package-resolution changes.

Review findings

  • [P2] Document the DM thread-session exception — extensions/slack/src/monitor/message-handler/prepare-routing.ts:206-209
Review details

Best possible solution:

Land the narrow DM-thread routing fix after documenting the DM exception and adding redacted live Slack proof or an explicit maintainer proof override, while keeping Assistant App dispatch work in the linked follow-up.

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

Yes at source level: current main maps direct-message thread replies to threadTs and current tests assert thread-suffixed DM session keys. I did not establish a live Slack workspace reproduction in this read-only review.

Is this the best way to solve the issue?

No, not in the current PR form: the route change is narrow and preserves runtime bindings, but the public docs must be updated and real Slack behavior proof or an explicit maintainer override is still needed.

Full review comments:

  • [P2] Document the DM thread-session exception — extensions/slack/src/monitor/message-handler/prepare-routing.ts:206-209
    This branch makes direct-message thread replies bypass 🧵 session keys, but docs/channels/slack.md still says Slack thread replies always use parent thread_ts and that replyToMode="off" does not flatten inbound thread sessions. Update the Slack docs with the DM exception so shipped behavior does not contradict the public session contract.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.84

Acceptance criteria:

  • node scripts/run-vitest.mjs extensions/slack/src/monitor/message-handler/prepare.thread-session-key.test.ts extensions/slack/src/monitor/message-handler/prepare.test.ts extensions/slack/src/monitor/message-handler/dispatch.preview-fallback.test.ts extensions/slack/src/monitor/events/messages.test.ts
  • Redacted live Slack Socket Mode proof for a DM thread reply under a bot DM message, or explicit maintainer proof override

What I checked:

  • Current main routes DM thread replies to thread sessions: On current main, resolveSlackRoutingContext assigns direct-message thread replies to threadTs, which feeds the thread-suffixed session-key path. (extensions/slack/src/monitor/message-handler/prepare-routing.ts:206, 605a2c87ae80)
  • Current tests assert the old DM thread-session shape: Existing prepare coverage expects per-peer and main-scope DM thread replies to produce SessionKey values with 🧵 suffixes. (extensions/slack/src/monitor/message-handler/prepare.test.ts:1505, 605a2c87ae80)
  • Public docs still describe all inbound Slack thread replies as thread-scoped: The Slack docs say thread replies use the parent thread_ts for 🧵 session suffixes and that replyToMode="off" does not flatten inbound thread sessions, with no DM exception. Public docs: docs/channels/slack.md. (docs/channels/slack.md:952, 605a2c87ae80)
  • PR head changes code and tests but not Slack docs: The patch changes prepare-routing.ts, Slack message event logging, focused prepare tests, and CHANGELOG.md; it does not modify docs/channels/slack.md. (extensions/slack/src/monitor/message-handler/prepare-routing.ts:206, d10ebe894875)
  • Real behavior proof is not present: The PR body lists local source/Vitest verification and explicitly says no live Slack workspace roundtrip was tested; the author comment asks for a possible maintainer proof override. (d10ebe894875)
  • Related report remains broader than this PR: The linked open issue covers both DM thread replies and Assistant App assistant_app_thread message_changed dispatch; this PR only fixes the DM routing path and adds a diagnostic for unresolved Assistant edits.

Likely related people:

  • steipete: Current-line blame for the Slack DM/thread routing branch, docs threading contract, and related tests points to Peter Steinberger, and the PR timeline shows steipete force-pushed the current head after follow-up routing/test commits. (role: recent Slack routing/docs contributor; confidence: high; commits: 7e0e29ef1749, d10ebe894875; files: extensions/slack/src/monitor/message-handler/prepare-routing.ts, extensions/slack/src/monitor/message-handler/prepare.test.ts, docs/channels/slack.md)
  • vincentkoc: The Slack history includes fix(slack): finalize replyToMode off threading behavior, which is directly adjacent to the inbound thread-session contract this PR changes. (role: replyToMode threading behavior contributor; confidence: medium; commits: 89a1e9981596; files: extensions/slack/src/monitor/message-handler/prepare-routing.ts, extensions/slack/src/monitor/message-handler/prepare.test.ts, docs/channels/slack.md)
  • Masataka Shinohara: Recent Slack history includes the thread-session history fix, which is adjacent to decisions about when Slack thread replies should use separate session keys and history context. (role: thread-session history contributor; confidence: medium; commits: b93ad2cd481f; files: extensions/slack/src/monitor/message-handler/prepare.ts, extensions/slack/src/monitor/message-handler/prepare.test.ts, docs/channels/slack.md)

Remaining risk / open question:

Codex review notes: model gpt-5.5, reasoning high; reviewed against 605a2c87ae80.

@kagura-chen

Copy link
Copy Markdown
Contributor Author

Re: Real behavior proof gate — this is a pure routing-logic fix in prepare-routing.ts (3-line change). The added test exercises resolveSlackRoutingContext with the exact DM-thread-reply payload pattern from the issue (channel_type: "im", thread_ts set, parent_user_id set) and confirms the session key no longer gets a :thread: suffix. I don't have a Slack workspace to produce live runtime evidence, so this may need a proof: override from a maintainer.

@steipete
steipete force-pushed the fix/slack-dm-thread-reply-routing branch from 50b2778 to f4e0f46 Compare May 16, 2026 12:35
@steipete
steipete force-pushed the fix/slack-dm-thread-reply-routing branch from f4e0f46 to d10ebe8 Compare May 16, 2026 12:46
kagura-chen and others added 8 commits May 16, 2026 16:17
…-scoped session

DM thread replies (user replies inside a thread under a bot message in a
DM) were routed to a thread-specific session key instead of the user's
main DM session.  This caused the agent to never receive the inbound on
the expected session, making the bot appear unresponsive.

The root cause was in prepare-routing.ts: canonicalThreadId for
isDirectMessage was set to threadTs when isThreadReply was true, creating
a session key like agent:main:slack:direct:u3:thread:<ts>.  DM threads
are a UI affordance — not a session boundary — so all DM messages should
route to the main DM session regardless of thread_ts.

Also adds a diagnostic logVerbose warning when assistant_app_thread
message_changed events fail sender resolution (Case 2 of openclaw#82390),
which was previously completely silent.

Fixes openclaw#82390
@steipete
steipete force-pushed the fix/slack-dm-thread-reply-routing branch from d10ebe8 to 899f30a Compare May 16, 2026 15:19
@steipete steipete added proof: override Maintainer override for the external PR real behavior proof gate. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 16, 2026
@steipete

Copy link
Copy Markdown
Contributor

Maintainer fixups pushed after rebase on origin/main.

Verification:

  • git diff --check
  • codex-review --parallel-tests ...: clean, no accepted/actionable findings
  • Focused rebased proof: pnpm test extensions/slack/src/threading-tool-context.test.ts && pnpm test src/auto-reply/reply/dispatch-from-config.test.ts -t "Slack DM TransportThreadId|thread-scoped session key|cleared route thread" && pnpm test src/auto-reply/reply/dispatch-acp-delivery.test.ts -t "Slack DM TransportThreadId|mirrors routed ACP replies" && pnpm test src/auto-reply/reply/get-reply-run.media-only.test.ts -t "transport thread metadata" && pnpm test src/auto-reply/reply/session.test.ts -t "transport thread routing" && pnpm test extensions/slack/src/monitor/message-handler/dispatch.preview-fallback.test.ts -t "transport thread metadata|non-main DM last-route|main-scope DM last-route" && pnpm test extensions/slack/src/monitor/message-handler/prepare.test.ts -t "DM thread replies|parent_user_id replies|open DMs|preserves Slack thread history"

Result: Slack DM thread replies use the direct/main DM session, while TransportThreadId keeps routed/tool/ACP/follow-up delivery anchored to the Slack UI thread. Explicit runtime DM-thread bindings still win. Live Slack roundtrip not run; applying proof override for deterministic routing/session fix.

@steipete
steipete merged commit ffdc7aa into openclaw:main May 16, 2026
120 of 126 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…-scoped session (openclaw#82418)

* fix(slack): route DM thread replies to main session instead of thread-scoped session

DM thread replies (user replies inside a thread under a bot message in a
DM) were routed to a thread-specific session key instead of the user's
main DM session.  This caused the agent to never receive the inbound on
the expected session, making the bot appear unresponsive.

The root cause was in prepare-routing.ts: canonicalThreadId for
isDirectMessage was set to threadTs when isThreadReply was true, creating
a session key like agent:main:slack:direct:u3:thread:<ts>.  DM threads
are a UI affordance — not a session boundary — so all DM messages should
route to the main DM session regardless of thread_ts.

Also adds a diagnostic logVerbose warning when assistant_app_thread
message_changed events fail sender resolution (Case 2 of openclaw#82390),
which was previously completely silent.

Fixes openclaw#82390

* chore(slack): polish DM thread routing PR

* test(slack): update DM thread routing contract

* test(slack): flatten non-main DM thread expectations

* fix(slack): preserve bound DM thread routes

* test(slack): align DM thread session fixtures

* fix(slack): keep flattened DM thread metadata scoped

* fix(slack): preserve DM thread delivery routes

---------

Co-authored-by: Peter Steinberger <[email protected]>
galiniliev pushed a commit to galiniliev/openclaw that referenced this pull request May 25, 2026
…-scoped session (openclaw#82418)

* fix(slack): route DM thread replies to main session instead of thread-scoped session

DM thread replies (user replies inside a thread under a bot message in a
DM) were routed to a thread-specific session key instead of the user's
main DM session.  This caused the agent to never receive the inbound on
the expected session, making the bot appear unresponsive.

The root cause was in prepare-routing.ts: canonicalThreadId for
isDirectMessage was set to threadTs when isThreadReply was true, creating
a session key like agent:main:slack:direct:u3:thread:<ts>.  DM threads
are a UI affordance — not a session boundary — so all DM messages should
route to the main DM session regardless of thread_ts.

Also adds a diagnostic logVerbose warning when assistant_app_thread
message_changed events fail sender resolution (Case 2 of openclaw#82390),
which was previously completely silent.

Fixes openclaw#82390

* chore(slack): polish DM thread routing PR

* test(slack): update DM thread routing contract

* test(slack): flatten non-main DM thread expectations

* fix(slack): preserve bound DM thread routes

* test(slack): align DM thread session fixtures

* fix(slack): keep flattened DM thread metadata scoped

* fix(slack): preserve DM thread delivery routes

---------

Co-authored-by: Peter Steinberger <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…-scoped session (openclaw#82418)

* fix(slack): route DM thread replies to main session instead of thread-scoped session

DM thread replies (user replies inside a thread under a bot message in a
DM) were routed to a thread-specific session key instead of the user's
main DM session.  This caused the agent to never receive the inbound on
the expected session, making the bot appear unresponsive.

The root cause was in prepare-routing.ts: canonicalThreadId for
isDirectMessage was set to threadTs when isThreadReply was true, creating
a session key like agent:main:slack:direct:u3:thread:<ts>.  DM threads
are a UI affordance — not a session boundary — so all DM messages should
route to the main DM session regardless of thread_ts.

Also adds a diagnostic logVerbose warning when assistant_app_thread
message_changed events fail sender resolution (Case 2 of openclaw#82390),
which was previously completely silent.

Fixes openclaw#82390

* chore(slack): polish DM thread routing PR

* test(slack): update DM thread routing contract

* test(slack): flatten non-main DM thread expectations

* fix(slack): preserve bound DM thread routes

* test(slack): align DM thread session fixtures

* fix(slack): keep flattened DM thread metadata scoped

* fix(slack): preserve DM thread delivery routes

---------

Co-authored-by: Peter Steinberger <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
…-scoped session (openclaw#82418)

* fix(slack): route DM thread replies to main session instead of thread-scoped session

DM thread replies (user replies inside a thread under a bot message in a
DM) were routed to a thread-specific session key instead of the user's
main DM session.  This caused the agent to never receive the inbound on
the expected session, making the bot appear unresponsive.

The root cause was in prepare-routing.ts: canonicalThreadId for
isDirectMessage was set to threadTs when isThreadReply was true, creating
a session key like agent:main:slack:direct:u3:thread:<ts>.  DM threads
are a UI affordance — not a session boundary — so all DM messages should
route to the main DM session regardless of thread_ts.

Also adds a diagnostic logVerbose warning when assistant_app_thread
message_changed events fail sender resolution (Case 2 of openclaw#82390),
which was previously completely silent.

Fixes openclaw#82390

* chore(slack): polish DM thread routing PR

* test(slack): update DM thread routing contract

* test(slack): flatten non-main DM thread expectations

* fix(slack): preserve bound DM thread routes

* test(slack): align DM thread session fixtures

* fix(slack): keep flattened DM thread metadata scoped

* fix(slack): preserve DM thread delivery routes

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack proof: override Maintainer override for the external PR real behavior proof gate. size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants