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
66 changes: 61 additions & 5 deletions .github/workflows/pm-console-edge-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@ name: pm-console-edge deploy
# (pm-stack/console/edge): every push to main that touches the console,
# or a manual run, runs the console's tests (which drive the Worker's
# routing and state against the host's real handler), bundles the
# Worker, and uploads it with the CLOUDFLARE_API_TOKEN and
# Worker, and releases it with the CLOUDFLARE_API_TOKEN and
# CLOUDFLARE_ACCOUNT_ID repository secrets, the ones message-bridge
# deploys with.
#
# The release (pm-stack/console/edge/release.mjs) starts from whatever
# is there, including nothing:
# 1. no Worker of that name: an empty one is stood up (edge/init);
# 2. this commit is uploaded as a version, which serves nothing yet;
# 3. that version is put at 100%;
# 4. the Worker is asked which version it is, and if it does not
# answer as this commit the version that was serving is put back
# and the run fails.
# So nothing outside this workflow is needed to bring the Worker up in
# an account that has none. That path is run for real, on a scratch
# Worker that is removed first and removed again afterwards, whenever a
# push changes how the Worker is stood up, and on a manual run that asks
# for it (scratch). The real Worker is not touched by that.
#
# The Worker has no secrets from this deploy: the keys it uses it makes
# itself, or are published by the host. Three secrets are optional, put
# there by the host's scripts/expose.py --edge-direct (off by default):
Expand Down Expand Up @@ -38,6 +52,10 @@ on:
description: "Existing Worker version id to put back instead of uploading; empty deploys this commit"
required: false
default: ""
scratch:
description: "First stand a scratch Worker up from nothing, deploy this commit to it, check it and remove it"
type: boolean
default: false

permissions:
contents: read
Expand All @@ -52,7 +70,7 @@ jobs:
deploy:
name: deploy pm-console-edge
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 30
steps:
- name: Check deploy secrets
id: secrets
Expand All @@ -77,11 +95,46 @@ jobs:
- name: Install the deploy tool
working-directory: pm-stack/console/edge
run: npm ci --no-audit --no-fund
- name: Bundle the Worker
- name: Bundle the Worker, and the empty one it is stood up from
working-directory: pm-stack/console/edge
run: |
node build.mjs
npx wrangler deploy --dry-run --outdir .wrangler/dry
npx wrangler deploy --dry-run --config init/wrangler.jsonc --outdir .wrangler/dry-init
- name: See whether this push changes how the Worker is stood up
id: standup
if: steps.secrets.outputs.ready == 'true' && inputs.rollback_version == ''
env:
GH_TOKEN: ${{ github.token }}
ASKED: ${{ inputs.scratch }}
BEFORE: ${{ github.event.before }}
run: |
# A manual run says whether it wants the scratch stand-up. A
# push gets it when it touches the release itself. If what
# the push changed cannot be read, the stand-up is run: it
# costs a few minutes and risks nothing.
scratch=false
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
if [ "$ASKED" = "true" ]; then scratch=true; fi
elif ! printf '%s' "${BEFORE:-}" | grep -Eq '^[0-9a-f]{40}$' || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
scratch=true
elif files="$(gh api "repos/${GITHUB_REPOSITORY}/compare/${BEFORE}...${GITHUB_SHA}" --jq '.files[].filename')"; then
if printf '%s\n' "$files" | grep -Eq '^(pm-stack/console/edge/(release\.mjs|release-plan\.mjs|wrangler\.jsonc|package\.json|package-lock\.json|init/.*)|\.github/workflows/pm-console-edge-deploy\.yml)$'; then
scratch=true
fi
else
scratch=true
fi
echo "scratch=$scratch" >> "$GITHUB_OUTPUT"
- name: Stand a scratch Worker up from nothing, deploy this commit to it, and remove it
if: steps.standup.outputs.scratch == 'true'
working-directory: pm-stack/console/edge
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
node release.mjs --sha "$GITHUB_SHA" --scratch
echo "Stood pm-console-edge-scratch up from nothing, deployed ${GITHUB_SHA::12} to it, heard it answer, and removed it." >> "$GITHUB_STEP_SUMMARY"
- name: Deploy
if: steps.secrets.outputs.ready == 'true'
working-directory: pm-stack/console/edge
Expand All @@ -100,7 +153,10 @@ jobs:
npx wrangler rollback "$ROLLBACK_VERSION" --yes --message "rollback from workflow run ${GITHUB_RUN_ID}"
echo "Put pm-console-edge back to version ${ROLLBACK_VERSION}." >> "$GITHUB_STEP_SUMMARY"
else
npx wrangler deploy --var "VERSION:${GITHUB_SHA::12}" --message "git ${GITHUB_SHA}"
# Stands the Worker up if there is none, uploads this commit
# as a version, puts it at 100%, and puts the previous
# version back if this one does not answer.
node release.mjs --sha "$GITHUB_SHA"
echo "Deployed pm-console-edge from ${GITHUB_SHA}." >> "$GITHUB_STEP_SUMMARY"
fi
- name: Check the deployed Worker answers
Expand All @@ -116,7 +172,7 @@ jobs:
| python3 -c 'import json,sys; print(json.load(sys.stdin)["result"]["subdomain"])')"
url="https://pm-console-edge.${sub}.workers.dev/console/health"
want="${GITHUB_SHA::12}"
for attempt in $(seq 1 20); do
for _ in $(seq 1 20); do
got="$(curl -fsS --max-time 10 "$url" | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d.get("version") if d.get("ok") and d.get("edge") else "")' 2>/dev/null || true)"
if [ "$got" = "$want" ]; then
echo "pm-console-edge answers as ${want}." >> "$GITHUB_STEP_SUMMARY"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,41 @@ Still open, and why:
staged in #12561 and needs two protected environments with their own
tokens before it can run.
- The Android project is still on androidbrowserhelper 2.5.0.

## 2026-11-23T01:25Z Update: the build never holds up a report

The last three commits of the Android-build change (#12723) merged
before any reviewer read them, so they were read again afterwards. Two
real faults came out of that: one in how the build travels, one in how
the edge keeps it.

A report that carries the build is megabytes; every other report is
kilobytes. The laptop gives a report twenty seconds. On a connection
too slow to send the build in that time, the report failed, and the
next was built the same way and failed too, for as long as the edge
still lacked the build. In that time no report arrived at all, so the
edge took the laptop for gone while it was there. Nothing of the kind
could happen before the build was put into reports.

- A report that carried the build and did not get through, whether cut
off or turned away, is followed at once by one without the build.
The build is tried again ten minutes later. At worst one report in
ten minutes is lost to it.
- A build file that cannot be read is left out the same way, where it
used to stop the report.
- Whether the build and the changed sections fit one report is now
measured on the report as sent, in bytes. It was estimated in
characters, and text outside ASCII is up to three bytes a character,
so the estimate could pass a report the edge then refused as too
large.
- When the build goes alone, the sections it displaced follow at once
instead of at the next ordinary report.

- The edge wrote a new build over the pieces of the old one and only
then recorded the new build. A write that stopped half-way left
pieces of two builds under the old record, and with the laptop away
those were handed out as the old build. The old record is now removed
before its pieces are touched, so a half-written copy is no copy: the
edge says it has none, hands nothing out, and asks for the build
again. Pieces left by a larger build are removed whether or not its
record survived.
45 changes: 43 additions & 2 deletions pm-stack/console/edge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ runs the fleet's tools can be reached.
| Direct actions (reply to or close a prompt, comment, rank an issue, move a task) | edge, once the laptop has been quiet for a minute | run at the edge through the laptop's own classes, and never sent to the laptop, so they are not done twice; a new prompt is filed at the edge and only its queue task is held for the laptop |
| Actions not safe to do late (merge, units, unblock, …) | laptop, relayed at once | refused, saying why |
| The dashboard's own pages, logs, one pull request's page | laptop | a plain notice with a link to the app |
| The signed Android build (`/console/pm-console.apk`) | laptop, and a copy at the edge | the copy is served, and the app says so when the copy is older than the laptop's newest |

The list of actions that may be done late is `HOLDABLE` in
`../src/edge-proto.ts`.
Expand Down Expand Up @@ -50,6 +51,15 @@ laptop: pm-console (../src/server.ts), reporting through ../src/sync.ts
state that changed, how current each unchanged one is, and what became
of anything held for it. The answer says whether anyone is looking, and
carries the actions the owner took while it was away.
- **The signed Android build travels in a report**, once per build, when
the edge says it lacks it, and is kept only if it matches its
fingerprint. It never stands in the way of the reports themselves,
which are how the edge knows the laptop is there. Beside sections that
would take the report past its room (counted in bytes as sent) it goes
alone and they follow at once. If a report carrying it does not get
through (a slow connection runs out of time, or it is turned away), or
the file cannot be read, the reports after that go without it, and it
is tried again ten minutes later.
- **An action for the laptop is relayed at once** when the laptop is in
reach; its answer carries what it read again, so the edge's copy shows
the change before the next report.
Expand Down Expand Up @@ -113,8 +123,39 @@ sign-in issuer's).
Pushes to `main` that touch the console deploy it
(`.github/workflows/pm-console-edge-deploy.yml`): the console's tests,
which drive this Worker's routing and state against the laptop's real
handler; a bundle; `wrangler deploy`; then a check that the deployed
Worker answers its health check as that commit.
handler; a bundle; the release; then a check that the deployed Worker
answers its health check as that commit.

The release is [`release.mjs`](release.mjs), and it starts from whatever
is there, including nothing:

1. No Worker of that name: an empty one is stood up
([`init/`](init/worker.ts): the Durable Object's class and an answer
that says it is empty). A version cannot be uploaded to a Worker that
does not exist, and the storage behind the class is only made by a
deploy.
2. This commit is uploaded as a version. It serves nothing yet.
3. That version is put at 100%.
4. The Worker is asked which version it is. If it does not answer as
this commit, the version that was serving is put back and the run
fails.

A new Durable Object migration in `wrangler.jsonc` cannot travel in a
version, so then steps 2 and 3 are one `wrangler deploy`.

So an account with no Worker needs nothing but this workflow to get
one. That is not taken on trust: whenever a push changes the release
itself (`release.mjs`, `release-plan.mjs`, `init/`, `wrangler.jsonc`,
the lockfile or the workflow), and on a manual run with `scratch`, the
same steps are first run on `pm-console-edge-scratch`, which is removed
before (so the start is nothing) and removed after. The real Worker is
not touched by that, and the scratch one is the only Worker the script
will ever delete.

```bash
gh workflow run pm-console-edge-deploy.yml # deploy main's head
gh workflow run pm-console-edge-deploy.yml -f scratch=true # and show the stand-up from nothing first
```

The Worker has no route in `wrangler.jsonc` on purpose. The laptop's
`scripts/expose.py` (on a 15 minute timer) sends the hostname through it
Expand Down
25 changes: 25 additions & 0 deletions pm-stack/console/edge/init/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// The Worker before its first version: the object's class, so that its
// state has somewhere to live, and an answer that says there is nothing
// here yet.
//
// A version cannot be uploaded to a Worker that does not exist, and the
// storage behind a Durable Object class is only created by a deploy. So
// when there is no Worker, release.mjs deploys this one first and then
// uploads the real one over it as a version.
//
// It answers 503 with `ok: false` on purpose: the host's
// scripts/expose.py sends the hostname through the Worker only once its
// health check says `ok`, and an empty Worker must never get the
// hostname.
import { DurableObject } from "cloudflare:workers";

export class PmEdge extends DurableObject {}

export default {
fetch(): Response {
return new Response(JSON.stringify({ ok: false, edge: true, empty: true }), {
status: 503,
headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
});
},
};
17 changes: 17 additions & 0 deletions pm-stack/console/edge/init/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// The empty Worker release.mjs stands up when there is none: see
// worker.ts. Everything here that is not a version's own (the name,
// the Durable Object class and its migration, the workers.dev
// address, logs) must say what ../wrangler.jsonc says; a test holds
// the two together (test/release.test.ts).
"name": "pm-console-edge",
"main": "worker.ts",
"compatibility_date": "2026-10-01",
"compatibility_flags": ["nodejs_compat"],
"workers_dev": true,
"preview_urls": false,
"observability": { "enabled": true },
"vars": { "PUBLIC_HOST": "pm.security.cab", "VERSION": "empty" },
"durable_objects": { "bindings": [{ "name": "PM", "class_name": "PmEdge" }] },
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["PmEdge"] }]
}
Loading