Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,71 @@ 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.

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; 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.
19 changes: 16 additions & 3 deletions pm-stack/console/edge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -278,7 +280,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
Expand Down
12 changes: 7 additions & 5 deletions pm-stack/console/edge/src/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Count>(
"gh:count",
Expand Down
91 changes: 80 additions & 11 deletions pm-stack/console/edge/src/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
/** When this object has asked to be woken, as the platform holds it:
* null when it has not. For health. */
getAlarm?: () => Promise<number | null>;
/** Work that may finish after the answer has gone. */
later?: (work: Promise<unknown>) => void;
/** How often the object's own clock wakes to read again what the
Expand All @@ -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;
Expand Down Expand Up @@ -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<string, { ok: boolean; error?: string }> } | null = null;
private setAlarm: (at: number) => Promise<void>;
private getAlarm: () => Promise<number | null>;
private cfg: EdgeConfig | null | undefined;
private mirrors = new Map<string, Mirror | null>();
private held: Held[] | null = null;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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<AndroidRelease | null> {
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 });
Expand All @@ -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<Released | null> {
if (this.released !== undefined) return this.released;
let kept: Partial<Released> | undefined;
try {
kept = (await this.kv.get("released")) as Partial<Released> | 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<void> {
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
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -867,12 +925,16 @@ export class Edge {
| { kinds?: Record<string, unknown>; reads?: Record<string, unknown> }
| 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<string, unknown> | undefined, into: Map<string, number>) => {
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);
}
}
};
Expand Down Expand Up @@ -1584,6 +1646,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,
Expand Down
1 change: 1 addition & 0 deletions pm-stack/console/edge/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class PmEdge extends DurableObject<Env> {
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),
Expand Down
11 changes: 11 additions & 0 deletions pm-stack/console/scripts/edge-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading