Skip to content

fix(slack): remove redundant thread starter wrapper and system event preview#27654

Closed
sourman wants to merge 2 commits intoopenclaw:mainfrom
sourman:fix/slack-remove-redundant-thread-context
Closed

fix(slack): remove redundant thread starter wrapper and system event preview#27654
sourman wants to merge 2 commits intoopenclaw:mainfrom
sourman:fix/slack-remove-redundant-thread-context

Conversation

@sourman
Copy link
Contributor

@sourman sourman commented Feb 26, 2026

Summary

  • Problem: After the initial fix in fix(slack): reduce token bloat by skipping thread context on existing sessions #27609, there was still unnecessary token bloat from redundant context elements, while losing important sender information for multi-human threads.
  • Why it matters: The LLM needs to know WHO is speaking in threads with multiple participants, but doesn't need verbose metadata like timestamps, channel names, and message previews.
  • What changed:
    • Removed [Thread starter - for context] wrapper (thread starter is already in the thread history)
    • Reduced verbose system event from "System: [timestamp] Slack message in #channel from Sender: preview" to simple "Slack message from Sender"
  • What did NOT change: Thread history is still correctly injected on the first message with full context including the thread starter and all replies.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

Before this PR (after #27609):

[Thread starter - for context]
<@U0AF3PBGARJ> hello

System: [2026-02-25 23:49:28 UTC] Slack message in #all-slack from Ahmed Mansour: great can you checnge the server setup so it is ET?

great can you checnge the server setup so it is ET?

After this PR:

Slack message from Ahmed Mansour

great can you checnge the server setup so it is ET?

For the first message in a new thread session, full thread history is provided:

[Thread history - for context]
[Slack Ahmed Mansour (user) Wed 2026-02-25 23:47 UTC] <@U0AF3PBGARJ> hello
[slack message id: 1772063261.652889 channel: C07KS209JKG]

[Slack comply (assistant) Wed 2026-02-25 23:47 UTC] Hello, Ahmed. What do you need?
[slack message id: 1772063271.635929 channel: C07KS209JKG]

Slack message from Ahmed Mansour

what time is it on the server currently

This preserves sender context for multi-human threads while removing verbose metadata.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

  1. Start a Slack thread with multiple people (or simulate with different senders)
  2. Send multiple follow-up replies
  3. Check the session file in ~/.openclaw/agents/main/sessions/
  4. Verify: First message includes [Thread history - for context] with full thread
  5. Verify: Subsequent messages show "Slack message from SenderName" (clean sender identification)
  6. Verify: No [Thread starter - for context] wrapper appears

AI-Assisted PR

  • Mark as AI-assisted in the PR title or description
  • Include prompts or session logs if possible (super helpful!)
  • Confirm you understand what the code does

This PR was developed with Claude Sonnet 4.6. I understand the changes and have verified they reduce token bloat while preserving sender context for multi-human threads.

Combined impact of #27609 + this PR:

… 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>
@openclaw-barnacle openclaw-barnacle bot added channel: slack Channel integration: slack size: XS labels Feb 26, 2026
@sourman sourman force-pushed the fix/slack-remove-redundant-thread-context branch from 86bfdf6 to 5157c8e Compare February 26, 2026 15:29
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>
@sourman
Copy link
Contributor Author

sourman commented Feb 27, 2026

Addressed in #29067 - session-based sticky routing + context bloat fixes

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.

1 participant