Skip to content

feat(pm-console): the owner's switch for Cloudflare acting while the laptop is away - #12712

Merged
dezren39 merged 4 commits into
mainfrom
claude/pm-remaining
Nov 22, 2026
Merged

dezren39 merged 4 commits into
mainfrom
claude/pm-remaining

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Why

Direct mode (#12579: the edge reading and acting by itself while the laptop is away) is merged and deployed, and off. /console/health on the Worker says directEnabled: false with neither token present. Turning it on took a command on the laptop, expose.py --edge-direct on, which in turn needed wrangler installed there (npm ci in edge/). #12518 is open on exactly that last step.

What changes

A switch in the app: More → Laptop away

  • Says whether Cloudflare acts by itself, what that covers, and what the Worker's own check of each kind of read found (from the public health answer).
  • Says what turning it on hands over: the repository automation token and the queue store token, kept as the Worker's secrets.
  • The switch is an owner action, edge.direct, that runs the setup script on the laptop. It is never held for later: the tokens come from the laptop's secret store, so the laptop has to be there.

expose.py --edge-direct

  • Sends the secrets through Cloudflare's API (PUT …/workers/scripts/<name>/secrets) with the token the script already holds, instead of through wrangler. Nothing has to be installed on the laptop, and the value travels in a request body, not on a command line.
  • Turning it off now takes the two tokens away (DELETE …/secrets/<name>) instead of leaving them on the Worker. The opt-in goes off first and is remembered at once; a token left behind by a run that stopped part-way is taken away by the next run, and that tidying never fails a run.

Checks

  • python3 -m unittest: 20 pass. The direct test now covers: off by default; --check previews and does nothing; unreadable secret; Cloudflare refusing part-way (nothing remembered); the three uploads; neither value in anything printed, recorded or written; no re-upload on later runs; off removes both tokens; off stopped part-way is finished by the next run and can be turned on again.
  • bun test: 140 pass. New: the switch runs the script with on/off, records only the choice, refuses anything but a boolean, is never holdable, and passes a failure's reason on; the screen's reading of the health answer.
  • In Chrome through the edge code: the screen in its off state, the switch relayed to the host and recorded.

Not checked

  • The upload against the real account. The endpoint and body are Cloudflare's documented ones (Workers Scripts → Secrets: list, add, delete); the first real use is the owner's tap.

Refs #12518.


Generated by Claude Code


Run Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • New Features
    • Added a “Laptop away” page to view edge-serving status, direct-action readiness, and available checks, with a control to enable or disable direct actions.
    • Enabling direct actions configures the required edge access; disabling the feature removes its access tokens.
  • Documentation
    • Updated setup guidance to explain the Sign-in and Laptop away controls, direct-action setup, and how to turn the feature off.

…laptop is away

Direct mode (#12579) is merged and deployed but off, and turning it on
took a command on the laptop plus a tool that may not be installed
there. It is now a switch in the app.

- More, Laptop away: says whether Cloudflare acts by itself, what that
  covers, what the Worker's own check of each kind of read found, and
  what turning it on hands over (the repository automation token and
  the queue store token). The switch runs the setup script on the
  laptop; it is never held for later.
- expose.py --edge-direct sends the secrets through Cloudflare's API
  with the token it already holds instead of through wrangler, so the
  laptop needs nothing installed. Turning it off now takes the two
  tokens away instead of leaving them on the Worker.

Refs #12518.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
The mode is remembered as off as soon as the Worker's opt-in is off;
the two tokens are then taken away, and a token left behind by a run
that stopped there is taken away by the next run. Tidying that cannot
be done never fails a run that changes nothing else.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
@dezren39
dezren39 requested a review from a team as a code owner November 22, 2026 23:43
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T23:52:03.805250Z d884ad9 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The console adds a Laptop away view that reports edge health and offers a direct-actions toggle. The toggle calls a new console action, which invokes the expose script. The script now configures and removes Worker tokens through Cloudflare’s API and can retry cleanup after an interrupted disablement.

Changes: Laptop-away direct actions

Layer / File(s) Summary
Worker secret lifecycle
pm-stack/console/scripts/expose.py, pm-stack/console/scripts/test_expose.py, pm-stack/console/edge/README.md
The expose script uploads Worker secrets through Cloudflare’s API. When disabling direct actions, it records the off state before deleting the tokens. Tests cover check mode, upload and deletion failures, and later cleanup attempts.
Direct-action API
pm-stack/console/src/actions.ts, pm-stack/console/src/ops.ts, pm-stack/console/test/signin.test.ts
The edge.direct action validates and audits the requested state, then delegates to Ops.edgeDirect. Tests cover script arguments, invalid inputs, and script errors.
Laptop-away status and control
pm-stack/console/public/app.js, pm-stack/console/test/app.test.ts, pm-stack/console/README.md
The More page adds the Laptop away view. It displays edge health and checks, and provides an enable or disable control. Tests cover health-state mapping.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant viewAway
  participant actions
  participant OpsEdgeDirect
  participant exposepy
  participant CloudflareAPI
  viewAway->>actions: edge.direct with requested on state
  actions->>OpsEdgeDirect: call edgeDirect(on)
  OpsEdgeDirect->>exposepy: run --edge-direct on or off
  exposepy->>CloudflareAPI: upload or delete Worker secrets
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers: claude

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 556300b79d

ℹ️ 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".

Comment thread pm-stack/console/scripts/expose.py Outdated
Comment on lines +300 to +301
if wanted == current:
if not wanted and marker.exists():

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 Revoke partially uploaded tokens when explicitly turning off

If the first enable attempt uploads GITHUB_TOKEN but a subsequent PUT fails, no edge-direct marker is created. A later explicit --edge-direct off computes wanted == current == False and returns here without removing the uploaded token because the marker does not exist. Ordinary timer runs also skip cleanup forever. Run token cleanup for an explicit off request even without a marker, so failed initial provisioning can be revoked as promised.

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.

Real. Fixed in the next commit two ways: an attempt to turn it on that fails part-way takes away what it had uploaded (so it leaves the Worker holding nothing), and an explicit --edge-direct off always looks for leftover tokens, marker or not. Tested with the second upload refused, and again with the tidying refused too and a later explicit off finishing it.


Generated by Claude Code

Comment thread pm-stack/console/scripts/expose.py Outdated
Comment on lines +305 to +306
try:
take_tokens_away()

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 Serialize background cleanup with enabling direct mode

After direct mode has previously been turned off, the quarter-hour pm-console-expose.timer can run this cleanup concurrently with the new UI action: Ops.expose() starts Python directly rather than through the systemd service, and neither path takes a shared lock. If the enable run uploads GITHUB_TOKEN before the timer lists secrets, the timer can delete that freshly uploaded token while the enable run continues uploading QUEUE_TOKEN and setting EDGE_DIRECT and the marker to on. Both runs can report success, but direct mode remains unusable, and subsequent runs skip repairs because the marker already says on. Serialize the marker read, secret mutations, and marker write across script invocations.

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.

Real. Fixed in the next commit: a run that may change something takes a lock in the state directory, so the timer's run and one started from the app take turns (--status and --check only look and do not wait). And a mode that is marked on is no longer trusted blindly: each run lists what the Worker holds and gives back anything it has lost, so the state you describe could not persist even if it arose another way. A repair that fails part-way removes nothing, since the mode was on. Six planted faults in the reworked logic are each caught by the tests.


Generated by Claude Code

…urns

Two review findings on the switch:

- An attempt to turn direct mode on that failed after the first upload
  left that token on the Worker with no marker, so neither a later
  explicit off nor the timer removed it. A failed attempt now takes
  away what it uploaded, and an explicit off always looks for
  leftovers, marker or not.
- The timer's run could delete a token the app's run had just uploaded,
  leaving the mode marked on and unusable. Runs that may change
  something now take turns (a lock in the state directory), and a mode
  that is on gets back anything the Worker has lost on the next run.

Six planted faults in the reworked logic are each caught.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants