From 26179463977419cd2c0258eb88fcebf33b665b20 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 22 Jun 2026 09:44:30 -0700 Subject: [PATCH] fix(delegation): emit high-concurrency cost warning once per process (#50848) * chore: re-trigger CI (workflows did not dispatch on prior head) * fix(delegation): emit high-concurrency cost warning once per process _get_max_concurrent_children() runs on every get_definitions() schema rebuild (via _build_top_level_description / _build_tasks_param_description), not just on actual delegate_task calls. With max_concurrent_children>10 the cost advisory fired on every turn / agent spawn across every session, spamming the log even when delegate_task was never used. Gate it behind a module-level _HIGH_CONCURRENCY_WARNED flag so it warns at most once per process. --- tools/delegate_tool.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/delegate_tool.py b/tools/delegate_tool.py index 5e1875b5198..1be02f240e0 100644 --- a/tools/delegate_tool.py +++ b/tools/delegate_tool.py @@ -130,6 +130,12 @@ _SUBAGENT_TOOLSETS = sorted( _TOOLSET_LIST_STR = ", ".join(f"'{n}'" for n in _SUBAGENT_TOOLSETS) _DEFAULT_MAX_CONCURRENT_CHILDREN = 3 +# One-shot guard: the high-concurrency cost advisory is emitted at most once +# per process. _get_max_concurrent_children() runs on every get_definitions() +# schema rebuild (via _build_top_level_description / _build_tasks_param_description), +# so without this flag a config of max_concurrent_children>10 spams the log on +# every turn / agent spawn even when delegate_task is never called. +_HIGH_CONCURRENCY_WARNED = False MAX_DEPTH = 1 # flat by default: parent (0) -> child (1); grandchild rejected unless max_spawn_depth raised. # Configurable depth cap consulted by _get_max_spawn_depth; MAX_DEPTH # stays as the default fallback and is still the symbol tests import. @@ -374,11 +380,14 @@ def _get_max_concurrent_children() -> int: try: result = max(1, int(val)) if result > 10: - logger.warning( - "delegation.max_concurrent_children=%d: each child consumes API tokens " - "independently. High values multiply cost linearly.", - result, - ) + global _HIGH_CONCURRENCY_WARNED + if not _HIGH_CONCURRENCY_WARNED: + _HIGH_CONCURRENCY_WARNED = True + logger.warning( + "delegation.max_concurrent_children=%d: each child consumes API tokens " + "independently. High values multiply cost linearly.", + result, + ) return result except (TypeError, ValueError): logger.warning(