Public: anyone can read this; the crew can change it.

Sentinel: backup was degraded 43 minutes today: Primary (s3.us-east-005.backblazeb2.com/openplatform-dr-backups) cannot be read: names snapshots/ failed after 5 attemp… #17858

opened this

Merged 34h 21m ago, live in production

mason/forge:mason/17852-sentinel-backup-was-degraded-43-minutes → main 0 commits fork 1 thread · 1 unresolved

  • Merged. mason/17852-sentinel-backup-was-degraded-43-minutes was merged into main as ddebb72.

Review

Sign in to review this change.
3 files changed +146 −4
docs/features/backup-truth.md +2 −1
@@ -6,7 +6,8 @@ row: Backups that cannot lie
66
77 - **Read from the bucket.** `src/snapshot/bucket.ts` lists the primary and mirror stores every 5 minutes, in the serving process (no CronJob to die). Home's backup tile, vitals (one `backup` card) and the MCP `backups` tool's `verdict` all call `backupVerdict`.
88 - **Three states.** `green`, `red`, and `unknown`: nothing read yet since boot, or no restore drill yet. Unknown is never a calm tile and never an alarm; only red raises the one `backup` card. A store error is scrubbed of keys and presigned queries before it is kept.
9 - **Red when:** the newest snapshot is over 26 h old; a lane cannot be read or holds nothing; the newest restore drill failed, did not run, or brought back no rows; or the check itself has not run for 20 min (dead man's switch). The reason says when it last ran: `The backup check has not run for 25 min (last ran 2026-11-02T08:00:00Z); it is the alarm, and it is down.`
9 - **Red when:** the newest snapshot is over 26 h old; a lane holds nothing; a lane has never read whole and its read fails (red at its first failure); a lane that read whole has not answered for over an hour (`... cannot be read: <reason> (not answering for 1 h).`); the newest restore drill failed, did not run, or brought back no rows; or the check itself has not run for 20 min (dead man's switch). The reason says when it last ran: `The backup check has not run for 25 min (last ran 2026-11-02T08:00:00Z); it is the alarm, and it is down.`
10 - **A store that stops answering (#17852).** A lane that read whole and then fails to read keeps its last whole read for up to 60 min (`UNANSWERED_HOLD_MS`): amber, never green, and never the `backup` card. Its snapshot is still judged by its age against now, so one that turns 26 h old during the hold is red. The lane and the unknowns say `not answering for N min (reason); its last whole read, <time>, stands for up to 1 h`, the same words on `/settings/backups`, in the terminal's Resilience dialog and in MCP `backups` → `verdict.lanes`. The next whole read clears it, and the run record still keeps each failed read.
1011 - **The run record.** Every run of the check appends one JSON line (`at`, and each lane's `ok` and `newestAt`) to `backup-checks.jsonl` under the data directory. The count is kept in memory; once the file holds 400 runs it is cut back to the last 200. A disk that refuses the write never stops the check. The verdict carries `runs` and `checkLine` (`The backup check last ran <ISO> (3 min ago); 42 runs on record.`), shown in the Resilience dialog, the home tile's title and the `backup` card, so a person can see the check is alive.
1112 - **Catch-up.** A boot with the newest snapshot older than the last 08:00 UTC slot takes one two minutes later (`snapshotDue`). A snapshot cut short by a release has no manifest, so it counts as lost.
1213 - **In the terminal.** The Resilience dialog (palette: Resilience, admins) opens with the same verdict, each lane's newest, and every reason. On the web it is home's backup tile and `/settings/backups`; for an agent, `verdict` in the MCP `backups` tool.
src/snapshot/bucket.ts +41 −3
@@ -30,6 +30,15 @@ export const LATE_MS = 26 * 3_600_000;
3030 export const READ_EVERY_MS = 5 * 60_000;
3131 /** No read for this long, however it went, is red. */
3232 export const CHECK_STALE_MS = 20 * 60_000;
33 /**
34 * How long a lane that read whole may go unanswered before it is red (#17852). A listing the store
35 * did not answer says nothing of what the bucket holds: an object store's own trouble (Backblaze
36 * answered every listing with a 5xx for 43 minutes on 2026-12-03) held the backup red, and the
37 * forge degraded, with last night's snapshot fresh in it. Until this long, the lane's last whole

This comment is part of the over-100-column lines the gate flags. Run bun scripts/gate.ts --fix and commit the rewrap.

38 * read stands, its snapshot still judged by its age against now, and the miss is said; past it,
39 * the lane cannot be read and is red, as it always was.
40 */
41 export const UNANSWERED_HOLD_MS = 60 * 60_000;
3342
3443 export interface LaneRead {
3544 /** `primary`, `mirror`; a platform lane would add its own name. */
@@ -42,6 +51,11 @@ export interface LaneRead {
4251 readonly count: number;
4352 /** Set when the store could not be read: the reason, never a credential. */
4453 readonly error?: string;
54 /**
55 * Set on a lane's last whole read kept in place of reads that failed since (`keepReads`): when
56 * the first of them ended, and the newest one's reason. `readAt` stays the whole read's.
57 */
58 readonly unanswered?: { readonly since: string; readonly error: string };
4559 /**
4660 * What the lane does to a snapshot's bodies before they leave (`bodiesOf`): encrypted before
4761 * upload, or not. Absent on a lane the forge only lists.
@@ -257,10 +271,21 @@ export async function readLane(
257271 }
258272 }
259273
260 /** Keep what a pass read. */
274 /**
275 * A lane's read in place of `read`: a failed read of a lane whose last kept read was whole keeps
276 * that one, marked with when the store stopped answering and why (`UNANSWERED_HOLD_MS`); any
277 * other read is itself.
278 */
279 function heldRead(read: LaneRead, kept: LaneRead | undefined): LaneRead {
280 if (read.error === undefined || kept === undefined || kept.error !== undefined) return read;
281 return { ...kept, unanswered: { since: kept.unanswered?.since ?? read.readAt, error: read.error } };
282 }
283
284 /** Keep what a pass read, a lane that stopped answering on its last whole read (`heldRead`). */
261285 export function keepReads(dataDir: string, lanes: LaneRead[], now = Date.now()): void {
262286 const prev = reads.get(dataDir);
263 reads.set(dataDir, { lanes, checkedAt: new Date(now).toISOString(), since: prev?.since ?? new Date(now).toISOString() });
287 const kept = lanes.map((r) => heldRead(r, prev?.lanes.find((p) => p.lane === r.lane)));
288 reads.set(dataDir, { lanes: kept, checkedAt: new Date(now).toISOString(), since: prev?.since ?? new Date(now).toISOString() });
264289 }
265290
266291 export function forgetReads(dataDir: string): void {
@@ -301,7 +326,14 @@ export function judge(
301326 : `The backup check has not run for ${ageWords(sinceCheck)} (last ran ${checkedAt}); it is the alarm, and it is down.`,
302327 );
303328 } else if (checkedAt === null) unknowns.push("The bucket has not been read yet, so nothing is known about the backups.");
304 for (const r of state?.lanes ?? []) {
329 for (const kept of state?.lanes ?? []) {
330 // A lane unanswered past the hold is unreadable; within it, its last whole read is judged.
331 const unanswered = kept.unanswered;
332 const silentMs = unanswered === undefined ? 0 : Math.max(0, now - Date.parse(unanswered.since));
333 const r: LaneRead =
334 unanswered !== undefined && !(silentMs <= UNANSWERED_HOLD_MS)
335 ? { ...kept, error: `${unanswered.error} (not answering for ${ageWords(silentMs)})` }
336 : kept;
305337 let says: string;
306338 let red = true;
307339 // Every word a store or the configuration supplied is made printable before it joins the line.
@@ -357,6 +389,12 @@ export function judge(
357389 // forge's alarm either: what it holds is its owner's doing, night after night.
358390 if (r.hosted !== undefined && r.error === undefined && (r.hosted.absent ?? []).length > 0)
359391 unknowns.push(`${lane[0]!.toUpperCase()}${lane.slice(1)}: ${hostedAbsentWords(r.hosted)}.`);
392 // Not answering, within the hold: said on the lane and not calm, and not the alarm yet.
393 if (unanswered !== undefined && r.error === undefined) {
394 const missed = `not answering for ${ageWords(silentMs)} (${printable(unanswered.error)}); its last whole read, ${r.readAt}, stands for up to ${ageWords(UNANSWERED_HOLD_MS)}`;
395 says = `${says}; ${missed}`;
396 unknowns.push(`${lane[0]!.toUpperCase()}${lane.slice(1)} (${where}) is ${missed}.`);
397 }
360398 lanes.push({ ...r, backsUp, afterSpinDown, state: red ? "red" : "green", says, line });
361399 }
362400 if (state !== undefined && !lanes.some((l) => l.state !== "retired")) {
test/backup-unanswered.test.ts added +103
@@ -0,0 +1,103 @@
1 /**
2 * A store that stops answering is not a lost backup (#17852): the lane's last whole read stands
3 * for `UNANSWERED_HOLD_MS`, said on the lane and amber, and past it the lane cannot be read and is
4 * red as before. A lane that has never read whole is red at its first failure, as before.
5 */
6
7 import { expect, test } from "bun:test";
8 import { backupVerdict, keepReads, UNANSWERED_HOLD_MS, type LaneRead } from "../src/snapshot/bucket.ts";
9 import type { DrillResult } from "../src/snapshot/drill.ts";
10
11 const T = Date.parse("2026-12-03T06:21:00Z");
12 const MIN = 60_000;
13 const at = (ms: number): string => new Date(ms).toISOString();
14 const ERROR = "names snapshots/ failed after 5 attempts: an unexpected error has occurred";
15
16 const whole = (readAt: number, newestAt = at(T - 6 * 3_600_000)): LaneRead => ({
17 lane: "primary",
18 where: "s3.example.com/backups",
19 offBox: true,
20 newestAt,
21 newestName: newestAt,
22 newestBytes: 5_000_000,
23 count: 14,
24 readAt: at(readAt),
25 });
26 const failed = (readAt: number): LaneRead => ({
27 lane: "primary",
28 where: "s3.example.com/backups",
29 offBox: true,
30 newestAt: null,
31 newestName: null,
32 newestBytes: null,
33 count: 0,
34 error: ERROR,
35 readAt: at(readAt),
36 });
37 const drill: DrillResult = {
38 at: at(T - 3_600_000),
39 snapshotId: "s",
40 ms: 1,
41 counts: { repositories: 4, issues: 9, users: 2, pulls: 1, apps: 1 },
42 health: "ok",
43 verdict: "green",
44 failedStep: null,
45 phases: [],
46 budgetMs: 1,
47 reason: null,
48 };
49
50 let n = 0;
51 /** Each pass in turn kept for a fresh data directory, as the watch keeps them. */
52 function passes(...reads: readonly [number, LaneRead][]): string {
53 const dir = `unanswered-${n++}`;
54 for (const [ms, read] of reads) keepReads(dir, [read], ms);
55 return dir;
56 }
57
58 test("a lane that read whole and then stops answering keeps its last read, amber, not red", () => {
59 const dir = passes([T, whole(T)], [T + 5 * MIN, failed(T + 5 * MIN)], [T + 10 * MIN, failed(T + 10 * MIN)]);
60 const v = backupVerdict(dir, drill, T + 11 * MIN);
61 expect(v.state).toBe("unknown");
62 expect(v.reasons).toEqual([]);
63 const lane = v.lanes[0]!;
64 expect(lane.state).toBe("green");
65 expect(lane.newestBytes).toBe(5_000_000);
66 // Counted from the first failure, and its reason said on the lane and in the unknowns.
67 expect(lane.says).toContain("not answering for 6 min");
68 expect(lane.says).toContain(ERROR);
69 expect(lane.says).toContain(`its last whole read, ${at(T)}, stands`);
70 expect(v.unknowns.some((u) => u.startsWith("Primary (s3.example.com/backups) is not answering for 6 min"))).toBe(true);
71 });
72
73 test("a lane unanswered past the hold is red, saying how long", () => {
74 const dir = passes([T, whole(T)], [T + 5 * MIN, failed(T + 5 * MIN)], [T + 65 * MIN + 1, failed(T + 65 * MIN + 1)]);
75 const v = backupVerdict(dir, drill, T + 5 * MIN + UNANSWERED_HOLD_MS + 1);
76 expect(v.state).toBe("red");
77 expect(v.note).toBe("unreadable");
78 expect(v.lanes[0]!.state).toBe("red");
79 expect(v.reasons[0]).toBe(`Primary (s3.example.com/backups) cannot be read: ${ERROR} (not answering for 1 h).`);
80 });
81
82 test("a lane that has never read whole is red at its first failure", () => {
83 const dir = passes([T, failed(T)]);
84 const v = backupVerdict(dir, drill, T + MIN);
85 expect(v.state).toBe("red");
86 expect(v.reasons[0]).toBe(`Primary (s3.example.com/backups) cannot be read: ${ERROR}.`);
87 });
88
89 test("a held snapshot still ages: one late by now is red though the read was whole", () => {
90 const newest = at(T - 26 * 3_600_000 + 2 * MIN);
91 const dir = passes([T, whole(T, newest)], [T + 5 * MIN, failed(T + 5 * MIN)]);
92 const v = backupVerdict(dir, drill, T + 5 * MIN);
93 expect(v.state).toBe("red");
94 expect(v.note).toBe("late");
95 });
96
97 test("a whole read after the misses clears them", () => {
98 const dir = passes([T, whole(T)], [T + 5 * MIN, failed(T + 5 * MIN)], [T + 10 * MIN, whole(T + 10 * MIN)]);
99 const v = backupVerdict(dir, drill, T + 11 * MIN);
100 expect(v.state).toBe("green");
101 expect(v.lanes[0]!.says).not.toContain("not answering");
102 expect(v.lanes[0]!.unanswered).toBeUndefined();
103 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs