Skip to content

Ride bb connect through tunnel resets instead of failing visitors - #4313

Merged
SawyerHood merged 3 commits into
mainfrom
bb/investigate-cloudflare-logs-for-robb-getbb-app-thr_j2j7gu9n5f
Sep 25, 2026
Merged

SawyerHood merged 3 commits into
mainfrom
bb/investigate-cloudflare-logs-for-robb-getbb-app-thr_j2j7gu9n5f

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Users saw spotty bb connect sessions all day on 2026-09-24. Every reset of a server's TunnelDO reached visitors as errors. Resets come from gate deploys, from wrangler tail attaching or detaching (proven on staging: each start and each stop dropped every hibernated tunnel), from platform restarts, and from network drops. After #4268 the gate restarts an object whose tunnel socket vanished, which bounded each outage to seconds. But during those seconds:

  • In-flight requests failed with 500.
  • New requests got 503 offline until the bb redialed.
  • Browser WebSocket reconnects were refused with 503.
  • The redial often hit the restart and got a 500 itself, which cost another 2 s of backoff.

On staging, four tail attach/detach events against 8 servers produced 85 failed requests and 132 refused WebSocket reconnects. A redeploy wave against 10 servers produced 291 failed requests.

Two client-side mechanisms made it worse, and both were reproduced on staging:

  1. Stalled servers kill their own tunnel. After an event-loop stall longer than 40 s, the tunnel heartbeat timer runs before the queued heartbeat replies are processed. It terminates a healthy tunnel, and every request the server was about to answer fails with 502. This produces a 504 → 502 → 503 pattern.
  2. Two bb processes on one credential flap. Each dial replaces the other's tunnel, and both redial within seconds. One production server has redialed about 225 times an hour for 10+ hours.

What changed

Gate (apps/connect):

  • TunnelDO records tunnelLostAt on an unclean tunnel close or a vanished-socket restart. For 15 s after a loss, visitor requests and WebSocket upgrades wait for the tunnel to come back instead of answering 503. A clean close (1000) or an owner revoke clears it, so an intentionally stopped bb still shows offline at once.

  • All worker → DO calls go through fetchTunnelDo. Only GET/HEAD requests (tunnel dials are GET upgrades) are replayed, after 50 ms and then 250 ms, with a fresh stub each time, and only when:

    • the object threw its own restart error, or
    • it threw a Cloudflare error marked retryable that is not overloaded and not Network connection lost..

    An unreachable object isn't retried because more load keeps it unreachable. Other methods are never replayed, because in-flight requests that were already forwarded receive the same abort error. This is the bounded, fresh-stub, no-overload retry proposed in Evaluate safe retries for retryable Connect Durable Object dispatch failures #2065.

Client:

  • packages/tunnel-client: when two heartbeat ticks are more than 25 s apart on the monotonic clock (5 s late), the process stalled, so the deadline restarts instead of the tunnel being terminated.
    • Machine sleep doesn't advance the monotonic clock. After wake, a dead tunnel is still dropped at the first beat, as before.
    • The grace is granted once per answered heartbeat, so a process whose ticks are always late still drops a dead tunnel.
  • plugins/connect:
    • Stopping closes the tunnel with 1000 instead of terminate().
    • The handshake timeout drops from 15 s to 10 s.
    • A close on the current tunnel with the gate's "replaced by a new tunnel connection" reason (now shared as TUNNEL_REPLACED_CLOSE_REASON in @bb/tunnel-contract) means another bb took over. The client backs off 5 minutes and reports why.

Docs: AGENTS.md now forbids tailing the production bb-connect gate (wrangler tail or dashboard live logs), because every attach and detach drops all connected tunnels. It points to stored Workers Logs, GraphQL analytics, and staging tails instead.

Not in this PR:

  • Slow large downloads: a visitor reading a large download slowly can still exhaust the object's memory (exceededMemory), because there's no backpressure. A hard cap was tried and removed: it cut real downloads (for example ~300 MB server-move archives) that succeed today. Proper flow control is Connect gate buffers slow downloads without backpressure until the tunnel object runs out of memory #4314.
  • Machine tunnels: the host daemon's machine tunnel (apps/host-daemon/src/connect-tunnel) gets the heartbeat fix through TunnelSession, but not the clean close, the handshake timeout or the takeover backoff. Its stops still close with 1006, so visitors wait up to 15 s before a machine share shows offline.

Behavior notes:

  • Old clients: the gate stays compatible with them. They never send clean closes, so their shutdowns get the 15 s hold before showing offline.
  • Long-dead servers: after a gate restart, tunnelLostAt is when the restart noticed the vanished socket. A server whose tunnel died long before sees a one-time 15 s hold on its next visit.
  • Planned restarts: a restart or update of a new client closes cleanly, so it shows offline at once instead of being held. The offline page retries.

No server/daemon wire changes. Rollout: a gate deploy is itself a reset wave. Deploy once, straight to 100%, at a quiet time. The client fixes ship with the next bb release.

How you verified

Unit tests (each new test fails with its fix reverted):

  • @bb/connect:
    • Held requests are forwarded when the tunnel redials.
    • Held requests get 503 at the grace deadline, at once after a clean close, or on revoke.
    • The restarted object holds without aborting again.
    • Worker replay: the restart error, a retryable error and a dial are replayed. POST, Network connection lost., overloaded objects and non-retryable errors are not. It gives up after two replays.
  • @bb/tunnel-client (heartbeat.test.ts):
    • A 90 s stall keeps a healthy tunnel.
    • A dead tunnel is still dropped after the stall grace.
    • A dead tunnel is dropped at the first beat after a 10-minute machine sleep.
    • Chronically late beats still drop a dead tunnel.
    • Unanswered beats terminate after a minute.
  • bb-plugin-connect:
    • Clean close on stop.
    • The 10 s handshake deadline.
    • A 5 minute backoff after replacement, and a normal redial after 1006.
    • A late "replaced" close from a stale socket doesn't touch the current tunnel's status.

pnpm exec turbo run typecheck test --filter=@bb/tunnel-contract --filter=@bb/tunnel-client --filter=@bb/connect --filter=bb-plugin-connect passes (13 tasks). @bb/host-daemon typechecks.

Staging (vibecodethis.site). Lab harness: real ConnectTunnel clients plus authenticated GET/POST/slow/WebSocket visitors. Baseline is main's gate with main's client:

Scenario Baseline This PR
4 tail attach/detach events × 8 servers 85 / 3,111 failed, 132 refused WS reconnects 0 / 3,111 failed, 0 refused (p99 1.6 s)
Redeploy wave, 10 servers, 2 min 291 / 1,921 failed, WS gap up to 8.9 s 1 / 1,666 failed (one in-flight POST), gap up to 1.2 s
75 s server event-loop stall 35 × 502, tunnel reconnect no 502, no reconnect, queued requests answered (rerun on the final heartbeat code: 40 answered)

An independent review (Claude Opus) found the original response cap and the wall-clock stall detection flawed. Both are addressed in the third commit.

Refs #2065, #4314

AGENT GENERATED

🤖 Generated with Claude Code

SawyerHood and others added 2 commits September 25, 2026 01:08
Any reset of a TunnelDO (a gate deploy, a `wrangler tail` attaching or
detaching, a platform restart, a network drop) used to surface to visitors
as 500s for in-flight requests, 503 offline until the bb redialed, refused
WebSocket reconnects, and a 500 on the redial itself when it hit the
vanished-socket self-restart.

Gate:
- Record an unexpected tunnel loss and, for 15 s after it, hold visitor
  requests and WebSocket upgrades until the tunnel returns instead of
  answering 503. Clean closes and owner revokes still answer 503 at once.
- Replay GET/HEAD requests and tunnel dials that hit the self-restart or a
  retryable platform error, but never "Network connection lost.", which
  means the object is unreachable and more load keeps it that way.
- Cancel a single response whose unread backlog passes 64 MB (80 MB per
  isolate) instead of letting a slow reader exhaust the isolate and reset
  every tunnel it hosts.

Client:
- A heartbeat tick that fires late means the process stalled; restart the
  deadline instead of terminating a healthy tunnel after the stall.
- Close the tunnel with 1000 on stop so the gate treats it as offline at
  once, shorten the handshake timeout to 10 s, and back off five minutes
  when another bb with the same identity replaces the tunnel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Attaching or detaching a wrangler tail resets bb-connect's Durable Objects
and drops every connected tunnel; point agents at stored Workers Logs,
GraphQL analytics, and staging tails instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Remove the 64/80 MB unread-response cap: it cut real downloads whose
  backlog peaks below the crash point (server-move archives, APKs, video
  streams) and did not release memory for a reader that stopped entirely.
  Flow control is tracked in #4314.
- Measure heartbeat tick lateness on the monotonic clock so machine sleep
  no longer looks like an event-loop stall and a dead tunnel is still
  dropped at the first beat after wake; grant the stall grace once per
  answered heartbeat so chronically late ticks still drop a dead tunnel.
- Do not replay requests onto an overloaded Durable Object.
- Only report "another bb took over" for the current, running tunnel.
- Stop exporting worker-internal helpers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@SawyerHood
SawyerHood merged commit 9781a21 into main Sep 25, 2026
18 checks passed
@SawyerHood
SawyerHood deleted the bb/investigate-cloudflare-logs-for-robb-getbb-app-thr_j2j7gu9n5f branch September 25, 2026 01:57
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
…#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]>
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