Skip to content

Drop unusable desktop browser snapshots instead of closing daemon sessions - #3450

Merged
andrewkchan merged 1 commit into
mainfrom
akc/drop-unusable-browser-snapshots
Sep 11, 2026
Merged

andrewkchan merged 1 commit into
mainfrom
akc/drop-unusable-browser-snapshots

Conversation

@andrewkchan

@andrewkchan andrewkchan commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

Currently, we synchronize browser tabs between desktop app main processes, host daemon processes, and the server process. Each browser tab is associated with a thread ID. We do this so that agents can interact with browser tabs that might be opened in a desktop app window elsewhere (note you can have multiple desktop apps across multiple machines, but only ever 1 server process).

If we try to synchronize a browser tab associated with a thread ID that the server doesn't have, the server process will throw an error, and the host daemon which forwarded this message to the server will be forcibly disconnected. Moreover this will happen in a loop because on reconnect we will retry browser tabs synchronization through that host daemon.

Today, you can open browser tabs inside a plugin pane, which gets a fake thread ID of the form plugin-panel:cloud-sandbox:cloud-machines:pane-1. The server won't be able to find any such thread ID and so using the browser inside the plugin pane trivially trips this bug and can cause the local machine/daemon to get disconnected. This PR should fix that bug by making the server just ignore these browser tabs instead of forcibly disconnecting the host daemon.

What was wrong

The server handles every host-daemon WebSocket message inside a single try/catch in onDaemonSocketMessage, and any handler error closes the daemon session (1008 inactive-session). The desktop app forwards desktop-browser.changed tab snapshots through the host daemon, and syncDesktopBrowserTabs starts with requirePublicThread, which throws thread_not_found when the snapshot's scope isn't a live thread. Browser tabs opened in a plugin page's right panel report their panel-state id (for example plugin-panel:cloud-sandbox:cloud-machines:pane-1) as their thread id, so one such tab made the server drop the whole host session. The desktop broker re-sends every known scope after each reconnect, so the host got stuck in a loop: connect, snapshot, session closed. It showed as offline, and each drop was logged as the misleading Daemon heartbeat rejected, closing socket.

What changed

  • apps/server/src/ws/daemon-protocol.ts: errors from syncDesktopBrowserTabs are now caught. The server logs Dropping desktop browser snapshot the server cannot apply with host, instance, generation, thread id and the error, and drops the snapshot. The daemon session stays open.
  • The catch-all log is now Daemon message rejected, closing socket and includes messageType, so the next unexpected rejection names the message that caused it.
  • No wire change; HOST_DAEMON_PROTOCOL_VERSION is unchanged.
  • The desktop-side fix, which stops the broker publishing plugin-panel browser tabs at all, is in a stacked follow-up PR.

How you verified

  • Added drops snapshots for synthetic, missing, or deleted threads without closing the daemon session to apps/server/test/desktop-browsers.test.ts. It sends snapshots scoped to a plugin-panel id, a missing thr_ id and a deleted thread. It asserts the socket is not closed and nothing is stored, and that a valid snapshot on the same session is still applied.
    • Before the fix: AssertionError: plugin-panel:cloud-sandbox:cloud-machines:pane-1: expected "vi.fn()" to not be called at all, but actually been called 1 times
    • After the fix: pnpm exec turbo run test --filter=@bb/server -- test/desktop-browsers.test.ts → Tests 18 passed (18)
  • pnpm exec turbo run typecheck --filter=@bb/server passes.
  • Found on bb Nightly 0.42.2-nightly: server.log showed a thread_not_found "heartbeat rejected" about every 30s for the local host. Local Storage had browser-panel state for plugin-panel:cloud-sandbox:cloud-machines:pane-1.

🤖 Generated with Claude Code

AGENT GENERATED

…sions

A desktop-browser.changed snapshot whose scope is not a live thread made
syncDesktopBrowserTabs throw thread_not_found, and the catch-all in
onDaemonSocketMessage closed the whole daemon session. Plugin-page browser
tabs report their panel-state id as a thread id, so the host reconnect loop
kept the machine offline. Catch and log sync failures and keep the session;
name the message type in the remaining catch-all log.

Co-Authored-By: Claude Opus 5 <[email protected]>
@andrewkchan
andrewkchan merged commit 3526458 into main Sep 11, 2026
16 checks passed
@andrewkchan
andrewkchan deleted the akc/drop-unusable-browser-snapshots branch September 11, 2026 00:00
andrewkchan added a commit that referenced this pull request Sep 11, 2026
## Human comments

See human comments in
[#3450](#3450) for more
context

## What was wrong

Plugin pages reuse the shared browser deck with
`threadId={panelStateId}` (`PluginPanelRightPanelHost.tsx`). So a native
browser tab opened in a plugin page's right panel is scoped to a
synthetic id such as `plugin-panel:cloud-sandbox:cloud-machines:pane-1`.
The desktop browser broker published a `desktop-browser.changed`
snapshot for every scope it had seen. These synthetic scopes therefore
went through the host daemon to the server, which has no thread to
attach them to. #3450 makes the server drop such snapshots instead of
closing the daemon session. This PR stops the desktop app sending them
in the first place.

## What changed

- `apps/desktop/src/desktop-browser-broker.ts`: `publish()` notifies its
daemon-bound listeners only when the scope is a real thread id
(`isRawThreadId` from `@bb/domain`). Plugin-panel browser tabs stay
local to the desktop app. The renderer's local control-state IPC is
unchanged.
- `apps/desktop/test/desktop-browser-broker-snapshots.test.ts` (new):
with one real-thread tab and one plugin-panel tab, only the real
thread's snapshot is published across window registration, host connect
and a tab change.
- `apps/desktop/test/desktop-browser-view-manager.test.ts`: the
reconnect test checks daemon-bound snapshots, so it now uses real-format
thread ids. The fixture helper gained an optional `threadId`, which
still defaults to `"thread-1"` for every other test.
- No server/daemon wire change; `HOST_DAEMON_PROTOCOL_VERSION` is
unchanged.

## How you verified

- New test, before the broker change: `AssertionError: expected Set{
'thr_23456789ab', …(1) } to deeply equal Set{ 'thr_23456789ab' }`. After
the change it passes.
- `pnpm exec turbo run test --filter=@bb/desktop` → `Test Files 42
passed (42)`, `Tests 318 passed | 1 skipped (319)`.
- `pnpm exec turbo run typecheck --filter=@bb/desktop` passes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

Co-authored-by: Claude Opus 5 <[email protected]>
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