#20389: fix(slack): inject thread history on first thread turn, not only on session reset
channel: slack
size: XS
Cluster:
Slack Thread Management Improvements
## Summary
- Thread history fetched by `resolveSlackThreadHistory` was silently discarded because `threadContextNote` was gated on `isNewSession` (which only means "user triggered a reset"), not on "first inbound message in a new thread session"
- Use the already-computed `ctx.IsFirstThreadTurn` alongside `isNewSession` so thread context is injected when it should be
- Log errors in `resolveSlackThreadHistory` instead of silently swallowing them via bare `catch {}`
## Test plan
- [x] `pnpm build` passes
- [x] `pnpm test src/slack/monitor/message-handler/prepare.test.ts` — 12 tests pass
- [x] `pnpm test src/auto-reply/reply/` — 474 tests pass
- [x] Verified fix on a live instance with `replyToMode: "first"` and `thread.initialHistoryLimit: 20`
🤖 AI-assisted (Claude) — fully tested on a live OpenClaw instance. Root-caused via debug patch instrumentation on the bundled output. We understand the change.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes a bug where Slack thread history (fetched by `resolveSlackThreadHistory`) was silently discarded on the first message in a new thread session. The root cause was that `threadContextNote` in `get-reply-run.ts` was gated solely on `isNewSession` (which only reflects a user-triggered `/new` or `/reset`), rather than also checking `ctx.IsFirstThreadTurn` (which is true for the first inbound message in a new thread). Additionally improves observability by logging errors in `resolveSlackThreadHistory` instead of silently swallowing them.
- **Core fix**: `shouldInjectThreadContext = isNewSession || ctx.IsFirstThreadTurn` ensures thread history/starter context is injected on first thread turn, not only on explicit session resets
- **Error logging**: `catch {}` in `resolveSlackThreadHistory` now logs the error via `logVerbose` before returning the empty fallback
- **Backward-compatible**: `IsFirstThreadTurn` is `undefined` for non-Slack channels, so the `||` fallback preserves existing behavior
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — the fix is narrowly scoped, backward-compatible, and well-tested.
- The change is small, logically sound, and addresses a clear bug. The `IsFirstThreadTurn` property is only set in Slack's prepare.ts and is `undefined` for all other channels, so the `||` fallback preserves existing behavior perfectly. The error logging improvement is unambiguously positive. One minor inconsistency (parallel `isNewSession` gates at lines 188 and 211-219 not updated) prevents a score of 5 but is non-breaking.
- `src/auto-reply/reply/get-reply-run.ts` — lines 188 and 211-219 still gate `ThreadStarterBody` on `isNewSession` alone, which is inconsistent with the new `shouldInjectThreadContext` logic at line 262.
<sub>Last reviewed commit: 4f8196a</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#22433: Slack: fix thread context loss after session reset
by stgarrity · 2026-02-21
88.1%
#19083: Slack: preserve per-thread context and consistent thread replies
by jkimbo · 2026-02-17
87.7%
#16893: fix(threads): inject thread starter context on every turn, not just...
by battman21 · 2026-02-15
86.5%
#23320: fix(slack): respect replyToMode when incomingThreadTs is auto-created
by dorukardahan · 2026-02-22
85.0%
#20406: fix(slack): respect replyToMode when computing statusThreadTs in DMs
by QuinnYates · 2026-02-18
83.5%
#5935: fix(slack): persist thread starter body across thread messages
by thisischappy · 2026-02-01
83.3%
#10686: fix(slack): use thread-level sessions for channels to prevent conte...
by pablohrcarvalho · 2026-02-06
82.1%
#12244: fix(slack): preserve thread context for DM thread replies
by junhoyeo · 2026-02-09
81.9%
#16186: fix(slack): thread history on subsequent turns, inbound meta contex...
by markshields-tl · 2026-02-14
81.7%
#14720: fix(slack): pass threadId in plugin read action (#14706)
by lailoo · 2026-02-12
81.1%