openclaw - 💡(How to fix) Fix [Bug] v2026.3.11: Discord thread context re-injected every turn (context pollution + cache bust) [3 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#44447Fetched 2026-04-08 00:46:56
View on GitHub
Comments
3
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
commented ×3

Root Cause

The compiled runtime treats Discord threads as if they need repeated volatile metadata on every turn. Unlike Slack (fix #32133) and iMessage (fix #33295), Discord lacks guards to limit this injection to the first turn.

Fix Action

Fix / Workaround

Manual Patch Applied (Local)

Post-Patch Validation

HIGH: This is a manual patch on compiled files in dist/. It will be lost on the next OpenClaw update/reinstall. Recommended:

  1. Apply official fix in source
  2. Maintain post-update revalidation script
RAW_BUFFERClick to expand / collapse

Bug Summary

In OpenClaw v2026.3.11, Discord threads re-inject volatile metadata on every conversation turn, causing context contamination, unnecessary token increase, and prompt cache loss.

Observed Symptoms

  • In Discord threads, the following are re-injected every turn: message_id, reply_to_id, timestamp, Thread starter, and Chat history since last reply
  • Thread starter and history are unnecessarily repeated on every message
  • Performance degradation in long threads

Root Cause

The compiled runtime treats Discord threads as if they need repeated volatile metadata on every turn. Unlike Slack (fix #32133) and iMessage (fix #33295), Discord lacks guards to limit this injection to the first turn.

Affected Files (compiled dist/)

  • dist/pi-embedded-D6PpOsxP.js - Metadata injection in threads
  • dist/compact-1mmJ_KWL.js - Session handler without isNewSession guard

Manual Patch Applied (Local)

File: dist/pi-embedded-D6PpOsxP.js

  • Prevented injection for Discord threads: message_id, reply_to_id, timestamp, Thread starter, and Chat history since last reply

File: dist/compact-1mmJ_KWL.js

  • Added isNewSession guard to limit thread starter to first turn
  • Fixed regression: replaced resolveAgentMainSessionKey with buildAgentMainSessionKey(...)

Post-Patch Validation

  • ✅ New writer and reasoning sessions show real toolCall after restart
  • ✅ Discord threads stop loading useless repeated context
  • ✅ Prompt caching works effectively in long threads

Regression Risk

HIGH: This is a manual patch on compiled files in dist/. It will be lost on the next OpenClaw update/reinstall. Recommended:

  1. Apply official fix in source
  2. Maintain post-update revalidation script

Related Issues

  • #41355 - Discord: ThreadStarterBody re-injected on every turn (echo contamination)
  • #34228 - Discord thread sessions reset unexpectedly on each new message
  • #37047 - Discord thread starter metadata injects changing timestamp, busting prompt cache

Environment

  • OpenClaw: v2026.3.11
  • Channel: Discord threads
  • Patch date: March 2026

extent analysis

Fix Plan

To address the issue of Discord threads re-injecting volatile metadata, we need to apply the following fixes:

  • Prevent metadata injection for Discord threads in dist/pi-embedded-D6PpOsxP.js
  • Add an isNewSession guard to limit thread starter to the first turn in dist/compact-1mmJ_KWL.js

Code Changes

Here are the specific code changes:

// dist/pi-embedded-D6PpOsxP.js
if (channel === 'discord' && !isNewSession) {
  // Prevent injection of message_id, reply_to_id, timestamp, Thread starter, and Chat history since last reply
  delete metadata.message_id;
  delete metadata.reply_to_id;
  delete metadata.timestamp;
  delete metadata.threadStarter;
  delete metadata.chatHistory;
}

// dist/compact-1mmJ_KWL.js
function buildAgentMainSessionKey(session) {
  if (isNewSession) {
    // Only add thread starter to the first turn
    session.threadStarter = getThreadStarter();
  }
  // ...
}

function getThreadStarter() {
  // Implement logic to get the thread starter
}

Verification

To verify that the fix worked:

  1. Restart the application
  2. Test Discord threads to ensure that metadata is not re-injected on every turn
  3. Verify that prompt caching works effectively in long threads

Extra Tips

To prevent regressions, it's recommended to:

  • Apply the official fix in the source code
  • Maintain a post-update revalidation script to ensure the fix is not lost on future updates
  • Monitor related issues (#41355, #34228, #37047) for any updates or changes that may affect this fix.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Bug] v2026.3.11: Discord thread context re-injected every turn (context pollution + cache bust) [3 comments, 1 participants]