Clean up the rules and state of a VM that is already gone
Defect
A rig that deletes itself after 30 idle minutes, or whose max run ends, leaves its firewall rules and its laptop state record behind. down then failed on the missing VM, so nothing cleaned up the rules or the record, and the stale pointer kept steering bare recipes at a rig that no longer existed.
Fix
down now asks whether the instance exists (instances describe; the answer "was not found" is the only gone signal). When it is gone, down deletes that instance deny-registry and seal rules and clears its state record, and nothing else:
- The shared ssh and http rules are never touched.
- A state record written by another owner is refused with a message naming the owner.
- A rule that cannot be deleted keeps the state, so the next run retries.
- A VM whose status cannot be read (auth, network) is not treated as gone;
downruns the old flow.
up now records the owner in the state file, so a record can be matched to its owner. A new just lab reap does the same cleanup for every rig of this SIM_OWNER whose VM is gone. It skips other owners, records with no owner, other projects, and running or unreadable VMs.
sequenceDiagram
participant D as down or reap
participant G as gcloud
participant S as state record
D->>G: describe instance
alt exists
D->>G: unseal, delete rules, delete VM
D->>S: clear
else was not found
D->>S: owner matches this SIM_OWNER?
D->>G: delete this instance rules only
D->>S: clear
else any other error
D->>D: say it cannot tell, old flow
endProof
gce/engine-selftest.shgained cases for down on a gone VM, a failed rule delete keeping state, another owner refused, an unreadable VM not read as gone, and reap (own, other owner, no owner, running). With the previoussimulation.sh18 of them fail; with this change none do.tests/run.sh: 630 passed, 0 failed.tests/recipe-arguments.sh: 271 passed.