Skip to content

Refuse project caches that a running process uses - #32

Merged
mattt merged 3 commits into
mainfrom
mattt/busy-caches
Nov 17, 2026
Merged

mattt merged 3 commits into
mainfrom
mattt/busy-caches

Conversation

@mattt

@mattt mattt commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Plonge treats a project as quiet when its HEAD log and newest agent transcript are old, but a long-running service, such as a systemd unit that runs .venv/bin/python, updates neither. clean could then delete the .venv while the service runs, and the service's next restart fails.

This adds internal/procs, which takes one snapshot of the running processes: on macOS, one lsof -w -n -P +c 0 -F pcLfn call and one ps -axww -o pid=,user=,args= call; on Linux, a read of /proc/<pid>/ (exe, cwd, root, fd, maps, cmdline, comm). A process uses a cache when it has a file open or a library mapped under it, works in it, runs an executable from it, or names a path in it on its command line. The command line is needed because a venv's bin/python is a symlink to the base interpreter, so the executable that lsof or /proc reports is outside the .venv.

engine.Inspect takes the snapshot after the agent check, and scan.RefuseUsed moves each used candidate to refused before measuring, so scan and the dry run show it; --include-active does not override it. clean --apply checks again before each deletion through a new clean.Options.InUse, with a fresh snapshot before the first deletion and again only when the last one is more than 10 seconds old. A refusal reads Refused ~/code/app/.venv: in use by python3.12 (PID 4312), whose command line names bin/python, and the JSON refusal gains a processes array. Global rules are unchanged.

If the snapshot fails (lsof or ps missing, failing, or slower than 30 seconds, or /proc unreadable), a new processes activity source fails and every project counts as busy; a failed re-check skips the cache. This fails closed, like a failing paseo ls, because a missing tool does not show that no process uses a cache. "Not selected, busy project (Paseo)" becomes "Not selected, busy project".

Limits, which the README and docs/rules.md state: a service that is stopped at scan time, a timer or cron job, and a process that starts after the last check are not seen; neither is a process that names no cache path and holds nothing open there, such as python from an activated venv. Without root, another user's process is seen only through its command line, and on macOS ps joins words with spaces, so a path with a space can be missed.

This branch is based on main, not stacked on #30. After this merges, #30 can build its open-file list from a procs snapshot and drop listOpenFiles. This branch conflicts with #29 in internal/engine/engine.go, where both add to the clean.Options literal.

Departures from the design: lsof gets +c 0 because its default cuts command names to 9 characters (python3.1); the fail-closed test is in scan rather than engine, because scan.RefuseUsed handles the failure and engine has no tests; and a cmd/plonge test starts a real sleep in a cache, so the tests now run the system's lsof and ps on macOS.

Closes #31

@mattt
mattt marked this pull request as ready for review November 17, 2026 14:23
@mattt
mattt merged commit 233e21d into main Nov 17, 2026
2 checks passed
@mattt
mattt deleted the mattt/busy-caches branch November 17, 2026 14:23
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.

Refuse project caches that a running process is using

1 participant