From 90b9c2ab460bbf7e74860b9c73a2fe4b76ddce09 Mon Sep 17 00:00:00 2001 From: majdyz Date: Sat, 11 Apr 2026 00:13:59 +0700 Subject: [PATCH] fix(backend/executor): skip execution tier charge for nested tool calls execution_usage_cost(0) incorrectly charges 1 credit because 0 % threshold == 0. charge_node_usage passes 0 to _charge_usage to signal "no tier increment", but the modulo check fires at 0. Fix: skip execution_usage_cost entirely when execution_count == 0, preserving the intent that nested tool executions don't count against execution tiers. --- autogpt_platform/backend/backend/executor/manager.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.py index f63f8ec76c..e3c6702039 100644 --- a/autogpt_platform/backend/backend/executor/manager.py +++ b/autogpt_platform/backend/backend/executor/manager.py @@ -1101,7 +1101,13 @@ class ExecutionProcessor: ) total_cost += cost - cost, usage_count = execution_usage_cost(execution_count) + # execution_count=0 is used by charge_node_usage for nested tool calls + # which must not be pushed into higher execution-count tiers. + # execution_usage_cost(0) would trigger a charge because 0 % threshold == 0, + # so skip it entirely when execution_count is 0. + cost, usage_count = ( + execution_usage_cost(execution_count) if execution_count > 0 else (0, 0) + ) if cost > 0: remaining_balance = db_client.spend_credits( user_id=node_exec.user_id,