Expand description
Clears the version folders an upgrade leaves behind, and the portables it unpacked.
Every upgrade starts the new version on a copy of the old version’s data
(channels/<channel>/versions/<v>/), and the updater unpacks a new portable beside the running
one. Nothing removes the old ones, so a machine that upgrades daily gains 0.5-1 GB of each a day.
A folder of this srv’s own channel goes only when ALL hold:
- it is older than the version this srv runs (a newer one is another build’s, or a rollback already taken: not ours to judge);
- it is not one of the newest
keep_previousolder versions (the way back, one by default); - no running process names it: not in its command line, its working folder, its program path or
its environment (every agent’s shell carries
AGENTMUX_DATA_DIR), and the pid itssrv.lockrecords is not a live AgentMux process; - nothing in it was written for
idle(a day by default); - the machine’s processes could be read at all. A scan that fails keeps everything: a guard that cannot see must not approve.
Before a version folder goes, its data/attachments (the images and files old conversations
show) are copied into the running version’s attachments store, so no old image vanishes; a
copy that cannot finish keeps the folder.
A removal renames the folder first, which Windows refuses while any file in it is open, and only
then deletes it, so a crash leaves a *.removing-<pid> folder the next pass finishes. Portable
folders (agentmux-<v>-x64-portable) are the user’s: they are listed, and removed only when
oldversions:portables is on, and only those the updater unpacked for this channel (they record
it). Nothing here follows a symlink, and a name that is not a plain x.y.z is left alone.
run with dry_run only reads. old_versions_service calls it daily and the
/agentmux/old-versions route lets an agent look at the plan, or carry out what it shows.
Structs§
- Candidate
- InUse
- What is running right now.
- Layout
- Where the folders are, and which version this srv is.
- Plan
- Policy
- What goes, and whether the daily pass removes it or only reports it.
- Proc
View - One running process, as the guard needs it.
- Report
- Run
- The outcome of one
run.
Enums§
Constants§
- KEY_
CLEAN - Settings keys (the free-form part of the settings file).
- KEY_
IDLE_ HOURS - KEY_
KEEP_ PREVIOUS - KEY_
PORTABLES
Functions§
- layout_
from_ env - The layout of this srv, or
Nonewhen it has no per-version folders (atask devbuild, a test home). - plan
- Decides what could go. Reads only.
- remove
- Removes what
planfound, asking again for each folder at the last moment: a process may have started in it since. - run
- Plans, and unless
dry_run, removes.onlylimits a removal to folders an earlier dry run listed: what became removable since is left alone, so a removal is what the caller was shown.