Files
loki/scripts/test/deploy-runner-decoupling.ts
CatoandClaude Fable 5.1 95c40a9cd8 refactor: rename the product from FleetCrown to Loki (#695)
The product, its assistant, the repo, the host and every unit on the box now
share one name. 638 files, ~3,000 mentions: UI copy, config, env keys
(FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs,
articles, the deploy workflow other repos reuse, and nine file names.

- Three article slugs carried the old name and had been shared; permanent
  redirects keep those links alive (next.config.ts).
- test-no-retired-name.sh now also forbids the old product name across the
  whole repo, so the rename cannot creep back through templates and examples.
- ASSISTANT_STACK collapses the product and the assistant into one entry,
  because they are now the same name.

Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki`
database and role, loki.orangecat.ch (old host 308s to it; /api, /widget,
/embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases.
The Resend sending domain stays fleetcrown.orangecat.ch until the new domain
is verified in DNS.


Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 16:13:10 -07:00

81 lines
3.3 KiB
TypeScript

/**
* A deploy must end when the APP is live — not when an unrelated system is.
*
* The web app and the box-runner have opposite needs. The app wants to be live
* immediately; the runner wants to not kill an agent mid-task. Both used to
* share one job's wall-clock, and the runner won: measured on 2026-08-15, the
* ship step spent 480 of its 570 seconds watching a single in-flight agent,
* then restarted anyway. The app had been live and verified for eight of those
* minutes. It was the most expensive thing in the whole pipeline and it bought
* nothing — the cost of patience with the semantics of impatience.
*
* The fix is not a shorter timeout, which would only kill agents sooner. It is
* moving the wait to the box, where waiting is free: the deploy schedules a
* detached drain-then-restart and returns. This suite guards that the wait
* cannot migrate back into the deploy, because it would look like a reasonable
* thing to do again.
*/
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
const root = join(__dirname, "..", "..");
const deploy = readFileSync(join(root, "scripts/deploy-hetzner.sh"), "utf8");
const drainPath = join(root, "scripts/hetzner/drain-and-restart-runner.sh");
let passed = 0;
function check(name: string, fn: () => void) {
fn();
passed++;
console.log(` ✓ ${name}`);
}
function assert(cond: boolean, msg: string) {
if (!cond) throw new Error(msg);
}
check("the deploy does not wait for agents to drain", () => {
// The signature of the old loop: sleeping in a loop while counting agent
// processes. Any reintroduction reads like this, whatever it is named.
const waits = /waiting to drain|drain_box_runner_agents|drain timed out/.test(deploy);
assert(
!waits,
"deploy-hetzner.sh must not block on draining agents — schedule it on the box instead",
);
});
check("the runner restart is scheduled detached, not run inline", () => {
assert(
/systemd-run/.test(deploy),
"the runner restart must be detached via systemd-run so the deploy does not wait for it",
);
});
check("the deferred restart script exists and is shipped before it is invoked", () => {
assert(existsSync(drainPath), "scripts/hetzner/drain-and-restart-runner.sh must exist");
const syncIdx = deploy.indexOf("drain-and-restart-runner.sh");
const runIdx = deploy.indexOf("systemd-run");
assert(syncIdx !== -1, "the drain script must be rsynced to the box");
assert(
syncIdx < runIdx,
"the drain script must be synced BEFORE systemd-run invokes it, or the first deploy invokes a missing file",
);
});
check("the deferred restart cannot be killed by the restart it performs", () => {
const drain = readFileSync(drainPath, "utf8");
// systemd-run puts it in its OWN unit; restarting loki-box-runner kills
// that unit's cgroup, which must not contain this script.
assert(
/--unit=/.test(deploy),
"the drain must run in its own systemd unit, not inside the box-runner's cgroup",
);
assert(/systemctl restart/.test(drain), "the drain script is what actually restarts the runner");
});
check("the drain still has a cap, so a wedged agent cannot freeze runner code forever", () => {
const drain = readFileSync(drainPath, "utf8");
assert(/MAX=/.test(drain) && /cap/.test(drain), "the box-side drain must remain bounded");
});
console.log(`\n${passed} passed`);