# Compaction Ghost Bug Analysis ## Summary **Severity:** High — Causes agents to respond to messages intended for other agents, creating identity confusion and incorrect responses. ## The Bug When OpenClaw performs **context compaction** (summarizing long conversation history to fit within token limits), phantom "assistant" messages from other agents appear in the wrong session. This causes: - Socrates to respond to messages meant for Daedalus - Agents to think they've already responded when they haven't - Cross-contamination of agent identities ## Evidence ### Contaminated Session File File: `/home/hoffmann_admin/.openclaw/agents/main/sessions/f33ad779-d3c7-466e-bf77-bd18fcccbaef.jsonl` (Socrates session) **Lines showing contamination:** ```jsonl // Line ~21 — Matt asks @Daedalus89Bot, but Socrates responds: {"role":"assistant","content":[{"type":"text","text":"Waiting on Daedalus to chime in. 🎨"}]} // Line ~38 — Matt asks @hoffmann_butler_bot (Wadsworth), but Socrates responds: {"role":"assistant","content":[{"type":"text","text":"Noted — Matt's asking Wadsworth (the butler) to brief us"}]} // Line ~45 — Matt asks Wadsworth again, Socrates responds: {"role":"assistant","content":[{"type":"text","text":"Still waiting on Wadsworth to weigh in"}]} ``` ### Session Index Evidence Socrates session shows compaction occurred: ```json "authProfileOverrideCompactionCount": 1, "authProfileOverrideSource": "auto", ``` ## Root Cause Hypothesis The compaction process appears to: 1. Summarize conversation history from the **shared group chat** context 2. Include ALL assistant messages from the thread (regardless of which agent sent them) 3. Inject these into individual agent sessions as generic "assistant" role messages 4. The receiving agent then thinks it already responded (or responds on behalf of others) ## Impact | Agent | Effect | |-------|--------| | Socrates | Responds to Daedalus/Wadsworth mentions; confusion about identity | | Daedalus | Likely same issue (contaminated sessions found in backups) | | Wadsworth | May receive phantom responses from other agents | ## Files Affected **Contaminated session backups:** - `/home/hoffmann_admin/.openclaw/agents/session-backups-20260420160143/socrates-d480eeeb-2e0c-4549-86b4-48f4e14c2819.contaminated-moved.jsonl` - `/home/hoffmann_admin/.openclaw/agents/session-backups-20260420160143/daedalus-cc408ee6-7480-40f1-a9f8-81aa6ed49791.contaminated-moved.jsonl` - `/home/hoffmann_admin/.openclaw/agents/session-backups-20260420160143/main-*.contaminated-moved.jsonl` **Current potentially affected sessions:** - Socrates: `9aea55f5-6c1f-4875-a6b6-28fad18ebfdb` - Daedalus: Check for compaction count > 0 ## Reproduction Steps 1. Start a group chat with multiple agents bound (Socrates, Daedalus, Wadsworth) 2. Have conversation exceed context window (trigger compaction) 3. Observe that compacted context includes assistant messages from ALL agents 4. Individual agent sessions now contain phantom responses ## Potential Fixes ### Option 1: Agent-Specific Compaction (Recommended) When compacting context for a specific agent, filter assistant messages to ONLY include that agent's responses. Tag assistant messages with agent ID in the transcript. ### Option 2: Separate Session Per Agent Don't share session files for group chats. Each agent gets their own isolated session with only their own assistant messages. ### Option 3: Mark Foreign Assistant Messages When injecting compacted context, mark assistant messages from other agents as `role: "assistant_other"` or add metadata `{"agent": "daedalus"}` so the receiving agent knows it's not their own response. ## Immediate Mitigation 1. **Clear contaminated sessions** for Socrates and Daedalus 2. **Disable compaction** for group chat sessions (if configurable) 3. **Monitor** for `authProfileOverrideCompactionCount > 0` in agent sessions ## Detection Query ```bash # Find sessions with compaction that might be contaminated grep -l "authProfileOverrideCompactionCount.*[1-9]" \ /home/hoffmann_admin/.openclaw/agents/*/sessions/sessions.json # Check for foreign agent mentions in session files grep -E "(Wadsworth|Daedalus|Socrates)" \ /home/hoffmann_admin/.openclaw/agents/socrates/sessions/*.jsonl ``` ## Related Configuration OpenClaw config shows: - `session.dmScope: per-channel-peer` — may be related - Multiple agents bound to same Telegram group via different bot accounts - Compaction happens automatically when context window exceeded --- **Reported:** 2026-04-21 **Status:** Under investigation **Priority:** High — affects multi-agent coordination