Skip to content

Let the daemon own a browser engine move, one per thread at a time - #2340

Open
Luseefor wants to merge 9 commits into
mainfrom
ace/fix-2013-daemon-owned-engine-move
Open

Luseefor wants to merge 9 commits into
mainfrom
ace/fix-2013-daemon-owned-engine-move

Conversation

@Luseefor

@Luseefor Luseefor commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Moving a thread's browser to another engine ran in each client: save the engine, snapshot the tabs, close, reopen, load the pages. Two devices switching the same thread at once could close a browser the other was restoring, or load its pages twice.

Change

The daemon owns the move (ADR 0194). A client sends one browser.engine.move request (threadId, workspaceId, engine), and the reply is BrowserEngineMoved: the browser's state on the new engine, plus any tabs that didn't come back.

  • Moves of one thread queue (packages/browser/src/engine-move.ts). A queued move finds the browser already on its engine and only keeps the setting, so both devices see success.
  • BrowserService.rehost closes the browser the way a shutdown does, with its tabs kept in the tab store. It then reopens on the new engine through a one-off override and restores the tabs with the same ids. Private tabs stay private and the shown tab stays shown.
  • The thread's browser.backend is written only after that reopen succeeds. A daemon that stops mid-move has written nothing, so its next open brings the tabs back on the old engine.
  • If the new engine won't open, the tabs reopen where they were and the request fails with the reason. A single-page engine's one web page is carried as a tab.
  • The daemon writes the setting through apps/daemon/src/browser-engine-setting.ts and asks the same refusal as a settings write (ADR 0190).
  • Web and the iPhone send the request through @ace/client. If the daemon answers unsupported (a daemon older than this change), the client runs its old steps instead (packages/client/src/browser-engine-here.ts).
  • The fake daemon runs the same moveEngine.

Tests

  • Two devices moving at once end with one browser there and its page loaded once. Covered in packages/browser/src/engine-move.process.test.ts, and through the daemon socket with real settings in apps/daemon/src/browser-engine-move.server.process.test.ts.
  • A failed open brings three tabs back with the shown and private ones as they were, and never writes the setting.
  • A daemon that stops between close and reopen: a new daemon over the same tab store and setting reopens both tabs on the old engine.
  • A move queued behind one that failed still moves the browser, and its page loads once.
  • Against a daemon that answers unsupported, the client makes the move itself: packages/client/src/browser-engine-here.test.ts. These are main's old client tests, run through the public moveBrowserEngine.
  • The web engine-switch.test.tsx and the iPhone browser-engine.test.ts pass against the fake daemon.
  • fmt:check, lint, typecheck and check:size pass.

Mutations checked

  • Writing the setting before the reopen: the restart, failed-open and queued-after-failure tests fail.
  • Starting moves without the per-thread queue: the queued-after-failure test fails.
  • Not re-selecting the shown tab: the failed-open test fails.
  • Never detecting an older daemon: all 6 fallback tests fail.

Departures

  • The fake engines can't hold several tabs on the desktop side, so the multi-tab restore is tested on the rollback and restart paths. It's the same rehost code that a successful move uses.
  • A move now carries every tab, as a restart does. A tab whose address can't load stays a tab instead of being dropped, and the web test now checks that.
  • test:changed also hit failures that fail the same way on a clean origin/main: ace-account, account-machines, machine-account-source, list-motion, cutover, fleet, transfers (iOS bridge), service-home-identity and fingerprint. Others timed out under load and passed when run alone.

Closes #2013

Model: Claude Opus 5.5

Luseefor and others added 9 commits November 19, 2026 17:53
One request for the daemon to move a thread's browser to another
engine, answered with the browser's state there and the pages that
didn't load (#2013).

Co-Authored-By: spade <bot@acehq.dev>
Each client used to save the engine, close and reopen the browser
itself, so two devices switching one thread at once could close a
browser the other was restoring or load its pages twice (#2013).

BrowserService.moveEngine now runs the whole move, queued per thread;
a queued move finds the browser already on its engine and leaves it.
A failed open writes the previous engine back and reopens the pages.
ADR 0193 records the contract.

Co-Authored-By: spade <bot@acehq.dev>
The socket's browser bridge gets a port that reads the thread's
browser.backend and writes its thread layer, refused for an agent's
device as a settings write is (ADR 0190).

Co-Authored-By: spade <bot@acehq.dev>
@ace/client's moveBrowserEngine is now one browser.engine.move
request; the fake daemon answers it with the daemon's own move.

Closes #2013

Co-Authored-By: spade <bot@acehq.dev>
The move wrote the thread's engine, then closed the browser and cleared
its saved tabs, so a daemon stopping before the reopen came back on the
new engine with no tabs (Codex review of #2340).

The move now closes the browser as a shutdown does, its tabs kept in
the tab store, and reopens it on the new engine through a one-off
override with those tabs restored (ids, private and shown tabs as they
were). The setting is written only after that. A failed open reopens
the tabs on the engine the browser was on; a restart mid-move reopens
them where the setting still points.

Tests cover several tabs restored with the shown and private ones, a
restart mid-move, and a move queued behind one that failed.

Co-Authored-By: spade <bot@acehq.dev>
Phones and desktops update at different times. A daemon that answers
browser.engine.move with unsupported now gets the old client-side
steps, kept in browser-engine-here.ts; callers say whether they see a
browser open so the fallback only keeps the choice when none is.

Co-Authored-By: spade <bot@acehq.dev>
ADR 0194 (renumbered from 0193, taken on main and by #2324) now says
the setting is written after the reopen, what a restart mid-move does,
and that clients fall back to their own steps for older daemons.

Co-Authored-By: spade <bot@acehq.dev>
…wned-engine-move

Co-Authored-By: spade <bot@acehq.dev>
A move now brings back every tab as a restart restores them, so a tab
whose address can't load stays a tab instead of being skipped, and the
shown tab stays shown. The menu helper closes a menu the last pick left
open, since the move now answers in one round trip.

Co-Authored-By: spade <bot@acehq.dev>

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.

Browser engine moves aren't coordinated across devices: two clients switching at once can lose or duplicate pages

1 participant