Repository navigation
fix(opencode-plugin): serialize saveState to prevent ENOENT rename race - #3885
Merged
qin-ctx merged 1 commit intoAug 10, 2026
Merged
Conversation
qin-ctx
approved these changes
Aug 8, 2026
frankyang2008-eng
added a commit
to frankyang2008-eng/OpenViking
that referenced
this pull request
Oct 9, 2026
Sync upstream main (e546b79) - 19 commits, 315 files: - refactor(client): remove Python embedded mode (volcengine#3712) - perf(queue): stream semantic vectorization tasks (volcengine#3636) - perf(queuefs): defer embedding content materialization (volcengine#3871) - feat(memory): support event tag filtering (volcengine#3850) - feat(pathlock): keep lease alive across handoff (volcengine#3903) - feat(server): refresh read-replica API key index via store watcher (volcengine#3857) - feat(agent-evolution): add trajectory date filters (volcengine#3915) - feat(agent-evolution): add trajectory task query (volcengine#3856) - feat(web-studio): add account deletion workflow (volcengine#3912) - feat(web-studio): add scheduled resource sync management (volcengine#3909) - fix(watch): avoid global lock during resource moves (volcengine#3833) - fix(observer): ignore historical lock diagnostics in health (volcengine#3920) - fix(session): validate archive names when loading history (volcengine#3922) - fix(task-tracker): delete expired persisted tasks (volcengine#3913) - fix(storage): exclude zero-byte files from index expectations (volcengine#3904) - fix(semantic): reduce entity hallucinations in summaries (volcengine#3908) - fix(retrieval): record first-turn session recalls (volcengine#3907) - fix(opencode-plugin): serialize saveState to prevent ENOENT race (volcengine#3885) - fix(examples): align quick start with server mode (volcengine#3923) Reviewed: zero conflicts, all local dev-branch modifications preserved, no references to deleted embedded client modules, config backward-compatible.
frankyang2008-eng
pushed a commit
to frankyang2008-eng/OpenViking
that referenced
this pull request
Oct 9, 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.
What
Fixes #3877. Concurrent
saveState()calls in the OpenCode memory pluginshare the same
${statePath}.tmptemp file with no serialization, so onerenamecan fail withENOENTafter another already moved the file —observed as frequent
Failed to save session stateerrors duringdispose/flushAll, where debounced saves race batch flushes.Why it matters
The failure is swallowed inside
saveState, leaving a stale snapshot ondisk. If the process exits between a failed save and the next successful one,
the last pending messages lose their local recovery record (server-side
commit is unaffected). The bigger the state file, the easier the race hits.
How
Serialize saves through a promise chain (
enqueueSave()); at most onewrite+rename runs at a time. Each queued save re-serializes the in-memory
sessionsmap at execution time, so the tail save always persists thelatest state — no update is lost. All four save entry points
(
debouncedSaveState,flushAll,flushSession,handleSessionDeleted)now go through the chain.
Test
New test
concurrent saves never race the shared state file (#3877)intests/memory-session.test.mjs: slowswriteFile/renameviat.mock.method(shared CJSfs.promisessingleton) to widen the racewindow, fires concurrent
flushAll()calls while a session is createdmid-flight, and asserts (1) the final state file contains all sessions and
(2) rename never observed a missing source (
raceDetected === false).raceDetected: true(reproduces [Bug] 记忆插件 saveState 并发竞态导致本地状态文件 ENOENT(rename 失败) #3877)npm test→ 24/24 pass,npm run check→ 0 errors