Skip to content

Show why the Server menu lists no Connect servers - #2168

Merged
SawyerHood merged 1 commit into
mainfrom
bb/fix-1753-connect-servers-menu-reason
Aug 21, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/fix-1753-connect-servers-menu-reason

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

createConnectServerSync().runSync() in apps/desktop/src/connect-server-sync.ts treated every empty outcome of fetchServers() as null: no local runtime and no cached credential, connect plugin disabled (HTTP 503), connect plugin unpaired ({ code: "handler_error", message: "not_paired" }), server or gate unreachable, and a refused credential. It logged one line and returned, so main.ts was never told and never rebuilt the menu. buildMenuServerItems() mapped an empty connectAccountServers and createServerMenuItems() in menu.ts has no empty-state row, so Window > Server looked exactly like an account with no servers. fetchConnectAccountServers() even parsed rpcFailureSchema and discarded the result, although the server says which case it is on the wire.

Issue: #1753. Report: https://get-bb.github.io/reports/issues/1753.html

What changed

  • apps/desktop/src/connect-server-sync.ts: fetchConnectAccountServers() returns { ok: true, result } | { ok: false, reason } instead of T | null. The reason is derived from the response: 503 is plugin-disabled, handler_error/not_paired is not-paired, anything else (fetch threw, non-JSON, unknown shape) is unavailable. The gate path returns no-credential when the app has none, unauthorized when the gate refuses the credential (still calls onUnauthorized), unavailable otherwise. New required callback onSkipped(reason) fires for every skipped sync next to onServers. The log line now names the reason and is written once per failure streak plus once when the reason changes.
  • apps/desktop/src/main.ts: stores the reason in connectServerSyncSkipReason, clears it in onServers, and calls refreshApplicationMenu() from onSkipped because Electron menus are immutable once built. The menu gets the reason only when listMenuConnectServers() is empty, so a persisted Connect selection that is still listed gets no note under it.
  • apps/desktop/src/menu.ts: InstallApplicationMenuArgs.connectServersSkipReason: ConnectServerSyncSkipReason | null (required, not optional). A non-null reason renders one disabled row after the server radio items: No Connect servers — sign in to bb Connect / … Connect not paired on This Mac / … Connect plugin disabled / … sign in to bb Connect again / … could not reach bb Connect.

No wire change between server and host daemon; the desktop to local-server RPC request is unchanged, only the parse of its failure body. No CLI or doc surfaces.

Deviation from the reporter's prototype (Joesirven/bb@prototype/connect-server-list-skip-reason, no PR): the reason is pushed through a callback that rebuilds the menu, instead of a getSkipReason() polled at build time, so the row appears after the sync that produced it rather than after the next unrelated rebuild. Plugin-disabled and not-paired are told apart. The reason is set from the outcome, never before the fetch resolves. No clickable "Sign in to bb Connect…" item: that is a product decision and the issue asked for the disabled row as the minimum.

Relation to #1494 / #2161: in the reporter's exact startup flow (saved custom target that no longer answers) applyServerTarget() rejects on loadURL before the startup syncNow() runs, so the first sync fires from menu-will-show and the row shows from the second open of the menu. With #2161 the startup sync is reached and the row is there on the first open. This PR does not touch that flow.

How you verified

Tests (apps/desktop/test/connect-server-sync.test.ts, apps/desktop/test/menu.test.ts). With git checkout origin/main -- apps/desktop/src/connect-server-sync.ts apps/desktop/src/menu.ts apps/desktop/src/main.ts and the new tests: Tests 7 failed | 8 passed (15), including

× explains an empty Connect list with a disabled row when the sync was skipped
  TypeError: Cannot read properties of undefined (reading 'no-credential')
× reports no-credential without calling the gate when the app has none
  AssertionError: expected [] to deeply equal [ 'no-credential' ]
× names the reason on network failure, plugin disabled, or not paired
  AssertionError: expected null to deeply equal { ok: false, reason: 'unavailable' }
× reports a refused credential so the caller drops it
  AssertionError: expected [] to deeply equal [ 'unauthorized' ]

On this branch the same files pass (Tests 15 passed (15)).

pnpm exec turbo run typecheck test --filter=@bb/desktop --force on the committed tree (git status --porcelain empty): Tasks: 5 successful, 5 total, Test Files 34 passed (34), Tests 224 passed (224).

Manual: rendered the real menu.ts inside Electron 41 under Xvfb with the report's harness, using the servers array main.ts produces for the reporter's state (saved custom target, no local runtime, no credential). Before: This Mac | old-host.tailnet.ts.net:38886 | <separator> | Set Server URL…. After, with connectServersSkipReason: "no-credential" as main.ts now passes it after the skipped sync: This Mac | old-host.tailnet.ts.net:38886 | No Connect servers — sign in to bb Connect | <separator> | Set Server URL…, the new row greyed out and not clickable.

The server-side shapes the parser matches were checked against apps/server/src/routes/plugins.ts (503 + string error for a plugin that is not running) and apps/server/src/services/plugins/plugin-service.ts + plugins/connect/src/rpc.ts ({ code: "handler_error", message: error.message } where the handler rethrows ConnectListError.code), and match the report's live probe.

Fixes #1753

AGENT GENERATED: by Claude Opus 5

Independent verification

Checked out d4d3412ef (origin/main is an ancestor; mergeable: MERGEABLE) in a fresh worktree, read the issue and the report first, and verified the wire shapes the new parser matches against apps/server/src/routes/plugins.ts (503 + string error for not-running), plugin-service.ts ({ code: "handler_error", message } with the raw thrown message) and plugins/connect/src/rpc.ts (throw new Error(error.code) for ConnectListError).

Fail-before / pass-after:

git checkout origin/main -- apps/desktop/src/connect-server-sync.ts apps/desktop/src/main.ts apps/desktop/src/menu.ts
cd apps/desktop && pnpm exec vitest run test/connect-server-sync.test.ts test/menu.test.ts
  Tests  7 failed | 8 passed (15)
  AssertionError: expected null to deeply equal { ok: false, reason: 'unavailable' }
  AssertionError: expected [] to deeply equal [ 'no-credential' ]
  AssertionError: expected [] to deeply equal [ 'unauthorized' ]
  TypeError: Cannot read properties of undefined (reading 'no-credential')
git checkout HEAD -- <same files>
  Tests  15 passed (15)

pnpm exec turbo run typecheck test --filter=@bb/desktop --force on the clean committed tree: Tasks: 5 successful, 5 total, Test Files 34 passed (34), Tests 224 passed (224).

Live wire check (own dev instance, not mocks): ran the branch's fetchConnectAccountServers + createConnectServerSync with tsx against the real local server. Connect enabled but unpaired (HTTP 500 {"code":"handler_error","message":"not_paired"}) -> onSkipped(["not-paired"]); bb plugin disable connect (HTTP 503) -> onSkipped(["plugin-disabled"]); closed port -> onSkipped(["unavailable"]). One log line each.

Repro on the fixed branch: bundled the branch's real connect-server-sync.ts + menu.ts into Electron 41 under Xvfb, wired onSkipped/onServers to rebuild the application menu the way main.ts does, and fired onListRequested() (the menu-will-show trigger, the only one reached in the reporter's flow). Before the sync: This Mac | old-host.tailnet.ts.net:38886 | <separator> | Set Server URL…. After: This Mac | old-host.tailnet.ts.net:38886 | No Connect servers — sign in to bb Connect | <separator> | Set Server URL…, the new row greyed (enabled: false), 2 menu builds. Same harness with the live dev server as the local runtime and the plugin disabled: This Mac | No Connect servers — Connect plugin disabled | <separator> | Set Server URL…. No longer reproduces.

CI: all required checks pass (Checks, Tests x6, Package Smoke ubuntu + macos-15, version check); iOS/Node-compat smoke skipped by path filter.

Residual risks (none blocking): every desktop user whose bundled server is not paired to Connect now sees the greyed Connect not paired on This Mac row in Window > Server, which is the behaviour the issue asks for but is visible beyond the reporter's case; onSkipped rebuilds the menu on every skipped sync (every 10 min and on throttled menu open), mirroring the existing onServers path; after switching targets the previous reason can show for the sub-second window until the new sync completes; main.ts wiring is verified by reading plus the harness above, not by a unit test. The startup sync is still not reached when the saved custom target is dead (#1494 / #2161), so in that exact flow the row appears from the second open of the menu.

AGENT GENERATED: by Claude Opus 5

When the desktop's Connect server sync had nothing to list (no local
runtime and no cached credential, connect plugin disabled or unpaired,
server or gate unreachable) it wrote one log line and told nobody. The
Window > Server submenu then looked exactly like an account with no
servers, and in the one flow where that menu is the recovery path (a
saved custom target that stopped answering, #1494) the user had no hint
that signing in to bb Connect would populate it.

The sync now returns a typed outcome instead of null. The local RPC
failure body is parsed instead of discarded (HTTP 503 is plugin-disabled,
handler_error/not_paired is not-paired), the gate path distinguishes a
refused credential from an outage, and a new onSkipped(reason) callback
fires beside onServers. main.ts stores the reason, clears it on success,
and rebuilds the application menu from onSkipped too, because Electron
menus are immutable once built. menu.ts renders the reason as one
disabled row under the server list, only when no Connect server is
listed at all.

Fixes #1753

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood marked this pull request as ready for review August 21, 2026 07:03
@SawyerHood
SawyerHood merged commit 78bd562 into main Aug 21, 2026
13 checks passed
@SawyerHood
SawyerHood deleted the bb/fix-1753-connect-servers-menu-reason branch August 21, 2026 14:39
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.

Desktop: Server menu shows no Connect servers and no reason when the sync is skipped

1 participant