+
    iHàjD  ã                  ó~   € R t ^ RIHt ^ RIt^ RIHt ^ RIHt ]P                  ! ]	4      t
R R ltR R ltR	 R
 ltR# )z]Codex Responses recovery rungs: stale encrypted-reasoning strip and the replay verdict reset.)ÚannotationsN)ÚAny)ÚTurnRetryStatec               ó$   € V ^8„  d   QhRRRRRR/# )é   Úagentr   Ú	api_errorÚ	ExceptionÚreturnÚbool© )Úformats   "Ú>/home/ubuntu/.hermes/hermes-agent/agent/turn_recovery_codex.pyÚ__annotate__r      s&   € ÷ Qñ Q 3ð Q°9ð QÀñ Qó    c                óÜ   € \        VRR4      R8w  d   R# V P                  V4      P                  R4      p\        V\        4      ;'       d"    VP                  4       P                  4       R8H  # )uZ  401 ``token_expired`` from the Codex backend (#88510). It rejects a stale replayed
``encrypted_content`` blob with this auth signature, so a persisted session loops on "sign
in again" while a fresh session on the same bearer works. The caller treats it like
``invalid_encrypted_content`` â€” but only while cached reasoning items remain to strip.Ústatus_codeNi‘  FÚreasonÚtoken_expired)ÚgetattrÚ_extract_api_error_contextÚgetÚ
isinstanceÚstrÚstripÚlower)r   r   r   s   && r   Ú_is_codex_token_expiredr      s\   € ô
 ˆy˜-¨Ó.°#Ô5ÙØ×-Ñ-¨iÓ8×<Ñ<¸XÓF€FÜ�fœcÓ"×PÐP v§|¡|£~×';Ñ';Ó'=ÀÑ'PÐPr   c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r
   ÚNoner   )r   s   "r   r   r      s   € ÷ 3ñ 3¨ð 3°ñ 3r   c                ó"   € RV n         RV n        R# )z¡The replay verdict belongs to the route that earned it: a ``/model`` switch, fallback
activation or primary restore starts the new route with replay on (#61552).TFN)Ú_codex_reasoning_replay_enabledÚ _codex_reasoning_replay_rejected)r   s   &r   Úreset_codex_reasoning_replayr"      s   € ð -1€EÔ)Ø-2€EÖ*r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   r   r   Ú_retryr   Úmessageszlist[dict[str, Any]]Úapi_messagesr
   r   r   )r   s   "r   r   r      s4   € ÷ .ñ .Øð.Ø&ð.Ø2Fð.ØVYð.à	ñ.r   c           
     ó4  € VP                   '       gh   V P                  R8w  gW   \        \        V RR4      4      '       d;   \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       g   R# ^ RIHp V P                  4       pVe)   VP                  W#4      ;p'       d   V! V RV R	24       R# RVn         \        V R
R4      '       * pRV n	        V P                  W'R7      p\        V\        4      '       d   TM.  F-  p	\        V	\        4      '       g   K  V	P                  RR4       K/  	  V'       d   RMRp
V! V RV
 RVR,           RVR,           R24       \        P!                  RV P"                  W¨R,          VR,          4       R# )a  Stale ``codex_reasoning_items`` blob rejected by the provider: strip cached items (mutates
persisted ``messages``) and retry once. The first rung drops only the replayed blobs not stamped by
exactly this endpoint+model (it consumes its own precondition, so it cannot loop); a repeat goes on
to strip every item. The first full strip keeps replay on, since blobs the
route mints from now on are sealed with its current key; a repeat rejection means the route
cannot round-trip its own blobs, so replay is disabled for the session.Úcodex_responsesr    Tc              3  óú   "  € T Fq  p\        V\        4      ;'       dU    VP                  R 4      R8H  ;'       d9    \        VP                  R4      \        4      ;'       d    VP                  R4      x € Ks  	  R# 5i)ÚroleÚ	assistantÚcodex_reasoning_itemsN)r   Údictr   Úlist)Ú.0Ú_ms   & r   Ú	<genexpr>Ú1_recover_stale_codex_reasoning.<locals>.<genexpr>+   sx   é € ð 
ñ
 �ô	 �rœ4Ó ÷ 0ð 0Ø—‘�v“ +Ñ-÷0ð 0ä˜2Ÿ6™6Ð"9Ó:¼DÓA÷0ð 0ð —‘Ð.Ó/ô0ó ùs   ‚A;žA;º&A;Á!A;F)Ú_vlinesNu<   âš ï¸�  Encrypted reasoning replay was rejected â€” dropped z& item(s) minted elsewhere, retrying...r!   )Úkeep_replayr,   zstripped stalez-disabled replay for this session and strippeduD   âš ï¸�  Encrypted reasoning replay was rejected by the provider â€” Ú Úitemsz item(s) from r%   z message(s), retrying...zD%sInvalid encrypted reasoning recovery: %s %d items from %d messages)Ú)invalid_encrypted_content_retry_attemptedÚapi_moder   r   ÚanyÚagent.turn_recoveryr3   Ú_get_transportÚdrop_unverified_replayr!   Ú_disable_codex_reasoning_replayr   r.   r-   ÚpopÚloggerÚwarningÚ
log_prefix)r   r$   r%   r&   r3   Ú	transportÚremovedr4   Úreplay_statsr0   Úactions   &&&&       r   Ú_recover_stale_codex_reasoningrF      s•  € ð 	×8×8Ð8Ø�>‰>Ð.Ô.Ü”G˜EÐ#DÀdÓK×LÒLß‹sñ 
ñ
 ó
�s�sŠsñ 
ñ
 ó
÷ 
ò 
ñ Ý+à×$Ñ$Ó&€IØÒ¨Y×-MÑ-MÈhÓ-eÐ"e 'Ö"eÙ�ÐUÐV]ÐU^ð  _Eð  Fô  	GÙØ7;€FÔ4Ü˜eÐ%GÈÓOÔO€KØ-1€EÔ*Ø×8Ñ8¸Ð8Ó[€Lä(¨´t×<Ò<‰lÀ"ÒDˆÜ�bœ$×ÔØ�F‰FÐ*¨DÖ1ñ E÷ "-ÑÐ2a€FÙØØ
NØˆ(�!�L Õ)Ð*¨.¸ÀjÕ9QÐ8RÐRjð	lôô
 ‡N�NØNØ×Ñ˜&¨wÕ"7¸ÀjÕ9Qôñ r   )Ú__doc__Ú
__future__r   ÚloggingÚtypingr   Úagent.turn_retry_stater   Ú	getLoggerÚ__name__r?   r   r"   rF   r   r   r   Ú<module>rN      s4   ðÙ cÝ "ã Ý å 1à	×	Ò	˜8Ó	$€õQõ3÷.r   