Skip to content

fix(slack): thread sessions broken — fork gate + history injection - #23090

Closed
Taskle wants to merge 2 commits into
openclaw:mainfrom
Taskle:fix/thread-fork-gate-4927
Closed

Taskle wants to merge 2 commits into
openclaw:mainfrom
Taskle:fix/thread-fork-gate-4927

Conversation

@Taskle

@Taskle Taskle commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Thread sessions in Slack DMs are fundamentally broken. Agents lose all thread context after the first turn, making threaded conversations unusable.

Root Cause

Three independent gates conspire to break thread sessions:

1. Session fork gate (initSessionState)

The forkSessionFromParent call is gated by isNewSession, but the session is always pre-created by the outbound reply handler before initSessionState runs. So isNewSession is always false for thread sessions, and forking never fires.

Fix: Track forkedFromParent flag on the session entry. Gate on !alreadyForked instead of isNewSession.

2. Thread history fetch gate (prepare.ts)

if (threadInitialHistoryLimit > 0 && !threadSessionPreviousTimestamp) {

The !threadSessionPreviousTimestamp condition means thread history is only fetched on the very first turn. Once the session exists and has a stored timestamp, this gate blocks all subsequent fetches.

Fix: Remove && !threadSessionPreviousTimestamp — always fetch the last N messages.

3. Thread history injection gate (get-reply-run.ts)

const threadContextNote = isNewSession && threadHistoryBody ? ...

The isNewSession && condition discards fetched thread history when building the prompt on non-new sessions. Even if history was successfully fetched, it is thrown away.

Fix: Remove isNewSession && — always inject thread context when available.

Changes

File Change
src/auto-reply/session/init-session-state.ts Add forkedFromParent flag, gate fork on !alreadyForked instead of isNewSession, add error logging
src/slack/monitor/message-handler/prepare.ts Remove !threadSessionPreviousTimestamp from fetch gate
src/auto-reply/reply/get-reply-run.ts Remove isNewSession && from injection gate

Testing

Validated on a live OpenClaw instance with monkeypatched dist:

  • Thread history now appears on every turn (sliding window of last 20 messages)
  • Session forking fires correctly on first thread interaction
  • No regressions on non-thread DM sessions

…en session pre-created

When replyToMode='all', the bot's outbound reply calls recordSessionMetaFromInbound
which pre-creates the thread session entry before any user message arrives. This makes
isNewSession=false when the user's first thread reply is processed, so
forkSessionFromParent() is never called — even with inheritParent: true.

Replace the isNewSession gate with a forkedFromParent session flag that tracks whether
the fork has been attempted. This allows the fork to fire on the first user message
regardless of whether the session entry was pre-created by outbound delivery.

Also add logging to forkSessionFromParent's catch block, which previously swallowed
all errors silently.

Fixes openclaw#4927
Related: openclaw#23037, openclaw#12742, openclaw#12586
@openclaw-barnacle openclaw-barnacle Bot added the channel: slack Channel integration: slack label Feb 22, 2026
@Taskle Taskle changed the title fix(slack): thread session fork never fires — isNewSession gate bypassed by outbound pre-creation fix(slack): thread sessions broken — fork gate + history injection Feb 22, 2026
@Taskle
Taskle force-pushed the fix/thread-fork-gate-4927 branch 2 times, most recently from 5a45b73 to dad1d36 Compare February 22, 2026 02:09
Two gates block thread history on subsequent turns:

1. prepare.ts: `!threadSessionPreviousTimestamp` condition skips
   the thread history fetch when the session already has a stored
   timestamp (i.e. every turn after the first).

2. get-reply-run.ts: `isNewSession &&` condition discards the
   fetched thread history body when injecting it into the prompt
   on non-new sessions.

Remove both gates so thread context is fetched and injected on
every turn, giving the agent sliding-window thread awareness.
@Taskle
Taskle force-pushed the fix/thread-fork-gate-4927 branch from dad1d36 to 6a3a99c Compare February 22, 2026 02:24
@Taskle

Taskle commented Feb 22, 2026

Copy link
Copy Markdown
Contributor Author

The checks-windows (node, test) failure is not related to this PR — it's a pre-existing bug in src/memory/qmd-manager.test.ts where the test hardcodes Unix-style path separators (/agents/main/qmd/xdg-config) but Windows resolves with backslashes. Same test is failing on at least 7 other unrelated PRs (#23134, #23131, #23118, #23117, #23112, #23110, #23108). All Linux/bun/node checks pass

@vincentkoc

Copy link
Copy Markdown
Member

Consolidated into #23843 to land this as a focused continuity fix on current main with targeted tests + changelog.

This keeps the three thread-session gates in one mergeable PR:

  • parent-session fork gate for preseeded thread keys
  • thread history fetch gate beyond first turn
  • thread context prompt injection gate beyond first turn

Closing as superseded.
EOF && gh pr close 23090 --repo openclaw/openclaw --comment "Superseded by #23843."

@vincentkoc

Copy link
Copy Markdown
Member

Superseded by #23843.

@vincentkoc vincentkoc closed this Feb 22, 2026
@Taskle
Taskle deleted the fix/thread-fork-gate-4927 branch February 25, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants