Refresh active bb Connect sessions - #2357
Merged
ymichael merged 7 commits intoAug 25, 2026
Merged
Conversation
ymichael
force-pushed
the
bb/investigate-unexpected-bb-connect-logout-thr_nx834m7kxg
branch
from
August 25, 2026 03:07
8547ea0 to
b636a10
Compare
ymichael
deleted the
bb/investigate-unexpected-bb-connect-logout-thr_nx834m7kxg
branch
August 25, 2026 03:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
bb Connect authenticated requests by validating the Better Auth session cookie directly against D1. That bypassed Better Auth's normal session endpoint, so the configured sliding refresh never ran: a user who stayed active only through Connect still had a fixed seven-day database expiration and was logged out when it elapsed.
Separately, the Oxc migration changed the checked-in TanStack route tree's generated lint header from ESLint to Oxlint without changing TanStack Start's generator configuration. Every web dev-server start or production build therefore restored the generator's default
/* eslint-disable */header and leftapps/web/src/routeTree.gen.tsdirty.What changed
@bb/connect-db, and pass them explicitly to Better Auth.get-sessionroute after authenticated, non-cacheable Connect HTTP traffic. Normal dynamic requests therefore have no extra Worker hop. Better Auth still rechecks D1 and owns the update, race behavior, and renewed cookie attributes.Set-Cookiefield returned by Better Auth as a separate response header, so future auth configuration that emits more than one cookie cannot fold them into an invalid combined cookie.This does not change the server/host-daemon wire contract, so
HOST_DAEMON_PROTOCOL_VERSIONis unchanged. It adds no CLI, SDK, or user-facing configuration surface.How you verified
The session regression tests exercise Better Auth against real in-memory SQLite: Connect reports a fresh session as not due and a session at Better Auth's update-age boundary as due; Better Auth then moves the due session forward and returns its cross-subdomain cookie, while a fresh session remains unchanged. A two-cookie response test verifies both cookie fields stay separate through the boundary. Worker tests prove fresh dynamic traffic makes no account-worker request, due dynamic traffic renews, and cacheable responses and WebSockets skip refresh even when it is due. The real-workerd encoding suite verifies cached gzip bodies remain intact.
A local Cloud end-to-end check created a temporary account and expiring session, sent an authenticated request through the Connect wildcard gate, and observed the actual Connect → web Better Auth subrequest: the gate returned the expected offline 503 with a renewed cookie and D1 held the new seven-day expiration. The temporary account/server were removed afterward (zero rows remained).
The route-tree regression was reproduced on
main: starting the web dev server changed the tracked header back to/* eslint-disable */. With the inline TanStack Start router configuration, repeated forced web production builds leaveapps/web/src/routeTree.gen.tsbyte-for-byte unchanged.pnpm exec turbo run test --filter=@bb/connect --force(114 tests passed)pnpm exec turbo run test --filter=@bb/connect --force -- --run src/session.test.ts(15 tests passed)pnpm exec turbo run test --filter=@bb/connect --force -- --run src/worker.test.ts(76 tests passed)pnpm exec turbo run test --filter=@bb/connect --force -- --run src/response-encoding.test.ts(6 real-workerd tests passed)pnpm exec turbo run test --filter=@bb/web --force(79 tests passed)pnpm exec turbo run typecheck --filter=@bb/connect --filter=@bb/web --filter=@bb/connect-dbpnpm exec turbo run build --filter=@bb/web --force(route tree unchanged)pnpm exec wrangler deploy --dry-runfromapps/connect(261.20 KiB / 67.23 KiB gzip)pnpm install --frozen-lockfile --offline --ignore-scriptspnpm lint(zero errors)pnpm exec oxfmt --check apps/connect/package.json apps/connect/src/account-session.ts apps/connect/src/cache.ts apps/connect/src/session.ts apps/connect/src/session.test.ts apps/connect/src/worker.ts apps/connect/src/worker.test.ts apps/connect/test/encoding-fixture.ts apps/web/src/server/auth.ts apps/web/vite.config.ts packages/connect-db/src/constants.tsgit diff --checkFixes: N/A — reported directly in bb.