Skip to content

fix(sessions): skip cache when initializing session state#17978

Merged
steipete merged 2 commits intoopenclaw:mainfrom
Operative-001:fix/session-store-cache-freshness-17971
Feb 16, 2026
Merged

fix(sessions): skip cache when initializing session state#17978
steipete merged 2 commits intoopenclaw:mainfrom
Operative-001:fix/session-store-cache-freshness-17971

Conversation

@Operative-001
Copy link
Copy Markdown
Contributor

@Operative-001 Operative-001 commented Feb 16, 2026

Summary

Fixes #17971 - Session rotation on every Discord message (Windows)

Problem

When initSessionState() reads the session store, it uses the cached version by default. The cache is:

  • Process-local (each gateway process has its own)
  • Invalidated by mtime comparison (which can miss rapid writes or have coarse granularity on Windows)

When multiple gateway processes run simultaneously, or messages arrive in quick succession, one process may read stale cache and not find the session entry → generates new sessionId → creates new transcript file.

Symptoms:

  • 134+ orphaned .jsonl transcript files, each with only 1 exchange
  • Session rotates even 6-8 seconds apart
  • Bot "forgets" context after every message

Solution

Add skipCache: true when loading the session store in initSessionState(). This ensures session identity (sessionId) is always resolved from the latest on-disk state.

Why This Is Safe

  1. initSessionState is already on the critical path for every message
  2. The disk read is fast (small JSON file)
  3. The updateSessionStore call later in the function already uses locking and skipCache: true
  4. This matches the behavior of other critical session operations

Testing

Compatibility

  • Backward compatible: Yes
  • No config changes required
  • No migration needed

Greptile Summary

Fixes session rotation on every Discord message (particularly on Windows) by adding skipCache: true to the loadSessionStore() call in initSessionState(). The in-memory cache uses mtime-based validation which can miss rapid writes (Windows mtime granularity is ~2 seconds), and each gateway process maintains its own cache — causing stale reads, spurious new sessionId generation, and orphaned transcript files.

  • Adds skipCache: true to loadSessionStore() in initSessionState(), ensuring session identity is always resolved from the latest on-disk state
  • Aligns with existing patterns: updateSessionStore already uses skipCache: true internally, as do other critical callers like appendAssistantMessageToSessionTranscript and snapshotMainSessionMapping
  • Performance impact is negligible — the session store is a small JSON file read once per message

Confidence Score: 5/5

  • This PR is safe to merge — it's a minimal, well-targeted fix that aligns with existing patterns in the codebase.
  • The change is a single-line addition of skipCache: true to an existing function call, with no behavioral changes other than ensuring fresh disk reads. The pattern is already used by updateSessionStore and other critical callers. The fix directly addresses the root cause of [Bug]: Group/channel Discord sessions get new sessionId on every incoming message (Windows) #17971 (stale cache causing orphaned transcripts). Performance impact is negligible for a small JSON file read once per message.
  • No files require special attention.

Last reviewed commit: 94cbeb7

(4/5) You can add custom instructions or style guidelines for the agent here!

Fixes openclaw#17971

When initSessionState() reads the session store, use skipCache: true
to ensure fresh data from disk. The session store cache is process-local
and uses mtime-based invalidation, which can fail in these scenarios:

1. Multiple gateway processes (each has separate in-memory cache)
2. Windows file system where mtime granularity may miss rapid writes
3. Race conditions between messages 6-8 seconds apart

Symptoms: 134+ orphaned .jsonl transcript files, each with only 1
exchange. Session rotates on every incoming message even when
sessionKey is stable.

Root cause: loadSessionStore() returns stale cache → entry not found
for sessionKey → new sessionId generated → new transcript file.

The fix ensures session identity (sessionId) is always resolved from
the latest on-disk state, not potentially-stale cache.
@steipete steipete merged commit 16ddbbc into openclaw:main Feb 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Group/channel Discord sessions get new sessionId on every incoming message (Windows)

2 participants