Repository navigation
feat: add first-run workspace and plan onboarding - #1086
Conversation
| try { if (storageKey.value) raw = localStorage.getItem(storageKey.value) } catch { /* Storage can be disabled; setup remains usable. */ } | ||
| const state = restoreOnboardingState(raw, props.startAtGoal) | ||
| const state = props.firstTask | ||
| ? { step: 1, audience: 'personal', goal: defaultGoalForAudience('personal'), goalExplicit: false } |
There was a problem hiding this comment.
firstTask mode hard-codes audience 'personal', even when the user just created an organization on the onboarding page.
New user creates an organization (Free or paid) and lands on the dashboard with ?firstTask=1. The wizard starts with audience='personal', so teamSetup is false and the goals and setup steps for organization admins never appear. Back is hidden at step 1, so the user can't fix the audience, and the immediate persist watcher writes 'personal' over any saved onboarding state. Derive the audience from the org (personal vs not) instead of a constant.
There was a problem hiding this comment.
Fixed in 0fff6d6. The onboarding page now sends the audience it established (?firstTask=personal or ?firstTask=team; creating an org or confirming checkout sends team). The dashboard passes it to the wizard, which starts at the goal step for that audience, so new org admins get the team setup steps.
| } | ||
|
|
||
| return created.Name, nil | ||
| return created.Name, true, nil |
There was a problem hiding this comment.
firstLogin is true only on the request that creates the User CR, so onboarding is a one-shot signal that is lost if that callback fails later or if the first login came from the CLI.
seedUser creates the user, then generateKubeconfig or browserSessions.IssueHTTP fails (500), or the user abandons the redirect. The retry login sees an existing user, so firstLogin=false and AuthCallback never routes to /onboarding. The same happens to anyone whose first sign-in was railgrid login. Those users never get the workspace and plan picker. Base it on durable state (e.g., no non-personal orgs and onboarding not completed) rather than this create request.
There was a problem hiding this comment.
Fixed in 0fff6d6. A new User now gets a tenancy.railgrid.ai/portal-onboarding-pending annotation, whichever client created it. seedUser reports firstLogin while the annotation is present, and the portal callback clears it only after it has issued the browser session. A failed callback or a first sign-in through the CLI therefore still onboards on the next portal login. TestSeedUserFirstLoginLastsUntilAPortalLoginCompletes covers this. One case remains: a browser that drops the redirect after a successful callback still loses it.
| return | ||
| } | ||
| if existing.Spec.Personal || existing.Labels[tenancyv1alpha1.OrganizationCreatorLabel] != user || | ||
| existing.Spec.DisplayName != req.DisplayName || !existing.DeletionTimestamp.IsZero() || existing.Status.DeletionRequestedAt != nil { |
There was a problem hiding this comment.
The replay idempotency check compares only DisplayName, so a reused requestId with different WorkspaceCreation/CatalogEntryCreation returns 201 for an org with the original settings.
A client POSTs {displayName:'acme', requestId:X, catalogEntryCreation:'Members'} after an earlier {displayName:'acme', requestId:X} created the org with the Admin default. The replay returns 201 Created with the admin-only org, so the caller wrongly believes its requested policy took effect. A key reused with a different body should get 409 RequestConflict.
There was a problem hiding this comment.
Fixed in 0fff6d6. Both creation policies are now defaulted before the replay check, and a replay whose workspaceCreation or catalogEntryCreation differs from the stored organization returns 409 RequestConflict. The replay test covers this.
| // resumes the same organization even if the first request timed out. | ||
| unlock := h.orgCreate.Lock(user) | ||
| if req.RequestID != "" { | ||
| existing, err := h.mgr.client.Organizations().Get(r.Context(), orgUUID, metav1.GetOptions{}) |
There was a problem hiding this comment.
A requestId never expires: once the org it created is fully deleted, a replay recreates an organization under the same deterministic UUID.
User creates org via requestId X, deletes it, and deletion completes (Get returns NotFound). A later retry with X (stale client/sessionStorage, or script) skips the replay branch and Creates a new Organization with the identical UUID, reusing the deleted org's workspace path, billing entitlement key and Stripe customer mapping. Old state keyed by that UUID can then attach to the new org.
There was a problem hiding this comment.
Fixed in 0fff6d6. Request IDs must now be version 7 UUIDs, and the hub refuses any minted earlier than (soft-delete grace period minus 1h of clock-skew allowance), or more than 1h in the future. An org is purged no sooner than one grace period after it was created, so no accepted key can outlive its organization and recreate it under the same UUID. Client clocks running behind are still tolerated for most of the default 30-day grace. The portal mints v7 IDs (portal/src/lib/requestId.ts). The new TestRequestIDFreshStaysInsideTheGracePeriod covers the window.
| v-model="startWith" | ||
| labelledby="onboarding-start-label" | ||
| :options="startOptions" | ||
| :disabled="busy || !!createdOrg || canceled" |
There was a problem hiding this comment.
After an org is recorded in the session draft, Start with and the name are locked for the whole browser session, even when that org is gone or never becomes usable.
Org creation succeeds but the workspace times out, or the user deletes that org in another tab. Reloading /onboarding restores draft.org into createdOrg, which disables 'Start with' and makes the name readonly. Every submit polls the dead org for 60s and fails, and the user can't switch to a personal workspace or a new name until they close the tab. Validate draft.org on mount (as restoreCanceledCheckout does) and clear it on failure.
There was a problem hiding this comment.
Fixed in 0fff6d6. On mount, and after a failed submit, the page checks the recorded org. If it returns 403/404, is pending deletion, or the user is no longer its admin, the draft is released with a message. A Start over action also appears whenever an error is shown, so a workspace that never becomes ready doesn't lock the form for the rest of the session. A network failure during the check is treated as unknown and keeps the draft.
| try { | ||
| while (current() && Date.now() < deadline) { | ||
| const signal = AbortSignal.any([lifetime.signal, AbortSignal.timeout(12_000)]) | ||
| const billing = await tenant.fetchOrgBilling(checkoutOrg, signal) |
There was a problem hiding this comment.
checkActivation stops at the first fetchOrgBilling error instead of retrying inside the 60s window, and the error message depends on status, which is still empty at that point.
The user returns from Stripe and the first /billing read hits a transient 502/timeout (e.g., the 12s AbortSignal fires while the webhook is still processing). The loop throws straight to catch and shows 'Unable to confirm your subscription' with no retry, even though the subscription activates seconds later. Retry on error until the deadline, the way the not-yet-active case does.
There was a problem hiding this comment.
Fixed in 0fff6d6. A failed billing read is now retried inside the same 60s window instead of ending the confirmation.
| if (!current()) return | ||
| const personal = organizations.find(org => org.personal && !org.deletionRequestedAt) | ||
| if (personal) { | ||
| await openWorkspace(personal.uuid) |
There was a problem hiding this comment.
openPersonalWorkspace nests openWorkspace's own 60s deadline inside its own 60s loop, so the Personal path can spin for up to about 2 minutes before showing an error.
The personal org appears at t=55s but its workspace never gets a clusterName. openWorkspace polls for another 60s, so the user watches 'Preparing your personal workspace…' for about 115s, nearly double the intended budget. Share one deadline across both phases.
There was a problem hiding this comment.
Fixed in 0fff6d6. openWorkspace takes the caller's deadline, so the personal-workspace wait and the post-checkout wait each share a single 60s budget.
| ([status, user]) => { | ||
| [gettingStartedStatus, welcomeUser, currentScope, () => route.query.firstTask] as const, | ||
| ([status, user, _scope, request]) => { | ||
| if (status === 'ready' && user && request === '1') { |
There was a problem hiding this comment.
?firstTask=1 opens the welcome guide unconditionally, skipping claimFirstWelcome's once-only latch.
Any bookmarked or shared dashboard URL carrying firstTask=1 (e.g., from browser history after onboarding) reopens the first-task wizard at 'Your goal' for a user who already dismissed it. Because firstTask forces audience 'personal', it also overwrites their stored onboarding state. Honor the claim result, or have onboarding pass a one-time token instead of a plain query flag.
There was a problem hiding this comment.
Fixed in 0fff6d6. ?firstTask= now only picks the audience; the guide opens only if claimFirstWelcome grants it. The query is stripped either way, so a bookmarked or history URL can't reopen a dismissed guide or overwrite its stored state.
| @@ -464,6 +464,7 @@ func (k *keyedMutex) Lock(key string) func() { | |||
| // DELETE /api/users/me soft-delete self (O-8) | |||
| // POST /api/users/me/undelete undelete self (O-8) | |||
| func (h *Handler) RegisterUserOnly(r *mux.Router) { | |||
There was a problem hiding this comment.
The 'Effective routes' doc block for RegisterUserOnly doesn't list the new GET /api/billing/plans route.
The comment is the documented map of user-only (no org context) routes. A reviewer auditing which endpoints skip tenant middleware will miss that /api/billing/plans is reachable by any signed-in user. Add it to the list.
There was a problem hiding this comment.
Fixed in 0fff6d6. GET /api/billing/plans is now listed in the RegisterUserOnly route block.
cwilhit
left a comment
There was a problem hiding this comment.
Review of head 05e2923. No Critical or Warning findings. Three Notes inline. Local checks: go test ./pkg/hub/restapi ./pkg/hub/metering ./pkg/server/auth pass; the go vet run did not finish within the runner timeout, and portal tests/build and live-cluster/Stripe flows were not run.
| } | ||
|
|
||
| return created.Name, nil | ||
| return created.Name, true, nil |
There was a problem hiding this comment.
Note: firstLogin is a one-shot signal that is easy to lose. It is true only on the request that creates the User. If anything after seedUser fails in HandleCallback (e.g. generateKubeconfig) or the browser drops the response, the next login sees an existing user and returns firstLogin=false, so the portal never routes the user to /onboarding. A user who first signs in through the CLI consumes the flag the same way. Impact is a skipped setup screen, not data loss. Suggested fix: derive first-run from persisted state (e.g. the user has no non-personal org and has not completed onboarding) rather than from creation timing, or at least cover this with a test.
There was a problem hiding this comment.
Fixed in 0fff6d6 together with the comment above. The first-run state is now persisted on the User (an annotation cleared after a successful portal login) instead of depending on the creating request. The new seedUser test covers it.
| } | ||
| if existing.Spec.Personal || existing.Labels[tenancyv1alpha1.OrganizationCreatorLabel] != user || | ||
| existing.Spec.DisplayName != req.DisplayName || !existing.DeletionTimestamp.IsZero() || existing.Status.DeletionRequestedAt != nil { | ||
| writeStatus(w, http.StatusConflict, "RequestConflict", "organization creation request already used") |
There was a problem hiding this comment.
Note (test gap): The replay guard has several rejection branches (personal org, creator label mismatch, display-name mismatch, deletion pending) that all return 409 RequestConflict. The new test only covers the same-user success replay and the demoted-admin 403. A regression that dropped the creator or deletion check would not be caught. Please add table cases for each branch, especially the creator-label mismatch since it is the tenancy guard.
There was a problem hiding this comment.
Added in 7efaf6d: TestCreateOrg_ReplayRefusesAMismatchedOrganization has a case for each branch (personal org, another creator, different display name, each creation policy, deletion requested). Each case asserts reason RequestConflict rather than any 409, so a quota 409 can't mask a regression.
| } | ||
| if (!createdOrg.value) { | ||
| status.value = 'Creating your organization…' | ||
| const requestId = draft.value?.name === organizationName ? draft.value.requestId : crypto.randomUUID() |
There was a problem hiding this comment.
Note: The idempotency key is reused only when the name is unchanged. If the first POST times out client-side but the hub created the org, then the user edits the name and retries, a fresh requestId is minted. That creates a second organization and orphans the first against the per-user org quota. Consider keeping the draft's requestId for the whole attempt and, when the name differs, first resolving the existing org by that key, or locking the name field once a request has been sent.
There was a problem hiding this comment.
Fixed in 7efaf6d. The draft's request ID is kept for the whole attempt, as long as the hub will still accept it, and the name field is read-only once a request has been sent. A timed-out POST followed by a renamed retry therefore can't create a second org. Start over is the explicit way to begin with a new name.
- Carry the audience chosen on the onboarding page into the first-task guide (?firstTask=personal|team), so a new org admin gets the team setup steps instead of the personal ones. - Open the first-task guide only through the once-per-user welcome latch; the query no longer reopens a dismissed guide. - Keep firstLogin true until a portal login completes: new Users carry a portal-onboarding-pending annotation that the portal callback clears after issuing the session, so a failed callback or a first sign-in via the CLI still onboards on the next portal login. - Refuse a replayed org request whose workspace or catalog-entry creation policy differs from the organization it created (409). - Make org request IDs version 7 UUIDs and refuse any older than the soft-delete grace period minus clock skew, so a key can never outlive its organization and recreate a purged one under the same UUID. - Onboarding page: share one 60s budget across nested waits, retry transient billing reads while confirming activation, and release the recorded organization (with a Start over action) when it is deleted or no longer administered. - Document GET /api/billing/plans among the user-only routes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A POST that timed out may still have created the organization. Keep the draft's request ID for the whole attempt and lock the name once a request is sent, so editing the name and retrying cannot create a second organization; Start over is the explicit way to begin a new one. Add table cases for every replay conflict branch (personal org, another creator, display name, both creation policies, deletion requested), asserting the RequestConflict reason rather than any 409. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Verification