Repository navigation
Add the bb account plugin and move connect onto it, safe to roll back - #4253
Conversation
|
🚨 SLOP COP 🚨 · This PR adds a shared bb account sign-in and moves remote access onto it, while keeping credentials compatible with older bb releases. I’m reviewing security, code quality, performance, and opportunities to reuse existing code, with three parallel reviewers. I’ll also attempt isolated end-to-end verification and report any limits alongside the findings. |
| path: "/api/connect/tunnel-ticket", | ||
| body: null, | ||
| }); | ||
| if (result.status === 401) throw new NotSignedInError(); |
There was a problem hiding this comment.
🚨 slopcop/review — [P2] Keep ticket endpoint 401 eligible for credential fallback
A ticket endpoint can return 401 while the pairing remains valid: AccountService.fetch() checks /api/account/me and deliberately preserves the credential when that check succeeds (or cannot complete). This line turns that response into NotSignedInError, so ConnectTunnel skips both credential fallback and retries. Subsequent polls supply the same identity, which setAccount() ignores. I reproduced one ticket request, zero credential reads, paired: true, and nextRetryAt: null; another identical account update did not recover it. Reserve NotSignedInError for the confirmed signed-out response already handled by send(), and route other ticket 401s through fallback/retry.
There was a problem hiding this comment.
Fixed in 2b787f8. mintTunnelTicket no longer turns a 401 into NotSignedInError. Only bb account's confirmed signed-out answer, handled in send(), does that. Any other non-2xx from the ticket endpoint, 401 included, pauses tickets and dials with the server credential. New integration test (real bb-account plugin plus the stub): the ticket endpoint answers 401 while /api/account/me accepts the credential, and the tunnel connects with the credential and stays signed in. It fails on the previous code.
AGENT GENERATED
| ? await this.options.account.status(signal) | ||
| : await this.options.account.waitForStatusChange(revision, signal); | ||
| if (signal.aborted) return; | ||
| failures = 0; |
There was a problem hiding this comment.
🚨 slopcop/review — [P2] Reset retry backoff after credential synchronization succeeds
When upgrading a legacy Connect pairing, the local account status request can succeed while copy.sync() fails fetching /api/account/me during adoption. Resetting failures here makes every catch increment it back to one, so hosted migration attempts repeat after one second indefinitely during an outage. Running this class with successful status reads and failed synchronization produced delays [1000, 1000, 1000, 1000, 1000], rather than [1000, 2000, 4000, 8000, 16000]. Move the reset after successful synchronization so hosted failures retain the intended capped exponential backoff.
There was a problem hiding this comment.
Fixed in 2b787f8. failures resets only after the status read and the credential sync have both succeeded. New test: with adoption throwing, a 500 ms window sees at most 6 attempts (20 ms, 40 ms, 80 ms and so on), not one every 20 ms. It fails on the previous code.
AGENT GENERATED
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
This adds one shared bb account sign-in for remote access and hosted services. Connect uses that account while retaining a credential copy and an older authentication path so downgrades and gate rollbacks can keep working.
I found two issues worth fixing:
- Ticket endpoint 401 can strand remote access, even when the account credential remains valid. The executable reproduction made one ticket request, never attempted credential fallback, and scheduled no retry; an unchanged account update did not recover it.
- Credential migration failures never increase retry backoff. The reproduction observed five consecutive one-second retry delays when local status succeeded but synchronization failed.
The three parallel reviews covered security, correctness, performance, and architecture. No actionable security vulnerability surfaced. One optional cleanup: bb-account/src/base-url.ts and connect/src/base-url.ts duplicate the same environment/origin resolver; sharing it through the existing neutral connect-client package would keep that policy consistent.
Verification: all 195 account/Connect tests passed through Turbo. An isolated fresh dev server and daemon passed health checks, the built source CLI returned the expected account and Connect status, and browser automation opened bb account settings and its pairing-code form. Full hosted sign-in, an authenticated tunnel, and downgrade/rollback journeys were not verified in this run. The verification inventory also reported an unmapped browser CLI family; I did not alter its baseline.
Reviewed commit bcf60fa1d89850133e7535a0d3cf589c85ae3572. This is a comment-only review.
3f7df6c to
2b787f8
Compare
2b787f8 to
7765d29
Compare
7765d29 to
87f164a
Compare
87f164a to
570d4dd
Compare
3040cbc to
0c377d0
Compare
0c377d0 to
772f14e
Compare
ae51888 to
ba6988e
Compare
ba6988e to
c347feb
Compare
c347feb to
c542e22
Compare
c542e22 to
11bab84
Compare
Re-lands #4229 without tunnel tickets: the bb-account plugin owns this server's getbb.app credential and sign-in, and connect makes hosted requests through it. Changes from #4229, after the 2026-09-24 outage: - No tunnel tickets. Connect dials the gate with the raw server credential, as released builds do. bb account hands the credential only to the connect plugin, through the private bb-account.v1.connectCredential RPC. When the gate refuses it (401 or 403), connect retries with backoff and reports it through bb-account.v1.confirmRefusedCredential; bb account checks the credential with GET /api/account/me and signs out if getbb.app no longer accepts it. - Copy, don't move. Connect keeps the pairing under its old `credential` KV key, where builds from before bb account read it, and keeps it in step with bb account: it writes bb account's credential there, hands bb account a pairing an older build made after a downgrade, and removes its copy only after bb account signs out of that same pairing. Adoption never revokes or deletes a pairing. adoptConnectCredential now takes `replaces` and stores the offered credential only while bb account still holds what connect saw. - Account status and credential sync failures back off exponentially (the count used to reset before the sync ran). - The sign-in polls in the connect and bb account settings back off to 30 s while getbb.app or the tunnel is unreachable, instead of polling every 2 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
11bab84 to
b3d7fac
Compare
## Human comments ## What was wrong #4232 reverted the bb account stack after the 2026-09-24 connect gate outage. This PR brings back the web half of #4227: the endpoints a bb account client needs. It is the first layer of a four-PR stack that re-lands #4227, #4229 and #4230 so each part can be deployed and rolled back on its own. The re-land drops #4227's tunnel tickets, so the gate itself doesn't change. ## What changed - **bb-web** (from #4227, without the tunnel ticket endpoint): - `/api/account/me`, `/api/account/link/start`, `/api/account/link/poll` and the `/link` approval page; - `POST /api/connect/machine-code-lookup`; - the dashboard's connect UI moved into `components/connect-ui.tsx`. The pairing command it shows (`bb connect --code … --server …`) works for released bbs and new ones. - **Link approvals can't replace a newer sign-in** (SlopCop P1). Delivering a link credential, re-pairing from the dashboard, and disconnecting a server now deny every other approved, undelivered link for that server. An approved code is delivered at most two minutes past its expiry; before, it could be delivered at any time. - **connect-db:** `resolveServerCredential`, `serverCredentialFromHeaders`, `write-result`, and a `./testing` export. Migrations 0006/0007 are already on `main`; this adds none. - Nothing changes under `apps/connect`, the tunnel packages, or the deploy workflows. ## How you verified - `pnpm exec turbo run typecheck --filter="...[HEAD^1]"` and `test --filter="[HEAD^1]"` on this layer alone: pass (connect-db, web, connect). - New `account.test.ts` cases, all four failing on the previous code: - an approved, unpolled code is denied after a disconnect plus a newer link; - it is denied after another link replaces the server; - it is denied after a dashboard re-pair; - it isn't delivered past the grace. - Not changed, answered on the review: atomic delivery writes and an index for the expired-link prune. Both are follow-ups. - Staging (`vibecodethis.site`), last run 2026-09-25 02:40–03:07 UTC on `main` with #4313: this web (`630823a5`) with `main`'s gate. A released-style bb paired through it with a dashboard-style pairing code (`Paired as sawyer — reachable at https://sawyer.vibecodethis.site`), then upgraded, downgraded and signed in again on the new client (#4253). `POST /api/connect/tunnel-ticket` answers 404. Rolling this web back to the pre-stack version under the new client kept its tunnel and sign-in (details in #4253). No `wrangler tail` was used. ## Rollout 1. Merge. **Deploy Web** ships bb-web to 100%. It only adds routes. This PR touches `packages/connect-db`, so **Deploy Connect** also runs: it applies no migrations (none are pending, checked against production D1 on 2026-09-25) and `wrangler deploy`s the gate. The gate's own code is unchanged from production's (#4313, `000248de`); the connect-db additions it bundles are unused by it. So connected bbs just reconnect once; with #4313's visitor hold that is a short delay for visitors (staging: 75/75 one-second probes returned 200, one held 3.1 s). 2. Watch for 10 minutes: - bb-web 5xx on `getbb.app`, especially `/api/account/*` and `/api/connect/*`; - a dashboard pairing code still pairs a released bb (`npx -p bb-app@latest bb connect --code <code> --server https://<handle>.getbb.app`). ## Rollback - Web: `pnpm --filter @bb/web exec wrangler rollback <previous> --name bb-web -m "<reason>"`, where `<previous>` is the version `wrangler deployments status --name bb-web` shows before the merge deploys (`d929bb65-81be-4090-ad8e-70a6e9d46fd7` on 2026-09-29 16:54 UTC, `main` at #4454). Once #4253 has shipped, a web rollback keeps those bbs connected and signed in; only new sign-ins stop working until it rolls forward. - Gate: `pnpm --filter @bb/connect exec wrangler rollback 000248de-6a8b-4ca0-94f9-a7a27fe80b8f -m "<reason>"` (production's gate before the merge). Stack: 1 of 4. Base: `main`. Next: #4252. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
…unts (#4254) ## 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 through `bb-account.v1.fetch`, so it never sees the credential. ## How you verified - `pnpm exec turbo run typecheck --filter="...[HEAD^1]"` and `test --filter="[HEAD^1]"` on this layer: pass. - New test: bb cloud is turned off while the account-status call is held, and the completion rejects without sending; it fails on #4230's code. - Staging e2e (`vibecodethis.site`, 2026-09-25, `main` with #4313, #4252's gateway and #4253's client on one data dir): - `bb ai on`, then `bb settings ai-services set thread-title bb` and `… 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`; - bb cloud still answered, with the opt-in and task choices kept, after a downgrade to a build without bb-ai and an upgrade back (610 ms), while the web was rolled back to the pre-stack version (551 ms), and after the account was signed out and back in (755 ms). ## Rollout Ships in a bb release, after: - #4252 is deployed; - #4253 has been on dev servers. 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_day` rows. 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. > 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
#4229 moved Connect onto the new bb-account plugin. Two choices in it made the 2026-09-24 gate outage harder to recover from:
main, so the rollback locked them out.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 dialswss://<handle>.getbb.app/__tunnelwith 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 frombb-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 aretunnel connecting to …andtunnel 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 withGET /api/account/meand 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.Ride bb connect through tunnel resets instead of failing visitors #4313's client changes, carried into this tunnel. Ride bb connect through tunnel resets instead of failing visitors #4313 changed
main's oldtunnel.ts, which this PR replaces, so its client behavior is ported:replaced by a new tunnel connectionreason (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 keycredential, in the{serverUrl, handle, credential}shape builds from before bb account read.credentialCopyOfrecords the SHA-256 of the credential it last shared with bb account. On each bb account change:mainduring the outage window, like bee), it first offers it to bb account.adoptConnectCredentialtakesreplaces: the credential connect saw in bb account, or null for signed out. It answers:changedif bb account has moved on since;rejectedif/api/account/merefuses the offered credential;adoptedonce 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.
AccountLinkbackoff: 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.tsxandplugins/bb-account/app.tsx: 2 s while polls succeed, then doubling to 30 s while they fail, instead of a fixedsetInterval.Plugin SDK 0.6.3 (the
experimental_callersurface;mainis at 0.6.2).How you verified
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. WithoutconfirmRefusedCredentialit fails: connect retried forever;account.test.ts:confirmRefusedCredentialchecks only the current credential, keeps a valid one, signs out when getbb.app answers 401, and serves only the connect plugin;adoptConnectCredentialcompare-and-swap and no revocation;connectCredentialonly 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, Ride bb connect through tunnel resets instead of failing visitors #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.tsxin 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 previousapp.tsx.pnpm exec turbo run typecheck --filter="...[HEAD^1]"(101 tasks) andtest --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 (aTMPDIRunder$HOMEon the test machine), and oneapps/servermachine-environment test (a load flake).Staging end to end (
vibecodethis.site, 2026-09-25 UTC, onmainwith #4313)main's with Ride bb connect through tunnel resets instead of failing visitors #4313 (2e6e20c7, deployed with Add bb account endpoints to bb-web #4250's manualversions deploy); web = Add bb account endpoints to bb-web #4250 (630823a5); AI gateway = Add the bb-ai-gateway worker #4252 (c0cb8b9a). Nowrangler tailat any point.sawyer. Its hostname was probed every 5 s at/install/version.main9781a2126a, no bb account) paired with a dashboard-style code through #4250's webtunnel connectedat 02:40:18152c87ff0c, the #4254 head)tunnel connectedat 02:40:48. bb-account and Connect hold the same credential pluscredentialCopyOfmaintunnel connectedat 02:41:24could not refresh the bb account profile: … HTTP 500; stayed signed in,tunnel connected, bb cloud worked. Web rolled forwardtunnel closed (code 1006)at 02:42:12,tunnel connectedat 02:42:14. A one-second probe got 75/75 200s; one request was held 3.1 sbb account login --codewith a new codetunnel connectedat 02:49:19, bb cloud workedmaintunnel connectedat 02:49:53 from Connect's copy of the new pairingbb connect offR8:
Cloudflare GraphQL for
sawyer.vibecodethis.site, 02:39–03:06:internalError: 2 around the first deploy, then 0;clientDisconnected0–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 offcloses 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
copied connect's pairing into bb account,tunnel connecting to …andtunnel connected.grep 'plugin:connect\]\|plugin:bb-account\]' ~/.bb/logs/server-stdio.logon bee;/api/account/*status codes on bb-web;signed outlines, 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.
🤖 Generated with Claude Code