Skip to content

fix(gc): spare runtimes a live process still loads a plugin from - #191

Merged
uwuclxdy merged 3 commits into
uwuclxdy:mommyfrom
Staberman:fix/stable-plugin-dir
Nov 25, 2026
Merged

uwuclxdy merged 3 commits into
uwuclxdy:mommyfrom
Staberman:fix/stable-plugin-dir

Conversation

@Staberman

@Staberman Staberman commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #190.

Claude Code records a --plugin-dir plugin by the absolute path it was launched with, for example <profile>/runtime-<pid>-0/moshi-plugin. If the clauth start that created the runtime dies (killed, OOM) while its claude keeps running, the marker lock dies with it. The next sweep then retires the tree, plugin included, and /reload-plugins fails with Path not found. (A profile switch does not move the session's config dir; the dead clauth start is the real case.)

clauth never builds --plugin-dir itself, so a stable path can't be chosen on the clauth side. This PR spares the tree in the GC instead:

  • gc_runtime_trees takes one snapshot of every live process's --plugin-dir values (/proc/<pid>/cmdline on Linux, KERN_PROCARGS2 on macOS). gc_one_pair spares a runtime that one of those paths lies inside, as a fast path.
  • The snapshot is re-read just before the tree is retired, so a claude started 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 to ps and no subprocess may span the flock.
  • The match is a path prefix against the tree as walked and as canonical. The plugin path is not canonicalized, since it is a symlink out of the tree.
  • On Linux only processes owned by the user running clauth are read.
  • If the process table cannot be listed, every tree is spared for that sweep.
  • The delete path (rescue_profile_trees) passes LivePluginDirs::Off, so clauth delete behaves as before and delete --force still rescues transcripts.
  • Windows and other platforms are unchanged.

Tests (pure, no /proc needed): 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

  • Secrets redacted from any pasted output (no sk-ant-*, no ~/.claude/~/.clauth contents)
  • cargo fmt --all -- --check and cargo clippy --locked --all-targets --all-features -- -D warnings pass locally. The runtime:: 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 /proc path is untested locally.

AI

  • AI-assisted, I reviewed everything

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 uwuclxdy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/runtime.rs Resolved
Comment thread src/runtime.rs Resolved
Comment thread src/runtime.rs Resolved
Comment thread src/runtime.rs Resolved
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
uwuclxdy added a commit that referenced this pull request Nov 25, 2026
@uwuclxdy
uwuclxdy merged commit accf8a2 into uwuclxdy:mommy Nov 25, 2026
5 of 6 checks passed
@uwuclxdy

Copy link
Copy Markdown
Owner

Merged, thanks for the plugin-dir spare! I added a few things on top of your commits:

  • the plugin-dir reading is gated to linux and macOS, which fixes the Windows build
  • a plugin dir that shows up after the sweep's snapshot spares its tree before the supervisor gets stopped, not only right before the retire
  • on macOS only processes of the user running clauth count too
  • a tree a live session still holds skips the process-table read, so a sweep no longer walks every process once per live session
  • the read never runs while the state lock is held, and the spare right before the retire logs its line like the others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: a mid-run profile switch leaves Claude Code's --plugin-dir bound to the previous runtime dir, which GC then reaps, breaking /reload-plugins

2 participants