fixup! feat(status): a status page, for the phone of whoever looks after the box
check / check (push) Canceled after 0s

booting: a ready counts unless it's from before the latest outage
the server saw. The box's services restart together, so the button's
ready can come before the next check sees the IR port up; comparing
ready with when the port came up read that as booting, until the next
ready. A server restarted while the box stayed up did the same.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-12-02 18:23:54 -06:00
1 parent c335935e2d
commit f35da9b883
2 files changed
+25 -3

No files matched your search

+7 -3
View File
@@ -24,7 +24,7 @@ const fromButton = (source) => source.endsWith('-button');
/**
* @typedef {{ at: number, kind: string, source: string, reason?: string, code?: string, times?: number }} Event
* @typedef {{ name: string, up: boolean, at: number, since: number }} Check
* @typedef {{ name: string, up: boolean, at: number, since: number, outage?: number }} Check outage: when the latest outage we saw began
* @typedef {{ conversations: number, turns: number, huh: number, interrupts: number, irPresses: number, looks: number }} Tally
* @typedef {{ word: string, since?: number, why?: string }} State
* @typedef {{ state: State, heartbeat?: number, checks: (typeof CHECKS[number] & Partial<Check>)[], today: Tally, total: Tally, recent: Event[] }} Summary
@@ -82,7 +82,9 @@ export class Status {
/** @param {string} name @param {boolean} up @param {number} at */
check(name, up, at) {
const prev = this.#checks.get(name);
this.#checks.set(name, { name, up, at, since: prev && prev.up === up ? prev.since : at });
const since = prev && prev.up === up ? prev.since : at;
const outage = up ? prev?.outage : since;
this.#checks.set(name, { name, up, at, since, ...(outage === undefined ? {} : { outage }) });
}
size() { return this.#events.length; }
@@ -93,7 +95,9 @@ export class Status {
if (!up) return { word: 'not checked yet' };
if (!up.up) return { word: 'unreachable', since: up.since };
const ready = this.#events.findLast((e) => e.kind === 'ready');
if (!ready || ready.at < up.since) return { word: 'booting', since: up.since };
// Services restart together, so ready can come before the check sees the box up again: a ready
// counts unless it's from before the latest outage we saw.
if (!ready || ready.at < (up.outage ?? -Infinity)) return { word: 'booting', since: up.since };
const alive = Math.max(this.#heartbeat ?? 0, this.#events.findLast((e) => fromButton(e.source))?.at ?? 0);
if (now - alive > 3 * HEARTBEAT_MS) return { word: 'not responding', since: alive, why: 'no heartbeat from its button service' };
const last = this.#events.findLast((e) => e.kind === 'conversation' || e.kind === 'end');