fix(runtime): swap plugin cache links atomically - #134
Merged
NagyVikt merged 2 commits intoAug 7, 2026
Conversation
added 2 commits
August 7, 2026 12:27
A Stop hook died mid-session with "Plugin directory does not exist: <runtime>/plugins/cache/thedotmack/claude-mem/13.13.1 — run /plugin to reinstall". The plugin was not missing: its payload had been on disk since 2026-08-04, and only the runtime's `plugins/cache` symlink was gone, recreated ten seconds later while hooks were firing. linkPluginCache replaced each entry with rm() then symlink(). Between those two awaits the path does not exist, and runtimes are re-materialized while sessions are live — so a hook resolving a plugin installPath in that window hits the exact error this function's doc comment says it prevents. Stage the new link beside the target and rename() it over instead. rename(2) within one directory is atomic, so a concurrent reader sees the old entry or the new one, never neither. rename refuses to clobber a real directory, so remove-then-create stays as the fallback for Claude's lazy empty cache/ copy on a first materialization — no session can be reading it yet. On failure the staged link is cleaned up and the existing entry is left alone. The window was not theoretical. The new race test polls the path across 300 swaps: 441 ENOENTs against the old implementation, 0 against this one. It cannot false-fail, since an atomic rename has no window in which the entry is absent.
The fallback branch can't be atomic — POSIX has no way to replace a directory with a symlink in one step. Say so, instead of claiming no session can be reading it.
Contributor
Author
|
AI review (gate): no CRITICAL/HIGH. One finding, fixed in
Validation:
The race assertion is the load-bearing test: polling the target across 300 swaps yields 441 ENOENT against the old rm-then-symlink implementation and 0 against this one. Verified by reverting the implementation and re-running. |
NagyVikt
marked this pull request as ready for review
August 7, 2026 10:31
NagyVikt
deleted the
agent/claude/atomic-plugin-cache-symlink-2026-08-07-12-19
branch
August 7, 2026 10:31
This was referenced Aug 7, 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
Test plan