Skip to content

Revert the bb account stack, keeping connect-db migrations - #4232

Merged
SawyerHood merged 1 commit into
mainfrom
revert/bb-account-stack
Sep 24, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
revert/bb-account-stack

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The bb-connect gate deployed from #4227 (version 985dc695, 2026-09-24 01:07 UTC) broke tunnels for every server, old releases included. Tunnels opened, but the gate never answered their heartbeats: servers logged tunnel heartbeat missed 60–80 s after every dial and redialed forever. Across *.getbb.app, 503s went from a steady 9–10% (00:00–01:05) to 25–32% (01:10–01:25) and peaked at 55–56% (01:41–01:42); WebSocket upgrades roughly tripled from constant redials. Rolling the gate back to 6f79c289 at 01:43 brought 503s back to 12–14% within a minute. The root cause is not identified yet: the gate diff only adds the ticket check before the tunnel is handed to the Durable Object and does not touch heartbeats or routing.

main still carries that gate, so the next merge touching apps/connect/**, packages/connect-db/**, or packages/tunnel-contract/** would redeploy it. main's bb clients also dial with tunnel tickets that the rolled-back gate refuses, so main can't be released as is.

What changed

Rollout notes:

  • Merging redeploys the web worker without /api/account/*, /link, and /api/connect/tunnel-ticket. No released bb uses them.
  • If Deploy Connect is enabled, merging redeploys a gate equivalent to the live 6f79c289.
  • The deployed bb-ai-gateway worker is not removed by this PR; delete it in Cloudflare if wanted.
  • Any bb that ran main after Add the bb account plugin and move connect onto it #4229 had its Connect credential moved into the bb-account plugin. On this code it starts signed out; pair it again with bb connect --code <code>.

How you verified

  • pnpm install --frozen-lockfile passes with the reverted lockfile.
  • turbo run typecheck lint test for @bb/connect-db, @bb/web, @bb/connect, bb-plugin-connect, @bb/bundled-plugins, bb-plugin-plugin-api-docs: pass.
  • turbo run typecheck lint --filter=@bb/server: pass. Server test/services/plugins/builtin-plugins.test.ts and test/ai/*: 95 tests pass.
  • Production evidence for the incident and the recovery: Cloudflare zone analytics (per-minute edgeResponseStatus for *.getbb.app), wrangler tail bb-connect, and bee's server log. The bee log shows the pre-stack build dropping every minute from 01:08:24.

AGENT GENERATED

🤖 Generated with Claude Code

… migrations

The bb-connect gate deployed from #4227 at 01:07 UTC on 2026-09-24 left
tunnels up but unanswered: servers missed every heartbeat and redialed
every 60-80 s, and *.getbb.app 503s rose from ~10% to up to 56%. Rolling
the gate back to 6f79c289 restored service. This reverts the stack so
main matches production and the next Deploy Connect run does not
redeploy the broken gate.

Migrations 0006/0007 and the connect-db schema stay, because production
D1 already has them. The web code keeps the null-owner guards for
connect_code rows that the nullable user_id needs. #4228 (AI services)
stays; main returns to its post-#4228 state.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@SawyerHood
SawyerHood merged commit 9bfe862 into main Sep 24, 2026
18 checks passed
@SawyerHood
SawyerHood deleted the revert/bb-account-stack branch September 24, 2026 01:56
ymichael added a commit that referenced this pull request Sep 24, 2026
The plugin delete route refused every row with builtin provenance, so a
builtin dropped from the registry (bb-ai after #4232) could never be
removed. Only protect builtins that are still bundled, re-enable the
Uninstall action for orphaned builtins in Settings, and have the CLI
print the server's 409 message instead of a bare status code.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ymichael added a commit that referenced this pull request Sep 24, 2026
## Human comments

## What was wrong

When bb stops bundling a built-in plugin, its installed row stays.
Startup (`reconcileBundled`) only walks plugins that are currently
bundled: it installs new ones and never looks at rows whose built-in is
gone. After #4232 reverted #4229/#4230, data dirs that had run those
builds kept `bb-ai` and `bb-account` forever, showing as "Missing:
Plugin files are missing. Update or reinstall bb." The delete route
refuses built-ins, so users couldn't remove them either. #4240 made the
manual uninstall possible; this makes cleaning them up by hand
unnecessary.

## What changed

`apps/server/src/services/plugins/plugin-service.ts`:
- After bundled reconciliation and before `loadAll()`, startup deletes
every installed built-in whose name is no longer in this build's
registry. It uses the existing orphan check behind `isOrphanedBuiltin`,
now a shared `isOrphanedBuiltinRow` helper.
- It also deletes the plugin's settings, secrets and schedules through
the same helper manual removal uses (`deleteRemovedPluginData`,
extracted from `remove()`). That includes `onPluginUnregistered`, which
re-dispatches queued messages the plugin was holding.
- The row is deleted outright rather than tombstoned, so a plugin that
is bundled again later installs fresh.
- Startup deletes the row only after settings, schedules, and secret
cleanup succeeds. If secret removal fails, the row remains so the next
startup retries cleanup.
- Rows a user already uninstalled (tombstoned) are left alone, because
`listInstalledPlugins` skips them.
- Each removal is logged: `plugin <id> removed because bb no longer
bundles builtin:<name>; its settings, secrets, and schedules were
deleted`.
- The check compares against the static registry, not what loaded, so a
broken or partial build can't delete bundled plugins.

No wire or daemon protocol changes. No CLI or UI changes.

## How you verified

- `builtin-plugins.test.ts`: the old "marks a persisted builtin as
orphaned" test is replaced by "removes a builtin and its data once bb no
longer bundles it". It seeds a setting, a schedule and a secret file,
restarts without the built-in, and asserts the row, settings, schedule
and secrets directory are gone and the list is empty. It then re-bundles
and asserts a fresh, enabled install. It fails with the startup call
removed and passes with it.
- `builtin-plugins.test.ts` also simulates one secret removal failure,
confirms the registration remains, then confirms a second startup
removes the secret and row.
- `pnpm exec turbo run test --filter=@bb/server -- --run
test/services/plugins/builtin-plugins.test.ts`: 35/35.
- `pnpm exec turbo run typecheck --filter=@bb/server`: clean.
- `pnpm exec turbo run typecheck lint --filter=@bb/server`: clean.
- `turbo run test --filter=@bb/server -- test/services/plugins`:
521/521.
- Live, in a disposable `pnpm start:worktree` instance whose data dir
really went through #4230 then the revert, so it had `bb-ai` and
`bb-account` rows with their folders missing, plus one seeded `bb-ai`
setting. After restarting on this branch, both rows and the setting were
gone, the API listed no orphans, `bb-guide` was unchanged, and the
server log had both removal lines.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
SawyerHood added a commit that referenced this pull request Sep 29, 2026
## 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]>
SawyerHood added a commit that referenced this pull request Sep 29, 2026
## 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]>
SawyerHood added a commit that referenced this pull request Sep 29, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant