Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
docs(fsmonitor): correct the sweep's cost model after the batched lsof (#3852)
Maximilian Roos03ab088b90b6
diff --git a/benches/CLAUDE.md b/benches/CLAUDE.mdindex 4c92d6ac7..71c556987 100644--- a/benches/CLAUDE.md+++ b/benches/CLAUDE.md@@ -276,18 +276,14 @@ cargo run -p wt-perf -- timeline -- -C target/wt-prune-imported step prune --min# For another run, remove target/wt-prune-imported explicitly or choose a new path.```-**The `wt remove` exit-delay is machine-dependent and invisible to benches.**-After its last message, `wt remove` runs an in-process sweep-(`run_internal_sweep`) that enumerates `git fsmonitor--daemon` processes-*machine-wide* and resolves each one's socket with a ~50 ms `lsof` call —-sequential, before exit, while the shell wrapper waits on the process. On a-machine with N live daemons that appends roughly `N × 50 ms` of post-output-latency (measured: 115 daemons → 5.8 s after 0.4 s of actual removal output);-on daemon-free bench/CI machines it costs nothing, so `remove_e2e` never sees-it. To observe it, run `wt-perf timeline -- remove <branch>` on a real machine-and read the `internal-sweep` span and its `lsof -a -p …` children; the-`fsmonitor sweep: resolving sockets for N daemon(s)` debug line gives the-count.+**`wt remove` keeps working after its last message.** The in-process sweep+(`run_internal_sweep`) runs before exit, while the shell wrapper waits on the+process: one `pgrep` for `git fsmonitor--daemon` processes plus one `lsof` over+the whole PID set. Two spawns whatever the machine-wide daemon count, so+`remove_e2e` misses a fixed tail rather than one that grows with the machine.+To observe it, run `wt-perf timeline -- remove <branch>` on a real machine and+read the `internal-sweep` span; the `fsmonitor sweep: resolving sockets for N+daemon(s) via one lsof` debug line gives the count.## Output Locationsdiff --git a/src/commands/process.rs b/src/commands/process.rsindex 3682635f8..a6d31e54e 100644--- a/src/commands/process.rs+++ b/src/commands/process.rs@@ -491,10 +491,12 @@ fn spawn_detached_exec_windows(/// step is best-effort and additive — failures log at debug level and the/// `wt remove` operation proceeds regardless.///-/// It DOES delay process exit — the shell wrapper waits on it. The daemon-/// reap enumerates fsmonitor daemons machine-wide with one sequential ~50ms-/// `lsof` per daemon (measured: 115 daemons → ~5.8s of post-output latency;-/// see the `internal-sweep` / `enumerate-fsmonitor-daemons` trace spans and+/// It DOES delay process exit — the shell wrapper waits on it. Enumeration is+/// two spawns, one `pgrep` plus one `lsof` over the whole daemon PID set, flat+/// in the machine-wide daemon count. Any live daemon then costs a+/// `git worktree list`, and a classified orphan a `SIGTERM`→`SIGKILL` wait+/// bounded by `REAP_KILL_DEADLINE` — both flat in the daemon count too (see+/// the `internal-sweep` / `enumerate-fsmonitor-daemons` trace spans and/// benches/CLAUDE.md § Recording `wt remove` / `wt step prune` staging).////// Steps:diff --git a/src/git/fsmonitor.rs b/src/git/fsmonitor.rsindex ca3ab431a..d61bd4a8c 100644--- a/src/git/fsmonitor.rs+++ b/src/git/fsmonitor.rs@@ -606,6 +606,29 @@ mod tests {assert!(daemons_from_batched_lsof("").is_empty());}+ /// Socket lines with no parsable `p` line above them — leading output, or+ /// output under a `p` line that isn't a number — belong to no record.+ /// Attaching them to a neighbour would fabricate a class-1 orphan out of+ /// pid 301, whose own record holds only a socket-pair endpoint. Parsing+ /// resumes at the next valid `p` line, so pid 400 still classifies.+ #[cfg(unix)]+ #[test]+ fn batched_lsof_drops_lines_outside_a_parsable_record() {+ let batched = concat!(+ "nfsmonitor--daemon.ipc\n",+ "p301\n",+ "f21\n",+ "n->0x1\n",+ "pBAD\n",+ "nfsmonitor--daemon.ipc\n",+ "p400\n",+ "n/repo/.git/worktrees/b/fsmonitor--daemon.ipc\n",+ );+ let daemons = daemons_from_batched_lsof(batched);+ assert_eq!(daemons.len(), 1);+ assert_eq!(daemons[0].pid, 400);+ }+#[cfg(unix)]#[test]fn canonicalize_socket_resolves_symlinked_git_dir_and_falls_back_when_gone() {