
    oq'j
                    P    d Z ddlmZ ddlmZmZ e G d d                      ZdS )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S )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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 restart_with_compressed_messages restart_with_length_continuationc              #  j   K   t          |           D ] }|j        t          | |j                  fV  !d S )N)r   namegetattr)selffs     ;/home/ubuntu/.hermes/hermes-agent/agent/turn_retry_state.py__iter__zTurnRetryState.__iter__A   sG       	0 	0A&'$///////	0 	0    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       sD          (-,,,,+0"0000&+++++49+9999). .... */ ....6;-;;;;). ....49+9999*/!////.3%3333 (-,,,,!O!!!! .3$2222-2$22220 0 0 0 0r   r   N)r#   
__future__r   dataclassesr   r   r   r%   r   r   <module>r(      sy    4 # " " " " " ) ) ) ) ) ) ) ) #0 #0 #0 #0 #0 #0 #0 #0 #0 #0r   