
    `gj                    B    d Z ddlmZ ddlmZmZ e G d d             Zy)u  Per-attempt recovery bookkeeping for the conversation turn loop.

The inner retry loop in ``run_conversation`` (``while retry_count <
max_retries``) makes several distinct recovery attempts on a single model API
call: a credential-pool 429 retry, a per-provider OAuth refresh (codex,
anthropic, nous, copilot), a long-context compression restart, a length-
continuation restart, and a handful of format-recovery branches (thinking-
signature stripping, multimodal-tool-content stripping, llama.cpp grammar
fallback, image shrink, invalid-encrypted-content, 1M-beta header).

Each of those branches is guarded by a one-shot boolean so it fires at most
once per attempt. They used to be ~16 bare ``*_attempted`` / ``has_retried_*``
/ ``restart_with_*`` locals declared inline before the loop and threaded
through its 2,400-line body. ``TurnRetryState`` collapses them into one object
the loop mutates in place (``state.codex_auth_retry_attempted = True``), giving
the recovery bookkeeping a single named, testable home.

Loop-control variables (``retry_count``, ``max_retries``,
``max_compression_attempts``) intentionally stay as plain locals — they are the
``while`` mechanics, not recovery bookkeeping, and putting them on the object
would add indirection without clarifying anything.

This module is dependency-free so it can be unit-tested in isolation and
imported by the turn loop without an import cycle.
    )annotations)	dataclassfieldsc                     e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded<   dZ
ded	<   dZded
<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   d Zy)TurnRetryStateaq  One-shot recovery guards + restart signals for a single API-call attempt.

    A fresh instance is created for each iteration of the outer turn loop
    (once per ``api_call_count``). Each guard fires its recovery branch at most
    once; the ``restart_with_*`` signals are read by the loop after the attempt
    to decide whether to rebuild the request and retry.
    Fboolcodex_auth_retry_attemptedanthropic_auth_retry_attemptednous_auth_retry_attempted'nous_paid_entitlement_refresh_attemptedcopilot_auth_retry_attemptedvertex_auth_retry_attemptedthinking_sig_retry_attempted)invalid_encrypted_content_retry_attemptedimage_shrink_retry_attempted'multimodal_tool_content_retry_attemptedoauth_1m_beta_retry_attempted!llama_cpp_grammar_retry_attemptedprimary_recovery_attemptedhas_retried_429auth_failover_attempted restart_with_compressed_messages restart_with_length_continuationrestart_with_rebuilt_messagesc              #  t   K   t        |       D ]&  }|j                  t        | |j                        f ( y w)N)r   namegetattr)selffs     I/root/.hermes/venv/lib/python3.12/site-packages/agent/turn_retry_state.py__iter__zTurnRetryState.__iter__M   s3      	0A&&'$///	0s   68N)__name__
__module____qualname____doc__r	   __annotations__r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!        r    r   r       s     (-,+0"D0&+t+49+T9). $.(-- */ $.6;-t;). $.49+T9*/!4/.3%t3 (-,!OT! %*T) .3$d2-2$d2
 +0!4/0r(   r   N)r%   
__future__r   dataclassesr   r   r   r'   r(   r    <module>r+      s+   4 # ) /0 /0 /0r(   