From 9ffb1f01f9970a38d96c111533d484b67b2817d2 Mon Sep 17 00:00:00 2001 From: Staberman Date: Tue, 24 Nov 2026 04:11:21 -0300 Subject: [PATCH 1/3] fix(gc): spare runtimes a live process still loads a plugin from 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--0 is nobody's config dir and the stale-runtime GC reaps it. The next /reload-plugins then fails with "Path not found" for /. gc_runtime_trees now snapshots every live process's --plugin-dir values (/proc//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 #190 --- src/runtime.rs | 136 ++++++++++++++++++++++++++++++++++++++-- tests/inline/runtime.rs | 101 ++++++++++++++++++++++++++++- 2 files changed, 230 insertions(+), 7 deletions(-) diff --git a/src/runtime.rs b/src/runtime.rs index f29146e6..af3773cb 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -2089,6 +2089,103 @@ fn gc_codex_homes() { }); } +/// The `--plugin-dir` values of every live process, read once per sweep. +/// +/// Claude Code records a plugin by the absolute path it was launched with, and +/// `--plugin-dir /` stays bound to that runtime for the life of +/// the process. A mid-run profile switch repoints the process's config dir at +/// another runtime, so the config-dir liveness reads stop naming the original +/// one even though `/reload-plugins` still resolves the plugin through it. +/// Sparing on the launch-time path keeps that reload working. +pub(crate) enum LivePluginDirs { + /// Every readable live process's `--plugin-dir` values. + Named(Vec), + /// The process table could not be listed: spare every tree this sweep, the + /// fail-closed direction the job-store snapshot takes. + Unreadable, +} + +impl LivePluginDirs { + /// A snapshot holding exactly `dirs`. + #[cfg(test)] + fn named(dirs: Vec) -> Self { + LivePluginDirs::Named(dirs) + } + + /// Whether a live process's `--plugin-dir` lies inside `tree`, or the + /// snapshot is unreadable. + fn spares(&self, tree: &Path) -> bool { + match self { + LivePluginDirs::Unreadable => true, + LivePluginDirs::Named(dirs) => dirs.iter().any(|dir| plugin_dir_inside_tree(dir, tree)), + } + } +} + +/// Every value an argv gives `--plugin-dir`, in both the `--plugin-dir X` and +/// `--plugin-dir=X` spellings. PURE. +fn argv_plugin_dirs(argv: &[&[u8]]) -> Vec { + let mut dirs = Vec::new(); + let mut args = argv.iter(); + while let Some(arg) = args.next() { + let value = if *arg == b"--plugin-dir" { + args.next().copied() + } else { + arg.strip_prefix(b"--plugin-dir=") + }; + if let Some(value) = value.filter(|v| !v.is_empty()) { + dirs.push(bytes_to_path(value)); + } + } + dirs +} + +#[cfg(unix)] +fn bytes_to_path(bytes: &[u8]) -> PathBuf { + use std::os::unix::ffi::OsStrExt as _; + PathBuf::from(std::ffi::OsStr::from_bytes(bytes)) +} + +#[cfg(not(unix))] +fn bytes_to_path(bytes: &[u8]) -> PathBuf { + PathBuf::from(String::from_utf8_lossy(bytes).into_owned()) +} + +/// Whether `dir` lies inside `tree`, by path prefix in the tree's walked or +/// canonical spelling. Never canonicalizes `dir`: the plugin entry is a symlink +/// out of the tree, and following it would hide the very reference this check +/// exists to see. PURE apart from the tree's own canonicalize. +fn plugin_dir_inside_tree(dir: &Path, tree: &Path) -> bool { + dir.starts_with(tree) + || crate::canonical::identity(tree).is_ok_and(|canonical| dir.starts_with(canonical)) +} + +/// One snapshot of every live process's `--plugin-dir` values. Linux reads +/// `/proc//cmdline`, macOS the `KERN_PROCARGS2` argv; a process whose argv +/// the kernel withholds (another user's) is skipped, and elsewhere nothing is +/// inspected, so behaviour there is unchanged. +fn live_plugin_dirs() -> LivePluginDirs { + #[cfg(any(target_os = "linux", target_os = "macos"))] + { + let Some(pids) = live_process_pids() else { + return LivePluginDirs::Unreadable; + }; + LivePluginDirs::Named( + pids.into_iter() + .filter_map(process_argv) + .flat_map(|argv| { + let argv: Vec<&[u8]> = argv.iter().map(Vec::as_slice).collect(); + argv_plugin_dirs(&argv) + }) + .collect(), + ) + } + #[cfg(not(any(target_os = "linux", target_os = "macos")))] + { + LivePluginDirs::Named(Vec::new()) + } +} + fn gc_runtime_trees() { // One snapshot of Claude Code's job store per sweep, before the pair loop, // so the fast path never pays the walk per pair. A dead pair the snapshot @@ -2139,8 +2236,15 @@ fn gc_runtime_trees() { return; }; let _rescue_wait = crate::sessions::RescueLockBudget::arm(); + let plugin_dirs = live_plugin_dirs(); + if matches!(plugin_dirs, LivePluginDirs::Unreadable) { + logline!( + "clauth: spared every dead runtime tree this sweep: the live \ + process table could not be read for --plugin-dir" + ); + } for profile in entries.flatten() { - gc_profile_trees(&profile.path(), &job_trees); + gc_profile_trees(&profile.path(), &job_trees, &plugin_dirs); } } @@ -2148,7 +2252,7 @@ fn gc_runtime_trees() { /// first, then every dead runtime tree, retired and rescued. Tombstones go /// first because a kept `runtime.rescuing` blocks the rename that would retire /// a dead `runtime` beside it. -fn gc_profile_trees(profile: &Path, job_trees: &JobTrees) { +fn gc_profile_trees(profile: &Path, job_trees: &JobTrees, plugin_dirs: &LivePluginDirs) { // Strict predicates, not the loose pairing split: these walks hand // `remove_dir_all` whatever they match, so a future `runtime_state` or // `sessions.json` under a profile must fall through untouched. @@ -2175,6 +2279,7 @@ fn gc_profile_trees(profile: &Path, job_trees: &JobTrees) { &profile.join(&child_name), &profile.join(sessions), job_trees, + plugin_dirs, ); } else if is_sessions_dir_name(&child_name) && let Some(runtime) = paired_runtime_name(&child_name) @@ -2185,7 +2290,7 @@ fn gc_profile_trees(profile: &Path, job_trees: &JobTrees) { // rather than a reused one. let runtime = profile.join(runtime); if runtime.symlink_metadata().is_err() { - let _ = gc_one_pair(&runtime, &profile.join(&child_name), job_trees); + let _ = gc_one_pair(&runtime, &profile.join(&child_name), job_trees, plugin_dirs); } } } @@ -2218,7 +2323,11 @@ pub(crate) fn rescue_profile_trees(profile: &Path) -> Option { #[cfg(target_os = "macos")] let _item_budget = crate::lock::SharedSubprocessBudget::arm(crate::lock::SUBPROCESS_BUDGET); let _rescue_wait = crate::sessions::RescueLockBudget::arm(); - gc_profile_trees(profile, &crate::claude_jobs::job_trees()); + gc_profile_trees( + profile, + &crate::claude_jobs::job_trees(), + &live_plugin_dirs(), + ); let children = match std::fs::read_dir(profile) { Ok(children) => children, Err(e) if e.kind() == std::io::ErrorKind::NotFound => return None, @@ -3829,7 +3938,12 @@ fn rescue_claimed_tombstone(tombstone: &Path) { /// it is renamed to a tombstone under the lock and rescued outside it /// ([`retire_tree`]), and the flock is never held across a tree-sized walk; a /// runtime path that is itself a link is unlinked alone. -fn gc_one_pair(runtime: &Path, sessions: &Path, job_trees: &JobTrees) -> Result<()> { +fn gc_one_pair( + runtime: &Path, + sessions: &Path, + job_trees: &JobTrees, + plugin_dirs: &LivePluginDirs, +) -> Result<()> { // The job check sits here as a FAST PATH, before the state flock // `gc_one_pair_synced` takes: the store was read once above and the check // is a canonicalize + set lookup, not a walk. It is not the decision — a @@ -3851,6 +3965,18 @@ fn gc_one_pair(runtime: &Path, sessions: &Path, job_trees: &JobTrees) -> Result< } return Ok(()); } + // A live process's launch-time `--plugin-dir` into this tree spares it even + // when the process's config dir has moved on (a mid-run profile switch). + // The path is fixed at launch, so no later start can name a tree that + // was not already named when the snapshot was taken: there is no re-read. + if plugin_dirs.spares(runtime) { + logline!( + "clauth: spared runtime tree {}: a live process still loads a plugin from it \ + (--plugin-dir)", + runtime.display() + ); + return Ok(()); + } gc_one_pair_synced(runtime, sessions, || {}) } diff --git a/tests/inline/runtime.rs b/tests/inline/runtime.rs index 5556d1fc..75ad3ca2 100644 --- a/tests/inline/runtime.rs +++ b/tests/inline/runtime.rs @@ -8980,7 +8980,12 @@ fn gc_spares_a_pair_when_the_job_is_written_after_the_sweep_snapshot() { let snapshot = crate::claude_jobs::job_trees(); write_claude_job(tmp.path(), "37560ded", &runtime); drop(marker); - let _ = gc_one_pair(&runtime, &sessions, &snapshot); + let _ = gc_one_pair( + &runtime, + &sessions, + &snapshot, + &LivePluginDirs::Named(Vec::new()), + ); assert!( runtime.join(".claude.json").is_file(), "a job written after the sweep snapshot must still spare the tree" @@ -9010,7 +9015,12 @@ fn gc_spares_a_dead_isolated_pair_a_job_written_after_the_sweep_snapshot() { let snapshot = crate::claude_jobs::job_trees(); write_claude_job(tmp.path(), "37560ded", &runtime); drop(marker); - let _ = gc_one_pair(&runtime, &sessions, &snapshot); + let _ = gc_one_pair( + &runtime, + &sessions, + &snapshot, + &LivePluginDirs::Named(Vec::new()), + ); assert!( runtime.join(".claude.json").is_file(), "a job written after the sweep snapshot must spare an isolated tree" @@ -27955,3 +27965,90 @@ fn a_logged_out_shell_in_a_proxy_sessions_file_raises_no_line() { ); }); } + +/// Claude Code binds `--plugin-dir` to the runtime it launched under. After a +/// mid-run profile switch no process has that runtime as its config dir, but +/// the plugin is still loaded from it, so the sweep must keep it. +#[test] +fn gc_spares_a_runtime_a_live_plugin_dir_still_points_into() { + let tmp = tempfile::tempdir().expect("tempdir"); + with_fake_home(tmp.path(), || { + let profiles = tmp.path().join(".clauth").join("profiles"); + let runtime = profiles.join("a").join("runtime-6411-0"); + let sessions = profiles.join("a").join("sessions-6411-0"); + fs::create_dir_all(&runtime).expect("mkdir runtime"); + fs::create_dir_all(&sessions).expect("mkdir sessions"); + fs::write(runtime.join(".claude.json"), b"{}").expect("seed"); + let snapshot = crate::claude_jobs::job_trees(); + let live = LivePluginDirs::named(vec![runtime.join("moshi-plugin")]); + let _ = gc_one_pair(&runtime, &sessions, &snapshot, &live); + assert!( + runtime.join(".claude.json").is_file(), + "a live --plugin-dir into the runtime must spare it" + ); + }); +} + +#[test] +fn gc_collects_a_dead_runtime_no_plugin_dir_points_into() { + let tmp = tempfile::tempdir().expect("tempdir"); + with_fake_home(tmp.path(), || { + let profiles = tmp.path().join(".clauth").join("profiles"); + let runtime = profiles.join("a").join("runtime-6411-0"); + let sessions = profiles.join("a").join("sessions-6411-0"); + let sibling = profiles.join("a").join("runtime-6411-1"); + fs::create_dir_all(&runtime).expect("mkdir runtime"); + fs::create_dir_all(&sessions).expect("mkdir sessions"); + fs::write(runtime.join(".claude.json"), b"{}").expect("seed"); + let snapshot = crate::claude_jobs::job_trees(); + let live = LivePluginDirs::named(vec![sibling.join("moshi-plugin")]); + let _ = gc_one_pair(&runtime, &sessions, &snapshot, &live); + assert!( + !runtime.join(".claude.json").exists(), + "a plugin dir in a sibling runtime must not spare this one" + ); + }); +} + +#[test] +fn an_unreadable_process_table_spares_every_tree() { + assert!(LivePluginDirs::Unreadable.spares(Path::new("/p/runtime-1-0"))); +} + +#[test] +fn argv_plugin_dirs_reads_both_spellings() { + let argv: Vec<&[u8]> = vec![ + b"claude", + b"--plugin-dir", + b"/p/runtime-1-0/moshi-plugin", + b"--model=x", + b"--plugin-dir=/q/other", + b"--plugin-dir-no-mcp", + b"/not/this", + b"--plugin-dir", + ]; + assert_eq!( + argv_plugin_dirs(&argv), + vec![ + PathBuf::from("/p/runtime-1-0/moshi-plugin"), + PathBuf::from("/q/other") + ] + ); +} + +#[test] +fn a_plugin_dir_inside_a_tree_is_matched_by_prefix_only() { + let tree = Path::new("/p/runtime-1-0"); + assert!(plugin_dir_inside_tree( + Path::new("/p/runtime-1-0/moshi-plugin"), + tree + )); + assert!(!plugin_dir_inside_tree( + Path::new("/p/runtime-1-01/moshi-plugin"), + tree + )); + assert!(!plugin_dir_inside_tree( + Path::new("/home/u/.claude/moshi-plugin"), + tree + )); +} From 3e32d474e982d098b6c2a4af66b1d9c50ede3f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lautaro=20Ant=C3=BAnez?= Date: Tue, 24 Nov 2026 09:56:29 -0300 Subject: [PATCH 2/3] fix(gc): address review on plugin-dir spare 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. --- src/runtime.rs | 98 ++++++++++++++++++++++++++++++++++++----- tests/inline/runtime.rs | 63 ++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 11 deletions(-) diff --git a/src/runtime.rs b/src/runtime.rs index af3773cb..79549674 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -2089,23 +2089,36 @@ fn gc_codex_homes() { }); } -/// The `--plugin-dir` values of every live process, read once per sweep. +/// The `--plugin-dir` values of every live process, read once per sweep and +/// again just before a tree is retired. /// /// Claude Code records a plugin by the absolute path it was launched with, and -/// `--plugin-dir /` stays bound to that runtime for the life of -/// the process. A mid-run profile switch repoints the process's config dir at -/// another runtime, so the config-dir liveness reads stop naming the original -/// one even though `/reload-plugins` still resolves the plugin through it. -/// Sparing on the launch-time path keeps that reload working. +/// `--plugin-dir /` stays bound to that runtime for the life +/// of the process. If its `clauth start` dies (killed, OOM) while the `claude` +/// keeps running, the marker lock dies with it and the config-dir liveness +/// reads no longer hold the tree, yet `/reload-plugins` still resolves the +/// plugin through it. Sparing on the launch-time path keeps that reload working. pub(crate) enum LivePluginDirs { /// Every readable live process's `--plugin-dir` values. Named(Vec), /// The process table could not be listed: spare every tree this sweep, the /// fail-closed direction the job-store snapshot takes. Unreadable, + /// Plugin dirs play no part (the delete path, where the profile dir goes + /// either way and a spared tree would read as unrescued). + Off, } impl LivePluginDirs { + /// The snapshot to re-take before retiring a tree: a fresh read, except + /// that [`LivePluginDirs::Off`] stays off. + fn refreshed(&self) -> LivePluginDirs { + match self { + LivePluginDirs::Off => LivePluginDirs::Off, + _ => live_plugin_dirs(), + } + } + /// A snapshot holding exactly `dirs`. #[cfg(test)] fn named(dirs: Vec) -> Self { @@ -2117,6 +2130,7 @@ impl LivePluginDirs { fn spares(&self, tree: &Path) -> bool { match self { LivePluginDirs::Unreadable => true, + LivePluginDirs::Off => false, LivePluginDirs::Named(dirs) => dirs.iter().any(|dir| plugin_dir_inside_tree(dir, tree)), } } @@ -2165,6 +2179,10 @@ fn plugin_dir_inside_tree(dir: &Path, tree: &Path) -> bool { /// the kernel withholds (another user's) is skipped, and elsewhere nothing is /// inspected, so behaviour there is unchanged. fn live_plugin_dirs() -> LivePluginDirs { + #[cfg(test)] + if let Some(dirs) = PLUGIN_DIRS_OVERRIDE.with(|slot| slot.borrow().clone()) { + return LivePluginDirs::Named(dirs); + } #[cfg(any(target_os = "linux", target_os = "macos"))] { let Some(pids) = live_process_pids() else { @@ -2172,6 +2190,7 @@ fn live_plugin_dirs() -> LivePluginDirs { }; LivePluginDirs::Named( pids.into_iter() + .filter(|pid| process_is_ours(*pid)) .filter_map(process_argv) .flat_map(|argv| { let argv: Vec<&[u8]> = argv.iter().map(Vec::as_slice).collect(); @@ -2186,6 +2205,40 @@ fn live_plugin_dirs() -> LivePluginDirs { } } +/// Whether `/proc/` belongs to the user running clauth. Linux serves +/// `cmdline` of every user's process, so another user's argv must not keep a +/// tree on disk; macOS already withholds those argvs. A pid that vanished +/// reads as not ours. +#[cfg(any(target_os = "linux", target_os = "macos"))] +fn process_is_ours(pid: u32) -> bool { + #[cfg(target_os = "linux")] + { + path_owned_by_euid(&PathBuf::from(format!("/proc/{pid}"))) + } + #[cfg(target_os = "macos")] + { + let _ = pid; + true + } +} + +/// Whether `path` is owned by the effective uid of this process. +#[cfg(target_os = "linux")] +fn path_owned_by_euid(path: &Path) -> bool { + use std::os::unix::fs::MetadataExt as _; + // SAFETY: `geteuid` takes no arguments and cannot fail. + #[allow(unsafe_code)] + let euid = unsafe { libc::geteuid() }; + std::fs::metadata(path).is_ok_and(|meta| meta.uid() == euid) +} + +#[cfg(test)] +thread_local! { + /// Test seam: when set, [`live_plugin_dirs`] returns exactly these dirs. + static PLUGIN_DIRS_OVERRIDE: std::cell::RefCell>> = + const { std::cell::RefCell::new(None) }; +} + fn gc_runtime_trees() { // One snapshot of Claude Code's job store per sweep, before the pair loop, // so the fast path never pays the walk per pair. A dead pair the snapshot @@ -2326,7 +2379,10 @@ pub(crate) fn rescue_profile_trees(profile: &Path) -> Option { gc_profile_trees( profile, &crate::claude_jobs::job_trees(), - &live_plugin_dirs(), + // The profile dir goes either way: a tree spared here would count as + // unrescued, so `delete` would refuse and `delete --force` would drop + // its transcripts unrescued. + &LivePluginDirs::Off, ); let children = match std::fs::read_dir(profile) { Ok(children) => children, @@ -3966,9 +4022,10 @@ fn gc_one_pair( return Ok(()); } // A live process's launch-time `--plugin-dir` into this tree spares it even - // when the process's config dir has moved on (a mid-run profile switch). - // The path is fixed at launch, so no later start can name a tree that - // was not already named when the snapshot was taken: there is no re-read. + // when nothing else holds the tree: its `clauth start` died (killed, OOM) + // and took the marker lock with it while `claude` keeps running. This is + // the fast path off the sweep's snapshot; `gc_one_pair_synced_with` + // re-reads before it retires the tree. if plugin_dirs.spares(runtime) { logline!( "clauth: spared runtime tree {}: a live process still loads a plugin from it \ @@ -3977,7 +4034,7 @@ fn gc_one_pair( ); return Ok(()); } - gc_one_pair_synced(runtime, sessions, || {}) + gc_one_pair_synced_with(runtime, sessions, plugin_dirs, || {}) } #[cfg(test)] @@ -4030,6 +4087,17 @@ fn gc_one_pair_synced( runtime: &Path, sessions: &Path, remint_interleave: impl FnOnce(), +) -> Result<()> { + gc_one_pair_synced_with(runtime, sessions, &LivePluginDirs::Off, remint_interleave) +} + +/// [`gc_one_pair_synced`] with the plugin-dir mode: [`LivePluginDirs::Off`] +/// skips the plugin-dir re-read, anything else re-reads it fresh. +fn gc_one_pair_synced_with( + runtime: &Path, + sessions: &Path, + plugin_dirs: &LivePluginDirs, + remint_interleave: impl FnOnce(), ) -> Result<()> { // macOS: the tree's namespaced Keychain service, derived while the dir // still exists — the derivation canonicalizes it, so it cannot run once @@ -4095,6 +4163,13 @@ fn gc_one_pair_synced( #[cfg(test)] on_gc_recheck_hold(runtime, sessions); + // Re-read the live `--plugin-dir`s: a `claude` launched with one into this + // tree after the sweep's snapshot must still spare it. Taken here, just + // before the hold, because on macOS the process listing shells out to + // `ps` and no subprocess may span the state flock; the hold below then + // acts on this read the way it acts on the marker and job re-reads. + let plugin_spare = plugin_dirs.refreshed().spares(runtime); + // Re-check under a FRESH lock hold, then collect: between the decide above // and this hold a concurrently starting session can re-mint this same path, // so the removal keys on the world it runs in — markers, the job store AND @@ -4102,6 +4177,7 @@ fn gc_one_pair_synced( // delete below takes. let renamed = with_state_lock(|_held| { let spares = prune_stale_sessions(sessions).unwrap_or(1) != 0 + || plugin_spare || crate::claude_jobs::job_trees().spares(runtime) || !matches!( supervisor_state(runtime), diff --git a/tests/inline/runtime.rs b/tests/inline/runtime.rs index 75ad3ca2..602445cc 100644 --- a/tests/inline/runtime.rs +++ b/tests/inline/runtime.rs @@ -28052,3 +28052,66 @@ fn a_plugin_dir_inside_a_tree_is_matched_by_prefix_only() { tree )); } + +/// A `claude` launched with a `--plugin-dir` into the tree AFTER the sweep's +/// snapshot must still spare it: the retire re-reads the live plugin dirs. +#[test] +fn gc_rereads_plugin_dirs_before_retiring_a_tree() { + let tmp = tempfile::tempdir().expect("tempdir"); + with_fake_home(tmp.path(), || { + let profiles = tmp.path().join(".clauth").join("profiles"); + let runtime = profiles.join("a").join("runtime-6411-0"); + let sessions = profiles.join("a").join("sessions-6411-0"); + fs::create_dir_all(&runtime).expect("mkdir runtime"); + fs::create_dir_all(&sessions).expect("mkdir sessions"); + fs::write(runtime.join(".claude.json"), b"{}").expect("seed"); + let snapshot = crate::claude_jobs::job_trees(); + let late = runtime.join("moshi-plugin"); + PLUGIN_DIRS_OVERRIDE.with(|slot| *slot.borrow_mut() = Some(vec![late])); + let _ = gc_one_pair( + &runtime, + &sessions, + &snapshot, + &LivePluginDirs::Named(Vec::new()), + ); + PLUGIN_DIRS_OVERRIDE.with(|slot| *slot.borrow_mut() = None); + assert!( + runtime.join(".claude.json").is_file(), + "a plugin dir that appeared after the snapshot must spare the tree" + ); + }); +} + +/// The delete path ignores plugin dirs, so a live `--plugin-dir` never makes a +/// tree read as unrescued. +#[test] +fn the_delete_path_ignores_live_plugin_dirs() { + let tmp = tempfile::tempdir().expect("tempdir"); + with_fake_home(tmp.path(), || { + let profiles = tmp.path().join(".clauth").join("profiles"); + let runtime = profiles.join("a").join("runtime-6411-0"); + let sessions = profiles.join("a").join("sessions-6411-0"); + fs::create_dir_all(&runtime).expect("mkdir runtime"); + fs::create_dir_all(&sessions).expect("mkdir sessions"); + fs::write(runtime.join(".claude.json"), b"{}").expect("seed"); + PLUGIN_DIRS_OVERRIDE + .with(|slot| *slot.borrow_mut() = Some(vec![runtime.join("moshi-plugin")])); + let snapshot = crate::claude_jobs::job_trees(); + let _ = gc_one_pair(&runtime, &sessions, &snapshot, &LivePluginDirs::Off); + PLUGIN_DIRS_OVERRIDE.with(|slot| *slot.borrow_mut() = None); + assert!( + !runtime.join(".claude.json").exists(), + "Off must retire the tree despite a live --plugin-dir" + ); + assert!(!LivePluginDirs::Off.spares(&runtime)); + }); +} + +#[cfg(target_os = "linux")] +#[test] +fn a_path_owned_by_this_user_reads_as_ours() { + let tmp = tempfile::tempdir().expect("tempdir"); + assert!(path_owned_by_euid(tmp.path())); + assert!(!path_owned_by_euid(&tmp.path().join("missing"))); + assert!(process_is_ours(std::process::id())); +} From 8c578acca2f67c44d9104628b01c44c37ff60572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lautaro=20Ant=C3=BAnez?= Date: Tue, 24 Nov 2026 09:57:50 -0300 Subject: [PATCH 3/3] fix(gc): gate the delegating gc_one_pair_synced wrapper to tests --- src/runtime.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/runtime.rs b/src/runtime.rs index 79549674..971fa12c 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -4083,6 +4083,7 @@ fn gc_held_marker_set(file: File) { /// The removal hold renames the tree to its tombstone ([`retire_tree`]), and /// the rescue runs once the lock drops, because nothing but that tree may hold /// what its dead session wrote. +#[cfg(test)] fn gc_one_pair_synced( runtime: &Path, sessions: &Path,