fix(slack): reduce token bloat by skipping thread context on existing sessions#27609
Closed
sourman wants to merge 1 commit intoopenclaw:mainfrom
Closed
fix(slack): reduce token bloat by skipping thread context on existing sessions#27609sourman wants to merge 1 commit intoopenclaw:mainfrom
sourman wants to merge 1 commit intoopenclaw:mainfrom
Conversation
… sessions Thread history and thread starter were being included on every message in a thread, not just the first message. This caused significant token bloat since the session transcript already maintains the full conversation history. Changes: - Only fetch ThreadHistoryBody for new thread sessions (when !threadSessionPreviousTimestamp) - Only include ThreadStarterBody for new thread sessions (existing sessions already have it in their transcript) This fixes the issue where: - First message: Gets "[Thread history - for context]" with full thread (correct) - Subsequent messages: Were getting "[Thread starter - for context]" redundantly (now fixed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Greptile SummaryThis PR fixes token bloat in Slack threads by preventing redundant context from being fetched and included on every message. The fix ensures thread history and thread starter context are only included for new thread sessions - existing sessions already have this context in their transcript. Key changes:
The implementation is clean, well-tested, and addresses the stated problem effectively. Confidence Score: 5/5
Last reviewed commit: b40d384 |
sourman
pushed a commit
to sourman/openclaw
that referenced
this pull request
Feb 26, 2026
Further reduces token bloat by removing two redundant context elements: 1. [Thread starter - for context] wrapper - The thread starter is already included in the [Thread history - for context] on the first message, and the session transcript maintains context for subsequent messages. 2. Message preview in system events - The "Slack message in #channel from Sender: message preview" was duplicating the actual message body that follows. Removed the preview, keeping only the metadata label. Result: Messages now go directly to the LLM without redundant wrappers: - Before: "[Thread starter - for context]\n<@U0AF3PBGARJ> hello\n\nSystem: [timestamp] Slack message...\n\nactual message" - After: "actual message" The session transcript and initial thread history provide sufficient context for the LLM to understand the conversation. Related to openclaw#27609 (initial fix for thread history bloat) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
17 tasks
sourman
pushed a commit
to sourman/openclaw
that referenced
this pull request
Feb 26, 2026
Further reduces token bloat by removing two redundant context elements: 1. [Thread starter - for context] wrapper - The thread starter is already included in the [Thread history - for context] on the first message, and the session transcript maintains context for subsequent messages. 2. Message preview in system events - The "Slack message in #channel from Sender: message preview" was duplicating the actual message body that follows. Removed the preview, keeping only the metadata label. Result: Messages now go directly to the LLM without redundant wrappers: - Before: "[Thread starter - for context]\n<@U0AF3PBGARJ> hello\n\nSystem: [timestamp] Slack message...\n\nactual message" - After: "actual message" The session transcript and initial thread history provide sufficient context for the LLM to understand the conversation. Related to openclaw#27609 (initial fix for thread history bloat) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sourman
pushed a commit
to sourman/openclaw
that referenced
this pull request
Feb 26, 2026
Further reduces token bloat while preserving context for multi-human threads: 1. [Thread starter - for context] wrapper - The thread starter is already included in the [Thread history - for context] on the first message, and the session transcript maintains context for subsequent messages. 2. Verbose system event reduced to simple sender preamble - Changed from "System: [timestamp] Slack message in #channel from Sender: preview" to just "Slack message from Sender" for clean sender identification in multi-human threads. Result: Messages now show clean sender context without redundant metadata: - Before: "[Thread starter - for context]\nstarter\n\nSystem: [timestamp] Slack message in #channel from Sender: preview\n\nactual message" - After: "Slack message from Sender\n\nactual message" For the first message in a new thread session, full thread history is provided. Related to openclaw#27609 (initial fix for thread history bloat) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
This PR works well for requireMention = false, but for requireMention = true it actually breaks the context passing. need to rethink it |
4 tasks
sourman
pushed a commit
to sourman/openclaw
that referenced
this pull request
Feb 27, 2026
Further reduces token bloat while preserving context for multi-human threads: 1. [Thread starter - for context] wrapper - The thread starter is already included in the [Thread history - for context] on the first message, and the session transcript maintains context for subsequent messages. 2. Verbose system event reduced to simple sender preamble - Changed from "System: [timestamp] Slack message in #channel from Sender: preview" to just "Slack message from Sender" for clean sender identification in multi-human threads. Result: Messages now show clean sender context without redundant metadata: - Before: "[Thread starter - for context]\nstarter\n\nSystem: [timestamp] Slack message in #channel from Sender: preview\n\nactual message" - After: "Slack message from Sender\n\nactual message" For the first message in a new thread session, full thread history is provided. Related to openclaw#27609 (initial fix for thread history bloat) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
20 tasks
sourman
added a commit
to sourman/openclaw
that referenced
this pull request
Feb 27, 2026
Further reduces token bloat while preserving context for multi-human threads: 1. [Thread starter - for context] wrapper - The thread starter is already included in the [Thread history - for context] on the first message, and the session transcript maintains context for subsequent messages. 2. Verbose system event reduced to simple sender preamble - Changed from "System: [timestamp] Slack message in #channel from Sender: preview" to just "Slack message from Sender" for clean sender identification in multi-human threads. Result: Messages now show clean sender context without redundant metadata: - Before: "[Thread starter - for context]\nstarter\n\nSystem: [timestamp] Slack message in #channel from Sender: preview\n\nactual message" - After: "Slack message from Sender\n\nactual message" For the first message in a new thread session, full thread history is provided. Related to openclaw#27609 (initial fix for thread history bloat) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
Addressed in #29067 - session-based sticky routing + context bloat fixes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BAD
Good
Thread history and thread starter were being included on every message in a Slack thread
This PR Only fetches
ThreadHistoryBodyfor new thread sessionsChange Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Before: Every message in a Slack thread included
[Thread starter - for context]with the thread starter text.After: Only the first message in a thread session includes context (
[Thread history - for context]with full thread history or[Thread starter - for context]with just the starter). Subsequent messages rely on the session transcript which already has the full conversation history.Security Impact (required)
No)No)Yes- REDUCE API calls to Slack for thread history)No)No)Yes, explain risk + mitigation:No additional endpoints touches just reduced calls to slack for hsitory
Repro + Verification
~/.openclaw/agents/main/sessions/or open the tui and/sessionto open the session[Thread history - for context]with full thread[Thread history - for context]AI-Assisted PR
This PR was developed with GLM 5. I understand the changes and have verified they fix the token bloat issue.
Session file evidence: Before the fix, sessions included a Copy of every previous message in every new message in the thread. After the fix, only the first message should include this context wrapper.