mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-06 00:38:29 +01:00
* feat(ops): the cloud builder's liveness is public, deploys print its state, the queue says "offline" The shared cloud builder was offline all night on 2026-10-11 → 12 and nothing outside a signed-in page said so: /api/health reported the web app green, the fleet sweep probes only HTTP codes, and the box journal is the one place the restart's outcome is written. The owner found out by trying to work from a second computer. - GET /api/health/builder: 200 while the owner's cloud builder is connected and heartbeating, 503 otherwise, with the last heartbeat and version. Public on purpose (one boolean, one timestamp, about a service the operator runs); registered in scripts/test/api-route-auth.ts. - install-watchdog.sh: the box watchdog now probes it, so a state flip alerts on Telegram like a dead site does. - deploy-hetzner.sh: before scheduling the runner restart, print `systemctl is-active loki-box-runner`, the last runner journal lines and the last drain lines into the CI log — the first place a person without an ssh session can read why the builder is down. Warn-only. - feedback run-step: a job on the cloud queue while the cloud builder is offline reads "Cloud builder offline — nothing starts until it reconnects", not "Watch shows why" (nothing showed why). Tests: feedback-run-step (+2), api-route-auth, watchdog-check. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Xssd1hFZCUSxqjACjoVBB * fix(terminal): a private cloud builder reads "private", not "offline" Walking Loki as a brand-new account (2026-10-12): the Terminal's chip said "Cloud builder offline" beside an empty state that said "Cloud builder is private for this account". Presence is per account and a new account has none, so the chip mistook "not yours" for "down". The chip derivation moves into terminalHonesty() (one helper, the component stays under its 510-line ratchet) and names the gate first. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Xssd1hFZCUSxqjACjoVBB --------- Co-authored-by: Claude <noreply@anthropic.com>
274 lines
8.9 KiB
TypeScript
274 lines
8.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { summarizeRunStep, furthestRunEventKind } from "../../src/lib/feedback/run-step";
|
|
import {
|
|
deriveFeedbackWork,
|
|
FEEDBACK_WORK_PHASE,
|
|
WAITING_ON,
|
|
} from "../../src/lib/feedback/work-phase";
|
|
import { FEEDBACK_STATUS } from "../../src/lib/constants/statuses";
|
|
import { ORCH_STATE } from "../../src/lib/orchestration/contract";
|
|
|
|
const waitingCloud = summarizeRunStep({
|
|
latestKind: "dispatched",
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
pendingUnclaimed: true,
|
|
channel: "cloud",
|
|
localOnline: false,
|
|
cloudOnline: false,
|
|
});
|
|
assert.equal(waitingCloud.kind, "waiting_builder");
|
|
assert.match(waitingCloud.summary, /cloud builder/i);
|
|
// 2026-10-12: the cloud builder was offline all night and this read "Command
|
|
// is in the cloud queue. If this stays put, Watch shows why" — nothing showed
|
|
// why. Offline is a fact the line has to state.
|
|
assert.match(waitingCloud.summary, /offline/i);
|
|
assert.match(waitingCloud.detail ?? "", /nothing starts until it reconnects/i);
|
|
assert.doesNotMatch(waitingCloud.detail ?? "", /Watch shows why/);
|
|
|
|
const waitingCloudUp = summarizeRunStep({
|
|
latestKind: "dispatched",
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
pendingUnclaimed: true,
|
|
channel: "cloud",
|
|
localOnline: false,
|
|
cloudOnline: true,
|
|
});
|
|
assert.equal(waitingCloudUp.kind, "waiting_builder");
|
|
assert.match(waitingCloudUp.summary, /waiting for cloud builder to claim/i);
|
|
|
|
const waitingLocal = summarizeRunStep({
|
|
latestKind: "dispatched",
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
pendingUnclaimed: true,
|
|
channel: "local",
|
|
localOnline: true,
|
|
});
|
|
assert.equal(waitingLocal.kind, "waiting_builder");
|
|
assert.match(waitingLocal.summary, /This computer/i);
|
|
assert.doesNotMatch(waitingLocal.summary, /cloud/i);
|
|
|
|
const cloudQueuedLocalOnline = summarizeRunStep({
|
|
latestKind: "dispatched",
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
pendingUnclaimed: true,
|
|
channel: "cloud",
|
|
localOnline: true,
|
|
cloudOnline: false,
|
|
});
|
|
assert.equal(cloudQueuedLocalOnline.kind, "waiting_builder");
|
|
assert.match(cloudQueuedLocalOnline.summary, /Switch to This computer/i);
|
|
assert.match(cloudQueuedLocalOnline.detail ?? "", /Runs on/i);
|
|
|
|
const localOffline = summarizeRunStep({
|
|
latestKind: "dispatched",
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
pendingUnclaimed: true,
|
|
channel: "local",
|
|
localOnline: false,
|
|
});
|
|
assert.match(localOffline.summary, /Open Fleet Runner/i);
|
|
|
|
const hosted = summarizeRunStep({
|
|
latestKind: "dispatched",
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
hosted: true,
|
|
pendingUnclaimed: true,
|
|
});
|
|
assert.equal(hosted.kind, "hosted_queued");
|
|
|
|
assert.equal(furthestRunEventKind(["dispatched", "claimed", "launched"]), "launched");
|
|
|
|
const offline = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, {
|
|
id: "r1",
|
|
state: ORCH_STATE.WAITING,
|
|
outcome: null,
|
|
startedAt: new Date(),
|
|
finishedAt: null,
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
error: null,
|
|
builderOffline: true,
|
|
builderChannel: "cloud",
|
|
});
|
|
assert.equal(offline.phase, FEEDBACK_WORK_PHASE.STUCK);
|
|
assert.equal(offline.waitingOn, WAITING_ON.YOU);
|
|
assert.equal(offline.label, "Needs you");
|
|
assert.ok(offline.diagnostic?.toLowerCase().includes("offline"));
|
|
assert.equal(offline.watchable, true);
|
|
|
|
const localOfflineStuck = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, {
|
|
id: "r1b",
|
|
state: ORCH_STATE.WAITING,
|
|
outcome: null,
|
|
startedAt: new Date(),
|
|
finishedAt: null,
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
error: null,
|
|
builderOffline: true,
|
|
builderChannel: "local",
|
|
localOnline: false,
|
|
});
|
|
assert.equal(localOfflineStuck.phase, FEEDBACK_WORK_PHASE.STUCK);
|
|
assert.match(localOfflineStuck.detail ?? "", /Fleet Runner|This computer/i);
|
|
|
|
const youngOnline = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, {
|
|
id: "r2",
|
|
state: ORCH_STATE.WAITING,
|
|
outcome: null,
|
|
startedAt: new Date(),
|
|
finishedAt: null,
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
error: null,
|
|
builderOffline: false,
|
|
pendingUnclaimed: true,
|
|
builderChannel: "cloud",
|
|
localOnline: true,
|
|
cloudOnline: false,
|
|
});
|
|
assert.equal(youngOnline.phase, FEEDBACK_WORK_PHASE.QUEUED);
|
|
assert.equal(youngOnline.waitingOn, WAITING_ON.MACHINE);
|
|
assert.ok(youngOnline.stepSummary);
|
|
assert.match(youngOnline.stepSummary ?? "", /Switch to This computer/i);
|
|
assert.equal(youngOnline.watchable, true);
|
|
|
|
console.log("feedback-run-step: ok");
|
|
|
|
// ── Waiting its turn is not a broken builder ───────────────────────────────
|
|
// Loki runs one agent per project: while a run is open, the queue withholds
|
|
// the next command for that project. On 2026-09-17 a dispatch held that way
|
|
// was reported as "Retry — or Open Terminal for why it never started" on the
|
|
// row, while the panel beneath it said "confirm Fleet Runner is polling" —
|
|
// both wrong, contradicting each other, about a queue and a runner that were
|
|
// working exactly as designed.
|
|
const queuedBehind = summarizeRunStep({
|
|
latestKind: "dispatched",
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
pendingUnclaimed: true,
|
|
channel: "local",
|
|
localOnline: true,
|
|
queuedBehind: { label: "Next Best Task" },
|
|
});
|
|
assert.equal(queuedBehind.kind, "waiting_builder");
|
|
assert.match(queuedBehind.summary, /Next Best Task/);
|
|
assert.doesNotMatch(
|
|
`${queuedBehind.summary} ${queuedBehind.detail ?? ""}`,
|
|
/Fleet Runner is polling|confirm .* is polling|restart/i,
|
|
"must not send the reader to inspect a builder that is doing nothing wrong",
|
|
);
|
|
// Naming Retry to say it would NOT help is the point; offering it as the
|
|
// remedy is the bug. The copy has to say the wait ends by itself.
|
|
assert.match(queuedBehind.detail ?? "", /starts by itself|when the run ahead/i);
|
|
|
|
// A blocker with no recorded label still says the true thing.
|
|
const queuedUnnamed = summarizeRunStep({
|
|
latestKind: "dispatched",
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
pendingUnclaimed: true,
|
|
channel: "local",
|
|
localOnline: true,
|
|
queuedBehind: { label: null },
|
|
});
|
|
assert.match(queuedUnnamed.summary, /turn/i);
|
|
|
|
// Without a blocker the builder copy is unchanged — the fix must not swallow
|
|
// the real "nobody is claiming this" case.
|
|
assert.match(
|
|
summarizeRunStep({
|
|
latestKind: "dispatched",
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
pendingUnclaimed: true,
|
|
channel: "local",
|
|
localOnline: true,
|
|
}).detail ?? "",
|
|
/Fleet Runner is polling/,
|
|
);
|
|
|
|
// ── The row agrees with the panel ──────────────────────────────────────────
|
|
const heldRun = {
|
|
id: "run-held",
|
|
state: ORCH_STATE.WAITING,
|
|
outcome: null,
|
|
startedAt: new Date(Date.now() - 20 * 60_000), // far past the "never started" age
|
|
finishedAt: null,
|
|
deliveredAt: null,
|
|
lastProgressAt: null,
|
|
error: null,
|
|
pendingUnclaimed: true,
|
|
builderChannel: "local" as const,
|
|
localOnline: true,
|
|
cloudOnline: true,
|
|
queuedBehind: {
|
|
runId: "run-ahead",
|
|
label: "Next Best Task",
|
|
startedAt: new Date(Date.now() - 30 * 60_000).toISOString(),
|
|
},
|
|
};
|
|
const heldView = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, heldRun);
|
|
assert.equal(
|
|
heldView.phase,
|
|
FEEDBACK_WORK_PHASE.QUEUED,
|
|
"queued behind a run is QUEUED, not STUCK",
|
|
);
|
|
assert.match(heldView.detail ?? "", /Next Best Task/);
|
|
assert.doesNotMatch(heldView.detail ?? "", /never started/i);
|
|
|
|
// The same run with nothing ahead of it keeps the honest stuck reading.
|
|
const orphanView = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, {
|
|
...heldRun,
|
|
queuedBehind: null,
|
|
});
|
|
assert.equal(orphanView.phase, FEEDBACK_WORK_PHASE.STUCK);
|
|
assert.match(orphanView.detail ?? "", /never started/i);
|
|
|
|
console.log(" ✓ a dispatch waiting its turn is named, not blamed");
|
|
|
|
// A run that streamed once and then went quiet must not read "Agent is
|
|
// working" beside the phase's "Needs you" (run ccaf19cf, 2026-09-25: the
|
|
// laptop went offline at 17:21, the row still said working an hour later).
|
|
{
|
|
const now = Date.parse("2026-09-25T18:00:00Z");
|
|
const base = {
|
|
latestKind: "progress" as const,
|
|
deliveredAt: "2026-09-25T17:11:00Z",
|
|
channel: "local" as const,
|
|
localOnline: false,
|
|
cloudOnline: true,
|
|
now,
|
|
};
|
|
const quiet = summarizeRunStep({ ...base, lastProgressAt: "2026-09-25T17:21:00Z" });
|
|
assert.equal(quiet.summary, "Agent went quiet");
|
|
const fresh = summarizeRunStep({ ...base, lastProgressAt: "2026-09-25T17:58:00Z" });
|
|
assert.equal(fresh.summary, "Agent is working");
|
|
|
|
const view = deriveFeedbackWork(
|
|
FEEDBACK_STATUS.DISPATCHED,
|
|
{
|
|
id: "ccaf19cf-0000-0000-0000-000000000000",
|
|
state: ORCH_STATE.WAITING,
|
|
outcome: null,
|
|
startedAt: new Date("2026-09-25T17:10:00Z"),
|
|
deliveredAt: base.deliveredAt,
|
|
lastProgressAt: "2026-09-25T17:21:00Z",
|
|
latestEventKind: "progress",
|
|
builderChannel: "local",
|
|
builderOffline: true,
|
|
localOnline: false,
|
|
cloudOnline: true,
|
|
} as Parameters<typeof deriveFeedbackWork>[1],
|
|
now,
|
|
);
|
|
assert.equal(view.label, "Needs you");
|
|
assert.notEqual(view.stepSummary, "Agent is working");
|
|
}
|