From ee53c307aa9f453ef4a9c4a4f836a69d1819d37e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 20:28:33 -0600 Subject: [PATCH 1/3] fix(pm-console): the release's gate kept in storage, a deadline for the queue store, and the clock said in health The first of what else the Worker's object kept only in memory (#14001). - What GitHub last said of the released Android build, and when it was asked, were in memory: every object that started asked again, and the ten minutes between askings meant nothing. Stored under "released". - The queue store was asked with no deadline. It has twenty seconds for its answer and the body, like everything else the edge asks, and a read that runs out says so. - Health says whether the object's own clock is wanted and when it has next asked to be woken. After #14000 deployed nothing was asked of GitHub for three minutes, and from outside it could not be told whether no device takes notifications or the clock had stopped. - A time read back from storage further off than could have been set was cut down to the longest allowed, counted from now: every object counts from its own now, so it would never have come. For the release it is asked for again at once; a wait further off than GitHub can set is not kept to at all. Tested across several objects. Refs #14001, #13504 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF --- ...rchitecture_pm_platform_cloudflare_core.md | 48 ++++++++ pm-stack/console/edge/README.md | 13 ++- pm-stack/console/edge/src/direct.ts | 12 +- pm-stack/console/edge/src/edge.ts | 79 +++++++++++-- pm-stack/console/edge/src/worker.ts | 1 + pm-stack/console/scripts/edge-smoke.ts | 11 ++ pm-stack/console/src/ops.ts | 69 +++++++---- pm-stack/console/test/direct.test.ts | 110 +++++++++++++++++- pm-stack/console/test/edge.test.ts | 107 +++++++++++++++++ 9 files changed, 407 insertions(+), 43 deletions(-) diff --git a/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md b/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md index 0620a7e2c..3c549ec94 100644 --- a/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md +++ b/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md @@ -888,3 +888,51 @@ the ten-minute gate on asking for the released Android build is in memory, so every object that starts asks again; the queue store is asked with no deadline at all. #14001 has the list, to be gone through one by one. + +## 2026-11-24T02:30Z Update: in service, and the first of what else was only in memory + +**In service.** #14000 was in service by 02:13Z as `fbbba7f607e9`. Over the +three minutes after, health read every twenty seconds had a different +`woke` on eight of nine reads: the object is put away in service as +quickly as supposed, and nothing in its memory lasts from one read of +a list to the next. In those minutes it asked GitHub nothing +(`answers: 0`): nobody had the app open, and its hourly check of its +own reads was not yet due. What GitHub answers the deployed Worker's +tagged reads is appended below when it has been seen. + +**The first of #14001.** + +- _The released Android build._ What GitHub last said of it, and when + it was asked, were in memory, so the ten minutes between askings + meant nothing: every object that started asked again. Stored now + under `released`, read back once by each object, and removed when a + description is found out of step with its file. +- _The queue store had no deadline._ Every other request the edge + makes has one. It has twenty seconds for its answer and the body, + and a read that runs out says so ("the queue store did not answer + within 20 seconds"). The token is fetched before the time starts. +- _Health says what the object's own clock is doing_ (`clock.wanted`, + `clock.next`). After the deploy nothing was asked of GitHub for + three minutes, and from outside it could not be told whether no + device takes notifications or the clock had stopped. The time it has + asked to be woken at is the platform's to hold, so an object that + has just started can say it. + +**A fault in #14000's own hardening, found writing the first of +these.** A time read back from storage that was further off than could +have been set was cut down to the longest allowed, counted from now. +Every object that starts counts from its own now, so such a time would +have been cut down afresh each time and never come: for the released +build the gate would never have opened, and for GitHub's wait the edge +would never have asked again. Nothing the code writes is that far off, +so it would have taken a damaged record. A time yet to come on the +release's record is now asked for again at once, and a wait further +off than GitHub can set is not kept to at all. Both are tested across +several objects, which is what the first test of the wait's bound did +not do. + +**Checked.** The release's test is run again with a new object for +every request; 18 more single faults planted (the gate, the queue +store's deadline, the clock in health, the wait's bound), all failing +a test; the real-runtime check passes with the clock said by health +(42 checks). diff --git a/pm-stack/console/edge/README.md b/pm-stack/console/edge/README.md index fefead113..3a055e824 100644 --- a/pm-stack/console/edge/README.md +++ b/pm-stack/console/edge/README.md @@ -278,7 +278,18 @@ it (the laptop's, the sign-in issuer's). `AbortSignal.timeout`. The real-runtime check (`scripts/edge-smoke.ts`) leaves the Worker alone until health says another object answers, and only then asks whether a list is still asked for by its tag and - GitHub's wait still kept to. + GitHub's wait still kept to. What is known of the released Android + build is stored for the same reason (GitHub is asked for it every + ten minutes, not by every object that starts), and the queue store + has twenty seconds to answer like everything else the edge asks. + What is read back from storage is held to what could have been put + there: a time further off than could have been set is not kept to + at all, since cut down to the longest it would be cut down afresh + by every object that started and never end. Health's `clock` says + whether the object wakes itself each minute (it does while it does + the core itself and a device takes notifications) and when it has + next asked to be woken: the time is the platform's to hold, so any + object can say it. - **The same for what it reads.** A section the edge is refused for is the laptop's to read for the hour, exactly as it was before the edge read anything: the edge stops naming it under `owns`, the laptop's diff --git a/pm-stack/console/edge/src/direct.ts b/pm-stack/console/edge/src/direct.ts index d0713dfc0..eb28c71e3 100644 --- a/pm-stack/console/edge/src/direct.ts +++ b/pm-stack/console/edge/src/direct.ts @@ -313,14 +313,16 @@ export function githubMemory( }, {}, ); - // Only for as long as a wait could have been set for: a time - // read back is not kept to past that. + // A wait read back further off than one could have been set + // for is not one GitHub gave, and is not kept to at all. (Cut + // down to the longest instead, it would be cut down again by + // every object that started, each from its own now, and never + // end.) If GitHub is still turning this side away, the first + // call says so, with a time that is its own. const latest = now() + QUIET_MOST_MS; for (const allowance of ALLOWANCES) { const q = stored[allowance]; - if (q && (waits[allowance]?.until ?? 0) < q.until) { - waits[allowance] = { until: Math.min(q.until, latest), why: q.why }; - } + if (q && q.until <= latest && (waits[allowance]?.until ?? 0) < q.until) waits[allowance] = q; } const count = await take( "gh:count", diff --git a/pm-stack/console/edge/src/edge.ts b/pm-stack/console/edge/src/edge.ts index dedfc2e7c..8d1c14e3a 100644 --- a/pm-stack/console/edge/src/edge.ts +++ b/pm-stack/console/edge/src/edge.ts @@ -256,6 +256,9 @@ export interface EdgeOptions { /** Ask to be woken at a time: to read again what the owner is told * about, and to notice a machine gone quiet. */ setAlarm?: (at: number) => Promise; + /** When this object has asked to be woken, as the platform holds it: + * null when it has not. For health. */ + getAlarm?: () => Promise; /** Work that may finish after the answer has gone. */ later?: (work: Promise) => void; /** How often the object's own clock wakes to read again what the @@ -269,6 +272,16 @@ export interface EdgeOptions { * nothing done: to be done by a machine instead. */ class HandOver extends Error {} +/** What GitHub last said of the released build: when it was asked, + * whether it could be asked at all, what it described, and if it could + * not be asked, why. */ +interface Released { + at: number; + asked: boolean; + found: AndroidRelease | null; + trouble: string | null; +} + export class Edge { private kv: KV; private now: () => number; @@ -316,6 +329,7 @@ export class Edge { /** The last self-check: one direct read of each kind, and how it went. */ private selfCheckResult: { at: number; kinds: Record } | null = null; private setAlarm: (at: number) => Promise; + private getAlarm: () => Promise; private cfg: EdgeConfig | null | undefined; private mirrors = new Map(); private held: Held[] | null = null; @@ -346,8 +360,12 @@ export class Edge { /** The build that could not be kept when it was last sent, and when. */ private apkFailed: { sha256: string; at: number } | null = null; /** What GitHub last said of the released build, when, whether it - * could be asked at all, and if not, why. */ - private released: { at: number; asked: boolean; found: AndroidRelease | null; trouble: string | null } | null = null; + * could be asked at all, and if not, why. Null when nothing is known; + * undefined until it has been read back from storage, where it is + * kept under "released": an object that has just started (in service, + * nearly every one that is asked) would otherwise ask GitHub again + * each time, and the ten minutes between askings would mean nothing. */ + private released: Released | null | undefined = undefined; private syncRefused: KeyedLimiter; readonly docs: Docs; readonly push: Push; @@ -367,6 +385,7 @@ export class Edge { this.alarmFor = at; await setAlarm(at); }; + this.getAlarm = options.getAlarm ?? (async () => null); this.later = options.later ?? (() => {}); this.ownClockMs = options.ownClockMs ?? OWN_CLOCK_MS; this.syncRefused = new KeyedLimiter(SYNC_REFUSALS, 60_000, this.now); @@ -482,8 +501,9 @@ export class Edge { * every request; when it cannot be asked, what was last known stands. */ private async androidRelease(cfg: EdgeConfig): Promise { const now = this.now(); - const known = this.released; + const known = await this.releasedKnown(); if (known && now - known.at < (known.asked ? RELEASE_EVERY_MS : RELEASE_RETRY_MS)) return known.found; + let said: Released; try { const asked = await timed(RELEASE_ASK_MS, async (signal) => { const res = await this.fetchImpl(this.releaseUrl(cfg, "version.json"), { redirect: "follow", signal }); @@ -492,16 +512,54 @@ export class Edge { if (res.status === 404) return { found: null }; throw new Error(`GitHub answered ${res.status}`); }); - this.released = { at: now, asked: true, found: asked.found, trouble: null }; + said = { at: now, asked: true, found: asked.found, trouble: null }; } catch (error) { // Why it could not be asked is kept, and health says it: "none // published" and "could not ask" are different things, and for a // day the second looked like the first. const e = error as Error; const trouble = `${e.name && e.name !== "Error" ? `${e.name}: ` : ""}${e.message}`.slice(0, 160); - this.released = { at: now, asked: false, found: known?.found ?? null, trouble }; + said = { at: now, asked: false, found: known?.found ?? null, trouble }; + } + await this.releasedIs(said); + return said.found; + } + + /** What is known of the released build, read back from storage the + * first time this object is asked. What was stored is held to what + * could have been: a description that is one, and a time that has + * come. One yet to come would never fall due, in this object or the + * next, so what it is stored with is asked for again at once. */ + private async releasedKnown(): Promise { + if (this.released !== undefined) return this.released; + let kept: Partial | undefined; + try { + kept = (await this.kv.get("released")) as Partial | undefined; + } catch { + kept = undefined; + } + this.released = + kept && typeof kept.at === "number" && typeof kept.asked === "boolean" + ? { + at: kept.at > this.now() ? 0 : kept.at, + asked: kept.asked, + found: androidRelease(kept.found), + trouble: typeof kept.trouble === "string" ? kept.trouble.slice(0, 160) : null, + } + : null; + return this.released; + } + + /** What is known of the released build from now on, here and in + * storage; null when it is to be asked for afresh. */ + private async releasedIs(said: Released | null): Promise { + this.released = said; + try { + if (said) await this.kv.put("released", said); + else await this.kv.delete("released"); + } catch { + // Not stored: the next object asks GitHub itself. } - return this.released.found; } /** What is said of the released build: its name, its code and when it @@ -529,7 +587,7 @@ export class Edge { if (bytes.byteLength !== release.size || sha256 !== release.sha256) { // The description is out of step with the file: read it again // next time instead of trusting it for ten minutes. - this.released = null; + await this.releasedIs(null); return null; } return new Response(bytes, { @@ -1584,6 +1642,13 @@ export class Edge { // When this object started (Cloudflare starts another whenever // one has been put away). woke: this.woke, + // Its own clock: whether it wakes itself each minute to read + // what the owner is told about (it does while it does the core + // itself and a device takes notifications), and when it has + // next asked to be woken, for that or to notice a machine gone + // quiet. Notifications with no machine depend on this, and it + // is how that is seen to be alive from outside. + clock: { wanted: await this.clockWanted(cfg), next: await this.getAlarm().catch(() => null) }, hostSeen: this.hostSeen || null, // The commit the host's console is running, as it last said. hostVersion: this.hostVersion, diff --git a/pm-stack/console/edge/src/worker.ts b/pm-stack/console/edge/src/worker.ts index 822942c83..aecf3c4b3 100644 --- a/pm-stack/console/edge/src/worker.ts +++ b/pm-stack/console/edge/src/worker.ts @@ -86,6 +86,7 @@ export class PmEdge extends DurableObject { fetchImpl: fetch, }, setAlarm: (at) => ctx.storage.setAlarm(at), + getAlarm: () => ctx.storage.getAlarm(), ownClockMs: ownClockMs(env.OWN_CLOCK_MS), // A read started behind an answer is given the time to finish. later: (work) => ctx.waitUntil(work), diff --git a/pm-stack/console/scripts/edge-smoke.ts b/pm-stack/console/scripts/edge-smoke.ts index 0cd97f4fb..4d275d6a8 100644 --- a/pm-stack/console/scripts/edge-smoke.ts +++ b/pm-stack/console/scripts/edge-smoke.ts @@ -567,6 +567,17 @@ try { ) ).json()) as { result?: { devices?: number } }; check("a device takes notifications", subscribed.result?.devices === 1, JSON.stringify(subscribed)); + // With someone to tell, the object wakes itself, and health says so + // to anyone: that the clock is wanted, and when it has next asked + // to be woken (a time this runtime holds, not the object). + const clockSaid = ( + (await (await get("/console/health")).json()) as { clock?: { wanted: boolean; next: number | null } } + ).clock; + check( + "and health says the object's own clock is wanted, and when it next wakes", + clockSaid?.wanted === true && typeof clockSaid.next === "number" && clockSaid.next > Date.now() - 60_000, + JSON.stringify(clockSaid), + ); // The clock starts itself when a document is read. Its interval // is the run's shortened one, and the board goes stale half a // minute in: an alarm that fires and does its work reads the diff --git a/pm-stack/console/src/ops.ts b/pm-stack/console/src/ops.ts index b336925ba..182f14d2d 100644 --- a/pm-stack/console/src/ops.ts +++ b/pm-stack/console/src/ops.ts @@ -14,6 +14,7 @@ import type { Config } from "./config.ts"; import { OpError } from "./errors.ts"; import { plain } from "./plain.ts"; import { WORKERS_FILE, workersList } from "./platform.ts"; +import { timed, unread } from "./timed.ts"; export interface RunResult { code: number; @@ -33,6 +34,8 @@ export type Fetch = ( headers?: { get(name: string): string | null }; }>; export type Row = Record; +/** How long the queue store has to answer one asking, body and all. */ +export const QUEUE_ASK_MS = 20_000; /** Queue priorities, most urgent first (the queue's design scale). */ export const PRIORITY_SCALE = [10, 20, 30, 40, 50, 70, 90] as const; @@ -246,38 +249,54 @@ export class Ops { { type: "close" }, ], }; - const ask = async () => { + type Answer = { + results?: { + type?: string; + response?: { + result?: { + cols: { name: string }[]; + rows: { value?: string | number | null }[][]; + affected_row_count?: number; + }; + }; + }[]; + }; + /** One asking: the answer and its body, within the time. A queue + * store that never answers would otherwise hold the read for as + * long as it liked. (The token is fetched before the time starts: + * on a machine that is the fleet binary's work, not the store's.) */ + const ask = async (): Promise<{ status: number; ok: boolean; body: Answer | null }> => { if (this.queueToken === null) { this.queueToken = (await this.must([this.cfg.fleetBin, "secrets", "get", this.cfg.queueTokenName])).trim(); } - return this.fetchImpl(`${this.cfg.queueDbUrl}/v2/pipeline`, { - method: "POST", - headers: { Authorization: `Bearer ${this.queueToken}`, "Content-Type": "application/json" }, - body: JSON.stringify(body), - }); + const bearer = this.queueToken; + try { + return await timed(QUEUE_ASK_MS, async (signal) => { + const res = await this.fetchImpl(`${this.cfg.queueDbUrl}/v2/pipeline`, { + method: "POST", + headers: { Authorization: `Bearer ${bearer}`, "Content-Type": "application/json" }, + body: JSON.stringify(body), + signal, + }); + if (res.ok) return { status: res.status, ok: true, body: (await res.json()) as Answer }; + unread(res); + return { status: res.status, ok: false, body: null }; + }); + } catch (error) { + if ((error as Error).name === "TimeoutError") { + throw new OpError(502, `the queue store did not answer within ${QUEUE_ASK_MS / 1000} seconds`); + } + throw error; + } }; - let res = await ask(); - if (res.status === 401 || res.status === 403) { + let answered = await ask(); + if (answered.status === 401 || answered.status === 403) { // The token was rotated: fetch it again, once. this.queueToken = null; - res = await ask(); + answered = await ask(); } - if (!res.ok) throw new OpError(502, `queue store answered http ${res.status}`); - const results = - ( - (await res.json()) as { - results?: { - type?: string; - response?: { - result?: { - cols: { name: string }[]; - rows: { value?: string | number | null }[][]; - affected_row_count?: number; - }; - }; - }[]; - } - ).results ?? []; + if (!answered.ok) throw new OpError(502, `queue store answered http ${answered.status}`); + const results = answered.body?.results ?? []; return statements.map((_, i) => { const result = results[i]?.type === "ok" ? results[i].response?.result : undefined; if (!result) throw new OpError(502, "queue store refused the query"); diff --git a/pm-stack/console/test/direct.test.ts b/pm-stack/console/test/direct.test.ts index 7818a81cf..bbde71565 100644 --- a/pm-stack/console/test/direct.test.ts +++ b/pm-stack/console/test/direct.test.ts @@ -210,6 +210,91 @@ describe("the direct classes", () => { expect(h.calls[0].url).toBe(`${cfg.queueDbUrl}/v2/pipeline`); expect(h.calls[0].init.headers.Authorization).toBe("Bearer queue-test"); }); + + test("the queue store has twenty seconds to answer, body and all: stopped then, the read fails saying so, and however it ends no timer is left running", async () => { + // The timers a call starts, held here instead of run: the test fires the deadline itself. + const real = { set: globalThis.setTimeout, clear: globalThis.clearTimeout }; + const set: { fire: () => void; ms: number; cleared: boolean }[] = []; + globalThis.setTimeout = ((fire: () => void, ms: number) => set.push({ fire, ms, cleared: false })) as never; + globalThis.clearTimeout = ((id: number) => { + if (set[id - 1]) set[id - 1].cleared = true; + }) as never; + const started = async (count: number) => { + for (let turn = 0; turn < 100 && set.length < count; turn++) await Promise.resolve(); + expect(set.length).toBe(count); + }; + type Init = { signal: AbortSignal; headers: Record }; + const stopped = (signal: AbortSignal) => + new Promise((_resolve, reject) => signal.addEventListener("abort", () => reject(signal.reason))); + const good = { results: [{ type: "ok", response: { result: { cols: [{ name: "n" }], rows: [[{ value: 3 }]] } } }] }; + const classes = (fetchImpl: unknown) => + directClasses(edgeConfig, { githubToken: "gh-test", queueToken: "queue-test", fetchImpl: fetchImpl as Fetch }) + .ops; + const SQL = "SELECT count(*) AS n FROM tasks"; + try { + // Answered: under a deadline that had not run out, and its timer cleared. + const fine = classes( + asThePlatformFetch(async (_url: string, init: Init) => ({ + ok: !init.signal.aborted, + status: 200, + json: async () => good, + })), + ); + expect(await fine.sql(SQL, [])).toEqual([{ n: 3 }]); + expect(set.map((timer) => [timer.ms, timer.cleared])).toEqual([[20_000, true]]); + // Never answered: stopped at the deadline, and the read says what happened. + const hung = classes(asThePlatformFetch((_url: string, init: Init) => stopped(init.signal))); + const waiting = hung.sql(SQL, []).catch((error: Error) => error.message); + await started(2); + set[1].fire(); + expect(await waiting).toBe("the queue store did not answer within 20 seconds"); + // Answered, with a body that never ends: the same. + const endless = classes( + asThePlatformFetch(async (_url: string, init: Init) => ({ + ok: true, + status: 200, + json: () => stopped(init.signal), + })), + ); + const reading = endless.sql(SQL, []).catch((error: Error) => error.message); + await started(3); + set[2].fire(); + expect(await reading).toBe("the queue store did not answer within 20 seconds"); + // Refused: its answer's body is let go of, unread; and a failure that is not the + // deadline's is said as itself. + let letGo = 0; + const refused = classes( + asThePlatformFetch(async () => ({ + ok: false, + status: 500, + json: async () => ({}), + body: { + cancel: async () => { + letGo++; + }, + }, + })), + ); + expect(await refused.sql(SQL, []).catch((error: Error) => error.message)).toBe("queue store answered http 500"); + expect(letGo).toBe(1); + const down = classes( + asThePlatformFetch(async () => { + throw new Error("connection refused"); + }), + ); + expect(await down.sql(SQL, []).catch((error: Error) => error.message)).toBe("connection refused"); + expect(set.map((timer) => [timer.ms, timer.cleared])).toEqual([ + [20_000, true], + [20_000, true], + [20_000, true], + [20_000, true], + [20_000, true], + ]); + } finally { + globalThis.setTimeout = real.set; + globalThis.clearTimeout = real.clear; + } + }); }); describe("a local run's stand-ins", () => { @@ -1214,15 +1299,30 @@ describe("what the edge remembers of GitHub", () => { expect([first.u, first.e, first.t]).toEqual(["u", kept.etag, kept.text]); first.t = first.t.slice(0, -1); expect(await githubMemory(cut).get("u")).toBeUndefined(); - // A wait read back is kept to for no longer than one could have been set for. + // A wait read back that is further off than one can be set for is not GitHub's, and is not + // kept to: not by this object, and not by any after it. (One cut down to the longest wait + // would be cut down afresh by every object that started, and never end.) One that could + // have been set is kept to, to the minute. const far = mapStore( new Map([ - ["gh:quiet", { core: { until: clock.t + 400 * 24 * 60 * 60_000, why: "a time that cannot be right" } }], + [ + "gh:quiet", + { + core: { until: clock.t + 400 * 24 * 60 * 60_000, why: "a time that cannot be right" }, + search: { until: clock.t + 65 * 60_000, why: "the longest there is" }, + }, + ], ]), ); - expect(await githubMemory(far, { now: () => clock.t }).quiet()).toEqual({ - core: { until: clock.t + 65 * 60_000, why: "a time that cannot be right" }, - }); + const started = clock.t; + for (let object = 0; object < 4; object++) { + expect([object, await githubMemory(far, { now: () => clock.t }).quiet()]).toEqual([ + object, + { search: { until: started + 65 * 60_000, why: "the longest there is" } }, + ]); + clock.t += 20 * 60_000; + } + clock.t = started; // The most an entry may say it has is what an answer of the longest kept would have. const most = mapStore(); const full = { etag: 'W/"full"', text: "f".repeat(41) }; diff --git a/pm-stack/console/test/edge.test.ts b/pm-stack/console/test/edge.test.ts index 96245ccd9..ca9fbc4e7 100644 --- a/pm-stack/console/test/edge.test.ts +++ b/pm-stack/console/test/edge.test.ts @@ -669,6 +669,7 @@ async function setup(options: { direct?: boolean } = {}) { setAlarm: async (at) => { alarm.at = at; }, + getAlarm: async () => alarm.at || null, later: (work) => { behind.push(work); }, @@ -1097,6 +1098,7 @@ describe("before the host's first report", () => { deferred: 0, version: "test", woke: w.now.t, + clock: { wanted: false, next: null }, host: HOST, }); // The owner's page is the host's own, reached through the edge. @@ -2336,6 +2338,103 @@ describe("the Android build", () => { expect(await trouble()).toBeNull(); }); + test("the object put away between requests, as it is in service: GitHub is still asked for the release now and then, not by every object that starts", async () => { + const w = await setup(); + await w.hostReads(); + await report(w); + /** Another object over the same storage answers, as after every idle spell. */ + const ask = async () => { + w.edge.now = w.makeEdge(); + return ((await (await w.browse("/console/api/android")).json()) as Record).release; + }; + const trouble = async () => { + w.edge.now = w.makeEdge(); + return ((await (await w.browse("/console/health", { token: null })).json()) as Record) + .androidReleaseTrouble; + }; + // Nothing published. Asked once, however many objects are asked. + for (let i = 0; i < 5; i++) expect(await ask()).toBeNull(); + expect(w.github.asked).toEqual(["version.json"]); + // A release goes up, and is seen ten minutes on; then known to every object without asking. + w.github.apk = apk(9, 450_000); + w.github.version = await described(w.github.apk, "2026.11.23-a3a547e", 21755935); + w.now.t += 9 * 60_000; + expect(await ask()).toBeNull(); + w.now.t += 60_000; + for (let i = 0; i < 5; i++) expect((await ask())?.name).toBe("2026.11.23-a3a547e"); + expect(w.github.asked).toEqual(["version.json", "version.json"]); + // GitHub out of reach: tried each minute, not by each object, and each says why. + w.github.down = true; + w.now.t += 10 * 60_000; + for (let i = 0; i < 5; i++) expect((await ask())?.name).toBe("2026.11.23-a3a547e"); + expect(w.github.asked.length).toBe(3); + expect(await trouble()).toBe("github: connection reset"); + expect(w.github.asked.length).toBe(3); + w.now.t += 60_000; + expect((await ask())?.name).toBe("2026.11.23-a3a547e"); + expect(w.github.asked.length).toBe(4); + // A description found out of step with its file is asked for again by the next object, + // not trusted by it for ten minutes. + w.github.down = false; + w.now.t += 60_000; + w.github.version = await described(apk(8, 440_000), "2026.11.22-0000000", 21000000); + expect((await ask())?.name).toBe("2026.11.22-0000000"); + const askedBy = w.github.asked.filter((file) => file === "version.json").length; + w.build.bytes = apk(1); + w.build.at = w.now.t; + await report(w); + await report(w); + w.edge.now = w.makeEdge(); + expect((await download(w)).bytes).toEqual(apk(1)); + expect(w.stored.has("released")).toBe(false); + w.github.version = await described(w.github.apk, "2026.11.23-a3a547e", 21755935); + expect((await ask())?.name).toBe("2026.11.23-a3a547e"); + expect(w.github.asked.filter((file) => file === "version.json").length).toBe(askedBy + 1); + // What storage holds is held to what could have been put there. A time yet to come would + // never fall due, in one object or the next: what it is stored with is asked for again at + // once. Something that is not this at all is nothing known. + const versionAsks = () => w.github.asked.filter((file) => file === "version.json").length; + w.stored.set("released", { at: w.now.t + 400 * 24 * 60 * 60_000, asked: true, found: null, trouble: null }); + const before = versionAsks(); + expect((await ask())?.name).toBe("2026.11.23-a3a547e"); + expect(versionAsks()).toBe(before + 1); + // (And what was asked for then is stored with the time it was asked at.) + expect((w.stored.get("released") as { at: number }).at).toBe(w.now.t); + // With GitHub out of reach, what such a record described still stands while it is asked for. + const known = w.stored.get("released") as { found: unknown }; + w.stored.set("released", { ...known, at: w.now.t + 60_000 }); + w.github.down = true; + expect((await ask())?.name).toBe("2026.11.23-a3a547e"); + expect(versionAsks()).toBe(before + 2); + w.github.down = false; + w.now.t += 60_000; + for (const odd of [7, "x", { at: "soon", asked: true }, { at: w.now.t, asked: "yes" }, null]) { + w.stored.set("released", odd); + const asks = versionAsks(); + expect([odd, (await ask())?.name]).toEqual([odd, "2026.11.23-a3a547e"]); + expect([odd, versionAsks()]).toEqual([odd, asks + 1]); + } + // A description in storage that is not one is no release, whatever else the record says. + w.stored.set("released", { at: w.now.t, asked: true, found: { name: "../../etc", code: 1 }, trouble: 7 }); + expect(await ask()).toBeNull(); + expect(await trouble()).toBeNull(); + // Storage that cannot take it: GitHub is asked by each object, and the answer still given. + w.stored.delete("released"); + w.storeFails.add("released"); + const failing = versionAsks(); + expect((await ask())?.name).toBe("2026.11.23-a3a547e"); + expect((await ask())?.name).toBe("2026.11.23-a3a547e"); + expect(versionAsks()).toBe(failing + 2); + // One object asked twice still asks GitHub once: what it knows it has in mind as well. + const android = async () => + ((await (await w.browse("/console/api/android")).json()) as Record).release; + expect([(await android())?.name, (await android())?.name]).toEqual(["2026.11.23-a3a547e", "2026.11.23-a3a547e"]); + expect(versionAsks()).toBe(failing + 2); + w.edge.now = w.makeEdge(); + expect([(await android())?.name, (await android())?.name]).toEqual(["2026.11.23-a3a547e", "2026.11.23-a3a547e"]); + expect(versionAsks()).toBe(failing + 3); + }); + test("a copy whose replacement stops half-way is not handed out as either build", async () => { const w = await setup(); await w.hostReads(); @@ -5077,6 +5176,11 @@ describe("telling the owner, with no machine", () => { const { w, phone } = await subscribed(); // Subscribing asked for a wake: there is someone to tell. expect(w.alarm.at).toBe(START + 1_000); + // Health says so to anyone: the clock is wanted, and when it next wakes. It is how the + // path notifications depend on is seen to be alive from outside. + const clock = async () => + ((await (await w.browse("/console/health", { token: null })).json()) as { clock: unknown }).clock; + expect(await clock()).toEqual({ wanted: true, next: START + 1_000 }); // The laptop goes away for good. Nobody opens the app. w.net.hostUp = false; w.net.edgeUp = false; @@ -5084,6 +5188,9 @@ describe("telling the owner, with no machine", () => { await w.edge.now.alarm(); expect(w.pushes).toHaveLength(0); expect(w.alarm.at).toBe(w.now.t + 60_000); + // (Said by an object that has just started, too: the time is the platform's to hold.) + w.edge.now = w.makeEdge(); + expect(await clock()).toEqual({ wanted: true, next: w.now.t + 60_000 }); // The fleet answers on GitHub. w.now.t += 30_000; reply(w, 202, "Checked: the queue is moving."); From 3ce63df0b5da4ba18bdf788981e3b1c7980a114e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 20:31:21 -0600 Subject: [PATCH 2/3] fix(pm-console): a time further off than could have been set is not believed, by any object What the edge reads back of being turned away (which actions and lists are a machine's for now) cut a far-off time down to an hour from now. Every object that starts counts from its own now, and in service that is nearly every object asked: a year written down stood for a year. Its test asked one object and then moved the clock. Such a time is not believed at all now, and the test starts a new object for every look. Refs #14001 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF --- ...rchitecture_pm_platform_cloudflare_core.md | 14 +++++++++--- pm-stack/console/edge/src/edge.ts | 12 ++++++---- pm-stack/console/test/edge.test.ts | 22 +++++++++++++------ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md b/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md index 3c549ec94..abf8d4649 100644 --- a/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md +++ b/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md @@ -931,8 +931,16 @@ off than GitHub can set is not kept to at all. Both are tested across several objects, which is what the first test of the wait's bound did not do. +The same fault had been in the edge since step 3, in what it reads +back of being turned away (which actions and which lists are a +machine's for now): a time further off than could have been set was +cut down to an hour from now, and its test asked one object and then +moved the clock. Asked of a new object each time, as in service, a +year written down stood for a year. It is not believed at all now, and +the test starts a new object for every look. + **Checked.** The release's test is run again with a new object for -every request; 18 more single faults planted (the gate, the queue -store's deadline, the clock in health, the wait's bound), all failing -a test; the real-runtime check passes with the clock said by health +every request; 20 more single faults planted (the gate, the queue +store's deadline, the clock in health, the two bounds), all failing a +test; the real-runtime check passes with the clock said by health (42 checks). diff --git a/pm-stack/console/edge/src/edge.ts b/pm-stack/console/edge/src/edge.ts index 8d1c14e3a..2087f9998 100644 --- a/pm-stack/console/edge/src/edge.ts +++ b/pm-stack/console/edge/src/edge.ts @@ -925,12 +925,16 @@ export class Edge { | { kinds?: Record; reads?: Record } | undefined; const now = this.now(); - // Only what still stands, and never for longer than it could - // have been set for. + // Only what still stands, and nothing further off than it could + // have been set for (the longest is GitHub's own wait): a time + // like that is not one this side wrote, and is not believed at + // all. (Cut down to the longest instead, as it once was, it was + // cut down afresh by every object that started, each from its + // own now, and never came.) const still = (from: Record | undefined, into: Map) => { for (const [name, until] of Object.entries(from ?? {})) { - if (typeof until === "number" && until > now && !into.has(name)) { - into.set(name, Math.min(until, now + REFUSED_FOR_MS)); + if (typeof until === "number" && until > now && until <= now + QUIET_MOST_MS && !into.has(name)) { + into.set(name, until); } } }; diff --git a/pm-stack/console/test/edge.test.ts b/pm-stack/console/test/edge.test.ts index ca9fbc4e7..44aad4933 100644 --- a/pm-stack/console/test/edge.test.ts +++ b/pm-stack/console/test/edge.test.ts @@ -4359,15 +4359,23 @@ describe("the edge does the core itself", () => { ((await (await w.browse("/console/health", { token: null })).json()) as { refused: string[] }).refused; w.stored.set("away", { kinds: { "pr.merge": w.now.t + 10 * 60_000, "ask.send": w.now.t - 1, "issue.rank": "soon" }, - reads: { prs: w.now.t + 365 * 24 * 3600_000, board: w.now.t - 1 }, + // A year was written down for one, and the longest there can be for another. + reads: { prs: w.now.t + 365 * 24 * 3600_000, priorities: w.now.t + 65 * 60_000, board: w.now.t - 1 }, }); - w.edge.now = w.makeEdge(); - expect(await health()).toEqual(["pr.merge", "read.prs"]); + // Each time by an object that has just started, as in service. The year is not believed + // by any of them: one that cut it down to the longest would cut it down afresh each time, + // and it would never come. + const fresh = async () => { + w.edge.now = w.makeEdge(); + return health(); + }; + expect(await fresh()).toEqual(["pr.merge", "read.priorities"]); w.now.t += 11 * 60_000; - expect(await health()).toEqual(["read.prs"]); - // A year was written down; an hour is the longest it can stand. - w.now.t += 50 * 60_000; - expect(await health()).toEqual([]); + expect(await fresh()).toEqual(["read.priorities"]); + w.now.t += 53 * 60_000; + expect(await fresh()).toEqual(["read.priorities"]); + w.now.t += 60_000 + 1; + expect(await fresh()).toEqual([]); // Storage that cannot keep it does not stop the hand-over itself. w.storeFails.add("away"); w.ghRefuses.push((method, url) => method === "PUT" && url.includes("/merge")); From 062a0b6e21b86adb86b66558e75a61ddc31ffffe Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 20:41:12 -0600 Subject: [PATCH 3/3] docs(pm-console): what the live Worker showed at 02:39Z, and that searches carry no tag Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF --- ...0-00Z_architecture_pm_platform_cloudflare_core.md | 12 ++++++++++++ pm-stack/console/edge/README.md | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md b/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md index abf8d4649..61cc42821 100644 --- a/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md +++ b/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md @@ -944,3 +944,15 @@ every request; 20 more single faults planted (the gate, the queue store's deadline, the clock in health, the two bounds), all failing a test; the real-runtime check passes with the clock said by health (42 checks). + +**Seen in service, 02:39Z.** The hourly check of its own reads ran at +02:39:26 and all four came back good. Health then said +`answers: 5, unchanged: 0, kept: 3`, and said the same from two +objects that started after it (02:39:58 and 02:40:28), with `since` +still 02:39:26: what is kept, and the count, outlive the object in +service. Two of the five answers were not kept because GitHub gives +its search answers no tag (checked against its API): ranked issues are +a search, a full answer every time, drawn on the search allowance and +not the hour's. Not yet seen: GitHub's "not modified" to the deployed +Worker. Nothing has asked for a kept list a second time; the next +check of its own reads is at 03:39Z. diff --git a/pm-stack/console/edge/README.md b/pm-stack/console/edge/README.md index 3a055e824..06e0cd4f8 100644 --- a/pm-stack/console/edge/README.md +++ b/pm-stack/console/edge/README.md @@ -256,8 +256,10 @@ it (the laptop's, the sign-in issuer's). said "not modified" after. Health counts GitHub's answers and how many were "not modified" (`github.answers`, `github.unchanged`, counted since `github.since` whichever object answered) and says how - many answers are kept (`github.kept`). This does not give the edge - an allowance of its own: when the agents use the hour up, the edge + many answers are kept (`github.kept`). GitHub gives its search + answers no tag, so ranked issues (a search) are a full answer every + time; they draw on the search allowance, not the hour's. This does + not give the edge an allowance of its own: when the agents use the hour up, the edge is turned away with them until it turns (#13489 has what would change that). - **The object is put away whenever it is idle.** Cloudflare takes an