openclaw - 💡(How to fix) Fix Feature: Minimal inbound metadata mode for DM (direct) chats to reduce context bloat and hallucinations [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#62077Fetched 2026-04-08 03:09:18
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Root Cause

Root cause in code

Code Example

Conversation info (untrusted metadata):
{"message_id": "697", "sender_id": "292593739", "sender": "Vit Gruver", "timestamp": "Mon 2026-04-06 16:55 UTC"}

Sender (untrusted metadata):
{"label": "Vit Gruver (292593739)", "id": "292593739", "name": "Vit Gruver", "username": "VitGruver"}

---

const isDirect = !chatType || chatType === "direct";
const shouldIncludeConversationInfo = !isDirect || Boolean(directChannelValue && directChannelValue !== "webchat");

---

{
  "agents": {
    "defaults": {
      "envelopeMode": "full"
    }
  }
}

---

{
  "agents": {
    "myAgent": {
      "envelopeMode": "minimal-dm"
    }
  }
}
RAW_BUFFERClick to expand / collapse

Problem

In Telegram DM (1:1) chats, buildInboundUserContextPrefix injects full metadata blocks with every single user message:

Conversation info (untrusted metadata):
{"message_id": "697", "sender_id": "292593739", "sender": "Vit Gruver", "timestamp": "Mon 2026-04-06 16:55 UTC"}

Sender (untrusted metadata):
{"label": "Vit Gruver (292593739)", "id": "292593739", "name": "Vit Gruver", "username": "VitGruver"}

In a DM chat, sender never changes. Yet this ~500-800 char block repeats with every message. Over a 100+ message session, this adds 50-80KB of redundant metadata to the context window.

Consequences

  1. Context window waste — redundant metadata displaces useful conversation history, triggers compaction earlier
  2. Hallucination trigger — after 100+ repetitions of the identical JSON structure, the model learns the pattern and starts generating fake user messages (complete with fabricated message_id, sender_id, timestamps) within its own responses. We've observed this across multiple agents (different models, different personas) in long Telegram DM sessions. The hallucinated content includes the full metadata envelope, incrementing message_id values, and realistic fake user text.

Root cause in code

In inbound-meta.ts, the shouldIncludeConversationInfo check:

const isDirect = !chatType || chatType === "direct";
const shouldIncludeConversationInfo = !isDirect || Boolean(directChannelValue && directChannelValue !== "webchat");

For Telegram DMs, directChannelValue is "telegram" (not "webchat"), so the full metadata is always included even in 1:1 conversations.

Proposed Solution

Add a configuration option to use minimal metadata in DM chats:

{
  "agents": {
    "defaults": {
      "envelopeMode": "full"
    }
  }
}

Where envelopeMode could be:

  • "full" (default) — current behavior, all metadata on every message
  • "minimal-dm" — in DM chats, include sender info only once at session start; subsequent messages get only [msg:697 16:55] or similar compact format
  • "minimal" — compact format for all chat types

Alternatively, a per-agent override:

{
  "agents": {
    "myAgent": {
      "envelopeMode": "minimal-dm"
    }
  }
}

Environment

  • OpenClaw 2026.4.2
  • Telegram channel
  • Multiple agents (claude-opus-4-6, claude-sonnet-4-6)
  • Observed on both long sessions (300+ messages) and medium sessions (100+ messages)

extent analysis

TL;DR

To mitigate the issue of redundant metadata in Telegram DM chats, consider adding a configuration option to use minimal metadata, such as setting "envelopeMode" to "minimal-dm".

Guidance

  • Review the inbound-meta.ts file and the shouldIncludeConversationInfo check to understand why full metadata is being included in Telegram DM chats.
  • Consider implementing the proposed solution of adding an "envelopeMode" configuration option to control the level of metadata included in messages.
  • Evaluate the impact of setting "envelopeMode" to "minimal-dm" or "minimal" on the behavior of different agents and chat types.
  • Test the configuration change with multiple agents and session lengths to verify the fix.

Example

{
  "agents": {
    "defaults": {
      "envelopeMode": "minimal-dm"
    }
  }
}

This example sets the default "envelopeMode" to "minimal-dm" for all agents, which should reduce the amount of redundant metadata in Telegram DM chats.

Notes

The proposed solution assumes that the inbound-meta.ts file and the shouldIncludeConversationInfo check are the root cause of the issue. However, further testing and verification may be necessary to confirm this.

Recommendation

Apply the workaround by setting "envelopeMode" to "minimal-dm" to reduce redundant metadata in Telegram DM chats, as this is a targeted solution that addresses the specific issue without introducing unnecessary changes.

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