Repository navigation
Drop unusable desktop browser snapshots instead of closing daemon sessions - #3450
Merged
Merged
Conversation
…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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/catchinonDaemonSocketMessage, and any handler error closes the daemon session (1008 inactive-session). The desktop app forwardsdesktop-browser.changedtab snapshots through the host daemon, andsyncDesktopBrowserTabsstarts withrequirePublicThread, which throwsthread_not_foundwhen 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 exampleplugin-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 misleadingDaemon heartbeat rejected, closing socket.What changed
apps/server/src/ws/daemon-protocol.ts: errors fromsyncDesktopBrowserTabsare now caught. The server logsDropping desktop browser snapshot the server cannot applywith host, instance, generation, thread id and the error, and drops the snapshot. The daemon session stays open.Daemon message rejected, closing socketand includesmessageType, so the next unexpected rejection names the message that caused it.HOST_DAEMON_PROTOCOL_VERSIONis unchanged.How you verified
drops snapshots for synthetic, missing, or deleted threads without closing the daemon sessiontoapps/server/test/desktop-browsers.test.ts. It sends snapshots scoped to a plugin-panel id, a missingthr_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.AssertionError: plugin-panel:cloud-sandbox:cloud-machines:pane-1: expected "vi.fn()" to not be called at all, but actually been called 1 timespnpm exec turbo run test --filter=@bb/server -- test/desktop-browsers.test.ts→Tests 18 passed (18)pnpm exec turbo run typecheck --filter=@bb/serverpasses.0.42.2-nightly:server.logshowed athread_not_found"heartbeat rejected" about every 30s for the local host. Local Storage had browser-panel state forplugin-panel:cloud-sandbox:cloud-machines:pane-1.🤖 Generated with Claude Code