Skip to content

connect-next 3/5: Node gate and frps on Fly - #6049

Merged
SawyerHood merged 1 commit into
connect-next/2-server-ingressfrom
connect-next/3-gate
Oct 21, 2026
Merged

SawyerHood merged 1 commit into
connect-next/2-server-ingressfrom
connect-next/3-gate

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

bb connect next needs its data plane: a gate on Fly that admits visitors to https://<label>.next.getbb.app with every rule the Cloudflare gate applies, terminates the frp tunnels bb machines dial, signs a per-request assertion for the server's ingress (PR 2), and routes a visitor to whichever Fly machine holds the label's tunnel.

PR 3 of 5 (stack: account API → server ingress → gate → plugin → machine tunnels). Based on #6048.

What changed

  • apps/connect-next (Fly app bb-connect-next): Node HTTP gate plus frps 0.71.0 as a loopback child (bind, vhost and server-plugin hooks Login/NewProxy/CloseProxy/Ping). It pipes wss://tunnel.<domain>/~!frp to frps, checks frp logins against the account API (a client may only claim its own label and shares), admits visitors with the Cloudflare gate's rules (owner session, desktop session, machine credential, next-resource MCP OAuth, Origin refusal, header/cookie stripping, Set-Cookie filtering, offline page with a 15 s redial grace), signs an Ed25519 x-bb-gate-assertion per request and WebSocket, and refreshes sessions like the Cloudflare gate.
  • Load fixes from the staging load tests: batched account API lookups and presence (coalesced, jittered refreshes, retry with backoff), stale-while-revalidate answer cache with last-good answers through account API outages, 16 resolve batches in flight, 3 s drain on shutdown with fly-replay: elsewhere=true, WebSocket close frames for frp sockets on shutdown, hard exit inside Fly's kill_timeout, open-file limit raised to 65,536.
  • Regions (src/regions.ts, src/peer-server.ts): peers over Fly's private network (PEER_SECRET), announcements and lookups, fly-replay to the holder with HMAC'd state, private-network forwarding for bodies Fly cannot replay, duplicate-tunnel resolution.
  • fly.toml [[vm]] is performance-2x / 4 GB: flyctl deploy applies it to every machine, and the load test showed shared CPUs cannot carry the gate. docs/connect-next.md (Machine size, Machine plan) says all regions use that size and that staging overrides it with --vm-size shared-cpu-2x --vm-memory 1024 on its deploy command.
  • Dockerfile, workflow .github/workflows/deploy-connect-next.yml (manual Deploy Connect Next, pinned flyctl SHA-256).
  • scripts/e2e-local.sh (+ e2e-local.ts, e2e-peer-gate.ts): the whole path on one machine; it needs the plugin (PR 4) and machine tunnels (PR 5) to pass fully.

No production deploy happens on merge: the workflow is manual.

How you verified

  • pnpm exec turbo run typecheck test --filter=@bb/connect-next: 87/87 tests (units, plus real frps/frpc against a stand-in account API and bb server in test/gate.e2e.test.ts, the Fly replay stand-in in test/fly.ts).
  • oxfmt --check, pnpm lint: clean.
  • Staging (bb-connect-next-staging, next.vibecodethis.site): 2,500 real frpc tunnels. Before the load fixes a shared-cpu-2x 1GB machine sustained only ~30–40 req/s (CPU throttled), performance-2x 4GB held 2,500 tunnels at ~280 req/s with ~1.3× CPU headroom, and the account API was flooded by presence writes. After the fixes: visitor errors from the gate went from ~0.4% to 0, Worker load fell ~15×, no frp Login waits ran out on a mass reconnect, and a stop with 2,294 tunnels took 0.7 s. Details in docs/connect-next.md (Presence, shutdown and limits; Regions).
  • Local end to end: results on PR 5 (top of the stack).

AGENT GENERATED

apps/connect-next: visitor admission with the Cloudflare gate's rules, frps
behind server-plugin hooks, per-request gate assertions, batched account API
lookups and presence, answer cache, regions with fly-replay and private
network forwarding, graceful drain, Dockerfile, fly.toml, manual deploy
workflow, and the local end-to-end scripts.
@SawyerHood
SawyerHood merged commit e63a056 into main Oct 21, 2026
53 checks passed
@SawyerHood
SawyerHood deleted the connect-next/3-gate branch October 21, 2026 17:21
SawyerHood added a commit that referenced this pull request Oct 21, 2026
## Human comments

## What was wrong

With the account API (PR 1), the server ingress (PR 2) and the gate (PR
3) in place, nothing on a bb server dials the gate yet. bb needs an
opt-in builtin plugin that runs `frpc` to the gate with the server's
link credential, points it at the tunnel ingress, and serves the server
machine's port shares on the next address too.

PR 4 of 5 (stack: account API → server ingress → gate → plugin → machine
tunnels). Based on #6049.

## What changed

- `packages/frp-client` (`@bb/frp-client`): frpc download and SHA-256
verification (frp 0.71.0), config writing (wss with a trusted CA file
and server name, credential in metadatas, proxies), log redaction and an
`FrpcSupervisor` (restart with backoff, hot reload, login-refusal
handling); `./testing` fixtures that run real frps and gate hooks.
- `plugins/connect-next` (builtin `bb--connect-next`, disabled by
default; registered in `builtin-registry.ts`, bundled plugins,
`bb-official.json`, the bundled marketplace): requires `bbPluginSdk
>=0.6.66` (the ingress member from PR 2); setting `enabled`, RPC
`status`/`setEnabled`, CLI `bb connect-next status|on|off`, a settings
section with state, address and shared ports, and a skill. The next
domain follows the bb account: `next.<host of the account's base URL>`
(`BB_CONNECT_NEXT_SERVER` and `BB_CONNECT_FRPC` override the server and
binary). It opens the server's tunnel ingress through
`bb.server.internal_DO_NOT_USE_openTunnelIngress` and proxies `<label>`
to it and `<label>--<port>` straight to `127.0.0.1:<port>` for shares.
- `plugins/bb-account`: `bb-account.v1.connectCredential` also answers
`bb--connect-next` (read-only; adopting and refusing a pairing stay
connect-only).
- `plugins/connect`: `connect.internal_DO_NOT_USE.serverShares` /
`waitForServerSharesChange` (long poll, answers only
`bb--connect-next`), and share listings carry `nextUrl` for
server-machine shares while connect next is on (`bb connect expose`
prints it on a second line).
- `apps/server`: the real-frps tunnel ingress test (moved here from PR 2
because it drives the plugin's frpc).
- `docs/configuration.md` (Connect next section), `turbo.json` (plugin
typecheck needs the SDK types).
- Fix from the staging test: the settings section description, the
`enabled` setting and the plugin description no longer hard-code
`next.getbb.app` (wrong on staging, `next.vibecodethis.site`); they say
`next.<your bb account's domain>` and the section shows the address
derived from the account.

## How you verified

- `pnpm exec turbo run typecheck --filter='...[connect-next/3-gate]'`:
109/109 tasks pass.
- `pnpm exec turbo run test --filter='[connect-next/3-gate]'`
(turbo.json changed, so every package ran): all green except failures
that are unrelated to this change and pass on rerun or fail on main for
the machine: `@bb/server` timeouts under full-repo load in
`timeline-in-turn-window`, `plugin-native-server-loading`,
`plugin-service` (75/75 when rerun), `@bb/host-daemon`
`command-discovery` (stray `/tmp/.git` on bee; 28/28 with `TMPDIR`
outside `/tmp`), `@bb/scripts` `ci-bun` (no `zip` binary on bee).
Relevant counts: `@bb/frp-client` 38/38, `bb-plugin-bb--connect-next`
26/26 (incl. the new copy test: fails with the old `(next.getbb.app)`
copy), `bb-plugin-connect` 141/141, `bb-plugin-bb-account` 61/61,
`@bb/server` 3,637 passed (incl. real frps + plugin frpc through the
ingress).
- `oxfmt --check`, `pnpm lint`: clean.
- Local end to end: results on PR 5.

> AGENT GENERATED
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