From 05e0d355ddaddbce58d7d7d9343f03141f34b5df Mon Sep 17 00:00:00 2001 From: Gabriel Jablonski Date: Thu, 19 Mar 2026 20:51:04 -0300 Subject: [PATCH] fix(captain): prevent clamp ArgumentError when captain limits are negative (#242) When creating an inbox, `usage_limits` eagerly computes captain limits even though only the `:inboxes` value is needed. If `total_count` in `get_captain_limits` resolves to a negative number, `clamp(0, negative)` raises `ArgumentError: min argument must be less than or equal to max argument`, causing a 500 on inbox creation. Ensure `total_count` is floored at 0 so the clamp range is always valid. Co-authored-by: Claude Opus 4.6 (1M context) --- .../app/models/enterprise/account/plan_usage_and_limits.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enterprise/app/models/enterprise/account/plan_usage_and_limits.rb b/enterprise/app/models/enterprise/account/plan_usage_and_limits.rb index f0580003c..df688b039 100644 --- a/enterprise/app/models/enterprise/account/plan_usage_and_limits.rb +++ b/enterprise/app/models/enterprise/account/plan_usage_and_limits.rb @@ -62,7 +62,7 @@ module Enterprise::Account::PlanUsageAndLimits # rubocop:disable Metrics/ModuleL private def get_captain_limits(type) - total_count = captain_monthly_limit[type.to_s].to_i + total_count = [captain_monthly_limit[type.to_s].to_i, 0].max consumed = if type == :documents custom_attributes[CAPTAIN_DOCUMENTS_USAGE].to_i || 0