Files
loki/scripts/test/runner-update-hold.ts
CatoandClaude adfbdcfe07 fix(session): the builder updates, the sheet changes things, one box, a preview is the site (#1305)
The owner used Loki from a phone (2026-10-18) and could not tell whether
anything worked. Four separate faults, each passing every check:

The cloud builder ran code days behind the app. Its restart waits for
every agent to be idle, and autopilot refilled the queue the instant one
finished: ten consecutive deploys (23:38 → 09:12) found "2 agent(s)
working — deferring restart". Hence "Model: not known yet" of an answer
the screen was showing. Now, while the cloud runner's heartbeat version is
behind the deploy's, the commands route hands it no work-starting
commands (dispatch, launch_agent, auto_continue, browser_task) — a
person's own words into a session still go through — so the idle moment
comes, the restart lands, the queue resumes on the new code. Server-side
on purpose: a runner-side rule would have waited for the very restart it
was meant to allow. Control's builder line says "a newer version waits
for its agents to finish" meanwhile.

An agent renamed a preview site, committed, and reported "the work lives
only on this machine — tell Loki where this preview's remote should
live". The box contract says push or fail loudly; a preview folder is
served from disk and has no remote by design, so the change had been live
since the save and the owner read a failure and a chore. Every dispatch
to a preview folder now carries "Where this goes" (lib/previews/
delivery-note), and the contract has the same section.

The session sheet's Change and Set typed /model and /effort into the
terminal and closed; Claude Code drew its picker behind the conversation
and nothing on screen moved. Each row now lists its choices; a tap sends
the command with the choice named (/model sonnet, /effort high), the
sheet stays open and says what is changing, and settles when the log
names it. The sheet is built like the Settings sheet.

The session box had a 26px library button beside 44px round ones, a 36px
chip and a 34px Keys pill, the microphone second from the left in one
view and beside Send in the other, and "claude" on the tab beside
"Message Claude…". One row, one size, one order in both views; the
agent's name everywhere (terminal-strip-tabs badgeNames).

Widget: the owner's change list reads what needs them first (the line
counted nine, the list showed none); "9 needs you" → "9 need you"; a
failed call is named ("my call to Loki to save your note failed… Your
words are still here — press it again") instead of "one of my calls to
Loki failed — nothing for you to do".

Tests: runner-update-hold, preview-delivery-note, owner-changes-order,
session-sheet-browser (new); builder-presence, widget-changes,
widget-self-report, inject-context-boundaries extended.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-18 13:37:05 +02:00

41 lines
2.4 KiB
TypeScript

/**
* While the cloud builder runs code older than this deploy, the commands
* route hands it no new work — or the restart it waits for never comes
* (lib/runner-update-hold).
*
* Run: npx tsx scripts/test/runner-update-hold.ts
*/
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { FLEET_RUNNER_COMMAND_TYPES } from "@/lib/pending-command-contract";
import { claimableTypes, HELD_WHILE_UPDATING, holdsNewWork } from "@/lib/runner-update-hold";
// What starts work waits; what a person is waiting on this second does not.
for (const t of ["dispatch", "launch_agent", "auto_continue", "browser_task"])
assert.equal(holdsNewWork(t), true, `${t} starts work and waits for the restart`);
for (const t of ["inject", "close_tab", "peek_tab", "peek_start", "peek_stop", "switch_agent"])
assert.equal(holdsNewWork(t), false, `${t} is a person at the screen and is never held`);
assert.equal(holdsNewWork("something_new"), false, "an unknown type is not held by accident");
for (const t of HELD_WHILE_UPDATING)
assert.ok((FLEET_RUNNER_COMMAND_TYPES as readonly string[]).includes(t), `${t} is a command`);
// The claim list: what the runner asked for, minus the work-starters while
// it is behind; everything it asked for once it is current.
const asked = ["inject", "dispatch", "peek_start", "auto_continue"];
assert.deepEqual(claimableTypes(asked, false), asked, "current: exactly what it asked for");
assert.deepEqual(claimableTypes(asked, true), ["inject", "peek_start"], "behind: no work-starters");
assert.deepEqual(claimableTypes(undefined, false), FLEET_RUNNER_COMMAND_TYPES, "no list: all");
assert.ok(!claimableTypes(undefined, true).includes("dispatch"), "no list, behind: still held");
assert.ok(claimableTypes([], true).includes("inject"), "an empty list reads as all");
// The route applies it to the CLOUD channel from the runner's own heartbeat
// version, so a runner that predates this rule is held by it too.
const route = readFileSync("src/app/api/control/commands/route.ts", "utf8");
assert.match(route, /runnerChannel === "cloud"/, "the hold is the cloud builder's");
assert.match(route, /builderBehind\(/, "behind = the heartbeat version against the deploy's");
assert.match(route, /claimableTypes\(requested, holding\)/, "the claim asks for the held list");
console.log(
"✓ runner-update-hold: a builder behind the deploy starts no new work until it restarts",
);