# Retention: every setting off unless devvm retention sets it, and shown # bare, off when unset; a bad key or value, or none (KEY=), refused before # the file is written; devvm's commands apply the settings once a day, # devvm gc --retention at once, each deleting only what its settings name, # never a VM nor a tool any VM's state lists. env EXPORTS=$XDG_DATA_HOME/devvm/exports env SHARE=$XDG_DATA_HOME/devvm/tools mkdir $EXPORTS exec sh -c 'cd "$EXPORTS" && for f in devvm-old-12345612345612-20200101-000000 devvm-new-abcdefabcdefab-20991231-235959; do echo x > $f.tar.gz; done' # No file: nothing is deleted, by a command or gc --retention. exec devvm space exec devvm gc --force --retention stdout '^==> retention_off$' exists $EXPORTS/devvm-old-12345612345612-20200101-000000.tar.gz ! exists $DATA/retention.run # Bare, every setting is off. exec devvm retention cmp stdout want-all-off ! stderr . ! exists $DATA/retention.run # Bad keys and values, and a key with no value, are refused, and nothing # is written. ! exec devvm retention history.age=30 stderr '^devvm: bad_duration value=30$' ! exec devvm retention history.age=forever stderr '^devvm: bad_duration value=forever$' exec devvm retention history.age=90m exec devvm retention history.age=off ! grep retention $DATA/settings.json ! exec devvm retention logs.network.size=10M stderr '^devvm: retention_bad ' ! exec devvm retention history.age= stderr '^devvm: retention_bad reason=history\.age= has no value, and history\.age=off turns it off$' ! exec devvm retention history.age=30d tools.unused-age= stderr '^devvm: retention_bad ' ! grep retention $DATA/settings.json # Set: devvm retention shows them, and where each came from, and devvm # space shows each beside its row, with what it would free. exec devvm retention history.age=30d tools.unused-age=1d stdout '^==> retention_saved file=\S+/data/devvm/settings\.json$' grep '^ "retention": {\n "history.age": "30d",\n "tools.unused-age": "1d"\n }$' $DATA/settings.json exec devvm retention cmp stdout want-shown exec devvm retention --json cmp stdout want-shown.json ! exec devvm retention --json history.count=5 stderr '^devvm: json_shows_only command=devvm retention$' ! exec devvm retention history.count=x grep '^ "retention": {\n "history.age": "30d",\n "tools.unused-age": "1d"\n }$' $DATA/settings.json # config.toml's settings win, each shown with its path; devvm retention # refuses to change one, naming the file and the key, and changes the # rest. cp config.toml $CFG/config.toml exec devvm retention stdout '^history\.age=60d # \S*/config/devvm/config\.toml$' stdout '^tools\.unused-age=1d # devvm: settings\.json$' exec devvm retention --json stdout '"history.age": "config.toml",' ! exec devvm retention history.age=off stderr '^devvm: set_in_config file=\S*/config/devvm/config\.toml key=retention\.history\.age$' exec devvm retention history.count=3 exec devvm retention history.count=off rm $CFG/config.toml exec devvm space stdout '^history +2 +\S+ +only copy +- +gc --history +30d \(\S+\)$' stdout 'RETAIN' # The next command applies it, once: the old export goes, the new stays. exec devvm ls stderr '^retention_deleted exports=1 nix_files=0 orphans=0 tools=0$' ! exists $EXPORTS/devvm-old-12345612345612-20200101-000000.tar.gz exists $EXPORTS/devvm-new-abcdefabcdefab-20991231-235959.tar.gz exists $DATA/retention.run exec sh -c 'echo x > "$EXPORTS/devvm-old-12345612345612-20200101-000001.tar.gz"' exec devvm ls ! stderr retention_deleted exists $EXPORTS/devvm-old-12345612345612-20200101-000001.tar.gz # A day later (or a clock that went back) it applies again. exec touch -t 202001010000 $DATA/retention.run exec devvm ls stderr '^retention_deleted exports=1 ' # Tools: a current build no VM has is recorded idle, deleted a day later; # one a VM's state lists stays. # A VM made with the two agents builds their tool images; once it's gone # no VM has them. project agents git exec devvm --tools none --agents claude,codex --network open --no-git-protect exec devvm rm --force --no-export mkdir $VMS/12345612345612 exec sh -c 'printf "{\"version\": 1, \"id\": \"x\", \"name\": \"devvm-gone-12345612345612\", \"image\": \"base\", \"dir\": \"/p\", \"backend\": \"lima\", \"created\": \"2020-01-01T00:00:00Z\", \"tools\": {\"names\": [\"claude\"], \"made\": {\"files\": [\"%s\"]}}}\n" "$(cd "$SHARE" && ls claude-*.erofs)" > "$VMS/12345612345612/vm.json"' json_set $SHARE/*.erofs.json built=2020-01-01T00:00:00Z exec devvm gc --force --retention stdout '^==> retention_deleted exports=0 nix_files=0 orphans=0 tools=0$' exec sh -c 'grep -l "\"idle_since\": " "$SHARE"/*.json' stdout '/codex-\S+\.erofs\.json$' ! stdout claude json_set $SHARE/codex-*.erofs.json idle_since=2020-01-01T00:00:00Z # While a VM is being made (its start hangs), retention keeps the tools # and runs the rest; once its devvm is killed, nothing holds the lock. project making git exec sh -c ': > "$STUB_DIR/start-hangs"' ! exec devvm --network open &u& wait_file $STUB_DIR/hanging exec devvm gc --force --retention stdout '^==> retention_deleted exports=0 nix_files=0 orphans=0 tools=0$' exec sh -c 'grep -l "\"idle_since\": \"2020-01-01T00:00:00Z\"" "$SHARE"/codex-*.erofs.json' kill -KILL u wait u rm $STUB_DIR/start-hangs exec sh -c 'rm -f "$STUB_DIR/hanging"' exec devvm gc --force --retention stdout '^==> retention_deleted exports=0 nix_files=0 orphans=0 tools=1$' exec sh -c 'ls "$SHARE"' ! stdout codex stdout '^claude-' # KEY=off turns a setting off. exec devvm retention history.age=off tools.unused-age=off ! grep retention $DATA/settings.json exec devvm retention cmp stdout $WORK/want-all-off -- config.toml -- [retention] history.age = "60d" -- want-shown -- logs.runs=off # devvm: default history.age=30d # devvm: settings.json history.count=off # devvm: default tools.unused-age=1d # devvm: settings.json orphans.age=off # devvm: default nix-cache.size=off # devvm: default -- want-shown.json -- { "version": 1, "settings": { "history.age": "30d", "history.count": "off", "logs.runs": "off", "nix-cache.size": "off", "orphans.age": "off", "tools.unused-age": "1d" }, "sources": { "history.age": "settings.json", "history.count": "built-in", "logs.runs": "built-in", "nix-cache.size": "built-in", "orphans.age": "built-in", "tools.unused-age": "settings.json" } } -- want-all-off -- logs.runs=off # devvm: default history.age=off # devvm: default history.count=off # devvm: default tools.unused-age=off # devvm: default orphans.age=off # devvm: default nix-cache.size=off # devvm: default