-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
[Bug]: Group/channel Discord sessions get new sessionId on every incoming message (Windows) #17520
Description
Summary
Summary
Discord group/channel sessions create a new sessionId on nearly every incoming message instead of reusing the existing
session. This causes the bot to lose all conversation context ("memory loss") — each interaction starts fresh with no
prior history.
Environment
- OpenClaw: 2026.2.13 (203b5bd)
- Platform: Windows 11 Home 10.0.26200
- Node: 24.13.1
- Gateway mode: local (Scheduled Task)
- Model: claude-opus-4-6
- Channel: Discord, group/channel type, requireMention: false
Steps to reproduce
Reproduction
- Configure a Discord channel with groupPolicy: "allowlist" and a channel set to allow: true
- Send a message in the Discord channel that triggers a bot run
- Run openclaw sessions --json --active 20 and note the sessionId for the channel key
- Send another message, wait for reply
- Check sessionId again — it will be different
The session key (agent:main:discord:channel:) stays the same, but sessionId rotates on almost every interaction.
Expected behavior
Expected behavior:
When a Discord message triggers a run in a group/channel session, the gateway should
reuse the existing sessionId for that channel's session key (e.g.
agent:main:discord:channel:). The conversation transcript should accumulate across
messages, allowing the bot to remember prior context. The sessionId should only change
when an explicit reset policy triggers (daily reset, idle timeout, /new command, or
context limit reached).
Actual behavior
Observed Behavior
- 134+ orphaned .jsonl transcript files in the sessions directory — one per minted sessionId
- Each transcript contains only a single exchange (1 user message + 1 assistant response)
- sessions.preview returns only 4 items (latest exchange), no prior history
- Bot explicitly states: "this is a fresh conversation with no prior messages in it"
- Session is stable when idle — sessionId only changes when a Discord message triggers a run
- Rotation happens even 6-8 seconds apart between consecutive messages
OpenClaw version
2026.2.13 (203b5bd)
Operating system
Windows 11 Home 10.0.26200 (Build 26200), Node.js 24.13.1
Install method
No response
Logs, screenshots, and evidence
Debug Log Evidence
With logging.level: "debug", consecutive Discord-triggered runs for the same channel show different sessionIds:
20:27:17 embedded run start sessionId=0730aeb3 (channel:1471935020200493120)
20:27:25 embedded run start sessionId=3d14dac8 (channel:1471935020200493120) ← 8 sec later, NEW
20:27:58 embedded run start sessionId=e3987442 (channel:1471935020200493120) ← 33 sec later, NEW
20:29:16 embedded run start sessionId=6649c869 (channel:1471935020200493120) ← NEW
20:31:03 embedded run start sessionId=6649c869 (channel:1471935020200493120) ← held once
20:36:57 embedded run start sessionId=50abf3c2 (channel:1471935020200493120) ← NEW
20:37:03 embedded run start sessionId=a95d5e45 (channel:1471935020200493120) ← 6 sec later, NEW
20:37:14 embedded run start sessionId=77bcf5f9 (channel:1471935020200493120) ← 11 sec later, NEW
All diagnostic entries show sessionKey=unknown, suggesting the session key isn't being resolved during the run
pipeline.
What Has Been Ruled Out
Theory: Gateway process restarting
How Tested: Confirmed single stable PID across checks
Result: Not the cause
────────────────────────────────────────
Theory: Multiple gateway instances
How Tested: gateway probe → 1 target, 0 beacons
Result: Not the cause
────────────────────────────────────────
Theory: Session store file corruption
How Tested: sessions.json always valid (0/1000 parse failures at 25ms polling during active writes)
Result: Not the cause
────────────────────────────────────────
Theory: Session store not persisting
How Tested: File size stable, LastWriteTime updating
Result: Not the cause
────────────────────────────────────────
Theory: Session cache race
How Tested: OPENCLAW_SESSION_CACHE_TTL_MS=0
Result: Still rotates
────────────────────────────────────────
Theory: contextPruning
How Tested: Set contextPruning.mode: "off"
Result: Still rotates
────────────────────────────────────────
Theory: Session reset config
How Tested: Added session.resetByType.group: { mode: "idle", idleMinutes: 10080 }
Result: Still rotates
────────────────────────────────────────
Theory: Hooks/cron interference
How Tested: All 4 hooks bundled, 8 cron jobs all sessionTarget: "isolated", none target the channel
Result: Not the cause
────────────────────────────────────────
Theory: Scheduled Task lifecycle
How Tested: Fixed all settings (logon mode, battery, timeout) — was causing gateway kills but fixing it didn't resolve
session rotation
Result: Separate issue, fixed but not the cause
Session Store Entry (sample)
The session entry in sessions.json looks correct and is present:
{
"key": "agent:main:discord:channel:1471935020200493120",
"kind": "group",
"sessionId": "0730aeb3-38ca-406b-9543-d5ac378470f1",
"sessionFile": "...\\sessions\\0730aeb3-38ca-406b-9543-d5ac378470f1.jsonl",
"compactionCount": 0,
"chatType": "channel",
"channel": "discord",
"groupId": "1471935020200493120"
}
The entry exists, the file is valid JSON, but the next run ignores it and mints a new sessionId anyway.
Suspected Root Cause
The session resolution path for kind: "group" Discord channel runs is not looking up or reusing the existing session
entry from the store. By the time embedded run start fires in the debug logs, a new sessionId has already been
assigned — the decision happens upstream in the session init/resolution code, not in the store read.
Workaround
None found. WSL2 has not been tested but may exhibit the same behavior since the parse-failure theory (non-atomic
Windows file writes) was disproven.
Config (redacted)
{
"channels": {
"discord": {
"enabled": true,
"groupPolicy": "allowlist",
"guilds": {
"<guild_id>": {
"requireMention": false,
"users": ["<user_id>"],
"channels": {
"<channel_id>": { "allow": true }
}
}
},
"intents": {}
}
},
"agents": {
"defaults": {
"contextPruning": { "mode": "cache-ttl", "ttl": "30m", "keepLastAssistants": 3 },
"compaction": { "mode": "safeguard", "memoryFlush": { "enabled": true } }
}
},
"session": {
"resetByType": { "group": { "mode": "idle", "idleMinutes": 10080 } }
}
}Impact and severity
● Affected: All Discord group/channel sessions on Windows. Direct sessions
(webchat, CLI) and cron jobs with sessionTarget: "isolated" are NOT affected —
only kind: "group" Discord channel sessions exhibit this behavior.
Severity: Blocks core functionality. The bot is unable to maintain any
conversation context in Discord channels, making it effectively stateless. It
cannot reference anything said earlier in the conversation, follow multi-step
instructions, or build on prior exchanges.
Frequency: Always. Reproduces on every Discord message. Out of 8 consecutive
runs captured in debug logs, 7 received a new sessionId (including messages sent
just 6-8 seconds apart). Over the lifetime of this install, 134+ orphaned
transcript files accumulated — one per discarded session.
Consequence:
- Complete loss of conversational memory in Discord channels
- 134+ orphaned .jsonl transcript files (each ~15-16KB) accumulating on disk with
no cleanup - Wasted API tokens: every interaction re-sends the full system prompt + workspace
bootstrap as a fresh session (~16K tokens base cost per message) instead of
appending to an existing cached context - Users experience the bot as "broken" — it repeatedly says "I don't have context"
and cannot perform any task requiring multi-turn conversation
Additional information
No response