Repository navigation
fix(gc): spare runtimes a live process still loads a plugin from - #191
Merged
Merged
Conversation
Claude Code records a --plugin-dir plugin by the absolute path it was launched with. After a mid-run profile switch the process's config dir moves to another runtime, so the original runtime-<pid>-0 is nobody's config dir and the stale-runtime GC reaps it. The next /reload-plugins then fails with "Path not found" for <runtime>/<plugin>. gc_runtime_trees now snapshots every live process's --plugin-dir values (/proc/<pid>/cmdline on Linux, KERN_PROCARGS2 on macOS) once per sweep, and gc_one_pair spares a runtime that any of them lies inside. The match is a path prefix on the walked or canonical tree, never a canonicalize of the plugin path, which is a symlink out of the tree. An unreadable process table spares every tree for that sweep, like an unreadable job store. Other platforms are unchanged. clauth never passes --plugin-dir itself, so a stable path cannot be chosen on the launch side; the GC is the only place to fix it. Fixes uwuclxdy#190
uwuclxdy
requested changes
Nov 24, 2026
uwuclxdy
left a comment
Owner
There was a problem hiding this comment.
Thanks for picking up #190! A profile switch never moves a running session off its tree, though: the swap only relinks the tree's credentials, and the session's CLAUDE_CONFIG_DIR stays the same. What does lose the tree is a clauth start that dies (killed, OOM) while its claude keeps running. The marker lock dies with it, so the next sweep retires the tree, plugin included. Sparing on --plugin-dir covers that case for sessions launched with it, so we'll take this approach with the changes inline. A spare keyed on the session's own claude pid, which covers every orphaned session, comes with the 1.0 rework.
Re-read the live --plugin-dir values just before a tree is retired, so a claude launched with one after the sweep snapshot still spares it. The read sits outside the state flock because the macOS process listing shells out to ps. Keep the delete path on the old behaviour (LivePluginDirs::Off): a spared tree would read as unrescued there. On Linux read only processes owned by the effective uid, since cmdline is readable for every user's process. Reword the comments: the case spared is a clauth start that died while its claude keeps running, not a profile switch.
uwuclxdy
added a commit
that referenced
this pull request
Nov 25, 2026
A plugin dir named after the snapshot spares its tree before the stop; on macOS only a process of the effective uid counts as ours. refs #191
uwuclxdy
added a commit
that referenced
this pull request
Nov 25, 2026
A tree a live session marker holds skips the early plugin-dir read; the read never runs under the state flock, and the late spare logs its line. refs #191
Owner
|
Merged, thanks for the plugin-dir spare! I added a few things on top of your commits:
|
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 #190.
Claude Code records a
--plugin-dirplugin by the absolute path it was launched with, for example<profile>/runtime-<pid>-0/moshi-plugin. If theclauth startthat created the runtime dies (killed, OOM) while itsclaudekeeps running, the marker lock dies with it. The next sweep then retires the tree, plugin included, and/reload-pluginsfails withPath not found. (A profile switch does not move the session's config dir; the deadclauth startis the real case.)clauth never builds
--plugin-diritself, so a stable path can't be chosen on the clauth side. This PR spares the tree in the GC instead:gc_runtime_treestakes one snapshot of every live process's--plugin-dirvalues (/proc/<pid>/cmdlineon Linux,KERN_PROCARGS2on macOS).gc_one_pairspares a runtime that one of those paths lies inside, as a fast path.claudestarted after the sweep began still spares it. The re-read sits right before the state-lock hold, not inside it, because the macOS process listing shells out topsand no subprocess may span the flock.rescue_profile_trees) passesLivePluginDirs::Off, soclauth deletebehaves as before anddelete --forcestill rescues transcripts.Tests (pure, no
/procneeded): argv parsing of both spellings, the prefix predicate, the unreadable-table fail-safe, a spare from a live plugin dir, a re-read that catches a late process, the delete path ignoring plugin dirs, and the Linux owner check.Checklist
sk-ant-*, no~/.claude/~/.clauthcontents)cargo fmt --all -- --checkandcargo clippy --locked --all-targets --all-features -- -D warningspass locally. Theruntime::tests (682) pass on macOS. The full suite stalls on macOS here, with or without this change, so I rely on CI for it. The Linux/procpath is untested locally.AI