Repository navigation
feat(pm-console): the owner's switch for Cloudflare acting while the laptop is away - #12712
Conversation
…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
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. |
|
Caution Review failedThe pull request is closed. Walkthrough
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. |
There was a problem hiding this comment.
💡 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".
| if wanted == current: | ||
| if not wanted and marker.exists(): |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
| try: | ||
| take_tokens_away() |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
Why
Direct mode (#12579: the edge reading and acting by itself while the laptop is away) is merged and deployed, and off.
/console/healthon the Worker saysdirectEnabled: falsewith neither token present. Turning it on took a command on the laptop,expose.py --edge-direct on, which in turn neededwranglerinstalled there (npm ciinedge/). #12518 is open on exactly that last step.What changes
A switch in the app: More → Laptop away
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-directPUT …/workers/scripts/<name>/secrets) with the token the script already holds, instead of throughwrangler. Nothing has to be installed on the laptop, and the value travels in a request body, not on a command line.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;--checkpreviews 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 withon/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.Not checked
Refs #12518.
Generated by Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit