Loading
Serve list from state and batch the live check
What changed
just lab list --json ran one gcloud compute instances describe per record, so 86 records took about 79 s. A client that draws a list cannot wait that long, and most of those records belong to VMs that are long gone.
listandlist --jsonnow read state alone and make no gcloud call. Each record carriesvm_checked: false.list --livemakes one batchedgcloud compute instances listcall per project, filtered to the lab label or the recorded names, and joins the result in. A record with no VM getsvm_gone: true.list --live --pruneremoves the records whose VM is gone. It keeps a record whose VM exists, whose snapshot, disk or<instance>-addraddress still exists, whose firewall rule still exists, or whose create window is open, sodowncan clean those. Each kind is one batched list per project, never one call per record.
The allowlisted keys from STATUS_JSON_KEYS are unchanged. vm_checked and vm_gone are new, so schema_version is 6. status --json still describes its one VM and reports vm_checked: true.
flowchart TD
A[just lab list] --> B{--live?}
B -- no --> C[read state files<br/>one jq run]
C --> D[records with vm_checked false<br/>zero gcloud calls]
B -- yes --> E[one batched instances list<br/>per project]
E --> F[join VMs into records<br/>no VM means vm_gone]
F --> G{--prune?}
G -- no --> H[records with vm_checked true]
G -- yes --> I[one list each: snapshots,<br/>disks, addresses, firewall rules]
I --> J{VM, snapshot, disk,<br/>address or rule left?}
J -- yes --> K[keep the record for down]
J -- no --> L[remove the record]Proof
engine-selftest.shasserts that the cached list makes zero gcloud calls, the live list makes exactly one, a gone VM is marked, and prune removes only records with no VM and nothing left, across a VM, snapshot, recorded snapshot, disk, address, recorded address, firewall rule and open create window. It also times 108 records under 1 s.- Against 84 real records on this machine, the cached list took 0.06 s and the live list 1.7 s.
Docs
gce/operations.md describes the three forms. It nets two fewer words, so the word budget holds.