← Back to PRs

#20389: fix(slack): inject thread history on first thread turn, not only on session reset

by lafawnduh1966 open 2026-02-18 21:15 View on GitHub →
channel: slack size: XS
## 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