fix(session): serialize canonical file access - #5383
Merged
chengyongru merged 2 commits intoAug 14, 2026
Merged
Conversation
chengyongru
force-pushed
the
codex/fix-windows-session-store-concurrency
branch
from
August 14, 2026 02:15
26b6daf to
f49b4d0
Compare
okwillbe
pushed a commit
to okwillbe/nanobot
that referenced
this pull request
Aug 15, 2026
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
SessionManagerinstances that point at the same canonical directoryos.replaceand existing fsync behaviorRoot cause
On Windows, an open reader for the destination JSONL file can deny
os.replace(tmp, target)with[WinError 5] Access is denied.The confirmed production path was internal and deterministic:
/api/sessionsran_sessions_list_payloadthroughasyncio.to_thread.session_list_index._scan_session_rowopened a canonical session JSONL file.JsonlSessionStore.savetried to replace that same file.The store also used one predictable
<session>.jsonl.tmp, so concurrent saves could share scratch state.Design
JsonlSessionStorenow owns oneFileLockat.session-files.lockper canonical sessions directory. Load/read/metadata/list/save/delete/repair and migration/restore use it. The exceptional direct consumers—WebUI index reconciliation and Dream pruning—enter the same boundary through a narrowSessionManager.locked_session_files()context manager.Different manager instances coordinate because they resolve the same lock path. Nested repair/delete operations reuse the same reentrant lock. Critical sections contain bounded local file work only; no LLM, provider, or network operation is locked.
Session and WebUI-index writers now use unique
open(..., "x")temp files. Atomic replacement and the existing conditional file/directory fsync policy are unchanged.Related work
PR #5382 retries
os.replaceon Windows. That may be useful defense against brief locks from uncoordinated external software, but it does not prevent the confirmed in-process reader/writer overlap, cover delete/repair/restore paths, coordinate multiple managers, or remove the shared temp-file race. This PR fixes the synchronization invariant at the persistence owner; a narrowly justified external-lock retry could still be layered inside that boundary later.Issue #5290 and PR #5291 concern deduplicating atomic JSONL writer code and persisting subagent transcripts. They are related to the write idiom but do not define this session-file concurrency boundary.
Validation
/modelthread returned 200 after refresh; post-refresh console clean; runtime cleanup complete