Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci: name Ubicloud VMs in gstack's -t<H> TTL grammar; reaper reads -t and legacy -x names

garrytan12c54c8503a1
diff --git a/scripts/bench/production-soak/ubicloud.sh b/scripts/bench/production-soak/ubicloud.sh
index b6e711103d..3221798a4a 100755
--- a/scripts/bench/production-soak/ubicloud.sh
+++ b/scripts/bench/production-soak/ubicloud.sh
@@ -3,12 +3,13 @@
# on ephemeral Ubicloud VMs, one VM per latency, in parallel (GBRA-174).
#
# UBI_OWNER=<thread> scripts/bench/production-soak/ubicloud.sh start [--pages 600000] [--hours 3]
-# [--rtts 65,2] [--size standard-16] [--storage 640] [--ttl-hours 14] [--out .context/production-soak]
+# [--rtts 65,2] [--size standard-16] [--storage 640] [--ttl-hours 15] [--out .context/production-soak]
# scripts/bench/production-soak/ubicloud.sh status [--out DIR] # last lines of each cell's run log
# scripts/bench/production-soak/ubicloud.sh collect [--out DIR] # copy each finished cell back, destroy its VM
#
-# start creates one VM per latency, named with an expiry (--ttl-hours) so the
-# operator reaper destroys it if nobody collects it, syncs this checkout
+# start creates one VM per latency, named with a TTL (--ttl-hours: a -t15 name
+# by default, above the 3-hour soak plus setup and collect) so the operator
+# reaper or gstack's reap destroys it if nobody collects it, syncs this checkout
# (uncommitted edits included), bootstraps it (vm-setup.sh) and launches
# run.sh detached on the VM, so the soak does not depend on this machine
# staying awake. collect copies <out>/rtt<N>/out back for every cell whose run
@@ -18,7 +19,7 @@ set -euo pipefail
cd "$(dirname "$0")/../../.."
UBI=scripts/ubicloud/ubi-runner.sh
CMD=${1:-}; shift || true
-PAGES=600000 HOURS=3 RTTS=65,2 SIZE=standard-16 STORAGE=640 TTL=14 OUT=.context/production-soak EXTRA=()
+PAGES=600000 HOURS=3 RTTS=65,2 SIZE=standard-16 STORAGE=640 TTL=15 OUT=.context/production-soak EXTRA=()
while [ $# -gt 0 ]; do
case $1 in
--pages) PAGES=$2; shift 2 ;;
diff --git a/scripts/ci-ubicloud.ts b/scripts/ci-ubicloud.ts
index d55b1dbc37..9d6e2dba04 100755
--- a/scripts/ci-ubicloud.ts
+++ b/scripts/ci-ubicloud.ts
@@ -27,8 +27,8 @@
* --diff doc-only diffs run only the doc checks and gitleaks (ci:local --diff)
* --record-weights write measured durations to scripts/ubicloud/weights.json
* --keep leave the VMs running (destroy with ubi-runner.sh down NAME)
- * --ttl-hours N VM expiry written into each name (default 2; 0 = no
- * expiry). The operator reaper destroys VMs past their
+ * --ttl-hours N VM TTL written into each name as -t<N> (default 2,
+ * at most 999). The operator reaper destroys VMs past their
* expiry, so a VM a sleeping machine never tore down
* dies within hours (scripts/ubicloud/reap-expired.ts)
*
@@ -52,9 +52,9 @@
* UNIT_SHARD_BUDGET_MS (unitShardCheck) and reports each shard's measured time. Durations of every run are
* merged into .context/ci-ubicloud/weights.json, which weights the next run.
*
- * VMs are named ubirun-<owner>-<epoch>-x<expiry epoch>-ciNN<hex> (owner:
- * UBI_OWNER or the runner's per-machine id; ubirun-<owner>-<epoch>-ciNN<hex>
- * with --ttl-hours 0). Each name is appended to <run>/vms.txt before its
+ * VMs are named ubirun-<owner>-<epoch>-ciNN<hex>-t<ttl hours> (owner:
+ * UBI_OWNER or the runner's per-machine id), gstack's runner grammar, so
+ * gstack's reap reads the same TTL. Each name is appended to <run>/vms.txt before its
* create request is sent. On exit, including SIGINT, SIGTERM, SIGHUP (a
* dropped terminal, a cancelled background operation) and SIGQUIT, in-flight
* `up` calls are allowed to finish (they destroy their own VM), then every
@@ -168,7 +168,7 @@ function parseArgs(argv: string[]): Opts {
if (opts.location !== GATE_LOCATION && !argv.includes("--lanes")) usage(`a full gate runs only in ${GATE_LOCATION}. Test timeouts and the mined shard weights are calibrated there; on 2026-10-19 us-east-a2 ran about half as fast and timed out tests that pass in ${GATE_LOCATION}, so a full run in ${opts.location} is not gate evidence. Wait for ${GATE_LOCATION} capacity or run bun run ci:local (and report it as local). To run a diagnostic subset in ${opts.location}, pass --lanes.`);
if (opts.pgImage && !/^[a-z0-9][a-z0-9._\/-]*(?::[A-Za-z0-9._-]+)?$/.test(opts.pgImage)) usage(`--pg-image ${opts.pgImage} is not an image reference`);
if (opts.pgImage && !argv.includes("--lanes")) usage("a full gate runs on the default Postgres image; --pg-image is a diagnostic run, so pass --lanes (for example --lanes pg-arms,e2e).");
- if (!Number.isInteger(opts.ttlHours) || opts.ttlHours < 0 || opts.ttlHours > 8760) usage("--ttl-hours must be a whole number of hours from 0 (no expiry) to 8760");
+ if (!Number.isInteger(opts.ttlHours) || opts.ttlHours < 1 || opts.ttlHours > 999) usage("--ttl-hours must be a whole number of hours from 1 to 999 (every gate VM carries a TTL; 999 is the longest)");
if (!Number.isInteger(opts.vms) || opts.vms < 0 || (opts.vms === 0 && argv.includes("--vms"))) usage("--vms must be a positive integer");
// Three slots per eight vCPUs: each slot's bun process, its children and its
// own PostgreSQL and PgBouncer keep about 2.5 threads runnable. One slot per
@@ -293,7 +293,7 @@ async function main() {
opts.vms = decision.vms;
log(`fleet: ${decision.reason} (pass --vms N to override)`);
}
- log(`provisioning ${opts.vms} × ${opts.size} in ${opts.location} (${opts.image === "stock" ? "stock Ubuntu 24.04" : `image ${opts.image}`}), ${opts.slots} slots each, ${opts.ttlHours ? `names expiring ${opts.ttlHours}h after creation` : "no expiry"}; logs in ${runDir}`);
+ log(`provisioning ${opts.vms} × ${opts.size} in ${opts.location} (${opts.image === "stock" ? "stock Ubuntu 24.04" : `image ${opts.image}`}), ${opts.slots} slots each, names expiring ${opts.ttlHours}h after creation; logs in ${runDir}`);
// ── Checkout tarball, packed once while the VMs boot ─────────────────────
const tarball = join(tmpdir(), `gbrain-ci-ubicloud-${process.pid}.tgz`);
@@ -339,7 +339,7 @@ async function main() {
rmSync(tarball, { force: true });
const live = vms.filter((vm) => vm.requested && vm.state !== "destroyed");
if (opts.keep) {
- log(`--keep: leaving ${live.map((vm) => vm.name).join(" ")} running; destroy with: scripts/ubicloud/ubi-runner.sh down NAME${opts.ttlHours ? ` (the operator reaper destroys them ${opts.ttlHours}h after creation; --ttl-hours 0 for no expiry)` : ""}`);
+ log(`--keep: leaving ${live.map((vm) => vm.name).join(" ")} running; destroy with: scripts/ubicloud/ubi-runner.sh down NAME (the operator reaper destroys them ${opts.ttlHours}h after creation; pass --ttl-hours up to 999 for longer)`);
return;
}
log(`destroying ${live.length} VM(s): ${live.map((vm) => vm.name).join(" ")}`);
@@ -397,7 +397,7 @@ async function main() {
};
const runBatch = async (vm: Vm, slot: number, lane: string, files: string[]) => {
- const logPath = join(runDir, "logs", `${String(++batchSeq).padStart(5, "0")}-${vm.name.slice(-8)}-s${slot}-${lane}.log`);
+ const logPath = join(runDir, "logs", `${String(++batchSeq).padStart(5, "0")}-${vm.name.replace(/-t\d+$/, "").slice(-8)}-s${slot}-${lane}.log`);
const cmd = `cd ${REMOTE_DIR} && SLOT=${slot} bash scripts/ubicloud/ci-item.sh ${lane} ${files.map(quote).join(" ")}`;
const r = await runner(["ssh", vm.name, cmd], { out: logPath, timeoutMs: BATCH_TIMEOUT_MS });
return { code: r.code, parsed: parseItemLog(readFileSync(logPath, "utf8")), logPath };
diff --git a/scripts/ubicloud/README.md b/scripts/ubicloud/README.md
index f779e63259..488832b115 100644
--- a/scripts/ubicloud/README.md
+++ b/scripts/ubicloud/README.md
@@ -24,29 +24,31 @@ the integrator runs the full gate.
## Ownership and teardown
-Every VM is named `ubirun-<owner>-<epoch>-<suffix>`, or
-`ubirun-<owner>-<epoch>-x<expiry epoch>-<suffix>` when it carries an expiry.
+Every VM the runner names is `ubirun-<owner>-<epoch>-<suffix>-t<H>`, gstack's
+runner grammar: its TTL ends H hours (1 to 999) after the creation epoch.
The owner is `UBI_OWNER` (lowercased, letters and digits only, at most 12
characters, starting with a letter) or a random per-machine id kept in the
runner's state directory. Set `UBI_OWNER` to your thread code
(`UBI_OWNER=gbra41 bun run ci:ubicloud`) so everyone can see whose VMs hold
the quota. Ubicloud names allow 63 characters of `[a-z0-9-]`, so a full name
-stays under 52.
-
-Ubicloud has no VM tags, so the expiry lives in the name. `ci:ubicloud` names
-every gate VM to expire two hours after creation (`--ttl-hours N` changes it,
-`--ttl-hours 0` means no expiry). `ubi-runner.sh up` and `run` take the same
-`--ttl-hours H`; without it their VMs never expire, which suits long dev,
-benchmark and eval VMs. `scripts/ubicloud/reap-expired.ts` is the operator
+stays under 50.
+
+Ubicloud has no VM tags, so the TTL lives in the name, and gstack's
+`ubi-runner.sh reap` reads it the same way. `ci:ubicloud` gives every gate VM a
+two-hour TTL (`--ttl-hours N` changes it, up to 999). `ubi-runner.sh up` and
+`run` take the same `--ttl-hours H`; without it their VMs get `-t999` (about
+41 days) for long dev, benchmark and eval VMs, and gstack's reap destroys a
+`ubirun-*` VM with no TTL once it is four hours old. `scripts/ubicloud/reap-expired.ts` is the operator
side of the leak guard: run from the operator's Capy automation, where the
Ubicloud token already lives (never from GitHub Actions), it lists the project's
-VMs, selects only names in the expiring format whose expiry plus a 15-minute
-grace has passed, and prints each `ubirun-*` VM's owner, age, expiry and action
+VMs, selects only names with a TTL (or the older
+`ubirun-<owner>-<epoch>-x<expiry epoch>-<suffix>` form, until none are left)
+whose expiry plus a 15-minute grace has passed, from any owner or tool, and prints each `ubirun-*` VM's owner, age, expiry and action
plus an owner-notice block (expired VMs grouped by owner and the thread code
the owner tag names). It is a dry run unless given `--apply`, which destroys
each expired VM through `ubi-runner.sh down`, and it refuses the whole run when
more than `--max` (40) VMs are expired. It never selects an owner-tagged name
-without an expiry, a legacy untagged `ubirun-<epoch>-*` name or a VM the
+without a TTL, a legacy untagged `ubirun-<epoch>-*` name or a VM the
runner did not name, whoever owns it.
Each name is recorded before its create request is sent: the runner writes
diff --git a/scripts/ubicloud/reap-expired.ts b/scripts/ubicloud/reap-expired.ts
index d7efbe5985..790248ad56 100644
--- a/scripts/ubicloud/reap-expired.ts
+++ b/scripts/ubicloud/reap-expired.ts
@@ -14,15 +14,22 @@
* are expired: a burst that large needs a human look (default 40)
* --now EPOCH evaluate at this time (default now; for tests and replays)
*
- * Only names in the expiring format are ever selected:
+ * Only names that carry a TTL are ever selected, in gstack's runner grammar
+ * (the one gstack's `ubi-runner.sh reap` reads, expiring H hours after the
+ * creation epoch):
*
- * ubirun-<owner>-<created epoch>-x<expiry epoch>-<suffix>
+ * ubirun-<owner>-<created epoch>-<suffix>-t<H>
*
* which `ci:ubicloud` writes for its gate VMs (`--ttl-hours`, default 2) and
- * `ubi-runner.sh up|run --ttl-hours H` writes on request. Owner-tagged names
- * without an expiry (`ubirun-<owner>-<epoch>-<suffix>`: long dev, benchmark
- * and eval VMs), legacy untagged `ubirun-<epoch>-*` names and VMs the runner
- * did not name are never selected. Ubicloud has no VM tags, so the expiry
+ * `ubi-runner.sh up|run` writes for every name it generates (`--ttl-hours H`,
+ * default 999), whichever tool and owner made the VM; or in the older form
+ * gbrain wrote before it, reaped until none are left:
+ *
+ * ubirun-<owner>-<created epoch>-x<expiry epoch>-<suffix>
+ *
+ * Owner-tagged names without a TTL (`ubirun-<owner>-<epoch>-<suffix>`), legacy
+ * untagged `ubirun-<epoch>-*` names and VMs the runner did not name are never
+ * selected. Ubicloud has no VM tags, so the expiry
* lives in the name and the list's location and name columns are all the
* reaper reads.
*
@@ -45,6 +52,7 @@ import { join } from "node:path";
const RUNNER = join(import.meta.dir, "ubi-runner.sh");
const MAX_NAME = 63;
const OWNER = "[a-z][a-z0-9]{0,11}";
+const TTL = new RegExp(`^ubirun-(${OWNER})-(\\d{10})-([a-z0-9][a-z0-9-]*)-t(\\d{1,3})$`);
const EXPIRING = new RegExp(`^ubirun-(${OWNER})-(\\d{10})-x(\\d{10})-([a-z0-9]{1,24})$`);
const NO_EXPIRY = new RegExp(`^ubirun-(${OWNER})-(\\d{10})-([a-z0-9]{1,24})$`);
const LEGACY = /^ubirun-(\d{10})-[a-z0-9]{1,24}$/;
@@ -56,7 +64,9 @@ export type ParsedName =
| { kind: "foreign" };
export function parseVmName(name: string): ParsedName {
- let m = EXPIRING.exec(name);
+ let m = TTL.exec(name);
+ if (m) return { kind: "expiring", owner: m[1]!, createdAt: Number(m[2]), expiresAt: Number(m[2]) + Number(m[4]) * 3600 };
+ m = EXPIRING.exec(name);
if (m) return { kind: "expiring", owner: m[1]!, createdAt: Number(m[2]), expiresAt: Number(m[3]) };
m = NO_EXPIRY.exec(name);
if (m) return { kind: "no-expiry", owner: m[1]!, createdAt: Number(m[2]) };
@@ -65,13 +75,11 @@ export function parseVmName(name: string): ParsedName {
return { kind: "foreign" };
}
-/** A gate VM name: expiring `ttlHours` after `createdAt`, or no expiry when ttlHours is 0. */
+/** A gate VM name in gstack's grammar: a TTL of `ttlHours` (1 to 999) after `createdAt`. */
export function expiringVmName(o: { owner: string; createdAt: number; ttlHours: number; suffix: string }): string {
- if (!Number.isInteger(o.ttlHours) || o.ttlHours < 0 || o.ttlHours > 8760) throw new Error(`ttl must be a whole number of hours from 0 to 8760, got ${o.ttlHours}`);
- const name = o.ttlHours
- ? `ubirun-${o.owner}-${o.createdAt}-x${o.createdAt + o.ttlHours * 3600}-${o.suffix}`
- : `ubirun-${o.owner}-${o.createdAt}-${o.suffix}`;
- if (name.length > MAX_NAME || parseVmName(name).kind !== (o.ttlHours ? "expiring" : "no-expiry")) throw new Error(`not a valid ubi-runner VM name: ${name}`);
+ if (!Number.isInteger(o.ttlHours) || o.ttlHours < 1 || o.ttlHours > 999) throw new Error(`ttl must be a whole number of hours from 1 to 999, got ${o.ttlHours}`);
+ const name = `ubirun-${o.owner}-${o.createdAt}-${o.suffix}-t${o.ttlHours}`;
+ if (name.length > MAX_NAME || !/^[a-z0-9]{1,24}$/.test(o.suffix) || parseVmName(name).kind !== "expiring") throw new Error(`not a valid ubi-runner VM name: ${name}`);
return name;
}
@@ -143,8 +151,8 @@ export function ownerNotices(plan: PlanRow[], o: { now: number; apply: boolean }
lines.push(` - ${row.location}/${row.name} expired ${span(o.now - p.expiresAt)} ago (created ${span(o.now - p.createdAt)} ago)${row.result === "failed" ? ": destroy FAILED, still running" : ""}`);
}
lines.push(o.apply
- ? ` Destroyed by the operator reaper at ${new Date(o.now * 1000).toISOString()}. Nothing to do unless a run still needed one: start long runs with ubi-runner.sh up/run --ttl-hours H, or without --ttl-hours for a VM that never expires.`
- : ` Dry run: nothing was destroyed. The operator reaper destroys these once it runs with --apply. Destroy them now with UBI_OWNER=${owner} scripts/ubicloud/ubi-runner.sh down <name> -l <location>. An expiry can't be extended; start long runs with ubi-runner.sh up/run --ttl-hours H, or without --ttl-hours for a VM that never expires.`);
+ ? ` Destroyed by the operator reaper at ${new Date(o.now * 1000).toISOString()}. Nothing to do unless a run still needed one: start long runs with ubi-runner.sh up/run --ttl-hours H (up to 999).`
+ : ` Dry run: nothing was destroyed. The operator reaper destroys these once it runs with --apply. Destroy them now with UBI_OWNER=${owner} scripts/ubicloud/ubi-runner.sh down <name> -l <location>. An expiry can't be extended; start long runs with ubi-runner.sh up/run --ttl-hours H (up to 999).`);
}
return lines.join("\n");
}
diff --git a/scripts/ubicloud/ubi-runner.sh b/scripts/ubicloud/ubi-runner.sh
index 11999bdfab..b77ad4f443 100755
--- a/scripts/ubicloud/ubi-runner.sh
+++ b/scripts/ubicloud/ubi-runner.sh
@@ -20,14 +20,15 @@
# letter) or a random per-machine id kept in $STATE_ROOT/owner-id. Ubicloud names
# allow 63 characters of [a-z0-9-], so a full name stays under 40.
#
-# Expiry: `up` and `run` with --ttl-hours H name the VM
-# ubirun-<owner>-<epoch>-x<expiry epoch>-<suffix>, expiring H hours after
-# creation (ci:ubicloud names its own VMs this way, 2 hours by default). The
-# operator reaper (scripts/ubicloud/reap-expired.ts) destroys VMs in that
-# format once the expiry has passed, whoever owns them. Without --ttl-hours a
-# VM never expires and is never reaped; use that, or a long TTL, for dev,
-# benchmark and eval VMs. Every parser here reads both formats, and the
-# expiring form stays under 52 characters.
+# Expiry: every name `up` and `run` generate ends in a TTL,
+# ubirun-<owner>-<epoch>-<suffix>-t<H>, expiring H hours after creation: H is
+# --ttl-hours (1 to 999), or 999 without it (about 41 days, for long dev,
+# benchmark and eval VMs). That is gstack's runner grammar, so the operator
+# reaper (scripts/ubicloud/reap-expired.ts) and gstack's reap both destroy a VM
+# once its TTL has ended, whoever owns it; ci:ubicloud names its gate VMs the
+# same way (2 hours by default). Every parser here still reads the older
+# ubirun-<owner>-<epoch>-x<expiry epoch>-<suffix> and TTL-less names, and a
+# generated name stays under 50 characters.
#
# Teardown: `up` records each VM's state (location, create status) before it
# sends the create request, and `down` destroys and polls until the VM is
@@ -237,18 +238,16 @@ write_state() {
"$1" "$2" "$3" "$4" "$5" "$6" "$$" >"$(state_dir "$1")/env"
}
-# new_name [TTL_HOURS]: a fresh name for this owner, carrying an expiry
-# TTL_HOURS after now when given.
+# new_name TTL_HOURS: a fresh name for this owner whose TTL ends TTL_HOURS after now.
new_name() {
- local now suffix
- now=$(date +%s)
+ local suffix
suffix=$(head -c4 /dev/urandom | od -An -tx1 | tr -d ' \n')
- if [ -n "${1:-}" ]; then echo "$PREFIX-$OWNER-$now-x$(( now + $1 * 3600 ))-$suffix"; else echo "$PREFIX-$OWNER-$now-$suffix"; fi
+ echo "$PREFIX-$OWNER-$(date +%s)-$suffix-t$1"
}
check_ttl() {
- [[ "$1" =~ ^[1-9][0-9]{0,3}$ ]] && [ "$1" -le 8760 ] \
- || die "--ttl-hours must be a whole number of hours from 1 to 8760 (omit it for a VM that never expires)"
+ [[ "$1" =~ ^[1-9][0-9]{0,2}$ ]] \
+ || die "--ttl-hours must be a whole number of hours from 1 to 999 (omit it for the longest TTL, 999 hours)"
}
valid_name() { [[ "$1" =~ ^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$ ]]; }
@@ -269,7 +268,7 @@ cmd_up() {
esac
done
[ -z "$name" ] || [ -z "$ttl" ] || die "up: --ttl-hours writes the expiry into the generated name, so it cannot be combined with -n"
- [ -n "$name" ] || name=$(new_name "$ttl")
+ [ -n "$name" ] || name=$(new_name "${ttl:-999}")
valid_name "$name" || die "invalid VM name '$name' (Ubicloud allows 1-63 of a-z, 0-9 and '-', starting and ending with a letter or digit)"
if [ "$GC_HOURS" -gt 0 ]; then
cmd_gc "$GC_HOURS" || log "stale-VM cleanup failed; continuing"
@@ -490,7 +489,7 @@ cmd_run() {
case ${up_args[i]} in -n|--name) name=${up_args[i+1]} ;; esac
done
[ -z "$name" ] || [ -z "$ttl" ] || die "run: --ttl-hours writes the expiry into the generated name, so it cannot be combined with -n"
- [ -n "$name" ] || { name=$(new_name "$ttl"); up_args+=(-n "$name"); }
+ [ -n "$name" ] || { name=$(new_name "${ttl:-999}"); up_args+=(-n "$name"); }
RUN_VM=$name
# Armed before the create request: an interrupted `up` still destroys its VM.
# A second signal must not cut teardown short, so the EXIT handler ignores them.
@@ -537,8 +536,8 @@ usage: ubi-runner.sh <command> [args]
up + sync + setup + command + pull + destroy; exits with COMMAND's status
up [-s SIZE] [-l LOCATION] [-n NAME | --ttl-hours H] [-S STORAGE_GIB] [-b IMAGE]
create a VM and wait for SSH; prints its name. --ttl-hours H
- names it to expire H hours from now (the operator reaper
- destroys it after that); without it the VM never expires
+ gives it a TTL of H hours (1-999; default 999), after which
+ the operator reaper and gstack's reap destroy it
ssh NAME [COMMAND] shell or login-shell command on the VM (user ubi, passwordless sudo)
sync NAME [SRC] [DEST] stream a checkout (tracked + untracked-unignored + .git)
pack [SRC] write that checkout tarball to stdout (with a slim .git: HEAD + origin/master)
@@ -552,8 +551,7 @@ usage: ubi-runner.sh <command> [args]
gc HOURS destroy this owner's VMs older than HOURS (never other owners')
cli ARGS... raw Ubicloud CLI passthrough (e.g. cli vm list)
-VMs are named $PREFIX-<owner>-<epoch>-<suffix>, or $PREFIX-<owner>-<epoch>-x<expiry>-<suffix>
-with --ttl-hours; set UBI_OWNER (e.g. your thread code) to tag them, otherwise a
+VMs are named $PREFIX-<owner>-<epoch>-<suffix>-t<ttl hours>; set UBI_OWNER (e.g. your thread code) to tag them, otherwise a
per-machine id is used.
defaults: size=$DEFAULT_SIZE location=$DEFAULT_LOCATION (env UBI_SIZE, UBI_LOCATION)
env: UBI_GC_HOURS (unset/0: no sweep on up), UBI_CREATE_GRACE (${CREATE_GRACE}s),
diff --git a/test/scripts/ci-ubicloud-teardown.slow.test.ts b/test/scripts/ci-ubicloud-teardown.slow.test.ts
index 39040f0e58..3009b1f5d1 100644
--- a/test/scripts/ci-ubicloud-teardown.slow.test.ts
+++ b/test/scripts/ci-ubicloud-teardown.slow.test.ts
@@ -74,9 +74,7 @@ describe("ci:ubicloud teardown", () => {
const requested = readFileSync(join(runDir, "vms.txt"), "utf8").trim().split("\n").map((l) => l.split(" ")[0]!);
expect(requested).toHaveLength(3);
for (const name of requested) {
- const tagged = /^ubirun-probe-(\d{10})-x(\d{10})-ci0[123][0-9a-f]{4}$/.exec(name);
- expect(tagged).not.toBeNull();
- expect(Number(tagged![2]) - Number(tagged![1])).toBe(2 * 3600);
+ expect(name).toMatch(/^ubirun-probe-\d{10}-ci0[123][0-9a-f]{4}-t2$/);
expect(api.events).toContain(`created ${name}`);
expect(api.events).toContain(`removed ${name}`);
}
diff --git a/test/scripts/ci-ubicloud-vm-names.test.ts b/test/scripts/ci-ubicloud-vm-names.test.ts
index 1f3592ca1a..f762f2cbcc 100644
--- a/test/scripts/ci-ubicloud-vm-names.test.ts
+++ b/test/scripts/ci-ubicloud-vm-names.test.ts
@@ -1,12 +1,13 @@
-// ci-ubicloud-vm-names.test.ts — VM names that carry an expiry
-// (ubirun-<owner>-<epoch>-x<expiry>-<suffix>) next to the older names, for
-// scripts/ubicloud/ubi-runner.sh and scripts/ci-ubicloud.ts.
+// ci-ubicloud-vm-names.test.ts — VM names in gstack's runner grammar
+// (ubirun-<owner>-<epoch>-<suffix>-t<H>) next to the older -x<expiry> and
+// TTL-less names, for scripts/ubicloud/ubi-runner.sh and scripts/ci-ubicloud.ts.
//
-// Protects: `up`/`run --ttl-hours H` name their VM with an expiry H hours
-// after creation (no --ttl-hours: no expiry, never reaped), the flag is
-// validated and cannot be combined with -n, and every existing parser
-// (list --mine, usage, gc, down) reads old and new names alike: gc ages a VM
-// by its creation epoch, never its expiry.
+// Protects: `up`/`run --ttl-hours H` name their VM with a -t<H> TTL, and
+// without --ttl-hours with -t999, so no generated name is TTL-less (gstack's
+// reap destroys those at four hours); the flag is validated (1 to 999) and
+// cannot be combined with -n; every parser (list --mine, usage, gc, down)
+// reads all three formats alike: gc ages a VM by its creation epoch, never its
+// expiry.
// Fails when: a new-format name is not owner-tagged for list --mine or usage,
// gc sweeps by the expiry or another owner's VM, or the flag is ignored.
// Network: none (in-process mock Ubicloud API).
@@ -60,36 +61,36 @@ async function run(args: string[], extra: Record<string, string> = {}) {
describe("--ttl-hours", () => {
for (const verb of ["up", "run"] as const) {
- it(`${verb} --ttl-hours 3 names the VM with an expiry three hours after creation`, async () => {
+ it(`${verb} --ttl-hours 3 names the VM with a three-hour TTL in gstack's grammar`, async () => {
const api = serve();
const proc = spawnRunner(verb === "up" ? ["up", "--ttl-hours", "3"] : ["run", "--ttl-hours", "3", "--", "true"], { UBI_OWNER: "gbra135" });
const name = (await waitForEvent(api, /^create-start /)).split(" ")[1]!;
proc.kill("SIGTERM");
await proc.exited;
- const m = /^ubirun-gbra135-(\d{10})-x(\d{10})-[0-9a-f]{8}$/.exec(name);
+ const m = /^ubirun-gbra135-(\d{10})-[0-9a-f]{8}-t3$/.exec(name);
expect(m).not.toBeNull();
- expect(Number(m![2]) - Number(m![1])).toBe(3 * 3600);
expect(Math.abs(Number(m![1]) - NOW)).toBeLessThan(120);
expect(name.length).toBeLessThanOrEqual(63);
expect(api.vms.size).toBe(0);
});
}
- it("without --ttl-hours the name carries no expiry", async () => {
+ it("without --ttl-hours the name carries the longest TTL, -t999", async () => {
const api = serve();
const proc = spawnRunner(["up"], { UBI_OWNER: "gbra135" });
const name = (await waitForEvent(api, /^create-start /)).split(" ")[1]!;
proc.kill("SIGTERM");
await proc.exited;
- expect(name).toMatch(/^ubirun-gbra135-\d{10}-[0-9a-f]{8}$/);
+ expect(name).toMatch(/^ubirun-gbra135-\d{10}-[0-9a-f]{8}-t999$/);
+ expect(name.length).toBeLessThanOrEqual(63);
});
it("refuses a bad value and the combination with -n before any create", async () => {
const api = serve();
- for (const bad of ["0", "1.5", "abc", "9000"]) {
+ for (const bad of ["0", "1.5", "abc", "1000", "024"]) {
const r = await run(["up", "--ttl-hours", bad], { UBI_OWNER: "t1" });
expect(r.code).toBe(1);
- expect(r.stderr).toContain("--ttl-hours must be a whole number of hours from 1 to 8760");
+ expect(r.stderr).toContain("--ttl-hours must be a whole number of hours from 1 to 999");
}
const both = await run(["up", "-n", "ubirun-t1-1790000000-aaaaaaaa", "--ttl-hours", "2"], { UBI_OWNER: "t1" });
expect(both.code).toBe(1);
@@ -109,25 +110,27 @@ describe("parsers read old and new names", () => {
{ name: `ubirun-other-${OLD}-x${OLD + 3600}-ci01ffff`, size: "standard-16" },
{ name: `ubirun-${OLD}-dddddddd`, size: "standard-2" },
{ name: "prod-db", size: "standard-2" },
+ { name: `ubirun-t1-${OLD}-eeeeeeee-t3`, size: "standard-2" },
+ { name: `ubirun-other-${NOW}-ffffffff-t999`, size: "standard-4" },
];
- it("list --mine and usage tag new-format names with their owner", async () => {
+ it("list --mine and usage tag -t<H> and -x<expiry> names with their owner", async () => {
serve({ seed });
const mine = await run(["list", "--mine"], { UBI_OWNER: "t1" });
- expect(mine.stdout.trim().split("\n").map((l) => l.split(/\s+/)[1])).toEqual(seed.slice(0, 3).map((s) => s.name));
+ expect(mine.stdout.trim().split("\n").map((l) => l.split(/\s+/)[1])).toEqual([0, 1, 2, 6].map((i) => seed[i]!.name));
const usage = (await run(["usage"], { UBI_OWNER: "t1" })).stdout;
- expect(usage).toMatch(/^t1\s+3\s+28\s+\(you\)$/m);
- expect(usage).toMatch(/^other\s+1\s+16$/m);
+ expect(usage).toMatch(/^t1\s+4\s+30\s+\(you\)$/m);
+ expect(usage).toMatch(/^other\s+2\s+20$/m);
expect(usage).toMatch(/^\(untagged\)\s+1\s+2$/m);
expect(usage).toMatch(/^\(other\)\s+1\s+2$/m);
});
- it("gc ages by creation epoch: it sweeps the caller's old VMs of both formats, not a young VM whose expiry passed", async () => {
+ it("gc ages by creation epoch: it sweeps the caller's old VMs of every format, not a young VM whose expiry passed", async () => {
const api = serve({ seed });
const gc = await run(["gc", "1"], { UBI_OWNER: "t1" });
expect(gc.code).toBe(0);
- expect(api.events.filter((e) => e.startsWith("destroy ")).sort()).toEqual([`destroy ${seed[0]!.name}`, `destroy ${seed[2]!.name}`].sort());
- expect([...api.vms.keys()].sort()).toEqual([seed[1]!.name, seed[3]!.name, seed[4]!.name, seed[5]!.name].sort());
+ expect(api.events.filter((e) => e.startsWith("destroy ")).sort()).toEqual([0, 2, 6].map((i) => `destroy ${seed[i]!.name}`).sort());
+ expect([...api.vms.keys()].sort()).toEqual([1, 3, 4, 5, 7].map((i) => seed[i]!.name).sort());
});
it("down destroys a new-format name", async () => {
diff --git a/test/scripts/ubi-runner.test.ts b/test/scripts/ubi-runner.test.ts
index 1980d0501c..0cc42fa3ff 100644
--- a/test/scripts/ubi-runner.test.ts
+++ b/test/scripts/ubi-runner.test.ts
@@ -75,7 +75,7 @@ describe("teardown waits for in-flight creates", () => {
const proc = spawnRunner(["up"], { UBI_OWNER: "t1" });
const started = await waitForEvent(api, /^create-start /);
const name = started.split(" ")[1]!;
- expect(name).toMatch(/^ubirun-t1-\d{10}-[0-9a-f]{8}$/);
+ expect(name).toMatch(/^ubirun-t1-\d{10}-[0-9a-f]{8}-t999$/);
proc.kill(signal);
expect(await proc.exited).toBe(130);
expect(api.events).toEqual([`create-start ${name}`, `created ${name}`, `destroy ${name}`, `removed ${name}`]);
diff --git a/test/scripts/ubicloud-reap-expired.test.ts b/test/scripts/ubicloud-reap-expired.test.ts
index c2ad86e88e..b88a9068ae 100644
--- a/test/scripts/ubicloud-reap-expired.test.ts
+++ b/test/scripts/ubicloud-reap-expired.test.ts
@@ -1,9 +1,10 @@
// ubicloud-reap-expired.test.ts — scripts/ubicloud/reap-expired.ts, the
// operator-side leak guard for ci:ubicloud VMs.
//
-// Protects: only VMs in the expiring name format
-// (ubirun-<owner>-<epoch>-x<expiry>-<suffix>) whose expiry plus the grace has
-// passed are ever selected; legacy untagged names, owner-tagged names without
+// Protects: only VMs whose name carries a TTL, in gstack's grammar
+// (ubirun-<owner>-<epoch>-<suffix>-t<H>, from any owner or tool) or the older
+// ubirun-<owner>-<epoch>-x<expiry>-<suffix>, and whose expiry plus the grace
+// has passed are ever selected; legacy untagged names, owner-tagged names without
// an expiry and names ubi-runner did not make are never selected, whoever
// owns them. Dry run is the default and destroys nothing; --apply destroys
// through ubi-runner.sh down; more expired VMs than --max refuse the whole run.
@@ -42,12 +43,24 @@ describe("parseVmName", () => {
expect(parseVmName(`${expired}-extra!`)).toEqual({ kind: "foreign" });
});
- it("the gate's name helper writes names of at most 63 characters that read back with their expiry", () => {
+ it("reads gstack's -t<H> grammar as expiring H hours after creation, for any owner or suffix", () => {
+ expect(parseVmName(`ubirun-gbra135-${NOW}-ci01a1b2-t2`)).toEqual({ kind: "expiring", owner: "gbra135", createdAt: NOW, expiresAt: NOW + 2 * H });
+ expect(parseVmName(`ubirun-trut4-${NOW}-e54c3f57-t4`)).toEqual({ kind: "expiring", owner: "trut4", createdAt: NOW, expiresAt: NOW + 4 * H });
+ expect(parseVmName(`ubirun-gsta30-${NOW}-a-b-c-t999`)).toEqual({ kind: "expiring", owner: "gsta30", createdAt: NOW, expiresAt: NOW + 999 * H });
+ expect(parseVmName(`ubirun-gbra1-${NOW}-t5`)).toEqual({ kind: "no-expiry", owner: "gbra1", createdAt: NOW });
+ expect(parseVmName(`ubirun-gbra1-${NOW}-aaaa-t1000`)).toEqual({ kind: "foreign" });
+ expect(parseVmName(`ubirun-${NOW}-aaaa-t3`)).toEqual({ kind: "foreign" });
+ });
+
+ it("the gate's name helper writes -t<H> names of at most 63 characters that read back with their expiry", () => {
const name = expiringVmName({ owner: "abcdefghijkl", createdAt: NOW, ttlHours: 2, suffix: "ci10ffff" });
- expect(name).toBe(`ubirun-abcdefghijkl-${NOW}-x${NOW + 2 * H}-ci10ffff`);
+ expect(name).toBe(`ubirun-abcdefghijkl-${NOW}-ci10ffff-t2`);
expect(name.length).toBeLessThanOrEqual(63);
expect(parseVmName(name)).toEqual({ kind: "expiring", owner: "abcdefghijkl", createdAt: NOW, expiresAt: NOW + 2 * H });
- expect(expiringVmName({ owner: "t1", createdAt: NOW, ttlHours: 0, suffix: "ci01abcd" })).toBe(`ubirun-t1-${NOW}-ci01abcd`);
+ expect(expiringVmName({ owner: "abcdefghijkl", createdAt: NOW, ttlHours: 999, suffix: "a".repeat(24) }).length).toBeLessThanOrEqual(63);
+ expect(() => expiringVmName({ owner: "t1", createdAt: NOW, ttlHours: 0, suffix: "ci01abcd" })).toThrow();
+ expect(() => expiringVmName({ owner: "t1", createdAt: NOW, ttlHours: 1000, suffix: "ci01abcd" })).toThrow();
+ expect(() => expiringVmName({ owner: "t1", createdAt: NOW, ttlHours: 2, suffix: "ci-01" })).toThrow();
expect(() => expiringVmName({ owner: "t1", createdAt: NOW, ttlHours: 1.5, suffix: "ci01abcd" })).toThrow();
expect(() => expiringVmName({ owner: "T-1", createdAt: NOW, ttlHours: 1, suffix: "ci01abcd" })).toThrow();
});
@@ -91,6 +104,47 @@ describe("planReap", () => {
});
});
+describe("planReap over both grammars", () => {
+ const ttlExpired = `ubirun-trut4-${NOW - 5 * H}-e54c3f57-t4`;
+ const ttlGate = `ubirun-gbra135-${NOW - 3 * H}-ci01a1b2-t2`;
+ const ttlLive = `ubirun-gsta30-${NOW - 6 * H}-154fa95a-t14`;
+ const ttlLong = `ubirun-gbra240-${NOW - 50 * H}-0654ca-t999`;
+ const ttlZero = `ubirun-gbra1-${NOW - H}-aaaaaaaa-t0`;
+ const rows = [ttlExpired, ttlGate, ttlLive, ttlLong, ttlZero, expired, live, noExpiry].map((name) => ({ location: LOC, name }));
+
+ it("destroys expired -t<H> names of every owner and expired -x<expiry> names, and keeps live and TTL-less ones", () => {
+ const action = Object.fromEntries(planReap(rows, { now: NOW, graceSeconds: 15 * 60 }).map((row) => [row.name, row.action]));
+ expect(action).toEqual({
+ [ttlExpired]: "destroy",
+ [ttlGate]: "destroy",
+ [ttlLive]: "keep",
+ [ttlLong]: "keep",
+ [ttlZero]: "skip",
+ [expired]: "destroy",
+ [live]: "keep",
+ [noExpiry]: "skip",
+ });
+ });
+
+ it("--apply destroys the expired -t<H> and -x<expiry> VMs through ubi-runner.sh down", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "reap-expired-ttl-"));
+ const mock = startMockUbicloud({ seed: rows });
+ try {
+ const proc = Bun.spawn(["bun", SCRIPT, "--apply", "--now", String(NOW)], {
+ env: { PATH: process.env.PATH ?? "/usr/bin:/bin", HOME: dir, UBICLOUD_API_TOKEN: "test-token", UBICLOUD_API_URL: mock.url, UBI_RUNNER_STATE: join(dir, "state"), UBI_POLL_SECONDS: "0.2" },
+ stdout: "pipe",
+ stderr: "pipe",
+ });
+ expect(await proc.exited).toBe(0);
+ expect(mock.events.filter((e) => e.startsWith("destroy ")).sort()).toEqual([ttlExpired, ttlGate, expired].map((n) => `destroy ${n}`).sort());
+ expect([...mock.vms.keys()].sort()).toEqual([ttlLive, ttlLong, ttlZero, live, noExpiry].sort());
+ } finally {
+ mock.stop();
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+});
+
describe("reap-expired CLI against the mock Ubicloud API", () => {
let mock: MockUbicloud | null = null;
let dir = "";