Fix agents disabled and disabledReason fields in APIs

What does this MR do and why?

The logic for checking whether a composite identity (agent) user is disabled was duplicated across three places: EE::Types::UserStatusType, Types::Users::DuoStatusType, and EE::Users::ParticipableService.

Also, the logic was incorrect in all 3 types and instead of checking credits of current_user, the actual user/agent was passed on to UsageQuotaService, making it to fail because service accounts won't have credits assigned to them.

This MR:

  • Centralizes the agent?(user) guard (service_account? && composite_identity_enforced?)
  • Maps all UsageQuotaService error reasons to human-readable messages
  • Fixes the quota usage check to use the correct user (current_user) instead of the user whose availability is being checked

This is a refactor with no functional change for the "no credits" path. The additional failure reasons (:user_missing, :namespace_missing, unknown) were previously swallowed and returned no message — they now surface a proper reason string, which will help debug issues like the one reported in #593981 (closed) where the duo developer service account was not showing up in the mention autocomplete.

References

Closes #593981 (closed)

How to set up and validate locally

No functional change for the happy path. To validate the disabled state:

  1. Apply the patch below to force credits to be exhausted:
diff --git a/ee/app/services/ai/usage_quota_service.rb b/ee/app/services/ai/usage_quota_service.rb
--- a/ee/app/services/ai/usage_quota_service.rb
+++ b/ee/app/services/ai/usage_quota_service.rb
@@ -36,7 +36,7 @@ def execute
-      if usage_quota_response(params.compact).dig("data", "errors")&.include?("402")
+      if true || usage_quota_response(params.compact).dig("data", "errors")&.include?("402")
  1. Make sure you have at least one foundational flow enabled for a group with Duo enabled
  2. Go to an MR or issue under that group and try to @-mention or assign the service account — it should show as disabled with the correct reason message

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Wanderson Policarpo

Merge request reports

Loading