Skip to content

Fall back to an existing principal when no personal bench slug matches on connect - #685

Merged
TheGreatAxios merged 6 commits into
mainfrom
cl-7506-fall-back-to-an-existing-principal-when-no-personal-bench
Sep 8, 2026
Merged

TheGreatAxios merged 6 commits into
mainfrom
cl-7506-fall-back-to-an-existing-principal-when-no-personal-bench

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

  • The connect flow resolves the caller's bench by exact personal-bench slug; when no principal carries it, connect-flow callers (credential test-and-persist, complete-setup, duplicate-callback recovery) fall back to the first principal from the same /api/me/principals read, and only a zero-principal caller yields no-personal-bench.
  • The fallback is opt-in per call site: the boot seeder keeps strict matching and still retries until the root bench is visible, and the caller enumeration on findPersonalTenant names all three connect-flow call sites.
  • Route-level tests pin POST /api/onboarding/complete and POST /api/onboarding/complete-setup for a root-bench-only admin (200 instead of 409 no_personal_bench) and the duplicate-callback recovery path.

Verification

  • bun run check exits 0 (typecheck, lint, full test matrix, structural checks) before each commit; the push-time pre-push gate ran the full suite green (935 pass / 0 fail on the final web shard).
  • bun test packages/onboarding exits 0: 195 pass, 0 fail across 15 files.
  • Independent three-round review of the full branch diff returned clean.

Closes CL-7506

A seeded admin's only membership is the root bench, whose slug never
equals the computed personal-bench slug, so a connect used to 409.
Cover the seeded-admin shape, the zero-principal shape, the
slug-match happy path, and the first-in-page-order pick rule.
findPersonalTenant hard-failed when no principal carried the computed
personal-bench slug, 409ing a seeded admin whose only membership is
the root bench. An exact slug match still wins; absent one, the first
principal in the same /api/me/principals read is used, and only a
zero-principal response yields no-personal-bench.
findPersonalTenant's tests pin the strict match as the default (the
boot seeder keeps throwing until the root bench is visible) with the
fallback opt-in via flag, and the pick rule asserts the full resolved
tenant. Route-level tests cover both connect surfaces for a
root-bench-only admin: POST /complete persists the credential instead
of 409, and POST /complete-setup reports unseeded instead of 409.
The fallback no longer fires for the boot seeder's org-slug lookup,
which must keep waiting for the root bench instead of seeding onto the
first visible principal. findPersonalTenant is strict by default; only
the connect flow (testAndPersistCredential and the /complete-setup
route) passes fallbackToFirstPrincipal.
A seeded admin whose browser double-fires the OAuth callback recovers
as connected rather than state_expired: a route-level test pins the
duplicate-callback recovery for a root-bench-only admin. The
findPersonalTenant principals stub drops an inert tenantDomain field;
that read only ever comes from GET /api/tenants/:id.
recentlyConnectedCredential resolves through the fallback like the
rest of the connect flow, so a seeded admin (root bench only) whose
second callback arrival burns the state still recovers the connection
that succeeded. The caller enumeration on findPersonalTenant names it.
@linear-code

linear-code Bot commented Sep 7, 2026

Copy link
Copy Markdown

CL-7506

@TheGreatAxios

Copy link
Copy Markdown
Contributor Author

Self-review (code-review skill) returned clean. Reviewer-of-record checks (commit subject/body style audits, diff-stat binary scan, commit-scope check) ran in-session on the final history; the deeper behavioral read ran as three independent review rounds — rounds 1 and 2 returned should-fix findings, all fixed, and round 3 returned clean.

@TheGreatAxios
TheGreatAxios merged commit 53479dd into main Sep 8, 2026
24 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-7506-fall-back-to-an-existing-principal-when-no-personal-bench branch September 9, 2026 04:16
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