theonedev/onedev · error · ExplicitException
Cannot set AI setting for non AI account
Error message
Cannot set AI setting for non AI account
What it means
AI settings can only be applied to accounts of type AI. If the target user's type is not AI (ordinary or service account), the setAiSetting endpoint rejects the request. Ordinary and service accounts do not consume AI features, so attaching an AiSetting to them is invalid.
Source
Thrown at server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java:520
} else {
user.setPassword(passwordService.encryptPassword(password));
userService.update(user, null);
return Response.ok().build();
}
} else {
throw new UnauthorizedException();
}
}
@Api(order=2000)
@Path("/{userId}/ai-setting")
@POST
public Response setAiSetting(@PathParam("userId") Long userId, @NotNull AiSetting aiSetting) {
User user = userService.load(userId);
if (user.isDisabled()) {
throw new ExplicitException("Cannot set password for disabled account");
} else if (user.getType() != AI) {
throw new ExplicitException("Cannot set AI setting for non AI account");
} else if (SecurityUtils.isAdministrator()) {
user.setAiSetting(aiSetting);
userService.update(user, null);
if (!getAuthUser().equals(user))
auditService.audit(null, "changed AI setting of account \"" + user.getName() + "\" via RESTful API", null, null);
return Response.ok().build();
} else if (user.equals(getAuthUser())) {
user.setAiSetting(aiSetting);
userService.update(user, null);
return Response.ok().build();
} else {
throw new UnauthorizedException();
}
}
@Api(order=2025)
@Path("/{userId}/two-factor-authentication")
@DELETEView on GitHub (pinned to d44925c47c)
Solutions
- Verify user.getType() == AI before posting AI settings
- Only include AI-type accounts in AI configuration scripts
- Create/use a dedicated AI account for AI settings rather than applying them to user accounts
Example fix
// before
await rest.post(`/users/${id}/ai-setting`, aiSetting); // 400: not AI
// after
const user = await rest.get(`/users/${id}`);
if (user.type === 'AI') {
await rest.post(`/users/${id}/ai-setting`, aiSetting);
} Defensive patterns
Strategy: validation
Validate before calling
const user = await rest.get(`/users/${userId}`); if (user.type !== 'AI') throw new Error('AI settings can only be set on AI accounts'); Type guard
function isAiAccount(user) { return user.type === 'AI'; } Try / catch
try { await rest.post(`/users/${id}/ai-setting`, aiSetting); } catch (e) { if (e.status === 400 && /non AI account/.test(e.message)) { /* wrong account type, skip */ } else throw e; } Prevention
- Only post AI settings to AI-type accounts
- Maintain a separate inventory of AI/bot accounts
- Verify account type before applying AI configuration
When it happens
Trigger: Calling POST /rest/v1/users/{userId}/ai-setting with the id of a non-AI (ordinary or service) account.
Common situations: Scripts iterating all users and applying AI settings unconditionally; confusing user ids between an AI bot account and a human account; provisioning templates applied to all accounts.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Cannot set password for service or AI account
- Cannot reset two factor authentication for service or AI acc
- Reviewer not found:
- Assignee not found:
- Not authenticated
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/22982474a251b044.
Report an issue: GitHub.