Repository navigation
Conversation
On a machine enrolled through bb connect, the bb launcher puts the machine credential in BB_SERVER_HEADERS and points BB_SERVER_URL at the stored server, but the CLI never read BB_SERVER_HEADERS. Plain bb in an ordinary shell therefore reached the connect gate without the credential and got HTTP 401. cliFetch, which every CLI server request goes through, now attaches those headers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This comment has been minimized.
This comment has been minimized.
ymichael
deleted the
bb/bb-cli-never-sends-the-machine-credential-401-on-thr_xv9nbyag6k
branch
December 1, 2026 05:15
scowalt
pushed a commit
to scowalt/bb
that referenced
this pull request
Dec 1, 2026
## Human comments ## What was wrong On a machine enrolled through bb connect, running plain `bb` in an ordinary shell (outside a bb terminal or agent shell) returned HTTP 401. The `bb` launcher reads the machine's `config.json`, sets `BB_SERVER_URL` to the stored server, and passes the machine credential to the CLI in `BB_SERVER_HEADERS` (`packages/bb-app/src/launcher.ts`, `applyManagedConfigEnv`). Nothing in `apps/cli` read `BB_SERVER_HEADERS`, so requests reached the bb connect gate without `x-bb-connect-machine`. `docs/configuration.md` already said the bundled CLI sends these headers. bb terminals and agent shells were not affected because their requests go through the daemon's loopback helper, which adds the credential itself. Found while reviewing get-bb#8266, which fixed only that managed path. ## What changed - `packages/config/src/cli.ts`: new `loadCliServerHeaders()` parses `BB_SERVER_HEADERS` with the existing `BB_SERVER_HEADERS_ENV` definition. The default is `{}`, and a malformed value throws instead of silently dropping the credential. - `apps/cli/src/client.ts`: `cliFetch` is the single function every CLI server request goes through, both SDK calls and the raw `status` and plugin-proxy fetches. It now starts from those headers, and request headers set by the caller take precedence. No wire changes, so no `HOST_DAEMON_PROTOCOL_VERSION` bump. No CLI, guide or doc changes: the existing `docs/configuration.md` text is now accurate. ## How you verified - **Live repro:** I built `bb-app` with `turbo run build --filter=bb-app` and put a local gate in front of a real server. The gate returns 401 unless `x-bb-connect-machine` matches, the way bb connect does. I ran `node packages/bb-app/dist/bb.js thread list` under `env -i` with `BB_DATA_DIR` pointing at a `config.json` holding `serverUrl` (the gate) and `machineCredential`. - Before the fix: `HTTP 401: sign in required`, and the gate logged `401 GET /api/v1/threads…`. - After the fix: exit 0 with threads listed. `bb status` (`/system/config`, `/plugins`, `/plugins/contributions`) and a plugin command (`POST /plugins/bb--git/cli`) all passed the gate. - **Tests:** in `apps/cli/src/__tests__/client.test.ts`, SDK requests and direct `cliFetch` requests must carry `BB_SERVER_HEADERS`, and a malformed value must throw. All three fail without the fix and pass with it. - `pnpm exec turbo run test typecheck --filter=@bb/cli --filter=@bb/config` passed (CLI 1460 tests, config 101). > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) 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
On a machine enrolled through bb connect, running plain
bbin an ordinary shell (outside a bb terminal or agent shell) returned HTTP 401. Thebblauncher reads the machine'sconfig.json, setsBB_SERVER_URLto the stored server, and passes the machine credential to the CLI inBB_SERVER_HEADERS(packages/bb-app/src/launcher.ts,applyManagedConfigEnv). Nothing inapps/clireadBB_SERVER_HEADERS, so requests reached the bb connect gate withoutx-bb-connect-machine.docs/configuration.mdalready said the bundled CLI sends these headers. bb terminals and agent shells were not affected because their requests go through the daemon's loopback helper, which adds the credential itself. Found while reviewing #8266, which fixed only that managed path.What changed
packages/config/src/cli.ts: newloadCliServerHeaders()parsesBB_SERVER_HEADERSwith the existingBB_SERVER_HEADERS_ENVdefinition. The default is{}, and a malformed value throws instead of silently dropping the credential.apps/cli/src/client.ts:cliFetchis the single function every CLI server request goes through, both SDK calls and the rawstatusand plugin-proxy fetches. It now starts from those headers, and request headers set by the caller take precedence.No wire changes, so no
HOST_DAEMON_PROTOCOL_VERSIONbump. No CLI, guide or doc changes: the existingdocs/configuration.mdtext is now accurate.How you verified
bb-appwithturbo run build --filter=bb-appand put a local gate in front of a real server. The gate returns 401 unlessx-bb-connect-machinematches, the way bb connect does. I rannode packages/bb-app/dist/bb.js thread listunderenv -iwithBB_DATA_DIRpointing at aconfig.jsonholdingserverUrl(the gate) andmachineCredential.HTTP 401: sign in required, and the gate logged401 GET /api/v1/threads….bb status(/system/config,/plugins,/plugins/contributions) and a plugin command (POST /plugins/bb--git/cli) all passed the gate.apps/cli/src/__tests__/client.test.ts, SDK requests and directcliFetchrequests must carryBB_SERVER_HEADERS, and a malformed value must throw. All three fail without the fix and pass with it.pnpm exec turbo run test typecheck --filter=@bb/cli --filter=@bb/configpassed (CLI 1460 tests, config 101).🤖 Generated with Claude Code