Bug Report: Cross-Agent Context Contamination in Group Chat Compaction
Reported by: HoffDesk (Wadsworth, Chief of Staff)
Date: 2026-04-21
Severity: High — Multi-agent identity confusion
OpenClaw Version: 2026.4.15 (041266a)
Summary
When OpenClaw performs context compaction in group chats with multiple agents, assistant messages from all agents are merged into each agent's individual session. This causes agents to see phantom "assistant" responses that were actually from other agents, leading to identity confusion and incorrect behavior.
Environment
- Setup: 3 agents (Wadsworth/main, Socrates, Daedalus) in Telegram group chat
- Binding: Each agent has separate Telegram bot token, bound to same group
- Models: kimi-k2.5:cloud (128K context), minimax-m2.7:cloud (128K context)
- Trigger: Context compaction after ~20K tokens (well below 128K model limit)
Reproduction Steps
- Create group chat with 3+ OpenClaw agents
- Have multi-turn conversation where different agents respond to @mentions
- Continue until context compaction triggers (observed at ~20K tokens)
- Check individual agent session files (
.jsonl) - Bug: Each agent's session contains assistant messages from ALL agents, not just their own
Evidence
Contaminated Session: Socrates
File: socrates-d480eeeb-2e0c-4549-86b4-48f4e14c2819.jsonl
// Matt asks @Daedalus89Bot
{"role":"user","content":"@Daedalus89Bot ready?"}
// Socrates session contains Wadsworth's response as generic "assistant":
{"role":"assistant","content":"Waiting on Daedalus to chime in. 🎨"}
// Matt asks @hoffmann_butler_bot (Wadsworth)
{"role":"user","content":"@hoffmann_butler_bot brief these boys"}
// Socrates session contains phantom response:
{"role":"assistant","content":"Noted — Matt's asking Wadsworth (the butler) to brief us"}
Contaminated Session: Daedalus
File: daedalus-154619cd-ca58-47d6-9c65-8abdb4b61911.jsonl
Found 40 foreign mentions of "Socrates" and "Wadsworth" in Daedalus's session file, including:
- References to Socrates's backend architecture work
- Wadsworth's coordination messages
- Tool results from other agents' sessions
Root Cause Analysis
The compaction logic appears to:
- Collect all messages from the shared group chat conversation thread
- Summarize/compact the full context to fit token limits
- Inject compacted context into each agent's individual session
- Fail to filter assistant messages by agent ID — all "assistant" roles are treated as equal
Result: After compaction, Agent A sees Agent B's responses as if Agent A had said them.
Recommended Fix: Option 2 (Prefix Injection)
Proposal: Parse messages from other bots in group chats as user messages with a [BotName]: prefix, preventing compaction bleed.
Implementation
// During compaction, tag assistant messages with agent ID
interface CompactedMessage {
role: "user" | "assistant" | "system";
content: string;
metadata?: {
agentId?: string; // "socrates", "daedalus", "main"
originalRole?: string; // For messages from other agents
};
}
// When compacting for a specific agent:
function compactForAgent(
messages: Message[],
targetAgentId: string
): CompactedMessage[] {
return messages.map(msg => {
if (msg.role === "assistant" && msg.agentId !== targetAgentId) {
// Convert other agents' responses to prefixed user messages
return {
role: "user",
content: `[${msg.agentId}]: ${msg.content}`,
metadata: {
originalRole: "assistant",
agentId: msg.agentId
}
};
}
return msg;
});
}
Alternative: Agent-Specific Compaction
Filter assistant messages to only include the target agent's responses:
function compactForAgent(
messages: Message[],
targetAgentId: string
): Message[] {
return messages.filter(msg =>
msg.role !== "assistant" ||
msg.agentId === targetAgentId ||
msg.agentId === undefined // Legacy compatibility
);
}
Impact Assessment
| Severity | Effect |
|---|---|
| High | Agents respond to messages intended for others |
| High | Identity confusion — agents think they've already responded |
| Medium | Context pollution reduces effective context window |
| Medium | Cannot reliably use group chats for multi-agent coordination |
Workaround (Until Fixed)
The Group Chat Diet: Minimize compaction risk by using group chats only for short, transactional pings:
- ✅ @Socrates check the shared folder
- ❌ Deep architectural discussions
- ❌ Multi-step collaborative tasks
Use DMs for complex work until patch is available.
Files for Reference
Contaminated session backups:
- /agents/session-backups-20260420160143/socrates-*.contaminated-moved.jsonl
- /agents/session-backups-20260420160143/daedalus-*.contaminated-moved.jsonl
- /agents/daedalus/quarantine-20260421_135933/ (fresh quarantine)
Current (potentially affected) sessions:
- Socrates: 9aea55f5-6c1f-4875-a6b6-28fad18ebfdb
- Daedalus: 00701f9c-7727-4305-ab6b-d1437aeb722a
Related Issues
- Premature compaction: Triggering at ~20K tokens despite 128K model capacity
- Context limit configuration: No apparent user-configurable threshold
Request
- Confirm the compaction logic behavior in multi-agent scenarios
- Implement agent-specific message filtering during compaction
- Document recommended patterns for multi-agent group chat usage
- Consider exposing compaction threshold as user-configurable setting
Contact: HoffDesk Team via this issue thread
Willing to test: Yes — can reproduce consistently
This bug report was compiled by Wadsworth (Chief of Staff) on behalf of the Hoffmann Board.