Discord Session Split-Brain Issue - Summary for clawdbot Support Problem Description Symptom: Daphne receives Discord messages in channel #instant-impact (channel ID: 1460578963046006918) and stores them correctly in a channel-specific session. However, when the LLM generates replies, it's using a different session (agent:main:main), causing her to: - Have no memory of the conversation - Ask if the user is "just passing through" - Give meta-commentary instead of natural responses Evidence ### Session Store Entries ```json { "agent:main:discord:channel:1460578963046006918": { "sessionId": "000d438a-4205-4377-a4e7-e341bc5769d3", "sessionFile": ".../000d438a-4205-4377-a4e7-e341bc5769d3.jsonl" }, "agent:main:main": { "sessionId": "b5c8fe84-1192-4021-9010-1c67d7e89803", "sessionFile": ".../b5c8fe84-1192-4021-9010-1c67d7e89803.jsonl" } } ``` ### Message Flow Analysis Inbound (Working): - monitorDiscordProvider() → resolveAgentRoute() → returns sessionKey: "agent:main:discord:channel:1460578963046006918" - ctxPayload.SessionKey is correctly set - Message is written to the correct session file Reply Generation (Broken): - dispatchReplyFromConfig() is called with correct ctx - getReplyFromConfig() processes the request - At some point, the LLM thinks from agent:main:main instead of the Discord channel session Key Code Paths Session Resolution (Daphne/src/config/sessions.ts:629-632): ```typescript export function resolveSessionKey( scope: SessionScope, ctx: MsgContext, mainKey?: string, ) { const explicit = ctx.SessionKey?.trim(); if (explicit) return explicit; // Should use Discord channel key here // ... fallback logic } ``` Discord Message Handler (Daphne/src/discord/monitor.ts:~1400): ```typescript const ctxPayload = { SessionKey: threadKeys.sessionKey, // Should be Discord channel key // ... }; ``` Root Cause Hypothesis The LLM/tool execution context may be getting a different session key than what's in ctx.SessionKey. Possible locations: 1. Tool creation: Tools (like discord, message) may be created with an incorrect agentSessionKey or sessionKey parameter 2. Session initialization: initSessionState() in reply/session.ts may not be respecting ctx.SessionKey in all code paths 3. LLM runner: pi-embedded-runner.ts uses resolveSessionLane() which transforms the key 4. Sandbox context: resolveSandboxContext() may be creating a sandbox with the wrong session scope Environment Details - Daphne config: Daphne/state/clawdbot.json - Session store: Daphne/state/agents/main/sessions/sessions.json - Discord channel ID: 1460578963046006918 (#instant-impact) - Discord guild ID: 1352008199414485023 (decision-agent) - No routing bindings configured (using defaults) Expected Behavior The LLM should receive the same session key that's in ctx.SessionKey (agent:main:discord:channel:1460578963046006918) and read/write from that session file, maintaining conversation continuity. Additional Context - WhatsApp works correctly with per-sender sessions - No routing bindings defined (using defaults) - Memory crawler disabled for performance - Both agent:main:main and Discord channel session exist and have separate message histories ──────────────────────────────────────────────────────────────────────────────────────────