Repository navigation
Add bb cloud AI: hosted titles and commit messages for signed-in accounts - #4254
Conversation
|
🚨 SLOP COP 🚨 · This PR adds hosted AI for thread titles and commit messages for signed-in BB accounts. I’m reviewing security, code quality, performance, and architectural duplication, and checking the available end-to-end verification.
|
| const key = accountKey(account.account); | ||
| const until = exhaustedUntil(key); | ||
| if (until !== null) throw new Error(limitReachedMessage(until)); | ||
| const response = await accountFetch( |
There was a problem hiding this comment.
🚨 slopcop/review — [P2] Recheck opt-in before sending the prompt
enabled is checked before await accountStatus(). If the user turns cloud AI off while that RPC is pending, this continuation still starts a new POST containing the prompt or diff after the disable operation succeeds. I reproduced this with the actual complete() function body and a deferred account-status response: disable first, release the response, then observe the POST with enabled === false.
Recheck enabled immediately before accountFetch, and add a regression test that holds account status pending while switching off. The current off-state tests only cover completions started after disabling.
AGENT GENERATED
There was a problem hiding this comment.
Fixed in ccf52e8. complete() checks enabled again right before accountFetch. New test: the account-status response is held, setEnabled(false) runs, then the response is released. The completion now rejects with the off message and sends nothing; on the previous code it sent the POST.
AGENT GENERATED
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
This adds an optional cloud service that writes thread titles and commit messages using your BB account. It starts off, includes a disclosure and on/off switch, and shows usage and daily-limit status in Settings and the CLI.
I found one P2 issue: a generation request waiting on account status can still send its prompt or diff after the user switches cloud AI off. Inline finding and suggested regression test. A deterministic harness using the actual completion function reproduced the POST after disabling.
The parallel security, code-quality, and performance reviews found no additional actionable issues. The architecture scan found that this correctly reuses the existing AI service registry and account transport; no substantial duplicate implementation needs extracting.
Verification: all 23 plugin tests and the plugin typecheck passed through Turbo. An isolated dev server and daemon started successfully. Using BB Browser Automation, I verified the signed-out settings disclosure, off-by-default state, enabling, persistence across reload, and switching back off. Signed-in cloud generation and budget exhaustion were not exercised. The verification inventory check separately reports an unmapped browser CLI family, outside this change.
AGENT GENERATED
f540d0a to
9b5e109
Compare
9b5e109 to
ccf52e8
Compare
ccf52e8 to
b3d2191
Compare
6e3d6f3 to
8278744
Compare
8278744 to
c42f8fc
Compare
c42f8fc to
9477749
Compare
9477749 to
363e931
Compare
363e931 to
127abca
Compare
127abca to
7516c81
Compare
152c87f to
d16a6a2
Compare
9ae6aac to
bebae76
Compare
…unts Re-lands #4230: the bb-ai plugin serves bb's title, branch name and commit message tasks through the bb-ai-gateway, for bbs signed in to a bb account. It calls the gateway through bb-account.v1.fetch, so it never sees the credential. One change from #4230: it checks the opt-in again right before sending, so turning bb cloud off while the account check is still pending sends nothing. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
bebae76 to
4a5164f
Compare
## Human comments ## What was wrong #4232 reverted the bb-ai-gateway worker with the rest of the bb account stack. The deployed worker was left in place, but its source and deploy workflow left `main`. It also used to deploy on every `packages/connect-db` change, which put it in the same merge as the web and gate deploys. Three workers shipping on one merge made the 2026-09-24 outage harder to read. ## What changed - `apps/ai-gateway` is back unchanged from #4227: - `POST /api/ai/v1/complete` and `GET /api/ai/v1/usage` on `bb-ai-gateway`; - calls go to OpenRouter; - metered at 50 cents per account per UTC day against the connect-db usage tables; - a nightly cron prunes request logs. - `pnpm cloud:dev` runs it next to the dashboard and the gate again. - **Deploy AI Gateway** now runs when `apps/ai-gateway/**`, `packages/connect-db/src/**` (the credential checks and schema it bundles) or the workflow itself changes. It no longer runs on migration-only connect-db changes, which put it in the same merge as the web and gate deploys. ## How you verified - `pnpm exec turbo run typecheck test --filter=@bb/ai-gateway` on this layer: pass. - Staging: this gateway deployed to `bb-ai-gateway-staging` (`c0cb8b9a`, last on 2026-09-25) and served the bb-ai e2e in #4254: titles and commit messages from bb cloud in about 0.6 s, metered against the daily budget. - No bb calls the gateway until a release includes #4254. ## Rollout 1. The `OPENROUTER_API_KEY` Actions secret must exist. It already does from #4227. 2. Merge after #4250. **Deploy AI Gateway** runs `wrangler deploy` for `bb-ai-gateway` alone. The worker already exists in production from the 01:07 UTC deploy on 2026-09-24, so this replaces it with the same code. 3. Watch: `GET https://getbb.app/api/ai/v1/usage` answers 401 without a credential; the worker shows no exceptions; OpenRouter spend stays flat until the bb-ai release. ## Rollback `pnpm --filter @bb/ai-gateway exec wrangler rollback 9cbac579-3396-4fb7-bc89-abac544419e4 -m "<reason>"` (production's gateway on 2026-09-24), or delete the `getbb.app/api/ai/*` route. Nothing released depends on it. Stack: 2 of 4. Base: #4250. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…#4253) ## Human comments ## What was wrong #4229 moved Connect onto the new bb-account plugin. Two choices in it made the 2026-09-24 gate outage harder to recover from: - **Connect could only dial with tunnel tickets.** Rolling the gate back to a version that doesn't know tickets returned 401 to every bb running `main`, so the rollback locked them out. - **Adoption moved the credential.** bb account adopted Connect's legacy pairing and deleted Connect's copy. When it held a different server's credential, it revoked the legacy one. A bb downgraded to an older build started signed out, as bee did after the revert. Separately, the sign-in dialogs in both plugins polled every 2 s whether or not the last poll failed. ## What changed This is #4229 plus these changes: - **No tunnel tickets** (`plugins/connect/src/tunnel.ts`, `hosted.ts`). Connect dials `wss://<handle>.getbb.app/__tunnel` with the raw server credential, as released builds do, so it works with every gate, including one that has been rolled back. Before each dial it reads the credential from `bb-account.v1.connectCredential` (private contract; only the connect plugin may call it, and other plugins and the CLI get "only the connect plugin"). Log lines are `tunnel connecting to …` and `tunnel connected`, as in released builds. - **A credential the gate refuses signs bb account out** (`bb-account.v1.confirmRefusedCredential`, connect-only). With tickets, a replaced or revoked credential showed up as a 401 from the ticket endpoint, which bb account checked and signed out on. Now the gate's 401 or 403 is the only signal. Connect passes the refused credential to bb account, which checks it with `GET /api/account/me` and signs out if getbb.app answers 401. It ignores a credential that is no longer current, and a check that fails changes nothing. Connect keeps retrying with backoff meanwhile. Without this, a bb whose server was replaced or removed would dial forever. - **#4313's client changes, carried into this tunnel.** #4313 changed `main`'s old `tunnel.ts`, which this PR replaces, so its client behavior is ported: - stopping closes the tunnel with 1000, so the gate shows the server offline at once instead of holding visitors; - the handshake timeout is 10 s; - a close with the gate's `replaced by a new tunnel connection` reason (another bb took the tunnel over) backs off 5 minutes and says why. - **Copy, don't move** (`plugins/connect/src/credential-copy.ts`). Connect keeps the pairing under its KV key `credential`, in the `{serverUrl, handle, credential}` shape builds from before bb account read. `credentialCopyOf` records the SHA-256 of the credential it last shared with bb account. On each bb account change: - Signed in: connect writes bb account's credential to its copy. If the copy isn't the one it last shared (an older build re-paired after a downgrade, or a bb that ran `main` during the outage window, like bee), it first offers it to bb account. - Signed out: a copy it shared is removed, so older builds see the sign-out. A copy it never shared (the normal upgrade) is offered. - **`adoptConnectCredential`** takes `replaces`: the credential connect saw in bb account, or null for signed out. It answers: - `changed` if bb account has moved on since; - `rejected` if `/api/account/me` refuses the offered credential; - `adopted` once stored. It never revokes or deletes a pairing. Keep Connect's copy for at least two releases after the first release with bb account; the Connect README says so. - **`AccountLink` backoff:** status and credential-sync failures back off exponentially up to 30 s. The failure count used to reset before the sync ran, so a failing adoption retried every second. - **Sign-in poll backoff** in `plugins/connect/app.tsx` and `plugins/bb-account/app.tsx`: 2 s while polls succeed, then doubling to 30 s while they fail, instead of a fixed `setInterval`. - Plugin SDK 0.6.3 (the `experimental_caller` surface; `main` is at 0.6.2). ## How you verified - Tests that fail before and pass after: - `account-integration.test.ts` (real bb-account plugin plus the stub getbb): - `signs out everywhere when getbb.app rejects the credential`: the stub gate refuses a revoked credential on the redial, bb account signs out, and connect tears the tunnel down. Without `confirmRefusedCredential` it fails: connect retried forever; - copies the legacy credential, keeps Connect's copy, revokes nothing, and dials with it; - prefers a pairing an older build made over a stale bb account sign-in; - retries when bb account is briefly unavailable while handing over the credential. - `account.test.ts`: `confirmRefusedCredential` checks only the current credential, keeps a valid one, signs out when getbb.app answers 401, and serves only the connect plugin; `adoptConnectCredential` compare-and-swap and no revocation; `connectCredential` only for the connect plugin. - `tunnel-lifecycle.test.ts`: dials the account's tunnel URL with the credential from bb account; a gate 401 is reported to bb account once per refusal and backs off; a 500 isn't reported; a stalled handshake reads the credential again; bb account being unavailable backs off, then dials. - `tunnel-lifecycle.test.ts`, #4313's tests ported to this tunnel: clean close on stop, the 10 s handshake deadline, the 5-minute backoff after a takeover, a normal redial after 1006, and a late "replaced" close from a stale socket. The first three fail on this PR's tunnel without the port. - `connect.test.ts`: mirrors bb account's pairing for older builds and removes it after sign-out; hands over a pairing an older build made after a downgrade; offers a rejected legacy credential once; backs off while adoption fails; remote access off and on redials. - `app.test.tsx` in both plugins: a failing sign-in poll isn't repeated within 2.5 s. The old code fails this; checked by running it against the previous `app.tsx`. - `pnpm exec turbo run typecheck --filter="...[HEAD^1]"` (101 tasks) and `test --filter="[HEAD^1]"` on this layer. The only failures were outside this change, and each passes when rerun alone: host-daemon command discovery and provider-acp native roots (a `TMPDIR` under `$HOME` on the test machine), and one `apps/server` machine-environment test (a load flake). - Both plugin SDK version guards pass with 0.6.3. ### Staging end to end (`vibecodethis.site`, 2026-09-25 UTC, on `main` with #4313) - **Setup:** gate = `main`'s with #4313 (`2e6e20c7`, deployed with #4250's manual `versions deploy`); web = #4250 (`630823a5`); AI gateway = #4252 (`c0cb8b9a`). No `wrangler tail` at any point. - **Test bb:** one fresh data dir throughout, label `sawyer`. Its hostname was probed every 5 s at `/install/version`. | Step | Time | What happened | Result | |---|---|---|---| | R1 | 02:40 | A released-style bb (`main` `9781a2126a`, no bb account) paired with a dashboard-style code through #4250's web | `tunnel connected` at 02:40:18 | | R2 | 02:40 | Upgraded in place to this stack (`152c87ff0c`, the #4254 head) | Copied the pairing and `tunnel connected` at 02:40:48. bb-account and Connect hold the same credential plus `credentialCopyOf` | | R3 | 02:41 | bb cloud AI through #4252's gateway | See #4254 | | R4 | 02:41 | Downgraded to `main` | #4289 removed the bb-account and bb-ai installs at startup and kept their KV. Connected at 02:41:15 from Connect's copy | | R5 | 02:41 | Upgraded again | bb account signed in from its KV, `tunnel connected` at 02:41:24 | | R6 | 02:41–02:42 | bb-web rolled back to the pre-stack version, and this client restarted under it | Logged `could not refresh the bb account profile: … HTTP 500`; stayed signed in, `tunnel connected`, bb cloud worked. Web rolled forward | | R7 | 02:42 | Gate redeployed with this client connected | `tunnel closed (code 1006)` at 02:42:12, `tunnel connected` at 02:42:14. A one-second probe got 75/75 200s; one request was held 3.1 s | | R8 | 02:43–02:49 | Another bb re-paired the server and dialed with the new credential | Logs below: this client backed off 5 minutes, then its redial got a 401 and bb account signed out | | R9 | 02:49 | `bb account login --code` with a new code | Connect saved its copy, `tunnel connected` at 02:49:19, bb cloud worked | | R10 | 02:49 | Server revoked on getbb.app, then a redial | gate 403, signed out at 02:49:24; restored and signed in again | | R11 | 02:49 | After the fresh sign-in, downgraded to `main` | `tunnel connected` at 02:49:53 from Connect's copy of the new pairing | | R12 | 02:51–03:06 | Upgraded again and held for 15 minutes | 174/174 probes 200; no Connect or bb account log lines; 0 heartbeat misses or stalls | | R13 | 02:51 | `bb connect off` | Clean close: the next visitor got 503 in 0.07 s, with no hold | R8: ``` [02:43:58] [plugin:connect] another bb connected with this server's identity and took over bb connect; reconnecting in 300000ms [02:48:58] [plugin:connect] tunnel connecting to wss://sawyer.vibecodethis.site/__tunnel?v=1 (origin http://127.0.0.1:19316) [02:48:58] [plugin:connect] the gate refused this bb's server credential (HTTP 401); reconnecting in 2000ms [02:48:58] [plugin:bb-account] getbb.app rejected this bb's credential (HTTP 401 on GET /api/account/me after the connect gate refused a tunnel); signed out [02:48:58] [plugin:connect] bb account signed out, so connect removed its copy of that pairing ``` Cloudflare GraphQL for `sawyer.vibecodethis.site`, 02:39–03:06: - 503s only in the takeover window (02:44–02:49) and the two stop checks (02:50–02:51); - one 401 (R8) and one 403 (R10); - staging Durable Object `internalError`: 2 around the first deploy, then 0; `clientDisconnected` 0–9 per 5 minutes. **Unchanged by this PR:** stopping the dev launcher's whole process group (SIGTERM) exits before the tunnel's clean close reaches the gate. With `main`'s client too, visitors saw one 502 and a 14 s hold before 503. `bb connect off` closes cleanly (R13). Earlier runs are in the PR history: round 1 on 2026-09-24 before #4313, and the ticket version's steps A–E in closed #4251. ## Rollout 1. Merge after #4250 and #4252 are deployed. The gate needs no change: this client dials exactly as released builds do, and production's gate already has #4313. Run it on dev servers first (bee), then ship a release. 2. On bee, expect `copied connect's pairing into bb account`, `tunnel connecting to …` and `tunnel connected`. 3. Watch: - `grep 'plugin:connect\]\|plugin:bb-account\]' ~/.bb/logs/server-stdio.log` on bee; - `/api/account/*` status codes on bb-web; - bb account `signed out` lines, which should only follow a server being removed or replaced on getbb.app. ## Rollback Revert this PR on `main` (and ship a patch release if it was released). A bb that ran it keeps its pairing when it goes back: Connect's copy is still in its KV (R4, R11). A bb that signed in fresh on this build also keeps it, because the copy is kept in step with bb account (R11). Since #4289, a build without bb account deletes that plugin's install, settings, secrets and schedules at startup. It keeps plugin KV, which is where bb account keeps its sign-in and bb-ai keeps its opt-in, and a built-in reinstalls under the same id. Upgrading again after a downgrade therefore comes back signed in, as R4 and R5 showed. Stack: 3 of 4. Base: #4252. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
## Human comments ## What was wrong bb cloud (the `bb-ai` plugin, #4254) only served thread titles and commit messages. Voice input had no hosted option, so a bb without a Codex login had no microphone. The plan left voice as phase 2 (`plans/bb-account-and-hosted-generation.md`, Part 8). The bb side already had everything voice needs: the plugin SDK's `transcribe` hook, the Voice input row in Settings → AI services, the server's transcribe route, `bb voice transcribe`, and the mic's readiness check. The missing pieces were a hosted endpoint and bb-ai implementing `transcribe`. ## What changed - **bb-ai-gateway** (`apps/ai-gateway`): new `POST /api/ai/v1/transcribe`. - Takes `{audio, format, hint}` with base64 audio, capped at 10 MB, and forwards it to OpenRouter's `POST /api/v1/audio/transcriptions` with `provider: {zdr: true, data_collection: "deny"}`. - Metering is shared with `/complete` through one `handleMetered` path: the same auth, rate limit, daily budget and request log. Transcription reserves 2¢ per call and settles to the reported cost. - `AI_TRANSCRIBE_MODELS` (new, required var, set in `wrangler.jsonc` for production and staging) lists the models in order. OpenRouter's transcription endpoint has no `models` fallback, so the gateway moves to the next model when one answers with an HTTP error, all within an 8 s deadline. It never retries after a timeout. - The vocabulary `hint` goes to `provider.options.groq.prompt`, the only hint option OpenRouter documents. - Default models: `microsoft/mai-transcribe-2`, then `openai/whisper-large-v3-turbo`. Both have ZDR endpoints. - **bb-account**: `bb-account.v1.fetch` accepts request bodies up to 16 MB instead of 1 MB, since base64 recordings didn't fit. Responses stay capped at 1 MB. - **bb-ai**: registers `transcribe`. - It sends the recording through `bb-account.v1.fetch` with a 10 s timeout. - It maps the MIME type or file extension to an OpenRouter format, so Chrome's `audio/webm;codecs=opus` becomes `webm` and Safari's `audio/mp4` becomes `m4a`. - It refuses recordings over 10 MB or in unknown formats without contacting getbb.app. - The opt-in, sign-in and used-up-budget checks are shared with `complete`. - bb cloud now appears for Voice input, and Automatic tries Codex, then bb cloud. - **Copy and docs**: `bb ai` help, the plugin README, overview and skill, `docs/configuration.md`, and the verify-bb feature map now cover voice input and say recordings are never stored. (Merged with #4522, which made bb cloud on by default and removed its settings page and disclosure, and #4525, which deleted the plan doc. The model comparison that was going into the plan is below.) **Model choice** (OpenRouter transcription models with ZDR endpoints, 2026-09-29): `microsoft/mai-transcribe-2` (Azure, about $0.0017/min at a launch price that ends 2026-12-31, #1 on FLEURS and #2 on Artificial Analysis's word-error-rate board), `openai/whisper-large-v3-turbo` (Groq/DeepInfra, $0.0002–0.0007/min, takes a vocabulary prompt on Groq), and Voxtral Mini Transcribe, Deepgram Nova-3 and AssemblyAI Universal-3.5 Pro. `openai/gpt-transcribe`, `google/gemini-3.5-transcribe` and `x-ai/grok-stt-1.0` have no ZDR endpoint. - **Stale docs from #4522**: the `bb-cloud-ai` skill, plugin overview, README, `docs/configuration.md` and the verify-bb feature map still described the removed opt-in and settings page. They now say bb cloud is on by default once you sign in, `bb ai off` turns it off, and disabling the plugin also stops it. The skill also covers voice input: accepted formats, the 10 MB limit, the 10 s timeout, and `bb voice transcribe`. No server, daemon or SDK changes. No `HOST_DAEMON_PROTOCOL_VERSION` bump. **Known issue, not addressed here:** through OpenRouter, MAI-Transcribe 2 answers 400 for WebM and MP4 audio but accepts the same speech as Ogg or MP3. Chrome and Safari recordings therefore get transcribed by Whisper after one refused MAI call. The follow-up is either to put Whisper first in `AI_TRANSCRIBE_MODELS` (config only) or to convert recordings to Ogg before upload. ## How you verified - `pnpm exec turbo run typecheck test lint --filter=@bb/ai-gateway --filter=bb-plugin-bb-ai --filter=bb-plugin-bb-account`: pass (gateway 32 tests, bb-ai 28, bb-account 59). - New gateway tests cover: - the exact OpenRouter request, including ZDR and the Groq hint, and the metering and request log, which never contains audio or text; - falling back on an HTTP error but not on a timeout; - charging nothing when every model refuses; - input validation (base64, the 10 MB cap, format, hint size); - the 2¢ reserve, so a nearly spent budget still allows a title but not a recording; - 401 without a credential; - a Miniflare test that sends a 4 MB body through the real Workers runtime and D1. - New bb-ai tests cover the fetch payload and timeout, refusals that send nothing (off, too large, unknown format), budget exhaustion from a transcription answer, and MIME/extension mapping. - Local end to end against real OpenRouter (`pnpm cloud:dev` with a key, plus `pnpm dev` signed in to a local account, `bb ai on`, and `bb settings ai-services set voice bb`): - `bb voice transcribe` on WebM, MP3 and M4A clips returned correct transcripts in 1.0–1.6 s. The gateway log showed MAI answering MP3 and Whisper answering WebM and M4A. - `bb ai usage` counted the requests. - After merging `main`: typecheck, test and lint pass again (bb-ai 24 tests, gateway 32, bb-account 59). - Recording with the mic in the app worked. ## Rollout Deploy the gateway (**Deploy AI Gateway**) before releasing bb-ai. A released bb-ai against an old gateway would show the mic and fail every recording with a 404. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Human comments
What was wrong
#4232 reverted the bb-ai plugin (#4230) together with the rest of the bb account stack. Its code wasn't implicated in the 2026-09-24 outage.
What changed
#4230 re-landed with one change:
complete()checks the opt-in again right before sending, so turning bb cloud off while the account check is still pending sends nothing (from SlopCop). The bb-ai plugin serves bb's thread title and commit message tasks through the bb-ai-gateway for bbs signed in to a bb account. It calls the gateway throughbb-account.v1.fetch, so it never sees the credential.How you verified
pnpm exec turbo run typecheck --filter="...[HEAD^1]"andtest --filter="[HEAD^1]"on this layer: pass.vibecodethis.site, 2026-09-25,mainwith Ride bb connect through tunnel resets instead of failing visitors #4313, Add the bb-ai-gateway worker #4252's gateway and Add the bb account plugin and move connect onto it, safe to roll back #4253's client on one data dir):bb ai on, thenbb settings ai-services set thread-title bband… commit-message bb;bb settings ai-services test thread-title→bb cloud (576ms): Add dark mode toggle to settings page;… test commit-message→bb cloud (586ms): feat(settings): add DarkModeToggle component and persist theme in …;bb ai status→Ready,Usage: <$0.01 of $0.50 today;Rollout
Ships in a bb release, after:
Merge it with the client PR or after it; on its own it changes nothing for a bb that isn't signed in.
Watch: bb-ai-gateway request volume and 4xx/5xx, OpenRouter spend, and
ai_usage_dayrows. Titles and commit messages keep working for signed-out bbs through their existing services.Rollback
Revert this PR (and ship a patch release if it was released). Users can also turn the plugin off in Settings → Plugins.
Stack: 4 of 4. Base: #4253.
🤖 Generated with Claude Code