Repository navigation
Conversation
ymichael
force-pushed
the
bb/6748-ship-pr2-server-routes-daemon-failover-thr_8fyb466bfh
branch
10 times, most recently
from
November 23, 2026 21:16
f671ad2 to
f2e2fce
Compare
…es experiment (#6748) Server: - Stable serverId (srv_<hex>, stored in app settings) in /health, system config, daemon session open, bb status --json and bb server access list. - Server access providers become ordered routes: serverAccessOrder and disabledServerAccessProviderIds replace defaultMachineAccess. Providers declare routeKind (bb connect: relay, Tailscale: private-overlay) for default ranking; providers of one kind follow the earliest-installed plugin. Plugin SDK 0.6.177. - Per-host grants table (host_server_access_grants); the install route stays the anchor. New machines install on a relay or custom route before local-network and private-overlay, and enrollment falls back to the next enabled route. - Core Local network provider: extra in-process listeners on private LAN IPv4s, no restart; turning it off closes the listeners and drops their connections. - Routes in system config and the session-open response, pushed live with server-routes.replace; the daemon reports its route with session.route and each session stores it. Settings -> "How devices reach this server", via <route> on each machine, bb server access list|enable|disable|order, and a Route column in bb machine list. - Admitted route addresses persist in app_settings_values (serverAccessOrigins) and are restored before the listener, so route hostnames pass the Host/Origin guards from the first request after a restart; an address survives a failed check and is dropped on a definite answer, when turned off, or when its plugin is disabled or removed. Plugin providers' addresses (Tailscale) are admitted with the experiment off too, as on main; core Local network and Manual only with it on. - Early adopter experiment serverRoutes: off advertises routes: [] and hides Local network, so daemons behave as before. - Migration 0165 copies grants and defaultMachineAccess without dropping hosts.server_access_grant_id or the old setting, so a downgrade still works; the anchor grant id is mirrored into the old column. Daemon: - Candidates are the learned routes in server order plus the install URL. Every dial probes /health + serverId in parallel (2 s timeout, rank i may win after i x 500 ms) with per-route headers. No mid-session switching: it stays on a working route until the connection drops. - Learned routes persist in <data dir>/server-routes.json (not the strict config.json, which older launchers would reject). - Guarded downloads prefer an encrypted route; the bb connect gate comes from the relay route; machine-auth-proxy follows the active route. HOST_DAEMON_PROTOCOL_VERSION 276 -> 277. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…plugins at registration - ServerAccessProviderDeclaration.routeKind is required, so new and rebuilt plugins must choose a kind instead of silently ranking as custom. - Registration still accepts a declaration without it (a plugin built against an SDK before 0.6.177) and fills in "custom" once there, in both the real and fake hosts; core's own fallback in server-access.ts is gone. - Marketplace installs bundle with esbuild and never type-check, so old plugins still install. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Settings → Machines shows the routes that are on, broken ones included with their error and a Fix action, and offers the others from an "Add a route" dropdown in the section header. Reordering appears only with two or more routes. The Add Machine dialog lists the choices inline. Settings → Mobile summarizes ready routes and links to Machines to change them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the experiment off, new machines picked the anchor relay-first and providers ranked by route kind, so a user whose migrated default was Tailscale got bb connect for new machines. Off now ranks by the user's order, then the earliest-installed plugin, then Manual, and installs on the first working one, as the single default route did on main. Route-kind ranking and the relay-first install rule apply only with serverRoutes on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ebasing onto main Main shipped its own 277 and SDK 0.6.179 since this branch bumped them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The settings section is now "How devices reach this server" on the Machines page. The experiment description, the Host guard message, the no-route enrollment error, the docs, the Plugin Guide surface and the Tailscale overview still sent people to "Settings → Machine access". The plugin authoring reference and the Tailscale overview also now state the install rule for the serverRoutes experiment both off and on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
bb connect's phone pairing section renders nothing until the account is signed in, but its wrapper still took the card's space-y-3 gap, leaving 12px of extra space under the text. The plugin section brings its own top margin and border, as it did on main, so render it without a wrapper or gap. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
"Turn off" on a plugin route (bb connect, Tailscale) only hid it from this list and dropped its hostname from the Host and Origin guards, so bb connect stayed signed in and connected while every request through it got 403 forbidden_host. Each route already has a real switch elsewhere, so the second one goes: - disabledServerAccessProviderIds is replaced by localNetworkEnabled (default false). Plugin routes are routes while their plugin reports them available and are turned off in the plugin's own settings (Manage). Manual is a route while machineServerUrl is set. - Local network and Manual get a menu with Remove (and Edit address for Manual) instead of Turn off; Add a route adds them back. - New machines install on the first working route in the user's order, with Local network last, whether or not serverRoutes is on. The relay-first install rule is gone, so ordering alone puts Tailscale ahead of bb connect. - bb server access enable|disable become add <id> [url] and remove <id>, for local-network and direct; plugin routes are refused with a pointer to the plugin's settings. - The ServerAccessStatus provider entries lose their enabled field. No daemon wire change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the Manual editor on save - Local network listed every private IPv4 on any interface, including virtual bridges such as OrbStack/UTM's bridge100 that only VMs on this computer can reach. It now offers and listens on the address this computer routes outbound traffic through (found by connecting a UDP socket without sending), and falls back to every private address when that is unknown. - Every route row has a menu: plugin routes carry Manage there (a broken one still shows Fix beside it), Manual has Edit address and Remove, Local network has Remove. - Saving a new Manual address left the add editor open, hidden only while Manual was set, so removing Manual brought the editor back. Saving now closes the add and edit editors. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dropping a route started dnd-kit's settle animation before the new order reached the list: the general settings mutation applies its optimistic patch asynchronously, so the displaced row's slot moved a frame later while its transform was still animating, and it shot above the list before sliding back. Apply the dropped order synchronously, as the providers list does, until the write settles. The lifted row in the routes, projects and providers lists is now fully opaque, so the row sliding under it no longer shows through. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each address in Settings → Machines → How devices reach this server gets a copy button after it, shown on hover and always on touch screens. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Plugin routes get a settings icon that opens the plugin's settings (a broken one keeps its Fix button instead), Manual gets edit and remove icons, and Local network gets a remove icon. Each icon has a tooltip. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The route rows and the phone card's ready routes share one address list with a copy button after each address. Co-Authored-By: Claude Opus 5.5 <[email protected]>
It makes Local network available to add rather than adding it, and machines prefer the highest route in the user's order that answers, not simply the first to answer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/6748-ship-pr2-server-routes-daemon-failover-thr_8fyb466bfh
branch
from
November 23, 2026 21:55
b9014f4 to
9c2f94d
Compare
ymichael
deleted the
bb/6748-ship-pr2-server-routes-daemon-failover-thr_8fyb466bfh
branch
November 23, 2026 22:04
ymichael
added a commit
that referenced
this pull request
Nov 25, 2026
…igation Behind the serverRoutes experiment (#7864), the desktop app knows a remote bb server by its serverId instead of one URL. - One entry per server. When a saved custom or bb connect entry's server advertises routes, it becomes a routed server in server-target.json (routedServers, activeRoutedServerId, target "server"). Saved entries for the same server fold in (other custom URLs are probed for the same serverId), keeping the user's name. Adding any address of a known server lands in that entry. The address the user added stays a route when the server stops advertising it. Account servers already reached as a route are hidden from the list. With the experiment off the server advertises no routes and nothing changes. - Pick on open with the daemon's rule, now shared in @bb/server-routes: ordered routes, parallel /health + serverId probes, 2 s timeout, rank i may win after i x 500 ms. The daemon resolver uses the same package. The race now also settles as soon as every better-ranked route has failed. The bb connect session is set up and sent only for the bb connect route. - Fail over by navigation, no loopback proxy: the active route is checked every 10 s and right away on resume, app activation and a failed main-frame load. Two misses in a row pick again; every window loads the same path, query and hash on the new route's origin. No switching up while the route in use works; if no route answers the page stays and checks continue. - Indicator: optional getServerRoute/onServerRouteChange/setServerRoute on the desktop contract; the native Server menu shows "<server> · via <route>" and a Route submenu (Automatic + each route); a toast on each switch (the preload holds the notice for the page that loads after the switch); command-palette actions to pin or unpin a route. - Docs: multiple-devices.md (one entry per server, what a switch keeps), configuration.md and the customization guide (server-target.json fields and rollback). Co-Authored-By: Claude Opus 5.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
What was wrong
Each machine knows its bb server by one URL, the one it was installed with. When that route stops working (for example the home internet drops for a bb connect-enrolled machine sitting on the server's own LAN, or a tailnet goes down), the machine disconnects even though another route to the same server would work. The server also had no stable identity a client could check a route against, and server access was one "connection method" per server (
defaultMachineAccess) rather than a set of routes.What changed
Server (behind the new early adopter experiment
serverRoutes; while it is off, the server advertisesroutes: [], the Local network route does not exist, and daemons behave exactly as on main, including the Tailscale plugin's address being admitted by the Host/Origin guards):serverId(srv_<hex>, stored in bb.db so it survives restarts and moves withbb server move), returned by/health, system config, daemon session open,bb status --jsonandbb server access list --json.serverAccessOrderreplacesdefaultMachineAccess, andlocalNetworkEnabled(default off) adds the Local network route. Plugin routes are routes while their plugin reports them available and are turned off in the plugin's settings; Manual is a route whilemachineServerUrlis set. Providers declarerouteKind(local-network | private-overlay | relay | custom) for default ranking; bb connect declaresrelayand the Tailscale plugin (Add an official Tailscale plugin that serves bb over Tailscale Serve #7862) declaresprivate-overlay. Kind ranking applies only withserverRouteson; while it is off, providers rank by the user's order, then Add an official Tailscale plugin that serves bb over Tailscale Serve #7862's earliest-installed-plugin order, then Manual, as the single default route did on main. Providers of one kind keep Add an official Tailscale plugin that serves bb over Tailscale Serve #7862's earliest-installed-plugin order, not load order. Plugin SDK 0.6.188.routeKindis required in the SDK types; registration still accepts a declaration without it, from a plugin built against an older SDK, and treats it ascustom(marketplace installs bundle with esbuild without type-checking, so such plugins still install); documented under the existingbb.experimental_serverAccess.registerentry indocs/api_to_audit.mdand in the Plugin Guide surface.host_server_access_grants); the install route stays the host's anchor. Enrollment falls back to the next enabled route when one needs setup.server-routes.replaceWS message. The daemon reports its route with a newsession.routemessage; each daemon session stores it.app_settings_values(serverAccessOrigins) and restored increateAppbefore the listener, so route hostnames work from the first request after a restart. An address survives a failed or timed-out availability check and is dropped on a definite answer, when the route is turned off, or when its plugin is disabled or removed. This replaces Add an official Tailscale plugin that serves bb over Tailscale Serve #7862's copy of the same mechanism. Plugin providers' addresses (Tailscale, bb connect) are admitted whether or notserverRoutesis on, as on main. Core's Local network and Manual addresses are admitted only while it is on.experimental_serverAccess.recheck()still refreshes the set directly, as Add an official Tailscale plugin that serves bb over Tailscale Serve #7862 does.bb server access list|add|remove|order(add/removecoverlocal-networkanddirect), and a Route column inbb machine list.defaultMachineAccessinto the new model but keepshosts.server_access_grant_idand the old setting row for one release, so going back a version works; the anchor grant id is mirrored into the old column.Host daemon:
/healthplus aserverIdcheck on all of them in parallel (2 s timeout; route i may win after i × 500 ms), sending each route only its own headers (the bb connect credential goes only to bb connect).resumeDaemonSessionsit keeps its session across the switch.<data dir>/server-routes.json, notconfig.json, whose strict schema would make an older launcher refuse the file after a rollback.Wire changes:
HOST_DAEMON_PROTOCOL_VERSION278 → 279 (serverRoutesin session open,routein the session-open request,server-routes.replace,session.route).Docs:
docs/multiple-devices.md,docs/configuration.md,docs/api_to_audit.md,bb guide machines/customization, the bb-cli command index, the plugin-authoring machines reference, and the Tailscale plugin's skill and overview. These no longer say "choose Tailscale as the connection method" ordefaultMachineAccess tailscale.Not in this PR: desktop and mobile route selection (later PRs), the prototype's
x-bb-gate-*peer-address strip (replaced by a separate auth change), and the better-route check, flap holds and backoff (a later shared-policy PR).How you verified
Tests added, each failing before its fix:
apps/host-daemon/src/server-routes.test.ts: ranking with head start,serverIdmismatch rejected, per-route headers, failover and return on redial, current route kept when nothing answers, no probing or saving while the server advertises no routes, persistence outsideconfig.json.apps/host-daemon/src/server-connection.test.ts: stays on its working route after learning better ones, then fails over and reportssession.routeon each redial.apps/server/test/services/machines/server-routes.test.ts: experiment off advertises nothing and acquires no grants; LAN advertised as soon as it is added; LAN connections dropped when it is removed; new machines install on Local network only when nothing else works; route addresses admitted from the first request after a restart (fresh modules); address kept through a failed check and dropped on a definite answer; Manual's address refused once its URL is cleared; with the experiment off a plugin route's address stays admitted and Manual's is dropped.apps/server/test/services/machines/server-access.test.ts: a declaration withoutrouteKind(an older plugin) registers on the real and fake hosts and ranks ascustom(fails without the registration default); install route prefers relay/custom over private-overlay/local-network with the experiment on; with it off, the user's first route and then the first registered plugin win over the relay (fails without the gate: a Tailscale-first order installed on the relay). Add an official Tailscale plugin that serves bb over Tailscale Serve #7862's tests stay as they were (address admitted until lost, kept across a restart and a failed check, dropped on plugin disable). Its "defaults to the earliest-installed plugin" test now checks route order and the install route instead of the removeddefaultProviderId.packages/db/test/migrate.test.ts: migration copies grants and the default without dropping the old column or row.Commands (all green):
pnpm exec turbo run typecheck lint --filter='...[origin/main]';pnpm exec turbo run testfor every changed package (app, cli, demo-server, host-daemon, server, db, domain, host-daemon-contract, plugin-sdk, sdk, server-contract, templates, test-helpers, bb-guide, connect, environment-modal-sandbox, plugin-api-docs);pnpm exec turbo run test --filter=@bb/integration-tests --force. Counts below.After rebasing onto main at 76d4358:
install-machine-script.test.tsandplugin-install.test.ts's git fallback. db, server and host-daemon were rerun after the final rebase onto Time server and plugin SQL in the query cost check, and fail every case on its ceiling #7934, which moves server SQL into@bb/dbdata modules (13/13 tasks). Following Time server and plugin SQL in the query cost check, and fail every case on its ceiling #7934,server-access.tswrites host columns throughsetHostColumns, andsql-in-data-modules.test.tspasses.--force, not a cache replay): 31/31 files, 80/80 tests.pnpm exec turbo run check:query-costs --filter=@bb/db: passes under Fail the query cost check on undeclared growth, and bound nine history lookups #7923's stricter growth check; cases added for every new query function (getOrCreateServerId,get/setServerAccessOrigins, the grants table functions,recordSessionRoute); no growth warnings from them.plugin-instance-lifecycle.test.ts"runs a provider callback only on the instance that registered it" now tolerates the background availability refresh on plugin change; it still asserts the stale record never reaches the old instance (same adjustment as the Tailscale plugin PR).Live, on an isolated
pnpm start:worktreeinstance with a second enrolled daemon ("Client A") and a TCP relay standing in for a breakable Manual route ordered first, Local network second:server-routes.json; Local network was not offered.server-routes.replaceand stayed on its working route. After a restart it dialed the saved top route (Manual) in 15 ms;bb machine listshowed Route "Manual".resumeDaemonSessionson, sessionhses_5zcdm8va5cresumed across the switch. Turning Local network on from Settings reached the connected daemon at once.routes: []and deleted its routes file, Local network disappeared, and the LAN listeners closed.http://127.0.0.1.sslip.io:25900), the first requests after a server restart returned403 forbidden_hoston/healthand/api/v1/system/configbefore the fix, and200on the very first request after it.direct), not Local network.Re-run after the rebase (it changed the daemon dial path: per-route headers now go through main's compressed WebSocket constructor and send queue), on the same setup:
http://127.0.0.1.sslip.io:25900) and learned Manual + 2 Local network routes.resumeDaemonSessionson, sessionhses_bmjc944x9hresumed across a Manual → Local network switch, and its row recordedlocal-network. Turning Local network off moved it back to Manual. Turning it on reached the connected daemon live.routes: []and deletedserver-routes.json, Local network disappeared, and the LAN listeners refused connections./healthand/api/v1/system/config.Known limit, unchanged by the rebase: if a daemon was installed on a Manual hostname while the experiment was on, it cannot reconnect after the experiment is turned off. The hostname gets
403 forbidden_hostagain, which is main's behaviour for a hostname withoutBB_APP_URL. It recovered as soon as the experiment was turned back on.Not exercised live: a real bb connect route (the dev server was unpaired) or a real Tailscale route (unit tests cover its admission with the experiment off).
Part of #6748
🤖 Generated with Claude Code