alibaba/spring-ai-alibaba · error · BizException
AccountNotFound
AccountNotFound
Error message
Account can not be found.
What it means
Thrown by AccountServiceImpl.login(Oauth2User) when, after either looking up an existing account or registering a new one and fetching it back via getAccountById, the account entity is still null. Practically this means the auto-registration path registered an account but the subsequent read failed, an unlikely internal-inconsistency condition in the OAuth2 login flow.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/AccountServiceImpl.java:165
String accountId;
AccountEntity accountEntity = getAccountByName(oauth2User.getUserId());
if (accountEntity == null) {
Account account = new Account();
account.setUsername(oauth2User.getUserId());
account.setNickname(oauth2User.getName());
account.setEmail(oauth2User.getEmail());
account.setIcon(oauth2User.getIcon());
account.setPassword(IdGenerator.uuid32());
accountId = registerAccount(account);
accountEntity = getAccountById(accountId);
}
else {
accountId = accountEntity.getAccountId();
}
if (accountEntity == null) {
throw new BizException(ErrorCode.ACCOUNT_NOT_FOUND.toError());
}
// cache it
Workspace workspace = workspaceService.getDefaultWorkspace(accountEntity.getAccountId());
if (workspace == null) {
throw new BizException(ErrorCode.DEFAULT_WORKSPACE_NOT_FOUND.toError());
}
accountEntity.setDefaultWorkspaceId(workspace.getWorkspaceId());
String key = getAccountCacheKey(accountEntity.getAccountId());
redisManager.put(key, accountEntity);
return createTokenResponse(accountId);
}
/**
* Invalidates access token on logout
* @param accessToken Token to invalidateView on GitHub (pinned to f82da0b50f)
Solutions
- Retry the OAuth2 login; transient read lag usually resolves on a second attempt.
- Check the account table for the row that registerAccount should have inserted and inspect app logs for save() failures.
- If using a read replica, ensure the post-registration read hits the primary or waits for replication.
- Clear/purge any stale Redis cache entries under the account cache key prefix and retry.
Example fix
// before: read immediately after register (replica may lag)
String accountId = registerAccount(account);
AccountEntity entity = getAccountById(accountId); // null -> BizException
// after: fail fast with a clear cause if the row is missing
String accountId = registerAccount(account);
AccountEntity entity = getAccountById(accountId);
if (entity == null) {
throw new IllegalStateException("Account row missing after registration: " + accountId);
} Defensive patterns
Strategy: retry
Validate before calling
// verify account row exists after registration before login proceeds
AccountEntity check = accountService.getAccountById(accountId);
if (check == null) { /* surface a clear registration-consistency error */ } Try / catch
try {
return accountService.login(oauth2User);
} catch (BizException e) {
if ("AccountNotFound".equals(e.getCode())) {
// one short retry for replica lag, then surface a 500 with the accountId
return retryLoginOnce(oauth2User);
}
throw e;
} Prevention
- Read the freshly registered account from the primary DB, not a lagging replica.
- Ensure registerAccount failures propagate instead of being swallowed.
- Avoid flows that can delete an account concurrently with its first OAuth2 login.
- Log the accountId with the error to speed up diagnosing DB consistency issues.
When it happens
Trigger: OAuth2 login with a new userId where registerAccount succeeds but getAccountById(accountId) returns null — e.g. the insert was rolled back, replication lag on a read replica, or the read races with a concurrent delete of the same username.
Common situations: Database read-replica lag immediately after registration; a concurrent request deleting the just-created account; DB transaction/save failure swallowed upstream so the id exists but the row does not; corrupted cache returning a stale/missing mapping.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/1f80f245c27ffed0.
Report an issue: GitHub.