fix(storage): prevent session recovery lock-order deadlocks - #1336
Merged
XingYu-Zhong merged 1 commit intoSep 22, 2026
Merged
Conversation
Serialize item/event/usage mutations on the per-thread queue before taking JSONL leases or event-index mutations, release the event-index section before usage work, and keep append + recordAppend atomic. Also fail fast on same-path read/replacement reentry in the JSONL access coordinator so a caller cannot silently self-deadlock. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
XingYu-Zhong
force-pushed
the
codex/fix-1335-session-deadlock
branch
from
September 21, 2026 01:53
688a84f to
1e754e5
Compare
Collaborator
|
Maintainer follow-up: pushed an amendment adding fail-fast guards to
Cross-path ordering is unchanged. Added 4 regression tests in One process note for whoever merges: the body says |
2 tasks
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 #1335.
Prevent a single conversation from permanently blocking its item/event RPCs when live-item recovery overlaps event append, compaction, or replacement. The thread queue is now acquired before JSONL leases and event-index mutation, and event append releases the event-index lock before waiting for the usage queue.
Why / 背景
Cold live-item recovery reads events while holding the thread queue. Previously, a replacement could hold a file lease while waiting for that queue, and event append could hold the event-index lock while waiting for it. Cold usage replay introduced another cycle: usage recovery waited for the event index while append held that index and waited for usage recovery. These cycles match the issue's stalled per-thread data path while health checks and other conversations remain responsive.
Changes / 变更
recordAppendin the same event-index critical section, then release it before updating the usage index.Media / 截图或录屏
Actual Electron desktop after cold restart, showing the event-recovered
COLD_RECOVERY_OKmarker. The history is a synthetic fixture; the desktop, Service Manager, Runtime, HTTP/SSE, and filesystem are real. This screenshot demonstrates recovered UI content; request completion and regression tests provide the concurrency evidence.Additional desktop interaction check
The reasoning selector remained usable after recovery (Off, High, and Ultra). This is a supplementary UI check, not evidence for the lock-order fix.
Screenshots are hosted on a separate evidence branch in the fork; this PR contains only the seven source/test files.
Tests / 测试
npm run typecheck,npm run build(includingbuild:kun),npm run check:file-lines, andgit diff --checkpassed.Targeted test commands (run inside kun/)
Validation / 验证
npm run test(limitations below).npm run typechecknpm run buildNotes / 备注
libnode.141.dylib; one unrelated in-memory room integration case timed out under load and passed in isolation. The top-level run stopped before the renderer test phase. The 233 targeted tests above passed after the final fix.