Skip to content

Desktop: end setup when OpenBot's page says the window's code traded, not before - #2934

Draft
ACl365 wants to merge 4 commits into
mainfrom
alex/2026-12-04/desktop-trade-success
Draft

ACl365 wants to merge 4 commits into
mainfrom
alex/2026-12-04/desktop-trade-success

Conversation

@ACl365

@ACl365 ACl365 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

What this changes

Since 1.2.8 (#2768), Desktop counts a connection through the window's own sign-in before that sign-in has worked. Once the browser sign-in comes back, Connect saves the connection, ends setup and counts openbot_connect completed. All of that happens before OpenBot's page at /desktop/signed-in trades the code for the window's session. A first setup whose trade then fails shows Sign in again, and a quit there counts as a setup that connected. This is the follow-up from #2791's review (desktop_connected.rs:1309).

Why. The page told Desktop when the trade failed (window_sign_in_failed) and never when it worked, so Desktop had nothing to wait for.

The fix. The page now tells Desktop when the trade works, the same way: a new page command, window_signed_in, beside window_sign_in_failed. Desktop ends setup and counts completed then.

One difference from "keep today's behaviour" for an older server, for your yes or no. An older page never sends window_signed_in, and Desktop still counts its good trades (below). Its failed trades are now counted as failed, like a new page's: failed, and setup_abandoned on quit, instead of today's completed. That's because every page already reports a failure. A quit during an older page's trade is also setup_abandoned now, and its completed comes after the trade. Keeping today's count exactly would mean keeping the miscount your review flagged. If you'd rather keep it, see Decisions.

In the page (app/):

  • finishWindowSignIn sends window_signed_in after a good trade and before the window goes on to next. A refused or missing code sends window_sign_in_failed as before, and never window_signed_in.
  • It waits at most 3 s for Desktop's answer (SIGNED_IN_TELL_WAIT_MS), so a Desktop that doesn't answer never holds the window there. Outside Desktop it sends nothing. A Desktop from before the command refuses it, and the window goes on.

In Desktop (desktop/src-tauri/):

  • Saved before the trade, kept after it. Connect still writes connection.json before the window goes to the page, because the window's own commands, the failure path and Sign in again read it (save_choice). It no longer ends setup there. Instead it holds a pending trade: the window's origin and, for Connect from the first screen, the screen, the window's wait and when Connect was asked.
  • window_signed_in, from /desktop/signed-in on the window's origin only (the ACL grants that origin, and the command checks the page), takes the trade. It ends setup and counts completed from the press. Said again, it changes nothing.
  • window_sign_in_failed takes the trade and counts failed from the press, since the window that pressed Connect has left for OpenBot's page and only Desktop can end its started. Letting go of the window's sign-in (forget_window_sign_in) no longer ends setup.
  • A quit while the trade runs, or at Sign in again after a first setup's failed trade, is setup_abandoned.
  • Counted once. Whatever settles the trade takes it under one lock.
  • A window Desktop shows anew while a trade waits (setup reopening the saved connection after a page load that never arrived) drops the trade.
  • The relay path and Move to Cloud are unchanged.

An older OpenBot. Desktop has to tell "an older page" from "the trade is still running". It does so from what the webview already reports, with no timeout and no server change:

  • An older page leaves /desktop/signed-in only after a good trade (location.replace(next)). After a bad one it says so and stays.
  • So once that page has loaded (a finished load, or the page answering), the window loading any other page on its origin while the trade waits counts as the trade done (older_page_traded). Setup ends and completed is counted. The count runs on its own thread, off the page-load handler.
  • A load elsewhere before that page loaded (a proxy or challenge sending the window away first) is not a trade, and counts nothing.

A timeout is wrong both ways: a slow trade gets counted before it works, or a quick quit after a good trade gets counted as abandoned. A flag in the server's metadata is Decision 2.

Decisions for you

  1. Older servers' failed trades (above). Yes means counted as failed, as this PR does. No means one optional field on the new page's window_sign_in_failed, with today's count when it's absent.
  2. A server flag instead. A field in the window sign-in's metadata saying the page sends window_signed_in would let Desktop keep exactly today's behaviour when the field is absent. The metadata is the server's, though, and during a rolling upgrade it need not match the release serving the page. I left it out.
  3. A crash while the trade runs, or after a failed first trade, is still not setup_abandoned. The next launch finds the saved connection and closes the session, as before. Counting it needs a second "kept" marker on disk, or not saving the connection until the trade, which changes what Sign in again shows. TELEMETRY.md says so, and a test pins it.

Where it runs

  • New state that outlives a request? No. The pending trade lives in Desktop's memory for one Connect. connection.json is written when it was before.
  • What happens on the second replica? n/a: Desktop and its window.
  • Anything serialised? No.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No: one page command.

Boundary and audit

  • Every acting call still goes through the gateway: nothing here calls the server.
  • No new refusal writes a row. window_signed_in from anywhere but the trade's page is refused by the ACL or the command, and is a page-to-Desktop message.
  • Nothing new is trusted from the client: Desktop reads the page's origin and path from the webview, not from the message, which carries nothing.

API and database

  • I read docs/api-and-migrations.md. Nothing under api/ changes: no request, server route, database or release-policy.json change. window_signed_in is a Tauri command under Desktop's ACL (build.rs, desktop_page::PERMISSIONS, the generated capability schemas).

Changelog

OpenBot Desktop.

  • Usage data counts a connection through the window's own sign-in once OpenBot's page has signed the window in, not before. A first setup whose sign-in didn't finish and is then quit now counts as abandoned, and the sign-in as failed. Nothing changes in the app (desktop/TELEMETRY.md).

Proof

Local, at 82a5c4ed8 on main ab684e590, on Bun 1.4.3 as CI runs it, and Rust stable 1.100. Since then main gained #2929, #2930 and #2931 (checked 12:00 UTC, 4 Dec). None touches this change's files, and the routes above are unchanged.

Tests across each boundary

  • Page to Desktop, through Tauri's IPC and ACL. The Rust tests send plugin:openbot-desktop|window_signed_in and window_sign_in_failed by name from the window's address, through the plugin's handler under its ACL (window_shell). The setup window, another host or port, another page on the origin, and a window with no OpenBot at its origin are all refused. The name matches across build.rs, PERMISSIONS, the schemas, the workbench's PAGE_COMMANDS (pageRegistry.test.ts checks it against the Rust source and the app) and the app's call.
  • The page, in Chromium and WebKit (app/tests/desktop-window-sign-in.test.tsx), against Tauri's IPC as the page sees it. Told once, after the trade and before the app's first request. Never told on a refused or missing code. A Desktop without the command. A Desktop that doesn't answer, where the page waits on its trade page, then goes on.
  • The real app (window_e2e, Desktop CI's macOS and Windows jobs). Against the stand-in's current page, the log shows the page's word reached the app (: its page said so). Against an older OpenBot's page, which says nothing, the app took the window going on as the trade done (: its page went on without saying so).
  • Desktop to usage data. Every Rust test asserts the exact events queued in the real telemetry state, and the next launch on the same files.

Routes

From every caller of connect_window_now, connect_to_openbot, sign_in_with_browser, show_window_at, window_sign_in_failed and SIGNED_IN_PATH across app/, desktop/ and shared/. Tests are in window_ipc_tests.rs unless named.

# Route Counted Test, or why none
1-3 First setup, Connect on a company's OpenBot, on OpenBot Cloud's sign-in, or with no screen (defensive); the page says it traded setup ends; completed from the press with its screen, or nothing with none a_window_sign_in_ends_setup_once_the_page_says_it_traded_the_code (3 cases)
4 The page says it again, or the window then goes home nothing more the same test
5 Trade refused (any page, any reason) failed from the press; quit = setup_abandoned; next launch adds none a_window_sign_in_whose_trade_failed_is_abandoned_on_quit
6 Sign in again after 5, and it works completed for that go; no abandon sign_in_again_after_a_failed_trade_ends_setup_once_the_page_says_it_traded
7 Quit while the trade runs setup_abandoned a_quit_before_the_page_says_it_traded_is_abandoned
8 Crash while the trade runs closed silently by the next launch (Decision 3) a_crash_before_the_page_says_it_traded_is_closed_by_the_next_launch
9 Older page, good trade, then a redirect completed once an_older_page_that_goes_on_without_saying_ends_setup_as_before; window_e2e_an_older_openbots_page_that_says_nothing_still_ends_the_trade
10 The window sent elsewhere before the trade's page loaded nothing the same Rust test
11 Desktop slower than the page's 3 s: window goes on first, the word comes late counted once the same Rust test
12 Window shown anew while a trade waits trade dropped; quit = setup_abandoned. That window can't come back signed in by that trade: only the page trades the code, and it says so first the_window_shown_anew_drops_a_waiting_trade
13 window_signed_in from anywhere but the trade's page refused only_the_windows_own_page_says_it_traded
14 The page's own Sign in inside the window (sign_in_with_browser) nothing, before and after; setup had ended existing sign_in_with_browser tests
15 Settings, Change, then the window's sign-in as 1-6: the same command those tests
16 Later launch with a saved window sign-in; relay connections; Move to Cloud unchanged existing connected_ipc tests, passing
17 New page with an older Desktop; a Desktop that never answers; a browser the page goes on; nothing sent in a browser a Desktop from before window_signed_in …, a Desktop that doesn't answer …; tellDesktopSignedIn

Red/green

Each change below was made, the touched tests were run, and the change was put back.

Desktop (connected_ipc::, 51 tests; every change below turned some red):

  • completed counted before the trade, as on main: 8 red. The first one: named true: nothing counted before the trade, left [Started, Completed { duration_ms: Some(522) }], right [Started].
  • Setup ended before the trade (keep in place of save_choice): 3 red. Quit gave no SetupAbandoned { step: ConnectOpenbot }.
  • The page's word ignored: 3 red.
  • The older-page fallback off: 1 red.
  • The failure path ending setup: 1 red.
  • A re-shown window keeping the old trade: 1 red.
  • The trade's own page counted as going on: 2 red.
  • Counted before the trade's page loaded: 1 red (not before its page loaded).
  • Any page may say it traded: 2 red (another page).
  • A failed trade not counted failed: 2 red.

Page (the /desktop/signed-in cases, Chromium only):

  • never told: 3 red;
  • told after going on: 1 red (the page must still be on its trade page while Desktop hasn't answered);
  • told with no time bound: 1 red.

Local runs

  • cargo fmt --check.
  • cargo test --bins: 552 pass, 0 fail, 1 ignored.
  • cargo test --lib connected::: 104 pass, 0 fail, 4 ignored (the window_e2e tests, which need a debug build).
  • cargo clippy --all-targets -- -D warnings: clean on this diff (see below).
  • biome lint --error-on-warnings . and biome format .: clean.
  • tsc --noEmit in app/ and desktop/: clean.
  • bun test desktop: 1,452 pass, 0 fail.
  • app/tests/desktop-window-sign-in*.test.*: 16 pass without a browser; 46 pass, 0 fail in Chromium and WebKit.

Unrelated, seen locally:

  • Rust 1.100's clippy flags doc_lazy_continuation at local_eval_ipc_tests.rs:691, a file this doesn't touch; Desktop CI passed on main.
  • install::tests::osascript_saying_user_canceled_is_a_closed_prompt fails on a Mac set to British English ("cancelled").

Still to do before merge. A real macOS build beside an installed Desktop, with its own bundle id, HOME and OPENBOT_DESKTOP_PROJECT and Cloud on. Run two first setups:

  • one good trade: started, completed, and no setup_abandoned on quit;
  • one failed trade: started, failed, then setup_abandoned on quit.

Both are read in PostHog for that build's installation only:

SELECT timestamp, event, properties.screen, properties.outcome, properties.step
FROM events
WHERE event IN ('oss.desktop.openbot_connect', 'oss.desktop.setup_abandoned')
  AND timestamp > now() - INTERVAL 1 DAY
  -- and that build's installation id
ORDER BY timestamp

… not before

OpenBot's page at /desktop/signed-in now tells Desktop when it traded the
window's code for its session (window_signed_in), the same way it tells it
when the trade fails (window_sign_in_failed). Desktop still saves the
connection before the trade, for the page and for Sign in again, but ends
setup and counts openbot_connect completed only once the page says the trade
worked. A failed trade, a quit while the trade runs, or a quit at Sign in
again after a first setup's failed trade is now setup_abandoned, not a
connection.

A page from an older OpenBot never sends window_signed_in. It goes on to the
sign-in's next page only after a good trade, so while a trade waits the window
loading that path is taken as the trade done, with the same events as before.
No timeout and no API change.
…ot goes on to as a good trade

Review follow-ups to the success signal:

- A trade OpenBot's page says failed is now counted openbot_connect failed
  by the desktop, from the press, so the window's started always has an
  ending: the window that pressed Connect has gone to OpenBot's page.
- A page from an older OpenBot leaves the trade's page only once the trade
  worked, so a load of any page on the window's origin but that one ends the
  trade, wherever the page went or a redirect took it, not only the exact
  path Desktop sent. It is counted on a thread of its own, off the
  webview's page-load handler.
- window_signed_in is refused from any page but /desktop/signed-in.
- Tests for a crash while the trade runs (closed by the next launch, as
  before), a late word after the window went on (counted once), and the
  window shown anew. The real-app test checks the page's word reached the
  desktop. Stale comments that said setup ends before the trade are fixed.
… page has loaded

Something in front of an OpenBot (a proxy, a challenge) can send the window
elsewhere before the trade's page ever runs: that is not a trade. The window
going on now counts only after /desktop/signed-in finished loading or
answered. The real-app test gains an older OpenBot's page, which says
nothing when the code traded, and checks the app took the window going on as
the trade done. TELEMETRY.md says completed's duration now includes the
trade.

This branch has not been deployed

No deployments
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.

1 participant