← Back to PRs

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

by Taskle open 2026-02-22 00:53 View on GitHub →
channel: slack size: XS
## 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`) ```typescript 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`) ```typescript 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

Most Similar PRs