Repository navigation
feat(pm-stack): serve the PM app from the edge; the laptop becomes a worker behind it - #12505
Conversation
…worker behind it The app ran only on the laptop, behind a tunnel, so it was as available as the laptop's uplink and processor: on 2026-11-22 the uplink dropped every tunnel connection for a quarter hour (#12414) and nothing loaded. A Cloudflare Worker (pm-stack/console/edge) now sits in front of the hostname and serves the app, its state, notifications and the phone widget from Cloudflare. - State is a copy the laptop reports (only the sections that changed, signed with a key made on the laptop; the edge learns the public half by asking the laptop through the tunnel, so there is no shared secret). The app shows how old the copy is. - An action that needs the laptop is relayed at once when it is in reach. Taken while it is not, one that is safe to do late (a prompt, an answer, a comment) is held and run at most once when the laptop is back; a merge, a unit operation or a task state change is refused. - The edge answers only when it is sure of the owner and otherwise passes the request to the laptop, so a fault in its check cannot lock the owner out. If the Worker throws, or has not heard from the laptop yet, requests go to the laptop as before. - Notifications are sent from the edge, and one says when the laptop has gone quiet for ten minutes, and when it is back. - Deploys run from GitHub Actions with the Cloudflare secrets message-bridge already uses. The Worker has no secrets of its own and no route in its config: expose.py sends the hostname through it once it answers its health check, and `expose.py --edge off` takes it off. - Merged console code now puts itself into service on the laptop (redeploy.sh, every minute), after a self-check that listens on nothing; code that does not start is left out. The classes that keep state (notifications, linked phones) take a Store instead of a file path, so the same code runs in both places. Tests: 98 bun tests (18 drive the Worker's real routing and state with the laptop's real handler behind them; 6 run redeploy.sh against a checkout made for the test), 12 python tests for expose.py. 36 of 37 planted faults caught; the one left changes no behaviour. The Worker was also run in the real runtime (wrangler dev) against a local host, 17 checks, and the app was driven in Chrome through the edge code with the host up, down and back. Design record: doc/2026-11-22T11-10-00Z_architecture_pm_console_edge. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 35 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…nd the edge's alarm Same pass as the code that adds them (#12505): the laptop timer that puts merged console code into service, the console's report to the edge, and the Durable Object alarm that notices a silent laptop. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7b881dc37
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const answer = await io.host(withHeader(forHost, "x-pm-edge", "1"), ACT_MS); | ||
| if (answer === null) return tell("/internal/hold", detail); |
There was a problem hiding this comment.
Deduplicate actions before relaying or holding them
If the laptop executes a relayed action but the connection drops before its response arrives, host() returns null and this branch queues the action for execution again. For non-idempotent actions such as ask.send or issue.comment, this creates duplicate prompts or comments when the next sync runs. The immediate request and held command receive unrelated IDs, so EdgeLink.take() cannot recognize the original execution. Assign and persist a shared deduplication ID before relaying, or avoid automatically retrying an ambiguously completed request.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real. Fixed in #12511: an action is named at the edge before it is relayed (x-pm-act), the laptop writes the name down before starting and the outcome after, and a held action offered under a name it already knows is answered from that record instead of being run. One still running when the edge gave up is left to finish. Tests cover the answer lost after the work and the edge giving up mid-work.
Generated by Claude Code
| this.push = new Push( | ||
| kvStore(this.kv, "push"), |
There was a problem hiding this comment.
Migrate existing notification and phone state to the edge
When this is deployed over an existing console, the new Durable Object starts with empty push and devices stores, while the existing subscriptions, VAPID key and phone-token hashes remain only in the laptop's files; the sync protocol does not transfer them. Existing browsers consequently stop receiving notifications even though viewNotify() still reports them as enabled based on their browser subscription. Existing widgets receive unlinked: true, which android/.../Fleet.java handles by forgetting their token. Import the existing state before switching these endpoints to the edge, or implement an explicit client recovery flow.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Half real. Notifications: fixed in #12511 from the client side, with no key moved between machines. On opening, the app checks whether the sender still holds this device and under which key, and re-makes or re-registers the subscription without asking. Until a device next opens the app the laptop goes on sending to it, since its own notifier and store are untouched. Phones: none has been linked yet (the build with the widget had not been handed out when the edge went in), so nothing was lost; carrying linked phones across an edge on/off change is tracked as a follow-up.
Generated by Claude Code
| OnBootSec=2min | ||
| OnUnitActiveSec=1min | ||
| AccuracySec=10s |
There was a problem hiding this comment.
Register the new laptop redeploy timer
The new every-minute timer is enabled by pm-stack/console/install.sh, but a search of doc/fleet-schedule-registry.md finds only the existing expose timer, not pm-console-redeploy.timer. This introduces an active laptop schedule outside the unified inventory. Add its cadence, service and operating context to the registry in this change, as required by the fleet-schedules rule in AGENTS.md.
AGENTS.md reference: AGENTS.md:L56-L61
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Already in the merged change: doc/fleet-schedule-registry.md, table 6, row pm-console-redeploy.timer (with its cadence, service and context), plus rows for the report to the edge and the silent-host alarm. The review ran on an earlier commit of the branch.
Generated by Claude Code
|
|
||
| const here = dirname(fileURLToPath(import.meta.url)); | ||
| const dist = join(here, "dist"); | ||
| rmSync(dist, { recursive: true, force: true }); |
There was a problem hiding this comment.
Reject unexpected arguments before rebuilding assets
The new build entry point never validates process.argv, so node build.mjs --dry-run, a misspelled flag or a stray positional argument reaches this deletion and rebuilds the output instead of failing before side effects. The new scripts/edge-smoke.ts similarly ignores arguments before opening a listener and issuing requests. Declare each command's supported arguments and reject everything else before performing work; the operator-script contract in AGENTS.md explicitly requires this for PM-stack scripts.
AGENTS.md reference: AGENTS.md:L44-L48
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in #12511: build.mjs and edge-smoke.ts refuse any argument before doing anything (exit 2 with a usage line).
Generated by Claude Code
| while IFS= read -r line || [ -n "$line" ]; do | ||
| case "$line" in | ||
| '' | '#'* | ';'*) continue ;; | ||
| *=*) settings+=("$line") ;; |
There was a problem hiding this comment.
Decode EnvironmentFile quoting before the self-check
For a supported service setting such as PM_CONSOLE_PORT="4872", this preserves the quote characters when constructing the self-check environment, unlike systemd's EnvironmentFile parsing. env --help specifies that it sets each NAME to VALUE, so it does not remove those quotes; readConfig() then rejects the value as a nondecimal port. The failed self-check also caches the code tree in deploy-failed, preventing subsequent automatic deployment of otherwise valid code. Parse the settings with semantics matching the service; install.sh already explicitly supports quoted port values.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real. Fixed in #12511: redeploy.sh strips one pair of quotes around a value, as systemd and install.sh do; the test now uses PM_CONSOLE_PORT="4872", a single-quoted value with a space, and an unquoted value containing quotes.
Generated by Claude Code
| for (const [name, s] of this.sections) { | ||
| if (s.goodAt === 0) continue; | ||
| const hash = createHash("sha1").update(JSON.stringify(s.data)).digest("base64url"); | ||
| out.push({ name, at: s.goodAt, hash, data: s.data }); |
There was a problem hiding this comment.
Preserve loader errors when mirroring host sections
If a laptop loader fails after its first successful read, Docs.refresh() retains the old data but records ok: false and the source error. This snapshot drops both health fields, and the edge treats the retained mirror as a successful Stamped load, reporting ok: true with no error. Consequently, the existing source-failure notices rendered by public/app.js disappear when the app is served from the edge, even while GitHub or queue reads continue failing. Include section health in the protocol and propagate health changes even when the data hash is unchanged.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real. Fixed in #12511: the report says of every section whether its latest read failed and why, including when the data (and so its fingerprint) has not changed; the edge shows that with the last good copy and remembers it across its own restarts.
Generated by Claude Code
| console = console_origin(env) | ||
| # Through the edge only if that is wanted and the Worker is really | ||
| # there; otherwise straight to this host, as before the edge existed. | ||
| edge = edge_choice(env.parent, None if args.check else args.edge) |
There was a problem hiding this comment.
Apply the requested edge choice during check mode
On an otherwise reconciled edge-on installation, expose.py --check --edge off discards the explicit off argument here and evaluates the existing on state instead. It therefore reports success without proposing removal of either PM_CONSOLE_EDGE_URL or the Worker route, although running the same command without --check changes both. Separate evaluation of the requested override from persistence of the marker so check mode accurately previews the requested operation without writing files.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real. Fixed in #12511: a choice given with --check is evaluated and nothing is written. Tested both ways (on→off and off→on), including that the marker file, the route and the environment are untouched afterwards.
Generated by Claude Code
| ensure_dns(cf, args.host, tunnel, zone, dns_needed) | ||
| # Last: by now the host is up, knows where the edge is, and is | ||
| # reachable behind the hostname the Worker will sit on. | ||
| ensure_edge_route(cf, zone, args.host, edge) |
There was a problem hiding this comment.
Validate the Worker's hostname before assigning its route
When the existing --host option selects a hostname other than pm.security.cab, this installs a route to a Worker whose PUBLIC_HOST remains hardcoded to pm.security.cab in edge/wrangler.jsonc. The workers.dev health check still succeeds, but entry.ts considers requests on the alternate hostname unrouted and returns 503 for host-key acquisition and host relays. Consequently, the laptop cannot enroll or report, and the alternate-host console stops opening. Align or validate the Worker's configured hostname before routing traffic through it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real. Fixed in #12511: the Worker's health answer now says which hostname it is built for, and expose.py only routes that hostname through it.
Generated by Claude Code
| await perform(table, docs, held.kind, held.args); | ||
| docs.logAct({ ...entry, status: "done", note: "Sent late: held while the laptop could not be reached." }); | ||
| await done({ ok: true }); |
There was a problem hiding this comment.
Record refused held answers as failures
When a held question answer is rejected after reconnect—for example because another answer already resolved the question—Work.submit() returns a nonempty refused array rather than throwing. This code discards that result and logs success, causing EdgeLink.take() to acknowledge the command successfully and the edge to remove it. The owner therefore sees the answer marked done even though it was not applied; unlike the immediate path in public/app.js, nothing reports the refusal reason. Inspect the returned outcomes and preserve failed or partially refused results in the held action's status.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real. Fixed in #12511: a late answer that comes back refused is recorded as failed with the reason ("not recorded: already-resolved"), and partly refused ones say how many were recorded.
Generated by Claude Code
|
Went live at 2026-11-22T11:49Z after #12511.
Not checked: the owner's real sign-in at the edge. Generated by Claude Code |
What
The PM app is served from Cloudflare. The laptop becomes a worker behind it.
Why. The app ran only on the laptop, behind a tunnel. On 2026-11-22 the laptop's uplink dropped every tunnel connection for a quarter hour (#12414) and nothing at
pm.security.cabloaded; under the fleet's compile load the pages were slow at the best of times.Now. A Worker (
pm-stack/console/edge) sits in front of the hostname.pm-console-edge-deploy.yml, the Cloudflare secrets message-bridge already uses). The Worker has no route in its config:expose.pysends the hostname through it once it answers its health check.redeploy.sh, every minute) after a self-check; code that does not start is left out.Design record:
doc/2026-11-22T11-10-00Z_architecture_pm_console_edge/.Evidence
cd pm-stack/console && bun testpython3 -m unittest discover -s pm-stack/console/scripts--edge offremembered; another Worker's route never touched)wrangler dev) against a local hostNot verified before merge: the owner's real sign-in token at the edge. The health check counts requests the edge answered as the owner's and requests it left to the laptop, so the first real visit shows which happened.
Going back
or revert this PR.
Generated by Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.