Skip to content

Slack: each outbound reply persists a new single-message delivery-mirror session instead of reusing the conversation's thread session #96535

Closed

Description

@gorkem2020

Summary

On Slack, when an agent posts a reply, the outbound delivery-mirror persists a brand-new session record keyed agent:<id>:slack:channel:<cid>:thread:<ts> for that reply, rather than appending to the conversation's existing thread session. Each reply carries a distinct timestamp, so a steady stream of single-message sessions accumulates: each contains only the bot's outgoing message (a session header plus one assistant delivery-mirror message, with no inbound user turn), or an empty transcript. An active agent accumulates dozens of these near-empty session records.

A secondary observation: the minted mirror entry has no spawnedCwd, so the session transcript header cwd can fall back to process.cwd() (the gateway process working directory) rather than the agent workspace directory.

Environment

  • OpenClaw 2026.6.1, host-native Node 24 install, gateway running dist/index.js gateway.
  • @openclaw/slack channel plugin 2026.6.1.
  • Still present on the latest release v2026.6.10: no functional change to the outbound mirror session path landed in 2026.6.5 through 2026.6.10.

Steps to reproduce

  1. Configure a Slack channel with an agent that replies in threads (normal threaded behavior).
  2. Have the agent post several replies on the channel.
  3. Inspect the agent session store (sessions.json) and the *.jsonl transcripts.

Expected vs actual

  • Expected: an outbound reply in a thread is mirrored into that thread's existing session (:thread:<rootTs>), so one thread maps to one session.
  • Actual: each outbound reply persists a separate session keyed :thread:<ts> containing only the bot's message, so a single conversation accumulates many assistant-only session records.

Evidence from a live deployment

  • Across the fleet, dozens of :thread:<ts> session entries appear only for Slack-active agents; on one channel a single agent accumulated 21 such entries.
  • The large majority are single-message records: a header plus one assistant message tagged model: "delivery-mirror" with an idempotency key of the form <...>:message-tool:call_<...>, and no inbound user turn; some have an empty transcript.
  • The suffixes are distinct, tightly spaced timestamps (seconds apart) within a continuous exchange. One minted session's outbound reply timestamp was observed becoming the :thread: suffix of the next minted session.
  • One minted key carried thread:/dev/null as its thread id, indicating a non-timestamp value reached the session-key suffix without validation.

Pointers for triage (verified present in the deployed build, not a claimed root cause)

Filenames are build-hashed esbuild chunk names; line numbers are from the deployed 2026.6.1 build.

  • The outbound delivery-mirror is rebuilt and persisted on every send: prepareOutboundMirrorRoute calls ensureOutboundSessionEntry and writes the mirror under the resolved route's session key (dist/message-action-runner-<hash>.js, around lines 565-590).
  • ensureOutboundSessionEntry calls recordSessionMetaFromInbound with no createIfMissing argument (dist/outbound-session-<hash>.js, around lines 122-141), and that defaults createIfMissing = params.createIfMissing ?? true (dist/store-<hash>.js:1254; the only skip is if (!existing && !createIfMissing) at line 1283), so a route key with no existing entry mints a new session.
  • The thread-suffixed key is built by resolveThreadSessionKeys as `${baseSessionKey}:thread:${normalizedThread}` (dist/session-key-<hash>.js, around lines 182-192).
  • The cwd fallback: the transcript header sets cwd: params.cwd ?? process.cwd() (dist/transcript-<hash>.js, around line 142); the mirror append passes cwd: entry.spawnedCwd (around line 745), which is absent on the mirror entry.

Related (not duplicate)

  • #80091 (Slack DM delivery mirrors split sessions; its fix PR #80111 was closed without merging). Same delivery-mirror routing area, but that report is a DM peer mis-classification.
  • #78505 (outbound thread reply does not promote the session key; closed). Closest conceptual match.
  • #87019 (Slack DM session fan-out; open) and umbrella #69208 (cross-channel transcript and session duplication).

Activity

  1. clawsweeper commented on Jun 24, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 24, 2026, 3:27 PM ET / 19:27 UTC.

    Summary
    Keep open: current main and the latest release still have a source-reproducible Slack outbound mirror path where an inherited child reply timestamp can win over the existing thread session and create a fresh mirror-only session entry.

    Reproducibility: yes. at source level: an inherited Slack child reply timestamp can enter outbound mirror routing and win over the recovered current thread session before ensureOutboundSessionEntry creates the missing mirror session. I did not run a live Slack workspace replay.

    Next step
    The source path, likely files, and focused regression tests are clear enough for one narrow fix PR, and no open PR currently owns this exact symptom.

    Review details

    Best possible solution:

    Fix Slack outbound mirror routing so inherited same-thread replies mirror into the canonical/current Slack thread session while preserving explicit reply/thread targets and ordinary top-level channel sessions.

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

    Yes, at source level: an inherited Slack child reply timestamp can enter outbound mirror routing and win over the recovered current thread session before ensureOutboundSessionEntry creates the missing mirror session. I did not run a live Slack workspace replay.

    Is this the best way to solve the issue?

    Yes, the narrow maintainable direction is to canonicalize Slack inherited same-thread reply routing to the thread root or existing thread session for delivery mirrors, rather than adding a config flag or changing generic precedence for every channel.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • No live Slack workspace replay was run in this read-only review; the reproduction is source-level plus reporter deployment evidence.
    • A broad generic precedence change could regress other channels or Slack's flat top-level channel-session policy, so the fix should stay Slack/thread-context-specific and be covered by sibling tests.

    Codex review notes: model internal, reasoning high; reviewed against 7e2b2d2987b2.

    Label changes

    Label justifications:

    • P2: The issue is a normal-priority Slack channel/session bug with limited blast radius to outbound delivery-mirror state.
    • impact:session-state: The reported behavior creates near-empty sibling sessions instead of updating the intended Slack thread session.
    • impact:message-loss: Outbound mirror records are associated away from the conversation thread, leaving persisted channel-message history incomplete for that thread.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs run src/infra/outbound/message-action-runner.threading.test.ts
    • node scripts/run-vitest.mjs run extensions/slack/src/channel.test.ts extensions/slack/src/threading-tool-context.test.ts
    • node scripts/run-vitest.mjs run src/plugin-sdk/thread-aware-outbound-session-route.test.ts extensions/slack/src/monitor/message-handler/prepare.thread-session-key.test.ts
    • pnpm tsgo:extensions

    What I checked:

    • Repository policy read: Root AGENTS.md plus the relevant scoped extension/channel/outbound guides were read fully; they require deep source/history review for channel and session routing decisions. (AGENTS.md:1, 7e2b2d2987b2)
    • Outbound mirror source: prepareOutboundMirrorRoute resolves thread/reply inputs, calls resolveOutboundSessionRoute with replyToId, threadId, and currentSessionKey, then calls ensureOutboundSessionEntry for any returned route. (src/infra/outbound/message-action-threading.ts:193, 7e2b2d2987b2)
    • Slack route source: resolveSlackOutboundSessionRoute builds the Slack base session key and passes replyToId, threadId, and currentSessionKey into buildThreadAwareOutboundSessionRoute. (extensions/slack/src/channel.ts:309, 7e2b2d2987b2)
    • Thread route precedence: buildThreadAwareOutboundSessionRoute defaults precedence to replyToId, then threadId, then currentSession, so a child Slack reply timestamp can win over the recovered current thread session. (src/plugin-sdk/core.ts:443, 7e2b2d2987b2)
    • Session entry creation: ensureOutboundSessionEntry calls recordSessionMetaFromInbound without createIfMissing, and recordSessionMetaFromInbound defaults createIfMissing to true before persisting a new session entry. (src/config/sessions/store.ts:1868, 7e2b2d2987b2)
    • Shipped release check: v2026.6.10 is present and its tagged source has the same Slack route and shared thread precedence shape, matching the reporter's latest-release claim. (src/plugin-sdk/core.ts:443, aa69b12d0086)

    Likely related people:

    • sandieman2: Recent merged work on Slack/reply delivery route dedupe and routed thread preservation touched the Slack channel and outbound routing surfaces implicated here. (role: recent reply and Slack routing contributor; confidence: high; commits: c67dc59b02b0; files: extensions/slack/src/channel.ts, src/infra/outbound/message-action-threading.ts)
    • amknight: Authored the merged Mattermost one-root reply-thread fix that is the closest sibling pattern for mirroring inherited replies to the root session. (role: adjacent one-root transport contributor; confidence: medium; commits: 2365a137d88c; files: src/infra/outbound/message-action-threading.ts, extensions/mattermost/src/session-route.ts)
    • jalehman: Recent session metadata/store refactors and current main history make this person relevant for the session-entry side of the bug. (role: recent session metadata contributor; confidence: medium; commits: 7e2b2d2987b2, 9512294e8f62; files: src/config/sessions/store.ts)
    • steipete: GitHub file history shows repeated Slack channel, outbound SDK, and channel refactor work that shaped the route and plugin seams involved here. (role: historical Slack/channel SDK contributor; confidence: medium; commits: 1507a9701b83, c4f0da00a9fe, 50c77f23c1c1; files: extensions/slack/src/channel.ts, src/plugin-sdk/core.ts)
    • vincentkoc: Recent Slack and outbound-adjacent history plus coauthorship on the Mattermost route fix make this a plausible reviewer for channel routing invariants. (role: adjacent channel/outbound contributor; confidence: low; commits: 7da955fae4ca, 2365a137d88c; files: extensions/slack/src/channel.ts, src/infra/outbound/message-action-threading.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    no-staleExclude from stale automation
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on Jun 24, 2026
  3. self-assigned this
    on Jun 30, 2026
  4. locked as resolved and limited conversation to collaborators on Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automation

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions