Skip to content

Agents on a host whose server moved to bb Connect get HTTP 401 from bb: launcher prefers config.json serverUrl over BB_SERVER_URL #4243

Closed

Description

@brsbl

Summary

On a machine whose bb server was moved to bb Connect, every agent thread on that machine gets HTTP 401: Unauthorized from the bb CLI, for example from bb thread show, bb project list, and bb machine list. The host daemon gives each thread an authenticated loopback proxy in BB_SERVER_URL. The bb-app launcher replaces it with serverUrl from the machine's config.json (the public https://<handle>.getbb.app URL), and the CLI calls that URL without the machine credential. Restarting doesn't help, because the config file is unchanged.

Versions and environment

  • Affected machine: bb 0.43.4-nightly.35739502552.1, installed through the desktop app and npm into ~/.bb, macOS on Apple silicon. It was originally the desktop-hosted server and is now a remote host of a bb Connect server (https://<handle>.getbb.app).
  • Minimal repro below: bb 0.43.5-nightly.35773768107.1, macOS 15.2 (Intel), Node 24.18.1.
  • Code cited at main dea024ee6cdc8d482ca13713684e8495a112e142.

Steps to reproduce

Minimal, needs no Connect server; it shows only the precedence:

D=$(mktemp -d)
echo '{"serverUrl":"https://example.invalid"}' > "$D/config.json"
(unset BB_CLI; BB_DATA_DIR="$D" BB_SERVER_URL=http://127.0.0.1:59999 bb --help | grep 'BB_SERVER_URL:')
rm "$D/config.json"
(unset BB_CLI; BB_DATA_DIR="$D" BB_SERVER_URL=http://127.0.0.1:59999 bb --help | grep 'BB_SERVER_URL:')
rm -rf "$D"

On a real affected machine:

  1. Move a desktop-hosted bb server to bb Connect, so the old desktop becomes a remote host whose ~/.bb/config.json contains serverUrl: https://<handle>.getbb.app and serverHeaders with the machine credential.
  2. Start any agent thread on that machine and have it run bb thread show <any-thread-id> --json.

Expected vs actual

Minimal repro, actual:

  BB_SERVER_URL: https://example.invalid      # config.json present: the explicit env var is ignored
  BB_SERVER_URL: http://127.0.0.1:59999       # config.json absent: the env var is used

Expected: the explicitly set BB_SERVER_URL is used in both cases.

Affected machine, actual, from an agent thread whose env has BB_SERVER_URL=http://127.0.0.1:59089 (the daemon's machine-auth proxy):

$ bb thread show thr_… --json
Error: HTTP 401: Unauthorized
{"ok": false, "error": {"code": "http_401", "message": "HTTP 401: Unauthorized"}}

$ bb --help | grep BB_SERVER_URL
  BB_SERVER_URL: https://<handle>.getbb.app

With NODE_DEBUG=net, the CLI connects directly to the Connect hostname on port 443, and never to the loopback proxy.

Expected: the CLI uses the daemon-provided proxy and the command succeeds. The proxy itself works: curl "$BB_SERVER_URL/api/v1/threads/thr_…" returns 200 application/json, and "$BB_CLI" thread show thr_… --json, which bypasses the launcher, succeeds.

Evidence

What you ruled out

  • Not a stale or expired machine credential: the daemon's proxy, which uses the same serverHeaders, authenticates fine.
  • Not shell configuration: no BB_SERVER_URL in shell profiles, and ~/.local/bin/bb only execs the installed launcher.
  • Still present at 0.43.5-nightly.35773768107.1 (minimal repro) and in main at dea024ee6 (code above).
  • No duplicate found in open or closed issues.

Suggested priority and effort

Every CLI call from every agent on an affected machine fails, so agents can't coordinate, report back, or open terminals. The workaround is to invoke "$BB_CLI" directly. Small fix: prefer an explicitly set BB_SERVER_URL over config.serverUrl in resolveServerUrl, or at least when the daemon provides it, plus a regression test. Terminals the user opens themselves don't set BB_SERVER_URL, so they keep resolving to config.serverUrl.

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.
  • If an agent wrote this, the body ends with > AGENT GENERATED and links the thread or report.

Found while coordinating agent workers on the affected machine, in bb thread thr_ixu6r7h84m.

AGENT GENERATED

Activity

  1. added
    bug
    remote
    cli
    on Sep 24, 2026
  2. added theissue type on Sep 24, 2026
  3. added
    partial-repro
    on Sep 24, 2026
  4. bb-slop-cop commented on Sep 24, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Classification: Bug · Priority: Medium · Effort: Low. Preserved bug, remote, and cli; added partial-repro.

    Reproduction report: PARTIALLY REPRODUCED, high confidence in the URL-selection cause. A focused regression fails in two clean checkouts of origin/main: saved configuration replaces the injected thread proxy URL. The CLI transport also does not forward BB_SERVER_HEADERS; live Connect 401s remain unverified.

    No PR: an existing passing test explicitly requires config-over-environment precedence, so changing that policy exceeds the automatic simple-fix gate.

  5. akrupa-appto commented on Sep 29, 2026

    @akrupa-appto

    still hitting this on bb desktop 0.44.0 after a server move to bb connect. it's the plain terminal case from #4277: on the old machine, bb status looks fine but any real call (bb project list, bb plugin list) returns 401, because the cli goes straight to https://<handle>.getbb.app without the machine credential. setting BB_SERVER_URL to the daemon's loopback proxy doesn't help either, config serverUrl wins.

    this issue got closed but #4277 is still open, so it's not fixed in a release yet. workaround for now is running bb over ssh on the server machine.

  6. timurkhakhalev commented on Oct 14, 2026

    @timurkhakhalev
    Contributor

    Additional reproduction: the remote CLI problem remains with BB 0.46.0 after moving a server from macOS to Linux, with the former desktop enrolled as an execution machine.

    There is also a desktop bundled-CLI entry point that needs coverage independently of the bb-app launcher:

    • The existing desktop-provided bb command resolves directly to the installed package's host-daemon/dist/bb, bypassing packages/bb-app/src/launcher.ts.
    • With BB_SERVER_URL unset, this CLI targets the default http://127.0.0.1:38886, although the machine's saved configuration points at the moved server.
    • With BB_SERVER_URL explicitly set to the public Connect endpoint, an API call returns HTTP 401. Supplying the saved headers as BB_SERVER_HEADERS does not authenticate this bundled CLI either.
    • The host daemon is connected. The same bundled CLI successfully reads a thread when explicitly pointed at the daemon's authenticated loopback proxy. This rules out an unavailable server or invalid machine credential for this reproduction.

    The current bundled CLI reads its server URL from the environment and does not load saved serverUrl/serverHeaders; its transport does not attach BB_SERVER_HEADERS. Thus #4277 addresses the packaged launcher's URL precedence and adds environment-header support, but its launcher configuration resolution is bypassed by this desktop entry point. Please include a regression check for an ordinary terminal using the existing desktop-provided command after a server move, with neither connection variable supplied by the user.

    The daemon-provided proxy was used only as a diagnostic control, not installed as a replacement command. No private addresses, identifiers, absolute installation paths, or credentials are included here.

    AGENT GENERATED

  7. salemsayed commented on Nov 20, 2026

    @salemsayed
    Contributor

    @SawyerHood a remaining path for this closed issue, still on main at fab8266: the packaged launcher still prefers config.json serverUrl over the caller's BB_SERVER_URL (launcher.ts#L1053-L1060, applied at #L1456-L1464 for runBbCli's managed mode).

    Agent threads avoid it because the daemon puts its own CLI first on PATH. But on a Connect machine whose login profile prepends ~/.local/bin (here an installer added export PATH="$HOME/.local/bin:$PATH" to ~/.bash_profile), bb terminals, --run-on script automations and threads on that machine reach the machine shim first. The shim runs the launcher, so every plugin command fails:

    bb --version          exit 0  0.50.2-nightly.44597192366.1
    bb <plugin> --help    exit 1  error: unknown command '<plugin>'
    bb plugin list        exit 1  Error: HTTP 401: Unauthorized
    "$BB_CLI" <plugin> --help   exit 0
    

    Minimal precedence repro, with no Connect server needed:

    D=$(mktemp -d); printf '{"serverUrl":"https://example.invalid"}\n' > "$D/config.json"
    env -i HOME=$HOME PATH=/usr/bin:/bin BB_DATA_DIR="$D" BB_SERVER_URL=http://127.0.0.1:59999 BB_CLI=<package>/host-daemon/dist/bb <data dir>/bin/bb status
    # Error: The bb server at https://example.invalid did not answer ...   (expected 127.0.0.1:59999)

    #4277 and #5486 carried the fix and were closed by the two-week rule, not on review. The shim staleness that makes this reachable is filed separately in #7897.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclipartial-reproremote

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions