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 @@ -549,3 +549,56 @@ fault. Adding the check to CI is the next change.
Not done, and filed as #13398: an older action held for a machine is
not ordered against a newer one about the same thing that the edge
does itself.

## 2026-11-23T16:50Z Update: step 4 in service, and step 5 (machines)

**Step 4 is in service.** Merged as #13287 after four rounds of review
(thirteen findings, all real, each with a test and most with a check
in a real browser that fails against the code before its fix). At
16:38Z the Worker and the laptop both ran `2a96e875037d`; the Worker
said it does the core itself and had been turned away for nothing.

Seen in that answer: the Worker's own read of pull requests had failed
a quarter of an hour earlier with GitHub's "rate limit exceeded" for
the owner's account. The Worker's token is the fleet's, and the fleet
had used the hour's allowance. The Worker treats that as "one too many
just now" and asks again in five minutes, which is right; but a
platform whose core reads stop when agents are busy is not doing the
core by itself. Filed with the gaps: its own allowance.

**Step 5 is built: the laptop is a machine.** Decision 5 above, as it
turned out:

- **A machine says what it is.** Each report carries the machine's name
and what it can do: the kinds of action it has and the sections it
reads. The edge keeps what it last said beside when it last reported.
A console older than this says nothing, and is shown as a machine
that has not said what it can do.
- **The edge answers for the whole.** `GET /console/api/machines` is
answered at the edge with no machine asked: what the edge does itself
right now, each machine and whether it is reporting, and what waits
for one. A machine serving the app by itself answers the same read
with itself.
- **What waits can be taken back.** `held.drop` removes one held action
before a machine has it, and records it as not sent under its name,
so the device that sent it learns so.
- **The screen** (More, Machines) says each of those in words, and that
one machine can be connected today.

What this does not do yet, and is filed: a second machine under its own
key; each action sent to a machine that can do it (today there is one,
so "a machine" is "the machine"); what is held kept per machine.

Review found two faults, both real. Taken back, an action could be
kept again when a device that never heard it was kept offered it again:
taking back now ends the name, and the offer is answered "taken back".
And the screen did not notice a machine going quiet unless something
else changed: it now asks again while it is open, and is drawn again
when what it shows has changed.

Checked: 351 tests under bun. 28 planted faults in the new code, all
caught. In a real Chrome against both demos, light and dark: the
screen with nothing in front of the machine and with the edge in front;
something held while the machine is out of reach, listed in the owner's
words, taken back after a question, and recorded as not sent. axe-core
over 21 screens and the new dialog: no violations.
65 changes: 50 additions & 15 deletions pm-stack/console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,40 @@ Set `PM_CONSOLE_EDGE_URL` to turn the reporting on; `scripts/expose.py`
does that when it sends the hostname through the Worker. Without it this
service reports to nobody and serves the app itself, as before.

### Machines

This host is a machine, and the platform treats it as one of however
many there are. A machine is anything that reports to the edge under a
key the edge knows. In every report it says what it is called
(`PM_CONSOLE_MACHINE`, or the host's own name) and what it can do: the
kinds of action it has, and the sections it reads. Nothing about a
machine is assumed from its being "the laptop".

More, Machines shows:

- **Cloudflare's own part**: whether it does the core itself, and what
it was turned away for lately.
- **Each machine**: whether it is reporting and when it was last heard
from, the commit it runs, and what only it reports and only it can
do, in words. What Cloudflare does itself is not counted as the
machine's.
- **What waits for a machine**: everything the owner did that is held
until one is back, oldest first, each with "Take back" (`held.drop`).
Taken back, it is recorded as not sent under its name, so the device
that sent it shows it under "could not be done"; offered again by a
device that never heard it was kept, it stays taken back.

The screen keeps itself current while it is open: a machine going
quiet or coming back, or something new waiting, draws it again.

The edge answers that screen itself, so it is there with every machine
away. Served straight from a machine, the machine answers with itself.

One machine can report today: the one the tunnel leads to, whose key is
the only one the edge takes reports under. Enrolling another under its
own key, and sending each action to a machine that can do it, are not
built.

### With no connection

The app opens and can be used with no connection, in a browser and in
Expand Down Expand Up @@ -333,21 +367,22 @@ the route if the console does not come up with its sign-in settings.

## Configuration

| Variable | Default | Meaning |
| --------------------------------------------------------- | -------------------------------------------------- | -------------------------------------------------- |
| `PM_CONSOLE_PORT`, `PM_CONSOLE_BIND` | `4872`, `127.0.0.1` | Listener; the address must be loopback |
| `PM_CONSOLE_OWNER_EMAILS` | none (nobody) | Comma-separated owner addresses |
| `PM_CONSOLE_ACCESS_TEAM_DOMAIN`, `PM_CONSOLE_ACCESS_AUD` | unset | The Access issuer; set together |
| `PM_CONSOLE_ISSUERS_FILE` | unset | JSON list of further issuers |
| `PM_CONSOLE_CERT_NAMES` | none | Certificate common names that are the owner |
| `PM_CONSOLE_DASHBOARD_URL` | `http://127.0.0.1:4870` | The dashboard behind the gate; loopback, or empty |
| `PM_CONSOLE_UNITS`, `PM_CONSOLE_PROTECTED_UNITS` | the stack's units | Units the console manages; units it will not stop |
| `PM_CONSOLE_ANDROID_PACKAGE`, `PM_CONSOLE_ANDROID_SHA256` | `today.developing.pmconsole`, none | The Android app's identity in the asset-links file |
| `PM_CONSOLE_ANDROID_APK` | `~/.local/state/pm-console/android/pm-console.apk` | The signed build the console hands to the owner |
| `PM_CONSOLE_DEVICES_FILE` | `~/.local/state/pm-console/devices.json` | Linked phones (hashes of their tokens) |
| `PM_CONSOLE_EDGE_URL` | unset (reports to nobody) | The public address the edge answers on, `https://` |
| `PM_CONSOLE_EDGE_KEY_FILE`, `PM_CONSOLE_EDGE_DONE_FILE` | `edge-key.json`, `edge-done.json` in the state dir | This host's signing key; what it ran for the edge |
| `PM_CONSOLE_REPO`, `PM_CONSOLE_QUEUE` | `developing-today/code`, `repo-health-code-pilot` | What it operates on |
| Variable | Default | Meaning |
| --------------------------------------------------------- | -------------------------------------------------- | ----------------------------------------------------- |
| `PM_CONSOLE_PORT`, `PM_CONSOLE_BIND` | `4872`, `127.0.0.1` | Listener; the address must be loopback |
| `PM_CONSOLE_OWNER_EMAILS` | none (nobody) | Comma-separated owner addresses |
| `PM_CONSOLE_ACCESS_TEAM_DOMAIN`, `PM_CONSOLE_ACCESS_AUD` | unset | The Access issuer; set together |
| `PM_CONSOLE_ISSUERS_FILE` | unset | JSON list of further issuers |
| `PM_CONSOLE_CERT_NAMES` | none | Certificate common names that are the owner |
| `PM_CONSOLE_DASHBOARD_URL` | `http://127.0.0.1:4870` | The dashboard behind the gate; loopback, or empty |
| `PM_CONSOLE_UNITS`, `PM_CONSOLE_PROTECTED_UNITS` | the stack's units | Units the console manages; units it will not stop |
| `PM_CONSOLE_ANDROID_PACKAGE`, `PM_CONSOLE_ANDROID_SHA256` | `today.developing.pmconsole`, none | The Android app's identity in the asset-links file |
| `PM_CONSOLE_ANDROID_APK` | `~/.local/state/pm-console/android/pm-console.apk` | The signed build the console hands to the owner |
| `PM_CONSOLE_DEVICES_FILE` | `~/.local/state/pm-console/devices.json` | Linked phones (hashes of their tokens) |
| `PM_CONSOLE_EDGE_URL` | unset (reports to nobody) | The public address the edge answers on, `https://` |
| `PM_CONSOLE_EDGE_KEY_FILE`, `PM_CONSOLE_EDGE_DONE_FILE` | `edge-key.json`, `edge-done.json` in the state dir | This host's signing key; what it ran for the edge |
| `PM_CONSOLE_MACHINE` | the host's own name | What this machine is called where machines are listed |
| `PM_CONSOLE_REPO`, `PM_CONSOLE_QUEUE` | `developing-today/code`, `repo-health-code-pilot` | What it operates on |

A malformed port, a listen address or dashboard address that is not
loopback, an edge address that is not plain `https://host`, or a
Expand Down
10 changes: 10 additions & 0 deletions pm-stack/console/edge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ action is the laptop's, relayed at once or held.
The list of actions that may be done late is `HOLDABLE` in
`../src/edge-proto.ts`.

"A machine" above is whatever reports under the key the edge holds. It
says what it is called and what it can do in each report (`machine` in
the report: its name, the kinds of action it has, the sections it
reads), and the edge keeps what it last said beside when it last
reported. `GET /console/api/machines` answers from that with no machine
asked: what the edge does itself right now (its own actions always, the
core when it has the means, less what it was turned away for), each
machine, and what is held. `held.drop` takes one held action back
before a machine has it, and records it as not sent under its name.

## How it is put together

```
Expand Down
1 change: 1 addition & 0 deletions pm-stack/console/edge/src/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export function directConfig(edge: EdgeConfig): Config {
edgeUrl: null,
edgeKeyFile: "",
edgeDoneFile: "",
machineName: "",
decisionsFile: "",
promptLabel: edge.promptLabel,
needsRepos: edge.needsRepos,
Expand Down
96 changes: 95 additions & 1 deletion pm-stack/console/edge/src/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ import {
type Held,
HOLDABLE,
keyId,
type MachineReport,
type MachinesAnswer,
machineReport,
type PublicKey,
publicKey,
subjectOf,
Expand Down Expand Up @@ -298,6 +301,10 @@ export class Edge {
private sure = 0;
private unsure = 0;
private hostVersion: string | null = null;
/** What the machine that reports says of itself: its name and what
* it can do. Null until one has said, or from a console older than
* the saying. */
private machine: MachineReport | null = null;
private latestApk: ApkMeta | null | undefined;
private keptApk: (ApkMeta & { chunks: number }) | null | undefined;
/** The build that could not be kept when it was last sent, and when. */
Expand Down Expand Up @@ -380,6 +387,43 @@ export class Edge {
touch: [],
audit: () => ({}),
},
// Something waiting for a machine is taken back by the owner
// before one has it. (One a machine was already handed may still
// be done: its answer then finds nothing waiting, and is let go.)
"held.drop": {
run: async (a) => {
await this.ready();
const held = await this.heldList();
const at = held.findIndex((h) => h.id === a.id);
if (at < 0) {
throw new OpError(404, "That is no longer waiting: a machine took it, or it was taken back already.");
}
const [gone] = held.splice(at, 1);
await this.saveHeld();
// Under its name it is over. A device that never heard it was
// kept offers it again: it is told it was taken back, and it
// is neither kept again nor handed to a machine.
await this.kv.put(`a:${gone.id}`, {
at: this.now(),
kind: gone.kind,
state: "done",
status: 410,
body: { error: "This was taken back before a machine took it." },
} satisfies Acted);
await this.actedIndex(gone.id);
await this.logAct({
Comment on lines +401 to +414

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Persist cancellation under the original action ID

If the original response saying an action was held is lost, its sending device keeps retrying it. Another device can take that action back here, but this only removes the held entry and writes an activity record; a:<original ID> remains in state given. A subsequent retry therefore passes through the relay path again, and keep() only deduplicates against currently held entries, so the canceled action is queued again—or executed immediately if the machine has returned. Persist a terminal cancellation under the original action ID and honor it before relaying or holding retries.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d5aea0c. Taking back now ends the name: a:<id> is written as done with a 410 and "This was taken back before a machine took it.", so a device that offers it again is answered from that, with the machine away or back, and it is neither kept again nor relayed. Test: offered again after the take-back, and once more after the machine returns; it is never run.


Generated by Claude Code

id: gone.id,
kind: gone.kind,
at: gone.at,
by: gone.who,
status: "failed",
note: "Not sent: taken back before a machine took it.",
});
return { dropped: gone.id, kind: gone.kind };
},
touch: [],
audit: (a) => ({ id: a.id }),
},
};
}

Expand Down Expand Up @@ -622,6 +666,46 @@ export class Edge {
await this.showEdge();
}

/** The platform's own part, each machine that reports, and what is
* held for one: what the Machines screen is drawn from. Answered
* here, so it is there with every machine away. */
private async machinesSaid(cfg: EdgeConfig | null): Promise<MachinesAnswer> {
await this.ready();
const primary = this.primary(cfg);
const refused = this.refusedKinds();
const seen = this.hostSeen || null;
return {
served: "edge",
platform: {
primary,
// What it does itself right now. Its own (notifications, linked
// phones, what is held) always; the core when it has the means,
// less what it was turned away for and a machine does for the hour.
actions: [
...Object.keys(this.table).sort(),
...(primary ? (DIRECT_ACTIONS as readonly string[]).filter((kind) => !refused.includes(kind)) : []),
],
sections: primary ? this.owned(cfg) : [],
refused: [...refused, ...this.refusedReads().map((name) => `read.${name}`)],
},
// One machine can report today: the one whose key this side holds.
machines:
seen === null
? []
: [
{
name: this.machine?.name ?? "A machine",
seen,
quiet: this.now() - seen >= HOST_QUIET_MS,
version: this.hostVersion,
actions: this.machine?.actions ?? [],
sections: this.machine?.sections ?? [],
},
],
held: [...(await this.heldList())],
};
}

/** What the app is told of this side, beside its state: how much is
* waiting for a machine, and whether this side does the core itself. */
private async showEdge(): Promise<void> {
Expand Down Expand Up @@ -672,12 +756,14 @@ export class Edge {
seq: number;
confirmed?: Record<string, { hash: string; at: number; error: string | null }>;
version?: string | null;
machine?: unknown;
}
| undefined;
this.hostSeen = host?.seen ?? 0;
this.hostSeq = host?.seq ?? 0;
this.confirmed = host?.confirmed ?? {};
this.hostVersion = host?.version ?? null;
this.machine = machineReport(host?.machine);
}
if (!this.awayRead) {
this.awayRead = true;
Expand Down Expand Up @@ -1175,7 +1261,14 @@ export class Edge {
this.hostSeen = now;
this.hostSeq = msg.at;
this.hostVersion = typeof msg.version === "string" && /^[0-9a-f]{7,40}$/.test(msg.version) ? msg.version : null;
await this.kv.put("host", { seen: now, seq: msg.at, confirmed: this.confirmed, version: this.hostVersion });
this.machine = machineReport(msg.machine);
await this.kv.put("host", {
seen: now,
seq: msg.at,
confirmed: this.confirmed,
version: this.hostVersion,
machine: this.machine,
});
if (wasSilent) {
try {
const delivery = await this.push.send("trouble", {
Expand Down Expand Up @@ -1480,6 +1573,7 @@ export class Edge {
}
if (seg.length === 1 && seg[0] === "push") return json(await this.push.status());
if (seg.length === 1 && seg[0] === "devices") return json(await this.phones.devices.list());
if (seg.length === 1 && seg[0] === "machines") return json(await this.machinesSaid(cfg));
// What needs only GitHub and the queue store is read here, by
// the code a machine would read it with.
const mine = this.mine(cfg);
Expand Down
Loading