Repository navigation
[issue sweep] Recover from an unreachable saved server target - #1519
SawyerHood wants to merge 4 commits into
Conversation
A saved remote server target went straight to a page load at startup. When the host was unreachable, `BrowserWindow.loadURL` rejected with `ERR_FAILED`, the rejection unwound to the top-level startup handler, and the window showed an Electron stack trace with no controls. The only way out was the Window menu, which the screen did not name, or hand-editing server-target.json. The `custom` and `connect` page loads now catch the rejection and show the shared startup error screen. That screen names the server that did not answer and carries two recovery buttons, Retry and Use This Mac. The window preload wires the buttons, because the view runs under `default-src 'none'` and can carry no scripts of its own. The channel stays off the main world, so a loaded page cannot switch servers. Also: `bbAppLoaded` becomes true only after a load resolves, the menu refreshes on the failure path, and the top-level handler keeps the stack in the log instead of on the screen. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🚨 SLOP COP 🚨 · I am SlopCop. I started the review for captured head I will check security, code quality, architecture, performance, and the desktop recovery route. |
| // The startup error view has no scripts of its own (CSP default-src 'none'), so | ||
| // the preload wires its recovery buttons from the isolated world. This channel | ||
| // stays off the main world on purpose: a loaded page must not switch servers. | ||
| window.addEventListener("DOMContentLoaded", () => { |
There was a problem hiding this comment.
🚨 slopcop/review — The recovery channel trusts buttons from remote pages
The preload runs on every document. A remote target can add this button and click it before loadURL resolves. The main handler then accepts use-this-mac because it checks only the global load flag. Validate the IPC sender and the exact local error view. A one-time token can also prove that the current screen offered this action.
There was a problem hiding this comment.
Real, and my change widened it. Fixed in e5c8331.
I confirmed the window you describe. The app window preload runs on the loaded server page (in-app browser views get no preload, so the exposure is the targeted bb server page itself, or an XSS on it). DOMContentLoaded fires before loadURL resolves, and this PR moved bbAppLoaded = true to after the load, so a page that shipped the same button markup and clicked it had a window where the main process accepted use-this-mac.
The fix follows your token suggestion, and adds the sender check:
loadStartupError()mints arandomUUID()per error screen and renders it into each button asdata-startup-error-token.- The preload forwards the token it read from the button. It wires no button that carries no token.
acceptStartupErrorAction()accepts a click only when the sender is a registered application window and the token equals the one the visible view rendered. The token is one use, andloadWindowUrl()clears it on every load, so the page that replaces an error screen starts with nothing to send.
A hostile page cannot read the token: it never sees that document.
Tested in test/startup-error-ipc.test.ts (9 cases: matching token, guessed token, no view offering recovery, sender that is not an application window, unknown action, missing/empty token, extra field, non-object). I also ran it in real Electron with the shipped preload.cjs: the payload arrives as {"action":"use-this-mac","token":"harness-token-1"}, the guard returns use-this-mac against the current token and null against a cleared one.
| }, | ||
| serverUrl, | ||
| }); | ||
| if (loaded) { |
There was a problem hiding this comment.
🚨 slopcop/review — A superseded load can disable the current recovery controls
loadUrlIntoWindow treats ERR_ABORTED as success. This helper then sets bbAppLoaded before applyServerTarget checks its generation. A newer failure can abort an older load, and the older task can set this flag to true. The visible error screen then rejects all recovery clicks. Move the state change after the generation check, and test two overlapping target changes.
There was a problem hiding this comment.
Real. Fixed in e5c8331.
You are right about the mechanism: loadUrlIntoWindow swallows ERR_ABORTED, so a load that a newer switch aborted returns as success. The older task could then set bbAppLoaded = true after the newer failure screen was already on screen, and the old guard would have dropped every click on visible buttons — the exact dead end this PR is meant to remove.
Two changes:
loadRemoteServerTarget()no longer touchesbbAppLoaded. Each branch ofapplyServerTarget()sets it after its ownisCurrent()check, so a superseded run cannot claim the workspace is open. The helper doc now says the caller owns the flag, because only the caller knows whether its switch is still current.- The recovery guard no longer depends on that flag at all. It checks the one-time view token instead, which
loadWindowUrl()clears on every load. So even if a stale flag were wrong again, the visible screen keeps working.
On the test you asked for: two overlapping target changes run inside applyServerTarget() in main.ts, which imports Electron at module scope and has no seam to drive it from a unit test. I did not add a fake seam just to test ordering. What I could test, I did test — the guard no longer reads that flag, so the failure mode you describe cannot silence the buttons. If you want the ordering itself locked down, that needs applyServerTarget extracted behind injected dependencies, which is a larger change than this issue.
| args: LoadRemoteServerPageArgs, | ||
| ): Promise<boolean> { | ||
| try { | ||
| await args.loadUrl({ url: args.serverUrl }); |
There was a problem hiding this comment.
🚨 slopcop/review — A half-open server can leave startup without recovery controls
This await has no product deadline. A server can accept the connection but never finish the document. The app then stays on the loading view until Chromium ends the request. Add a bounded timeout or abort policy, and ensure the old request cannot change state after the timeout screen appears.
There was a problem hiding this comment.
Correct as a gap, but I am not fixing it here. Reasons:
- It is not this bug and not a regression. The
awaitis unchanged in kind:main.tsalready didawait loadWindowUrl({ url: target.url })with no deadline. This PR only adds acatch. A half-open server behaved this way before and behaves this way after. - The reported failure rejects promptly. An unreachable host does not hang. I measured the three variants in real Electron:
ERR_NAME_NOT_RESOLVED (-105)for an unresolvable host,ERR_CONNECTION_REFUSED (-102)for a closed port, and the reporter sawERR_FAILED (-2). All three reject in about a second, and all three are now handled. - A naive deadline would hurt exactly these users. The people this fixes reach their server over a tunnel, where a slow first load is normal. A timeout also needs
webContents.stop()and a rule that the aborted request cannot change state after the timeout screen appears — the sameERR_ABORTED-is-success trap as your second finding. That is new machinery, in the path I am trying to make dependable, for a case outside the issue.
Worth noting the outcome differs too: a stalled load leaves the app on the loading view, which at least reads as "working," rather than the dead-end error screen this issue is about.
I think a bounded load deadline deserves its own issue, with a value chosen against real tunnel latency. I have not filed one, since that is a product call rather than mine to make.
There was a problem hiding this comment.
Filed as #1524 so this does not disappear with the pull request.
That issue records the finding as its own defect: the unbounded await at apps/desktop/src/remote-server-load.ts:32 and loadUrlIntoWindow() at apps/desktop/src/desktop-window-factory.ts:197, that it is pre-existing rather than caused by this change, the measured fast-failure cases this pull request does cover, and why a plain timeout race is the wrong fix — it needs webContents.stop(), it must survive ERR_ABORTED being reported as success, and it needs a deadline chosen against real tunnel latency.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
ELI5: The desktop app now shows Retry and Use This Mac when a saved server does not answer. The escape route works, but the control path trusts remote page content and has race conditions.
I reviewed captured SHA 0d3aa89dc2299c463703b55b4efffad6aba92db2. The pull request now points to a6ebcc78ed4cd4ef8e8e0211b815ff070abcb5bd.
Findings
-
High — A remote page can trigger recovery without user consent. The preload connects matching buttons on every document. The main handler does not verify the sender, the local error URL, or the actions offered by the current screen. A remote page can select and save This Mac before its load completes.
-
High — An old load can disable a newer recovery screen. Electron aborts the old navigation during an overlap. The window helper treats that abort as success. The old task can then set
bbAppLoadedbefore its caller checks the target generation. The visible error screen will reject its recovery clicks. Repeated clicks can also start concurrent actions because the handler has no action lock. -
Medium — A half-open server has no application timeout. A server can accept a connection and never complete the document. The app then shows no recovery controls until Chromium ends the request.
-
Resolved on the newer head — Connect renewal continued after a failed page load at the captured SHA. Commit
a6ebcc78now stops that renewal. -
Low — The error screen names a log directory that does not contain this failure. The remote load stack goes only to desktop stderr.
Architecture
I found no large duplicate implementation. RemoteServerStartupError duplicates the existing startup-error argument shape. More importantly, the target state, navigation generation, error actions, and global load flag remain spread through main.ts. A small target-load controller would make sender checks and overlap tests much easier.
Validation
- All 254 desktop tests passed across 34 files.
- The desktop Turbo typecheck passed.
- The desktop Turbo build passed all eight tasks.
- A real Electron run showed the unreachable-server screen and both buttons.
- Retry returned to the remote error screen.
- Use This Mac saved the built-in target and entered the local recovery path.
- The isolated local runtime did not finish, so the final workspace page did not open.
- The final GPT-5.6 review gate returned REQUEST CHANGES.
This needs follow-up for the two high-severity control-path defects and the missing timeout. I left this as a comment review, as required.
SlopCop found that the recovery channel trusted button markup. The window preload also runs on the loaded server page, and that page can host the same buttons and click them itself. `bbAppLoaded` was false until `loadURL` resolved, which left a window where a page could switch the app to the local server. The error view now renders a one-time token into each button. The preload forwards it, and `acceptStartupErrorAction()` accepts a click only from an application window, only against the token of the view that is showing. Every other page load clears the token, so a superseded screen cannot act. `bbAppLoaded` also moves after the generation check. `loadUrlIntoWindow` reports `ERR_ABORTED` as success, so an older aborted load could otherwise mark the workspace open over a newer failure screen and make the visible recovery buttons dead. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🚨 SLOP COP 🚨 · I am SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior. |
| return true; | ||
| } catch (error) { | ||
| args.logWarning( | ||
| `[desktop] could not load the bb server at ${args.serverUrl}: ${ |
There was a problem hiding this comment.
🚨 slopcop/review — Redact secrets from the displayed and logged server URL
normalizeCustomServerUrl() keeps URL user information and query data. A saved target such as https://user:[email protected]/?token=secret therefore puts those secrets on the recovery screen and in stderr after a failed load. The Electron error can repeat the full URL too. Please use a safe origin or host for user-facing text, and redact the URL inside the logged error. Keep the complete URL only for the load request.
There was a problem hiding this comment.
Real. Fixed in 30ca11b.
I checked the claim before acting on it: normalizeCustomServerUrl() (apps/desktop/src/server-target.ts:88) clears only hash. It keeps username, password, and search, so https://alice:[email protected]:38886/?token=s3cret is savable and reached both the recovery screen and stderr in full — and the Electron message repeated it a second time in the same log line.
describeServerUrl() now splits the target into what may be printed and what may not:
- Screen: the server is named with user information, query, and fragment stripped, so the host and port still appear. Naming the unreachable host is the point of the screen, so that part survives.
- Log: when the saved URL holds a credential or a query value, only the Electron error code is kept (
ERR_CONNECTION_REFUSED (-102)). I did not try to scrub the message, because I cannot prove an arbitrary message is free of the secret; the code is the part with diagnostic value. A target with no secret still logs the full stack, so ordinary debugging is unchanged. - Load request: unchanged. It still gets the complete URL, and a test asserts that.
- An unparseable target names nothing rather than echo raw input.
Four cases in test/remote-server-load.test.ts cover it: the secret URL (asserting the username, password, token value, and token= appear in neither the screen text nor the log, while the host does), the unparseable URL, the complete URL still reaching loadUrl, and the existing no-secret case that keeps the full stack.
One note on scope: this leak predates the PR in a worse form. An unreachable custom target used to render error.stack on screen, and that stack contains the full URL. So this is a fix, not only a new guard.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
ELI5: A saved bb server can be asleep. This change gives the app two safe buttons, like two doors. You can try again or return to this Mac.
I found one low-severity security issue. A custom server URL can contain a password or token. The failure path shows the complete URL and writes it to stderr. I left an inline comment that asks for a safe server label and log redaction.
The recovery design is otherwise sound. The main process checks a random, one-use token and the application window sender. Each new page load clears the token. I found no performance defect.
The exact commit passed all 263 desktop tests and the Turbo desktop typecheck. GitHub checks also pass.
I tested the route in Electron through the Dev Browser. An unreachable saved target showed Retry and Use This Mac. Retry produced a new recovery view. Use This Mac opened the local app and saved the built-in target.
The change adds no large duplicate implementation. RemoteServerStartupError duplicates the startup-error input shape. A later navigation controller could also group generation, load-state, and recovery-token rules. These are optional refactors.
SlopCop found that `normalizeCustomServerUrl()` clears only the fragment. A saved target such as `https://user:[email protected]/?token=secret` therefore reached the recovery screen and stderr in full, and the Electron message repeated it again. `describeServerUrl()` now names the server without its user information or query string. When the saved URL holds either, the log keeps only the Electron error code, because the rest of that message repeats the URL. A target with no secret still logs the full stack. The load request itself keeps the complete URL. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Closing without merging. This came out of the 13 Aug 2026 overnight issue sweep. Sawyer is closing the unmerged sweep pull requests rather than carrying them. The branch is left in place, so this can be reopened or cherry-picked. The review history, the measurements, and the answers to each Slop Cop finding stay on this pull request.
|
## What was wrong `applyServerTarget()` in `apps/desktop/src/main.ts` awaited `loadWindowUrl()` for `custom` and `connect` targets with no handler. `BrowserWindow.loadURL` rejects for every network-level failure (`ERR_CONNECTION_REFUSED`, `ERR_CONNECTION_TIMED_OUT`, `ERR_FAILED`, ...). At launch that rejection unwound to `runDesktopApp().catch(...)`, which rendered `error.stack` into the static, script-less error view: "Could not open bb" plus Electron internals and nothing to click. From Window > Server the same rejection was unhandled (`void setActiveServerTarget(...)`), so the window went blank and `bbAppLoaded` stayed `true`. `bbAppLoaded` was also set before the load was known to have succeeded. Issue: #1494. Report: https://get-bb.github.io/reports/issues/1494.html ## What changed - `apps/desktop/src/remote-server-load.ts` (new): `loadRemoteServerPage()` loads the remote URL and, on rejection, logs only the Electron error code plus the server origin and renders the shared startup error view: "Could not reach this bb server. The bb server at `<origin>` did not answer. Check that the machine is awake and reachable, then choose Window > Server to retry this server or switch to This Mac." `describeServerUrl()` prints only the origin, because a saved custom URL can carry a credential or a query token. A load the user already superseded (generation check) shows nothing. - `apps/desktop/src/main.ts`: both remote branches of `applyServerTarget()` go through a small `loadRemoteServerTarget()` wrapper around that helper. `bbAppLoaded` flips and the remote system-config sync starts only after the page loaded. A failed `connect` load stops the session renewal it had just started. `refreshApplicationMenu()` now runs on the failure path too. Deviation from the issue's proposal: this PR does not add Retry / Use This Mac buttons. The `data:` error view runs under `default-src 'none'` with no preload, so buttons need a new main-process IPC surface (that is what the closed #1519 built, +768 lines). This PR fixes the root cause (an unhandled rejection) and gives the user the server name and the existing menu route; the error view now has parity with the builtin and Connect-authentication failures. Actionable buttons can follow as a separate UI change. No wire, CLI, or doc changes. ## How you verified Live repro on origin/main with the built desktop shell under Xvfb (Electron, Linux), saved `custom` target `http://127.0.0.1:47771` with nothing listening: ``` BODY TEXT: Could not open bb Error: ERR_CONNECTION_REFUSED (-102) loading 'http://127.0.0.1:47771/' at rejectAndCleanup (node:electron/js2c/browser_init:2:89743) ... interactive controls on page: 0 ``` Re-selecting the same target from Window > Server on main: `URL: chrome-error://chromewebdata/`, empty body, 2x `UnhandledPromiseRejectionWarning` on stderr. Same two steps on this branch: ``` BODY TEXT: Could not reach this bb server The bb server at http://127.0.0.1:47771 did not answer. Check that the machine is awake and reachable, then choose Window ▸ Server to retry this server or switch to This Mac. Logs are under .../logs/. ``` stderr: `[desktop] could not load the bb server at http://127.0.0.1:47771: ERR_CONNECTION_REFUSED (-102)`, 0 unhandled rejections. Menu re-select shows the same named error instead of a blank window. Starting a server on 47771 and re-selecting the target from the menu then loads the page (`URL: http://127.0.0.1:47771/`). Tests: `apps/desktop/test/remote-server-load.test.ts` (6 tests) covers the error view copy and title, that the stack never reaches the screen, credential/query redaction on screen and in the log, the superseded-load path, and the success path. With origin/main's `main.ts` and without the new module the file fails with `Error: Cannot find module '../src/remote-server-load.js'` (the code path under test did not exist; `main.ts` runs on import and is not unit-testable). `apps/desktop/src/main.ts` is exercised by the live repro above. `pnpm exec turbo run typecheck test --filter=@bb/desktop --force` on the committed tree: `Tasks: 5 successful, 5 total`, `Test Files 35 passed (35)`, `Tests 228 passed (228)`. Fixes #1494 > AGENT GENERATED: by Claude Opus 5 ## Independent verification Verified by a second agent on a fresh worktree (`git fetch origin bb/fix-1494-remote-target-dead-end && git checkout -b verify-1494-r1 FETCH_HEAD`, HEAD `2bb375108`, `origin/main` is an ancestor, PR reports `MERGEABLE`). Commands run: - `pnpm install --frozen-lockfile --prefer-offline && pnpm exec turbo run build` - Fail-before: `git checkout origin/main -- apps/desktop/src/main.ts && rm apps/desktop/src/remote-server-load.ts`, then `pnpm exec vitest run test/remote-server-load.test.ts` from `apps/desktop` -> `FAIL ... Error: Cannot find module '../src/remote-server-load.js'` (1 failed suite). The helper under test does not exist on main; `main.ts` runs on import, so the call site itself has no unit seam. - Pass-after: `git checkout HEAD -- <those files>`, same command -> `Test Files 1 passed (1), Tests 6 passed (6)`. - `pnpm exec turbo run typecheck test --filter=@bb/desktop --force` -> `Tasks: 5 successful, 5 total`, `Test Files 35 passed (35)`, `Tests 228 passed (228)`. Live repro (built Electron shell under `xvfb-run`, own `--user-data-dir` and `BB_DATA_DIR` under `~/.bb-dev/scratch/1494-verify/`, saved custom target `http://127.0.0.1:47771` with nothing listening, CDP on 49333, main-process inspector on 49334; the report's `run-desktop-unreachable.sh`, `cdp-screenshot.mjs`, and `main-click-server-menu.mjs`): - Built from origin/main's `main.ts` (bug confirmed): startup body `Could not open bb / Error: ERR_CONNECTION_REFUSED (-102) loading 'http://127.0.0.1:47771/' at rejectAndCleanup (node:electron/js2c/browser_init...)`, 0 interactive controls. Window > Server > re-select same target: URL `http://127.0.0.1:47771/`, empty body, 2x `UnhandledPromiseRejectionWarning` on stderr. - Built from this branch: startup body `Could not reach this bb server / The bb server at http://127.0.0.1:47771 did not answer. Check that the machine is awake and reachable, then choose Window ▸ Server to retry this server or switch to This Mac.`; stderr `[desktop] could not load the bb server at http://127.0.0.1:47771: ERR_CONNECTION_REFUSED (-102)`; 0 unhandled rejections. Menu re-select shows the same named error (no blank window). After starting an HTTP server on 47771, menu re-select loads `http://127.0.0.1:47771/` (body `fake bb server up`), so the menu route recovers. CI at verification time: 11 checks pass, 2 skipped (Node Compatibility Smoke, iOS simulator flows), none failing or pending. Residual risks (none blocking): the unit test proves the helper's contract, not the `applyServerTarget()` call site (covered by the live repro only); the error view still has no clickable Retry / Use This Mac control; a half-open host still waits for Chromium's connect timeout before the named error appears (#1524); the loading view copy still says "Starting local services" for remote targets; the `connect` failure branch was checked by code reading only (no bb Connect server here); verified on Linux/Xvfb, not macOS (no platform branch in the changed code). > AGENT GENERATED: by Claude Opus 5 Co-authored-by: Claude <[email protected]>
Summary
A saved remote server target went straight to a page load at startup. When the host was unreachable,
BrowserWindow.loadURLrejected, the rejection unwound to the top-level startup handler, and the window showed a raw Electron stack trace with no controls. The only way out was the Window ▸ Server menu, which the screen did not name, or hand-editingserver-target.json.The
customandconnectpage loads now catch the rejection and show the same startup error screen the builtin and Connect-authentication failures use. That screen names the server that did not answer and carries two recovery buttons: Retry and Use This Mac.apps/desktop/src/remote-server-load.ts(new):loadRemoteServerPage()wraps the load. On rejection it logs the Electron detail and asks for the recovery screen. It never rethrows.apps/desktop/src/main.ts: both remote branches ofapplyServerTarget()go through that guard,refreshApplicationMenu()runs on the failure path so the menu no longer shows a target the app never reached, and a failed Connect load stops that server's session renewal.bbAppLoadedbecomestrueonly after the load resolves and after the generation check, becauseloadUrlIntoWindow()reportsERR_ABORTEDas success — an older aborted load must not mark the workspace open over a newer failure screen.apps/desktop/src/local-view.ts: the existing error view gained anactionslist. It renders no second design — the same shell, plus a button row.actionsis required on every call site, so each failure screen states its own recovery explicitly.apps/desktop/src/preload.ts: the view runs underdefault-src 'none'and can carry no scripts, so the window preload wires the buttons from the isolated world. This is the pattern the "bb is already running" dialog already ships. The channel stays off the main world on purpose: a loaded page must not be able to switch servers.apps/desktop/src/startup-error-ipc.ts(new): the channel, the action enum, the payload schema, andacceptStartupErrorAction(), which decides whether a click may act.A saved URL can hold a secret.
normalizeCustomServerUrl()clears only the fragment, so a target can carry user information or a query token.describeServerUrl()names the server on screen with those parts stripped, and when they are present the log keeps only the Electron error code, since the rest of that message repeats the URL. The load request still gets the complete URL.The click has to prove where it came from. That same preload also runs on the loaded server page, and a page can host the same button markup and click it itself. So markup proves nothing. Each error screen renders a one-time
randomUUID()token into its buttons; the preload forwards the token it read; the main process accepts a click only from a registered application window, and only against the token of the view that is showing.loadWindowUrl()clears the token on every load, so a superseded screen, a repeated click, and a page that replaced an error screen all act on nothing. A hostile page cannot read the token, because it never sees that document.The
use-this-maclabel followsBUILTIN_SERVER_NAME, so the button and the Server menu entry cannot drift apart.Two notes on scope:
probeBbServerfirst. A probe cannot replace the guard — the host can die between the probe and the load — so this change adds the guard only, and no second round trip on the happy path.Testing
pnpm exec turbo run typecheck --filter=@bb/desktoppasses.pnpm exec turbo run test --filter=@bb/desktop --force: 233 tests pass. Four suites fail to load on this Linux worktree because itsnode_moduleshas no Electron binary (desktop-window-factory,existing-server-dialog,window-state,preload-build). They fail the same way on the base commit and none of them are touched here.New automated tests:
test/remote-server-load.test.ts: aloadUrlthat rejects with the reporter's exact error (ERR_FAILED (-2)plus anode:electron/js2cframe) produces a handled outcome — the guard returnsfalse, the screen text names the server and contains neitherERR_FAILEDnorjs2c, and the log line contains both.test/local-view.test.ts: the error view renders the two buttons with the exact attribute the preload queries, and renders no button row when a failure has no recovery action.test/preload-browser-api.test.ts: a click on each rendered button reaches the main process onbb-desktop:startup-error:actionwith the right action and the view's token.test/remote-server-load.test.tsalso covers redaction: a saved URL with a credential and a query token leaks neither to the screen nor to the log while still naming the host, an unparseable target names nothing, andloadUrlstill receives the complete URL.test/startup-error-ipc.test.ts: nine cases on the trust decision — a matching token is accepted; a guessed token, a click while no view offers recovery, a sender that is not an application window, an unknown action, a missing or empty token, an extra field, and a non-object payload are all refused.Manual verification. I cannot reproduce macOS-over-Tailscale, so I simulated an unreachable host with a throwaway Electron harness (deleted before commit) that drove a real
BrowserWindowwith the real builtpreload.cjs:That confirms the four things I could not confirm by reading:
loadURLreally does reject for an unreachable host, the production guard turns that rejection into the named screen, a button underdefault-src 'none'really does reach the main process through the preload, and the token survives the round trip — the same payload is accepted against the live token and refused once it is cleared. A captured page image shows both buttons below the message, inside the shell padding and clear of the title-bar drag region.For a reviewer on macOS: open Server ▸ Set Server URL…, enter
http://127.0.0.1:38999, relaunch. Before this change the window shows the Electron stack; after it, the recovery screen. Retry re-runs the saved target; Use This Mac starts the local server and opens the workspace.Follow-up: #1524 tracks the one review finding this pull request does not fix — a saved target that accepts the connection and never answers still has no load deadline. That is pre-existing, and a naive timeout would abort slow but healthy tunnel loads.
Fixes #1494