From d0adf6486e2bd7356fac26918aa8f58d5b12f6e1 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 21:38:20 -0700 Subject: [PATCH] refactor(agent): hug/pack bracket spans in async_utils + aux_accounting, fix E305 blank lines --- agent/async_utils.py | 7 ++----- agent/aux_accounting.py | 20 +++++--------------- agent/auxiliary_client.py | 3 +++ 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/agent/async_utils.py b/agent/async_utils.py index 15c288f34d..2bc558fad2 100644 --- a/agent/async_utils.py +++ b/agent/async_utils.py @@ -18,12 +18,9 @@ _DEFAULT_LOGGER = logging.getLogger(__name__) def safe_schedule_threadsafe( - coro: Coroutine[Any, Any, Any], - loop: Optional[asyncio.AbstractEventLoop], - *, + coro: Coroutine[Any, Any, Any], loop: Optional[asyncio.AbstractEventLoop], *, logger: Optional[logging.Logger] = None, - log_message: str = "Failed to schedule coroutine on loop", - log_level: int = logging.DEBUG, + log_message: str = "Failed to schedule coroutine on loop", log_level: int = logging.DEBUG, ) -> Optional[Future]: """Schedule ``coro`` on ``loop`` from a sync context, leak-safe. diff --git a/agent/aux_accounting.py b/agent/aux_accounting.py index ee9d15bff2..052c026afc 100644 --- a/agent/aux_accounting.py +++ b/agent/aux_accounting.py @@ -43,10 +43,7 @@ def reset_accounting_context(token) -> None: def record_aux_usage( - response: Any, - task: Optional[str], - *, - provider: Optional[str] = None, + response: Any, task: Optional[str], *, provider: Optional[str] = None, base_url: Optional[str] = None, ) -> None: """Record an auxiliary response's token usage against the ambient session. @@ -85,17 +82,10 @@ def record_aux_usage( except Exception: logger.debug("Aux usage cost estimation failed", exc_info=True) session_db.record_auxiliary_usage( - session_id, - task, - model=model, - billing_provider=provider, - billing_base_url=base_url, - input_tokens=usage.input_tokens, - output_tokens=usage.output_tokens, - cache_read_tokens=usage.cache_read_tokens, - cache_write_tokens=usage.cache_write_tokens, - reasoning_tokens=usage.reasoning_tokens, - estimated_cost_usd=estimated_cost, + session_id, task, model=model, billing_provider=provider, billing_base_url=base_url, + input_tokens=usage.input_tokens, output_tokens=usage.output_tokens, + cache_read_tokens=usage.cache_read_tokens, cache_write_tokens=usage.cache_write_tokens, + reasoning_tokens=usage.reasoning_tokens, estimated_cost_usd=estimated_cost, ) except Exception: logger.debug("Aux usage recording failed (non-fatal)", exc_info=True) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 6111970139..bdef510b0f 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -105,6 +105,7 @@ def aux_probe_mode(): finally: _aux_probe_state.active = prev + from agent.credential_pool import load_pool from agent.model_metadata import ( MINIMUM_CONTEXT_LENGTH, get_model_context_length, @@ -2422,6 +2423,8 @@ def _relay_sync_stream( model_name=str(kwargs.get("model") or fallback_model), finalizer=dict, metadata=metadata, completed_response_predicate=lambda value: hasattr(value, "choices"), ) + + _RUNTIME_MAIN_COMPAT_SNAPSHOT: Tuple[Any, ...] = ("", "", "", "", "", "") _RUNTIME_MAIN_COMPAT_LOCK = threading.Lock()