fix(sessions): skip cache when initializing session state#17978
Merged
steipete merged 2 commits intoopenclaw:mainfrom Feb 16, 2026
Merged
fix(sessions): skip cache when initializing session state#17978steipete merged 2 commits intoopenclaw:mainfrom
steipete merged 2 commits intoopenclaw:mainfrom
Conversation
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.
…he-freshness-17971
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: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:
.jsonltranscript files, each with only 1 exchangeSolution
Add
skipCache: truewhen loading the session store ininitSessionState(). This ensures session identity (sessionId) is always resolved from the latest on-disk state.Why This Is Safe
initSessionStateis already on the critical path for every messageupdateSessionStorecall later in the function already uses locking andskipCache: trueTesting
Compatibility
Greptile Summary
Fixes session rotation on every Discord message (particularly on Windows) by adding
skipCache: trueto theloadSessionStore()call ininitSessionState(). 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.skipCache: truetoloadSessionStore()ininitSessionState(), ensuring session identity is always resolved from the latest on-disk stateupdateSessionStorealready usesskipCache: trueinternally, as do other critical callers likeappendAssistantMessageToSessionTranscriptandsnapshotMainSessionMappingConfidence Score: 5/5
skipCache: trueto an existing function call, with no behavioral changes other than ensuring fresh disk reads. The pattern is already used byupdateSessionStoreand 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.Last reviewed commit: 94cbeb7
(4/5) You can add custom instructions or style guidelines for the agent here!