Files
twenty/packages/twenty-server
Charles Bochet 7b6b624041 fix(server): bypass stale workspace cache when resolving currentUser during onboarding (#21461)
## Context

On twenty-main (multi-replica), signing up and naming a workspace lands
on a black screen at `/create/profile`; a manual refresh fixes it. From
the network trace: the post-activation `currentUser` response carries
`onboardingStatus: PROFILE_CREATION` (fresh) together with a non-ACTIVE
`currentWorkspace` and `workspaceMember: null` (stale).

## Root cause

`activateWorkspace` invalidates the core entity cache only on the
instance that served the mutation. When the follow-up `currentUser`
query is routed to a sibling instance, the auth context carries a
memoized pre-activation workspace snapshot. A stale transient workspace
cascades:

- `workspaceMember`/`workspaceMembers` resolve to null/empty
(`loadWorkspaceMember` skips non-active workspaces), permissions fall
back to defaults
- the client's metadata store never loads (`MinimalMetadataLoadEffect`
skips non-active workspaces), so `MinimalMetadataGater` shows the
loading skeleton forever on `/create/profile`

#20322 fixed the same staleness for `onboardingStatus` by reading the
workspace fresh from the database in the resolver — which is why the
status is fresh while the workspace object isn't, and why the client
navigates to a page it can't render.

#21480 bounds the staleness window to the designed 10s (absolute
memoizer TTL), but signup lives entirely inside that window: the client
reads `currentUser` ~1s after `activateWorkspace` and never refetches
while stuck.

## Fix

Apply the #20322 approach at the workspace status resolution layer:
`UserService.refreshWorkspaceIfPendingOrOngoingCreation` re-reads the
workspace from the database when the auth-context copy is in a transient
activation status (`PENDING_CREATION`/`ONGOING_CREATION`). Used in:

- `UserResolver.currentUser` — fresh `currentWorkspace` and permissions
- `UserService.loadWorkspaceMember` / `loadWorkspaceMembers` — covers
the `workspaceMember`/`workspaceMembers` resolve fields

No-op for active workspaces; the extra database read only happens for
workspaces mid-creation.

## Test plan

- Full `user.service.spec.ts` suite passes; lint and format clean.
- After deploy to twenty-main: sign up, name the workspace, verify
`/create/profile` renders the profile form with a populated
`workspaceMember` and ACTIVE `currentWorkspace` without refreshing.
2026-06-12 12:13:38 +00:00
..
2026-04-02 11:20:08 +00:00
2026-04-02 11:20:08 +00:00