+
    iHàj˜¥ ã            
      óü  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
HtHtHtHtHt ^ RIHt ^ RIHtHt ^ RIHtHt ^ RIHtHt ^ R	IHtHt ^ R
IHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't'H(t( ^ RI)H*t*H+t+ ^ RI,H-t- ^ RI.H/t/H0t0H1t1H2t2H3t3H4t4H5t5H6t6 ^ RI7H8t8 ^ RI9H:t:H;t; ^ RI<H=t= ^ RI>H?t? ]P€                  ! R4      tAR R ltBR R ltCR R ltDR R ltER R ltFR R ltGR R  ltHR! R" ltIR# R$ ltJR% R& ltKR' R( ltLR) R* ltMR+ R, ltNR- R. ltOR/R0R1R2R3R4/tPR5 R6 ltQR7 R8 ltRR9 R: ltSR; R< ltTR= R> ltUR? R@ ltVRA RB ltWRC RD ltXRE RF ltYRG RH ltZ][! ]P¸                  ]Pº                  ]P¼                  04      t_RI RJ lt`RK RL ltaRMRN/RO RP lltbRQRQRRRRRSRRRTRTRURT/tcRV RW ltdRX RY lteRZ R[ ltf]PÎ                  R\]PÐ                  R]]PÒ                  R^]PÔ                  R_/tkR` Ra ltlRbRc/Rd Re lltmR’tnRbRc/Rf Rg lltoRhRN/Ri Rj lltpRk Rl ltqRm Rn ltrRoRpRqRr/tsRs Rt lttRu Rv ltuRw Rx ltvRy Rz ltw ! R{ R|]x4      tyR} R~ ltzR R€ lt{R� R‚ lt|Rƒ R„ lt}]	 ! R… R†4      4       t~][! ]Pþ                  ]EP                   ]EP                  04      t‚][! ]P¸                  ]P¼                  ]Pº                  04      tƒ][! ]EP                  ]EP
                  04      t†R‡t‡Rˆ R‰ ltˆRŠ R‹ lt‰RŒ R� ltŠR“RŽ R� llt‹R� R‘ ltŒR# )”a  Recovery-branch handlers for the conversation turn's inner retry loop.

When the model call raises, one-shot recovery chains run before the generic retry/backoff
path. Handlers return ``True`` (request repaired in place; loop ``continue``s with the same
``retry_count``) or ``False`` (fall through). Guards live on ``TurnRetryState``; handlers
mutate ``agent`` / ``messages`` / ``api_messages`` in place. Logger name stays
``agent.conversation_loop`` (caplog pins); that module is only imported lazily (cycle + patch sites).
)ÚannotationsN)Ú	dataclass)ÚAnyÚDictÚListÚOptionalÚTuple)Ú1COMPRESSION_RETRY_CONTEXT_REDUCED_STATUS_TEMPLATE)Úfast_mode_unprovisionedÚmark_fast_mode_unavailable)Úis_output_cap_errorÚ(parse_available_output_tokens_from_error)Úis_zai_coding_overload_errorÚ!zai_coding_overload_retry_ceiling)ÚFailoverReasonÚclassify_api_error)
Ú#_looks_like_corrupt_image_rejectionÚ#_looks_like_image_content_rejectionÚ_sanitize_messages_non_asciiÚ_sanitize_messages_surrogatesÚ_sanitize_structure_non_asciiÚ_sanitize_structure_surrogatesÚ_strip_images_from_messagesÚ_strip_non_asciiÚclose_interrupted_tool_sequenceÚ record_reasoning_field_rejection)Úbuild_thinking_timeout_guidanceÚis_thinking_timeout)Ú_provider_model_key)ÚCONTENT_POLICY_NEXT_STEPSÚcontent_policy_copyÚexhausted_copyÚlimit_reset_copyÚnonretryable_copyÚprovider_label_forÚ	site_copyÚstamp_failure)ÚTurnRetryState)Ú_is_codex_token_expiredÚ_recover_stale_codex_reasoning©Údisplay_hermes_home)Úbase_url_host_matcheszagent.conversation_loopc               ó   € V ^8„  d   QhRR/# ©é   ÚreturnÚbool© )Úformats   "Ú8/home/ubuntu/.hermes/hermes-agent/agent/turn_recovery.pyÚ__annotate__r5   ,   s   € ÷ ?ñ ? dñ ?ó    c                 ó�   € \         P                  ! R4      P                  4       P                  4       P	                  RR4      p V R9   # )zJReturn whether the process genuinely needs an ASCII-only request fallback.FÚ_Ú->   Úasciiúus-asciiúansi-x3.4-1968)ÚlocaleÚgetpreferredencodingÚstripÚlowerÚreplace)Úencodings    r4   Ú_runtime_uses_ascii_encodingrC   ,   s=   € ä×*Ò*¨5Ó1×7Ñ7Ó9×?Ñ?ÓA×IÑIÈ#ÈsÓS€HØÐ>Ñ>Ð>r6   c               ó$   € V ^8„  d   QhRRRRRR/# ©r/   Úagentr   ÚlinesÚstrr0   ÚNoner2   )r3   s   "r4   r5   r5   2   s&   € ÷ Pñ P�3ð P ð P¨ñ Pr6   c                ó\   € V F%  pV P                  V P                   V 2RRR7       K'  	  R# )z?Force-``_vprint`` each line prefixed with ``agent.log_prefix``.T)ÚforceÚ
diagnosticN)Ú_vprintÚ
log_prefix©rF   rG   Úlines   &* r4   Ú_vlinesrQ   2   s.   € ãˆØ�‰˜×)Ñ)Ð*¨4¨&Ð1¸È$ˆÖOó r6   c               ó$   € V ^8„  d   QhRRRRRR/# rE   r2   )r3   s   "r4   r5   r5   8   s&   € ÷ Bñ B�3ð B ð B¨ñ Br6   c                óx   a a€ ^ RI Hp V! V V3R l\        S R\        S RR4      4      \        S RR4      R7       R# )	z7``print`` each line prefixed with ``agent.log_prefix``.)Úrender_notificationc                 ó`   <€ S U u. uF  p \        SP                   V  24      NK  	  up # u up i ©N)ÚprintrN   )rP   rF   rG   s    €€r4   Ú<lambda>Ú_plines.<locals>.<lambda><   s,   ø€ ÁÓFÁ¸”˜%×*Ñ*Ð+¨D¨6Ð2Ö3ÁÒFùÒFs   †"+Ú_notification_platformÚplatformÚcliÚ_notification_configN)r[   Úuser_config)Úgateway.warning_notificationsrT   Úgetattr)rF   rG   rT   s   fj r4   Ú_plinesra   8   s6   ù€ åAÙÝFÜ˜Ð 8¼'À%ÈÐUZÓ:[Ó\Ü˜EÐ#9¸4Ó@÷Br6   c               ó$   € V ^8„  d   QhRRRRRR/# rE   r2   )r3   s   "r4   r5   r5   A   s!   € ÷ #ñ #�3ð # ð #¨ñ #r6   c                ó:   € V F  pV P                  V4       K  	  R# )zN``_buffer_vprint`` each line (surfaces only if every retry+fallback exhausts).N)Ú_buffer_vprintrO   s   &* r4   Ú_blinesre   A   s   € ãˆØ×Ñ˜TÖ"ó r6   c               ó    € V ^8„  d   QhRRRR/# )r/   ÚerrorÚ	Exceptionr0   úOptional[int]r2   )r3   s   "r4   r5   r5   G   s   € ÷ Cñ C ið C°Mñ Cr6   c                óÌ  € . pV \        V RR4      \        V RR4      3 F(  pV'       g   K   VP                  \        V4      4       K*  	  RP	                  V4      P                  4       pRV9   dk   \        P                  ! RV4      pV'       g   R# \        P                  ! \        VP                  ^4      4      4      ^ ,          pRTu;8:  d	   R8:  d   V#  R# R	V9  g   R
V9  g   RV9  d   R# \        P                  ! RV4      pV'       g   R#  \        VP                  ^4      4      pRTu;8:  d	   R8:  d   T#  R#   \         d     EK2  i ; i  \         d     R# i ; i)z@Extract a provider-reported image dimension ceiling, if present.ÚmessageNÚbodyÚ zpatches after processingz"exceeding the limit of\s*(\d{2,7})i   é@  ÚimageÚ	dimensionzmax allowed sizez8max allowed size(?:\s+for [^:]+)?:\s*(\d{3,5})\s*pixels?)r`   ÚappendrH   rh   Újoinr@   ÚreÚsearchÚmathÚisqrtÚintÚgroupÚ
ValueError)rg   ÚpartsÚvalueÚtextÚmatchÚmax_dimensions   &     r4   Ú_image_error_max_dimensionr   G   sF  € à€EØœ ¨	°4Ó8¼'À%ÈÐQUÓ:VÓWˆß‰5ðØ—‘œS ›ZÖ(ñ Xð �8‰8�E‹?× Ñ Ó"€Dð " TÔ)Ü—	’	Ð?ÀÓFˆßÙÜŸ
š
¤3 u§{¡{°1£~Ó#6Ó7¸"Õ<ˆØ # }Ö <¸Ô <ˆ}ÐFÐ <À$ÐFØ�dÔ˜k°Ô5Ð9KÐSWÔ9WÙÜ�IŠIÐQÐSWÓX€EßÙðÜ˜EŸK™K¨›NÓ+ˆð   =Ö8°DÔ8ˆ=ÐBÐ8¸dÐBøô/ ô Ûðûô* ô Úðús#   ¬EÄE ÅEÅEÅE#Å"E#c               ó   € V ^8„  d   QhRR/# r.   r2   )r3   s   "r4   r5   r5   h   s   € ÷ 	ñ 	¸Tñ 	r6   c                óŠ   €  ^ RI Hp V! RR7      P                  RJd   R# V P                  RR7      #   \         d     R# i ; i)zFRefresh Nous runtime credentials after a fresh paid-entitlement check.)Úget_nous_portal_account_infoT)Úforce_freshF©rK   )Úhermes_cli.nous_accountr‚   Úpaid_service_accessÚ$_try_refresh_nous_client_credentialsrh   )rF   r‚   s   & r4   Ú._try_refresh_nous_paid_entitlement_credentialsrˆ   h   sG   € ðÝHá'°DÔ9×MÑMÐUYÓYÙØ×9Ñ9ÀÐ9ÓEÐEøÜô Úðús   ‚3 ¡3 ³AÁAc               ó    € V ^8„  d   QhRRRR/# )r/   rF   r   r0   r1   r2   )r3   s   "r4   r5   r5   t   s   € ÷ ñ ¨ð °ñ r6   c                ó(  € \        V RR4      p\        V\        4      '       d   VP                  R4      MRp\	        \        V\        4      ;'       d    \        V4      4      p\        V RR4      ;'       g    Rp\        V\        4      '       dƒ   V'       d{   \        V4      pWT8w  dj   WPn        \        V\        4      '       d   WQR&   \        V RR4      e-   \        V P                  R4      '       d   WPP                  n        Rp\        V R4       V# )	uÐ  Strip non-ASCII from ``_client_kwargs["default_headers"]`` and the API key.

Non-ASCII in the key makes httpx fail encoding the Authorization header â€” the usual
persistent cause of UnicodeEncodeError that survives message/tool sanitization (#6843,
e.g. Ê‹ instead of v from a bad copy-paste). Entra ID bearer providers are callables
minting ASCII JWTs; skip them (``_strip_non_ascii`` would crash). Returns True when
either the headers or the key were repaired.
Ú_client_kwargsNÚdefault_headersÚapi_keyÚ ÚclientTu’   âš ï¸�  API key contained non-ASCII characters (bad copy-paste?) â€” stripped them. If auth fails, re-copy the key from your provider's dashboard.)r`   Ú
isinstanceÚdictÚgetr1   r   rH   r   r�   Úhasattrr�   rQ   )rF   r‹   Ú_default_headersÚ	_repairedÚ_raw_keyÚ
_clean_keys   &     r4   Ú_repair_transport_credentialsr˜   t   sí   € ô ˜UÐ$4°dÓ;€NÜ@JÈ>Ô[_×@`Ò@`�~×)Ñ)Ð*;Ô<ÐfjÐÜ”ZÐ 0´$Ó7×kÐkÔ<YÐZjÓ<kÓl€IÜ�u˜i¨Ó.×4Ð4°"€HÜ�(œC× Ò §XÜ% hÓ/ˆ
ØÔ!Ø&ŒMÜ˜.¬$×/Ò/Ø,6˜yÑ)ä�u˜h¨Ó-Ò9¼gÀeÇlÁlÐT]×>^Ò>^Ø'1—‘Ô$ØˆIÜØðQôð
 Ðr6   c               ó4   € V ^8„  d   QhRRRRRRRRRRR	RR
R/# ©r/   rF   r   Ú	api_errorrh   Úmessagesúlist[dict[str, Any]]Úapi_messagesÚ
api_kwargsÚactive_system_promptr0   ztuple[bool, Any]r2   )r3   s   "r4   r5   r5   “   sO   € ÷ J&ñ J&ØðJ&Ø$ðJ&Ø0DðJ&ØTWðJ&àðJ&à+.ðJ&ð ñJ&r6   c                ó  € \        V4      P                  4       pRV9   ;'       g    RV9   pRV9   ;'       g    RV9   ;'       d    V'       * p\        V4      p	T	\        V\        4      ;'       d    \        V4      ,          p	T	\        V\
        4      ;'       d    \        V4      ,          p	V	'       g	   V'       dH   V	'       d   RV n        V ;P                  ^,          un        T P                  V	'       d   RMR4       RV3# V'       g   R	V3# \        4       '       g?   \        V 4      '       g   R	V3# V ;P                  ^,          un        \        V R
4       RV3# RV n        \        V\        4      ;'       d    \        V4      p
R	p\        V\         4      '       d   \        V4      pWÅ8w  d   TpRp\        V 4      pV ;P                  ^,          un        \        T V
'       g   V'       g	   V'       d   RMR4       RV3# )zîUnicodeEncodeError recovery: lone surrogates (clipboard paste) first, then an ASCII
codec under a non-UTF-8 locale. Sanitizes in place; bounded by the caller's
``_unicode_sanitization_passes < 2`` guard (surrogate strip, then ASCII-only).z'ascii'r:   Ú	surrogatez'utf-8'NuH   âš ï¸�  Stripped invalid surrogate characters from messages. Retrying...uP   âš ï¸�  Surrogate encoding error â€” retrying after full-payload sanitization...TFui   âš ï¸�  Repaired non-ASCII request credentials/headers without changing conversation content. Retrying...ud   âš ï¸�  System encoding is ASCII â€” stripped non-ASCII characters from request payload. Retrying...uT   âš ï¸�  System encoding is ASCII â€” enabling full-payload sanitization for retry...)rH   r@   r   r�   Úlistr‘   r   Ú_db_flush_scan_prefixÚ_unicode_sanitization_passesrd   rC   r˜   rQ   Ú_force_ascii_payloadr   r   )rF   r›   rœ   rž   rŸ   r    Ú_err_strÚ_is_ascii_codecÚ_is_surrogate_errorÚ_surrogates_foundÚ_messages_sanitizedÚ_system_sanitizedÚ_sanitized_systemÚ_transport_repaireds   &&&&&&        r4   Ú_recover_unicode_encode_errorr¯   “   sí  € ô �9‹~×#Ñ#Ó%€HØ 8Ñ+×BÐB¨w¸(Ñ/B€Oà%¨Ñ1×dÐd°iÀ8Ñ6K×6cÐ6cÐTcÔPcÐô 6°hÓ?ÐØœ L´$Ó7×gÐgÔ<YÐZfÓ<gÕgÐØœ J´Ó5×dÐdÔ:XÐYcÓ:dÕdÐ÷ ×/ßð +/ˆEÔ'Ø×*Ò*¨aÕ/Õ*Ø×Ñç ñ Wà^ô	
ð
 Ð)Ð)Ð)ßØÐ*Ð*Ð*ô (×)Ò)Ü,¨U×3Ò3ØÐ.Ð.Ð.Ø×*Ò*¨aÕ/Õ*ÜØØwô	
ð Ð)Ð)Ð)à!%€EÔô
 % \´4Ó8×gÐgÔ=YÐZfÓ=gÐàÐÜÐ&¬×,Ò,Ü,Ð-AÓBÐØÔ4Ø#4Ð Ø $Ðä7¸Ó>Ðð 
×&Ò&¨!Õ+Õ&ÜØç×#4×8Kñ 	oà^ô	ð Ð%Ð%Ð%r6   c               ó$   € V ^8„  d   QhRRRRRR/# )r/   rF   r   rž   r0   r1   r2   )r3   s   "r4   r5   r5   à   s!   € ÷ ñ ¨3ð ¸cð Àdñ r6   c                óp   € \        V\        4      '       d    \        V4      '       d   \        V R4       R# R# )a	  Strip image parts from the per-call ``api_messages`` copy; True if anything was removed.

Shared by the corrupt-image recoveries: a bad payload says nothing about the model, so it
is stripped for this attempt only and the model is never recorded as image-rejecting.uf   âš ï¸�  Provider rejected a corrupted image â€” stripped images from the retry payload and retrying...TF)r�   r£   r   rQ   )rF   rž   s   &&r4   Ú_strip_request_images_and_retryr²   à   s0   € ô
 �,¤×%Ò%Ô*EÀl×*SÒ*SÜ�Ðô  	AÙÙr6   c               ó4   € V ^8„  d   QhRRRRRRRRRRR	RR
R/# rš   r2   )r3   s   "r4   r5   r5   ë   sO   € ÷ Z'ñ Z'ØðZ'Ø$ðZ'Ø3GðZ'ØWZðZ'àðZ'à+.ðZ'ð ñZ'r6   c               ó   € \        V\        4      '       d.   \        V R^ 4      ^8  d   \        WW#WE4      w  reV'       d   RV3# \	        W4      '       d[   \        V 4      '       dJ   \        V RV P                   R24       \        P                  RV P                  V P                  4       RV3# Rp \        \        VRR4      ;'       g!    \        VR	R4      ;'       g    \        V4      4      p\        VR
R4      pVRJ ;'       g     R\        V4      u;8*  ;'       d    R8  Mu p	\        V 4      p
V P                  p\!        V4      pV	'       d_   V'       g   W«9  dQ   \#        V4      '       d@   V'       d   \%        W4      '       d   RV3# M!VP'                  V
4       \        V R4       RV3# \        V\(        4      '       d   VP+                  R4      MRpV	'       dX   \-        YT;'       g    T4      ;p'       d:   \        V RV P                   RRP/                  \1        V4      4       R24       RV3# \        V\2        4      '       d�   R\        V4      P5                  4       9   d   \        V RR4      R8X  dm   V P6                  R8X  d\   \        V RR4      '       gI   RV n        RV n        \        V RR4      ;'       g    RV n        RV n        / V n        \        V R4       RV3# RV3#   \         d     ELi ; i)a0  Recovery branches that run BEFORE ``classify_api_error``: UnicodeEncodeError
sanitization, Anthropic fast mode with no capacity (drop ``speed`` for that model),
provider image-content rejection (record the (provider, model);
build_api_request strips images from that model's requests only), an unknown-field
rejection naming a replayed reasoning key (recorded per (provider, host, model),
stripped on the retry), and the Bedrock
AnthropicBedrock SDK streaming fallback. Returns ``(retry_now, active_system_prompt)``;
the prompt may be ASCII-sanitized in place.r¥   Tu&   âš ï¸�  Fast mode isn't available for uV    on this Anthropic organization â€” using standard speed for this session, retrying...zK%sFast mode: %s has a fast-mode limit of 0; standard speed for this sessionrŽ   rl   Nrk   Ústatus_codeé�  éô  un   âš ï¸�  Server rejected image content â€” sending text only to this model; images stay in the session history.rœ   õ   âš ï¸�  z rejected replayed ú, u(    â€” retrying without it for this model.zunexpected event orderÚproviderÚbedrockÚanthropic_messagesÚ$_bedrock_converse_fallback_attemptedFÚbedrock_converseÚ_bedrock_regionz	us-east-1ug   âš ï¸�  AnthropicBedrock SDK streaming failed â€” falling back to native Converse API for this session.) r�   ÚUnicodeEncodeErrorr`   r¯   r
   r   rQ   ÚmodelÚloggerÚwarningrN   rH   rh   rw   r   Ú_image_rejecting_modelsr   r   r²   Úaddr‘   r’   r   rr   ÚsortedÚRuntimeErrorr@   Úapi_moder½   r¿   r�   r‹   )rF   r›   rœ   rž   rŸ   r    Ú
_recoveredÚ	_err_bodyÚ_err_statusÚ
_status_okÚ
_model_keyÚ	_rejectedÚ_corruptÚ_sentÚ_news   &&$$$$         r4   Úrecover_before_classificationrÒ   ë   s   € ô �)Ô/×0Ò0´W¸UÐDbÐdeÓ5fÐijÔ5jÜ+HØ˜h°jó,
Ñ(ˆ
÷ ØÐ-Ð-Ð-ô
 ˜y×5Ò5Ô:TÐUZ×:[Ò:[Ü�Ð?ÀÇÁ¸}ð  Mcð  dô  	eÜ�‰ÐdÐfk×fvÑfvÐx}÷  yDñ  yDô  	EØÐ)Ð)Ð)ð
 €IðÜœ 	¨6°4Ó8×qÐq¼GÀIÈyÐZ^Ó<_×qÐqÔcfÐgpÓcqÓrˆ	ô ˜) ]°DÓ9€Kà Ð$×GÐG¨´°KÓ0@×)FÔ)FÀ3Ô)F€Jô % UÓ+€JØ×-Ñ-€IÜ2°9Ó=€Hß—x JÔ$?ÔDgÐhq×DrÒDr÷
 ô
 /¨u×CÒCØÐ1Ð1Ð1ð Dð
 �M‰M˜*Ô%ÜØð6ôð
 Ð-Ð-Ð-ô
 +5°ZÄ×*FÒ*FˆJ�N‰N˜:Ô&ÈD€EßÔ?ÀÐRW×RgÐRgÐ[gÓhÐh�tÖhÜ�˜ %§+¡+ Ð.AÀ$Ç)Á)ÌFÐSWËLÓBYÐAZð  [Cð  Dô  	EØÐ)Ð)Ð)ô
 	�9œl×+Ò+Ø$¬¨I«×(<Ñ(<Ó(>Ô>Ü�E˜: rÓ*¨iÔ7Ø�N‰NÐ2Ô2Ü˜ÐEÀu×MÒMà59ˆÔ2Ø+ˆŒÜ '¨Ð/@À$Ó G× VÐ VÈ;ˆÔØˆŒØ!ˆÔÜ�ð  Aô  	BØÐ)Ð)Ð)ØÐ&Ð&Ð&øôs ô Úðús   Â2K. ÃK. Ã K. Ë.K=Ë<K=c               ó$   € V ^8„  d   QhRRRRRR/# )r/   rF   r   r›   rh   r0   rI   r2   )r3   s   "r4   r5   r5   H  s!   € ÷ "ñ " sð "°yð "ÀTñ "r6   c           	     óÐ  € ^ RI Hp ^ RIHp Rp \	        VRR4      ;'       g    \	        VRR4      pVe   \        V4      R,          p\        T R4       T'       d   \        T R	T 24        ^ R
IH	p T! T 4      '       d   \        T RR4       R#  T! T R4      '       g   \        T R4       \        T RRRRT! 4        R2R4       R#   \         d     L‹i ; i  \         d     LTi ; i)zsNous 401 that survived a credential refresh: likely Portal OAuth expired/revoked,
no credits, or agent key blocked.)Ú _print_nous_entitlement_guidancer*   rŽ   rl   NÚresponse:NéÈ   Nu/   ðŸ”� Nous 401 â€” Portal authentication failed.z   Response: ©Úis_anonymous_agentz:   Your session ended and Hermes couldn't start a new one.zL   Sign in with a Nous account (it's free), or switch providers with /model.úNous model accesszS   Most likely: Portal OAuth expired, account out of credits, or agent key revoked.ú   Troubleshooting:u.        â€¢ Re-authenticate: hermes auth add nousuA        â€¢ Check credits / billing: https://portal.nousresearch.comu$        â€¢ Verify stored credentials: z
/auth.jsonuK        â€¢ Switch providers temporarily: /model <model> --provider openrouter)
Úagent.conversation_looprÕ   Úhermes_constantsr+   r`   rH   rh   ra   Úhermes_cli.anon_authrÙ   )rF   r›   rÕ   r+   Ú
_body_textÚ_bodyrÙ   s   &&     r4   Ú_print_nous_401_diagnosticsrá   H  s  € õ IÝ4Ø€JðÜ˜	 6¨4Ó0×XÐX´G¸IÀzÐSWÓ4XˆØÒÜ˜U› DÕ)ˆJô ˆEÐDÔEßÜ�˜ z lÐ3Ô4ð	Ý;Ù˜e×$Ò$ô �EÐWØbôdáð %ñ ,¨EÐ3F×GÒGÜ�ÐlÔmÜØØØ8ØKØ
.Ñ/BÓ/DÐ.EÀZÐPØUöøô# ô Ùðûô ô Ùðús.   �C ¤$C Á,C Â C ÃCÃCÃC%Ã$C%c               ó$   € V ^8„  d   QhRRRRRR/# )r/   rF   r   Úkeyr0   rI   r2   )r3   s   "r4   r5   r5   m  s!   € ÷ !ñ !¨Cð !°cð !¸dñ !r6   c                ój  € ^ RI Hp ^ RIHp ^ RIHp \        V R4       V! V4      '       d   \        V RRR4       MUV! V4      '       d   RMR	p\        T R
V 2\        V\        4      '       d   \        V4      ^8”  d   RVR,           R2MR4       V! 4       p\        V RRV R2RV R2RRRRR4	       R# )zKAnthropic 401 that survived a credential refresh: show auth method + fixes.)Ú_is_oauth_token)Úis_token_providerr*   u-   ðŸ”� Anthropic 401 â€” authentication failed.z5   Auth method: Microsoft Entra ID (httpx event hook)z;   Run `hermes doctor` for credential-chain diagnostics, orz0   `az login` if your developer session expired.zBearer (OAuth/setup-token)zx-api-key (API key)z   Auth method: z   Token prefix: :Né   Nú...z   Token: (empty or short)rÛ   u"        â€¢ Check ANTHROPIC_TOKEN in z+/.env for Hermes-managed OAuth/setup tokensu$        â€¢ Check ANTHROPIC_API_KEY in z)/.env for API keys or legacy token valuesuJ        â€¢ For API keys: verify at https://platform.claude.com/settings/keysu[        â€¢ Hermes login (OAuth): run 'hermes auth add anthropic' to sign in again, then retryu>        â€¢ Inspect what Hermes holds: hermes auth list anthropicu=        â€¢ Legacy cleanup: hermes config set ANTHROPIC_TOKEN ""uA        â€¢ Clear stale keys: hermes config set ANTHROPIC_API_KEY ""N)
Úagent.anthropic_credentialsrå   Úagent.azure_identity_adapterræ   rÝ   r+   ra   r�   rH   Úlen)rF   rã   rå   ræ   r+   Úauth_methodÚ_dhhs   &&     r4   Ú _print_anthropic_401_diagnosticsrî   m  sÎ   € å;Ý>Ý4ÜˆEÐBÔCÙ˜×Òô 	ØØCØIØ>õ		
ñ 7FÀc×6JÒ6JÑ2ÐPeˆÜØØ˜{˜mÐ,Ü1;¸CÄ×1EÒ1EÌ#ÈcË(ÐUWÌ-Ð  C¥˜z¨Ñ-Ð]yô	
ñ
 Ó €DÜØØØ
,¨T¨FÐ2]Ð^Ø
.¨t¨fÐ4]Ð^ØTØeØHØIØMö
r6   c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r/   rF   r   r›   rh   Ú_retryr'   rµ   ri   r0   r1   r2   )r3   s   "r4   r5   r5   ‘  s4   € ÷ 2ñ 2Øð2Ø$ð2Ø.<ð2ØKXð2à	ñ2r6   c                óV  € ^ RI Hp VR8w  d   R# V P                  R8X  do   V P                  R9   d^   VP                  '       gL   RVn        V P                  RR7      '       d-   V P                  R8X  d   RMR	pV P                  R
V R24       R# V P                  R8X  dT   V P                  R8X  dC   VP                  '       g1   RVn        V P                  4       '       d   V P                  R4       R# V P                  R9   da   V P                  R8X  dP   VP                  '       g>   RVn	        V P                  RR7      '       d   V P                  R4       R# \        W4       V! V 4      '       dC   VP                  '       g1   RVn        V P                  4       '       d   V P                  R4       R# V P                  R8X  de   \        V R4      '       dS   VP                  '       gA   RVn        V P!                  4       '       d   \#        V R4       R# \%        W P&                  4       R# )zìPer-provider one-shot credential refresh on 401 (codex/xai, vertex, nous, copilot,
anthropic), printing user-facing diagnostics when the nous/anthropic refresh fails.
Returns True when a refresh succeeded and the call should be retried.)Ú_is_copilot_provideré‘  FÚcodex_responsesú	xai-oauthTr„   z	xAI OAuthÚCodexõ   ðŸ”� z. auth refreshed after 401. Retrying request...Úchat_completionsÚvertexu=   ðŸ”� Vertex AI token refreshed after 401. Retrying request...r¼   Únousu<   ðŸ”� Nous agent key refreshed after 401. Retrying request...uA   ðŸ”� Copilot credentials refreshed after 401. Retrying request...Ú_anthropic_api_keyuC   ðŸ”� Anthropic credentials refreshed after 401. Retrying request...>   rõ   úopenai-codex)rø   r¼   )rÜ   rò   rÈ   rº   Úcodex_auth_retry_attemptedÚ%_try_refresh_codex_client_credentialsrd   Úvertex_auth_retry_attemptedÚ&_try_refresh_vertex_client_credentialsÚnous_auth_retry_attemptedr‡   rá   Úcopilot_auth_retry_attemptedÚ'_try_refresh_copilot_client_credentialsr“   Úanthropic_auth_retry_attemptedÚ)_try_refresh_anthropic_client_credentialsra   rî   rû   )rF   r›   rð   rµ   rò   Ú_labels   &&&&  r4   Ú_refresh_credentials_after_401r  ‘  sÅ  € õ =à�cÔÙà�‰Ð+Ô+Ø�N‰NÐ;Ô;Ø×1×1Ð1à,0ˆÔ)Ø×6Ñ6¸TÐ6×BÒBØ$)§N¡N°kÔ$A‘[ÀwˆFØ× Ñ  5¨¨Ð0^Ð!_Ô`ÙØ‡~�~Ð+Ô+°·±À(Ô0JÐSY×Su×SuÐSuØ-1ˆÔ*Ø×7Ñ7×9Ò9Ø× Ñ Ð!`ÔaÙà�‰ÐDÔDØ�N‰N˜fÔ$Ø×0×0Ð0à+/ˆÔ(Ø×5Ñ5¸DÐ5×AÒAØ× Ñ Ð!_Ô`ÙÜ# EÔ5Ù˜E×"Ò"¨6×+N×+NÐ+NØ.2ˆÔ+Ø×8Ñ8×:Ò:Ø× Ñ Ð!dÔeÙà�‰Ð.Ô.Ü�EÐ/×0Ò0Ø×5×5Ð5à04ˆÔ-Ø×:Ñ:×<Ò<Ü�EÐ`ÔaÙÜ(¨×0HÑ0HÔIÙr6   c               ó4   € V ^8„  d   QhRRRRRRRRRR	R
RRR/# )r/   rF   r   r›   rh   Ú
classifiedrð   r'   rœ   r�   rž   r0   r1   r2   )r3   s   "r4   r5   r5   Æ  sO   € ÷ Wñ WØðWØ$ðWØ25ðWØ?MðWà"ðWà25ðWð 
ñWr6   c                ó  € VP                   \        P                  8X  d·   VP                  '       g¥   RVn        ^ RIHpHp V! V 4      '       d   V! W4      pRp	MI^ pV F?  p
\        V
\        4      '       g   K  RV
9   g   K$  V
P                  RR4       V^,          pKA  	  Rp	\        V RV	 R24       \        P                  R	V P                  W˜4       R# VP                   \        P                  8X  d   \        WWE4      '       d   R# V P                   R
8X  d‹   VP"                  '       gy   \%        \'        V RR4      4      '       d]   ^ RIHp V! V\'        VRR4      4      '       d=   RVn        RV n        \        V R4       \        P                  RV P                  4       R# VP                   \        P.                  8X  d�   VP0                  '       g~   RVn         ^ RIHp V! V P6                  4      w  rÞV'       d4   \        V RV R24       \        P                  RV P                  V4       R# \        P                  RV P                  4       R#   \8         d.   p\        P                  RT P                  T4       ^ p Rp?L�Rp?ii ; i)uÜ   One-shot format-recovery strips: thinking-signature â†’ invalid-encrypted-content
replay disable â†’ native-compaction reject â†’ llama.cpp grammar strip. Returns True when
the request was repaired and should be retried.T)Úremember_rejected_thinkingÚtracks_rejected_thinkingz+suppressed rejected Anthropic replay blocksÚreasoning_detailsNzstripped reasoning_detailsu*   âš ï¸�  Thinking block signature invalid, z and retrying...za%sThinking block signature recovery: %s from %d carrier/message(s) (canonical messages unchanged)rô   Ú!codex_responses_native_compactionF)Úis_native_compaction_rejectionrµ   u‹   âš ï¸�  Provider rejected native compaction (context_management) â€” disabled for this session, local compression stays active. Retrying...ze%sNative compaction rejection recovery: disabled codex_responses_native for this session and retrying)Ústrip_pattern_and_formatz5%sllama.cpp grammar recovery: strip helper failed: %su<   âš ï¸�  llama.cpp rejected tool schema grammar â€” stripped z' pattern/format keyword(s), retrying...zU%sllama.cpp grammar recovery: stripped %d pattern/format keyword(s) from tool schemasue   %sllama.cpp grammar error but no pattern/format keywords to strip â€” falling through to normal retry)Úreasonr   Úthinking_signatureÚthinking_sig_retry_attemptedÚagent.anthropic_thinking_replayr  r  r�   r‘   ÚpoprQ   rÂ   rÃ   rN   Úinvalid_encrypted_contentr)   rÈ   Ú(native_compaction_reject_retry_attemptedr1   r`   Úagent.native_compactionr  r  Úllama_cpp_grammar_patternÚ!llama_cpp_grammar_retry_attemptedÚtools.schema_sanitizerr  Útoolsrh   )rF   r›   r	  rð   rœ   rž   r  r  ÚremovedÚdetailrk   r  r  r8   Ú	_strippedÚ
_strip_excs   &&&&&&          r4   Ú_recover_format_errorsr!  Æ  sT  € ð ×ÑœN×=Ñ=Ô=Àf×Fi×FiÐFiØ.2ˆÔ+ßhá# E×*Ò*Ù0°ÓEˆGØB‰FàˆGÛ'�Ü˜g¤t×,Ô,Ð1DÈÖ1OØ—K‘KÐ 3°TÔ:Ø˜q•L’Gñ (ð 2ˆFÜ�ÐCÀFÀ8ÐK[Ð\Ô]Ü�‰ð-à×Ñ˜fô	
ñ
 ð ×ÑœN×DÑDÔDÔIgØ�x÷Jò Jñ ð
 	�‰Ð+Ô+Ø×?×?Ð?Ü”˜Ð CÀUÓK×LÒLåJÙ)¨)´W¸YÈÐW[Ó5\×]Ò]Ø>BˆFÔ;Ø6;ˆEÔ3ÜØð>ôô
 �N‰NðGà× Ñ ôñ
 ð ×ÑœN×DÑDÔDÈV×Mu×MuÐMuØ37ˆÔ0ð	ÝGÙ3°E·K±KÓ@‰LˆA÷ Ü�EÐYÐZcÐYdð  eLð  Mô  NÜ�N‰Nð>à× Ñ  )ôñ
 ä�‰ðDà×Ñô	
ñ
 øô# ô 	Ü�N‰NÐRÐTY×TdÑTdÐfpÔqØ�Iûð	ús   ÇI ÉJÉ#JÊJÚanon_on_paid_hostz*Reconnected to the free model's own route.Únamed_on_welcome_hostz-Reconnected to your Nous account's own route.Úsession_expiredz)Renewed the connection to the free model.c               ó(   € V ^8„  d   QhRRRRRRRR/# )r/   rF   r   r	  rð   r'   r0   r1   r2   )r3   s   "r4   r5   r5   '  s)   € ÷ (ñ ( ð (°#ð (¸~ð (ÐRVñ (r6   c                ó&  € \        VRR4      ;'       g    / p\        V\        4      '       d   VP                  R4      MRp\        V\        4      '       Ed   VP                  R4      R8X  dì   VP                  '       gÚ   RVn        VP                  R4      ;'       g    .  Uu. uF'  p\        V\
        4      '       g   K  V'       g   K%  VNK)  	  pp\        \        V RR	4      ;'       g    R	4      pV'       d
   V^ ,          MRpV'       dL   W‡8w  dF    W€n        Wx3V n        \        T RT RT R24       \        P                  RT P                  Yx4       R# \        V\        4      '       d   VP                  R4      MRp	V	\        9   d[   VP                  '       gI   RVn         \        V P!                  RR7      4      p
V
'       d   \        V R\        V	,           R24       R# R
# u upi   \         d     R
# i ; i  \         d    R
p
 LMi ; i)a¨  Two one-shot repairs for the Nous free tier, both silent on the wire and named once in chat.

``model_not_free``: the session asked the welcome host for a model it does not serve; move
to the first alternate the gateway named (its own model) and retry, instead of failing the
turn. ``anon_on_paid_host`` / ``named_on_welcome_host``: this process is pointed at the other
identity's host (a stale route); re-read the credentials, which heals the URL, and retry. The
refresh reports False when the store yields the same route, so a user-set
``NOUS_INFERENCE_BASE_URL`` falls straight through to the terminal copy. ``session_expired``
(403 ``invalid jwt``): the same forced refresh re-exchanges the free credential.

Reads the CLASSIFIER's context (``classified.error_context``): that is where
``_nous_welcome_tier`` parks ``welcome_refusal`` / ``welcome_route``. The turn's other context
(``extract_api_error_context``) never carries them.Úerror_contextNÚwelcome_refusalr  Úmodel_not_freeTÚ
alternatesrÁ   rŽ   Fu   â†ªï¸�  z+ isn't available without signing in; using z for now. Retrying...z5%sNous free tier: moved %s -> %s after model_not_freeÚwelcome_router„   r÷   z Retrying request...)r`   r�   r‘   r’   Úwelcome_model_switch_attemptedrH   rÁ   Ú_nous_model_switchrh   rQ   rÂ   ÚinforN   Ú_WELCOME_ROUTE_HEAL_COPYÚwelcome_route_heal_attemptedr1   r‡   )rF   r	  rð   ÚctxÚrefusalÚar*  Ú	requestedÚtargetÚrouteÚhealeds   &&&        r4   Ú_recover_welcome_tierr8  '  sÏ  € ô �*˜o¨tÓ
4×
:Ð
:¸€CÜ,6°s¼D×,AÒ,Aˆc�g‰gÐ'Ô(Àt€GÜ�'œ4× Ó  W§[¡[°Ó%:Ð>NÔ%NÐW]×W|×W|ÐW|Ø04ˆÔ-Ø")§+¡+¨lÓ";×"AÐ"A¸rÐ"AÓ_Ñ"A˜AÄjÐQRÔTW×FX”aÔ]^—a�aÑ"Aˆ
Ð_Üœ  w°Ó3×9Ð9°rÓ:ˆ	ß",�˜A–°$ˆß�fÔ)ðØ$”Ø,5Ð+>�Ô(ô �E˜X i [Ð0[Ð\bÐ[cÐcxÐyÔzÜ�K‰KÐOÐQV×QaÑQaÐclÔuÙÜ(2°3¼×(=Ò(=ˆC�G‰G�OÔ$À4€EØÔ(Ô(°×1T×1TÐ1TØ.2ˆÔ+ð	Ü˜%×DÑDÈ4ÐDÓPÓQˆF÷ Ü�E˜UÔ#;¸EÕ#BÐ"CÐCWÐXÔYÙÙùò- `øô ô Úðûô ô 	ØŠFð	ús6   Â$G)ÃG)ÃG)ÄG. Æ'H  Ç.G=Ç<G=È HÈHc          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r/   rF   r   r›   rh   r	  rð   r'   r0   r1   r2   )r3   s   "r4   r5   r5   R  s1   € ÷ ñ  sð °yð Ècð Ð[ið Ðnrñ r6   c                ó  € VP                   \        P                  8w  g   VP                  '       d   R# ^ RIHp V! V4      pVf   R# RVn        WPn        \        V RVR R24       \        P                  RV P                  V4       R# )a  A credit-limited 402 (OpenRouter: "...requested up to 65536 tokens, but can only afford
56272") means the account has credit and the output cap was too large: retry ONCE with the
cap lowered to the affordable budget instead of abandoning the provider as billing (#49769).
Same budget parse as the auxiliary client's retry. The 402 itself says the request's cap
exceeded the budget (which may be a boosted continuation cap above ``agent.max_tokens``),
so a second credit-limited 402 on this call is genuine exhaustion.F)Ú!_affordable_max_tokens_from_errorTuL   ðŸ’³ Credit balance covers fewer output tokens â€” retrying with max_tokens=Ú,rè   z6%sCredit-limited 402: retrying once with max_tokens=%d)r  r   ÚbillingÚaffordable_402_clamp_attemptedÚagent.auxiliary_clientr;  Ú_ephemeral_max_output_tokensrQ   rÂ   r.  rN   )rF   r›   r	  rð   r;  Ú
affordables   &&&&  r4   Ú_clamp_to_affordable_budgetrB  R  s   € ð ×ÑœN×2Ñ2Ô2°f×6[×6[Ð6[ÙÝHá2°9Ó=€JØÒÙØ,0€FÔ)Ø)3Ô&ÜˆEÐaÐblÐmnÐaoÐorÐsÔtÜ
‡K�KÐHÈ%×JZÑJZÐ\fÔgÙr6   c               ó$   € V ^8„  d   QhRRRRRR/# )r/   rF   r   r›   rh   r0   r1   r2   )r3   s   "r4   r5   r5   g  s&   € ÷ Bñ B˜Sð B¨Yð B¸4ñ Br6   c                ó€   € \        V P                  4       R R4      p\        V4      '       d   \        V! V4      4      # R# )Úreject_all_turnsNF)r`   Ú_get_transportÚcallabler1   )rF   r›   Úrejects   && r4   Ú_reject_all_turnsrI  g  s9   € Ü�U×)Ñ)Ó+Ð-?ÀÓF€FÜ&.¨v×&6Ò&6Œ4‘�yÓ!Ó"ÐA¸EÐAr6   c               ó$   € V ^8„  d   QhRRRRRR/# )r/   r	  r   r'  r0   r2   )r3   s   "r4   r5   r5   l  s!   € ÷ 2ñ 2¨3ð 2¸sð 2Àsñ 2r6   c                ó´   € \        VRR4      ;'       g    / P                  R4      '       g   V# / \        V\        4      '       d   TM/ CRR/C\	        V 4      C# )zÁWhat the credential pool sees: a plan limit (usage-window 402) benches only the refused model on the
credential, until its reset; every other failure passes the error context through unchanged.r'  NÚusage_windowT)r`   r’   r�   r‘   Ú_usage_window_reset_context)rF   r	  r'  s   &&&r4   Ú_pool_error_contextrN  l  sb   € ô �J °Ó6×<Ð<¸"×AÑAÀ.×QÒQØÐð2¤
¨=¼$× ?Ò ?‰}ÀRð 2È.ÐZ^ñ 2Ü)¨%Ó0ð2ð 2r6   c               ó   € V ^8„  d   QhRR/# )r/   r0   zdict[str, float]r2   )r3   s   "r4   r5   r5   u  s   € ÷ kñ kÐ*:ñ kr6   c                ó  €  ^ RI Hp ^ RIHp \	        V RR4      pVe   V! W2! V 4      R7      MRp\        T\        \        34      '       d   T^ 8”  d   R	TR
,          /# / #   \
         d    \        P                  RRR7       / u # i ; i)zè``{"reset_at": epoch s}`` for a usage-window 402: when the refused allowance frees up, from the usage
headers the 402 carried (the API's error body has no reset). Empty when the state names none, so the
pool keeps its default bench.)Úwindow_stop_resets_at_ms)Úcurrent_model_is_top_tierÚ_credits_stateN)Úmodel_is_top_tierz+usage-window reset unavailable for the poolT)Úexc_infoÚreset_atiè  )Úagent.credits_trackerrQ  Úagent.plan_limitsrR  r`   rh   rÂ   Údebugr�   rw   Úfloat)rF   rQ  rR  ÚstateÚ	resets_mss   &    r4   rM  rM  u  s•   € ðÝBÝ?Ü˜Ð/°Ó6ˆàÒ)ñ .¨eÐG`ÐafÓGgÕhØ/3ð 	ô
 .8¸	ÄCÌÀ<×-PÒ-PÐU^ÐabÔUbˆJ˜	 DÕ(Ð)ÐjÐhjÐjøô ô Ü�‰ÐBÈTˆÔRØŠ	ðús   ‚.A  Á $BÂBc               ó<   € V ^8„  d   QhRRRRRRRRRR	R
RRRRRRR/	# )r/   rF   r   r›   rh   r	  rð   r'   rµ   ri   r'  rœ   r�   rž   r0   ztuple[bool, bool]r2   )r3   s   "r4   r5   r5   …  sc   € ÷ ^&ñ ^&Øð^&Ø$ð^&Ø25ð^&Ø?Mð^&àð^&à/2ð^&à>Rð^&ð ð^&ð ñ	^&r6   c          
     ó*  € ^ RI Hp \        WV4      '       g5   \        WW#4      '       g#   V P                  R8X  d   \        W4      '       d   R&# \        W4      '       d   \        WWg4      '       d   R&# VP                  \        P                  8X  dž   \        VRR4      ;'       g    / P                  R4      '       gr   T! \        V RR	4      ;'       g    R	\        V R
R	4      ;'       g    R	4      '       d9   VP                  '       g'   RVn        \        V 4      '       d   \        V R4       R&# V P!                  WCP"                  VP                  \%        WV4      VP&                  R7      w  q“n        V	'       d   RV	3# VP                  \        P(                  8X  dk   VP*                  '       gY   RVn        T P-                  T\/        V4      ;'       g    RR7      '       d   \        V R4       RV	3# \0        P3                  R4       VP                  \        P4                  8X  dV   VP6                  '       gD   RVn        V P9                  V4      '       d   \        V R4       RV	3# \0        P3                  R4       VP                  \        P:                  8X  Ed¬   VP<                  '       Eg™   RVn        \        V RR4      p
\?        V
\@        4      '       d†   V
P                  R4      RJdq   V
P                  R4      R'9  d[   RV n!        \        V RV PD                   RV
R,           R24       \0        PG                  RV PH                  V PD                  4       RV	3# RV n%        ^ RI&H'p V! \Q        V4      4      V n)         ^ RI*H+p V! V PX                  4       V PR                  '       dS   ^ RI.H/p \        V RV PD                   RV R24       \0        PG                  RV PH                  WÐPD                  4       RV	3# \        V RV PD                   R 24       \0        PG                  R!V PH                  V PD                  4       RV	3# VP                  \        P`                  8X  d+   \c        W4      '       d   RV	3# \0        P3                  R"4       VP                  \        Pd                  8X  d’   V P                  R#8X  d�   V Pf                  '       do   VPh                  '       g]   RVn4        \        V R$R4      '       gC   RV n5         V Pl                  Po                  4        V Pq                  4        \        V R%4       RV	3# \s        WW44      '       d   RV	3# \u        WW#Wg4      '       d   RV	3# RV	3#   \Z         d     ELåi ; i  \Z         d     Lpi ; i)(u~  One-shot recovery chain that runs AFTER ``classify_api_error`` and before the
generic retry path. Order is load-bearing (each branch may ``return`` early):
welcome-tier repair â†’ credit-limited 402 output-cap clamp â†’ ``reasoning.context`` opt-out â†’ Nous paid-entitlement refresh â†’
Codex stale-reasoning strip on 401 ``token_expired`` â†’ credential-pool rotation â†’ image shrink â†’ multimodal-tool-content strip â†’ corrupt-image
strip â†’ Anthropic OAuth 1M-beta disable â†’ per-provider 401 credential refresh â†’
format-recovery strips.
Returns ``(retry_now, recovered_with_pool)``; the latter feeds the Nous rate-limit guard.)Ú_is_nous_inference_routerô   TFr'  NrL  rº   rŽ   Úbase_urluX   ðŸ”� Nous paid access verified â€” refreshed runtime credentials and retrying request...)rµ   Úhas_retried_429Úclassified_reasonr'  Úbilling_unverifiedrn   )r~   uE   ðŸ“� Image(s) exceeded provider size limit â€” shrank and retrying...zlimage-shrink recovery: no data-URL image parts found or shrink didn't reduce size; surfacing original error.u`   ðŸ“� Provider rejected list-type tool content â€” downgraded screenshots to text and retrying...znmultimodal-tool-content recovery: no list-type tool messages with image parts found; surfacing original error.Ú_wire_reasoning_configÚenabledÚeffortr¸   z rejects reasoning effort u<    â€” using the route's default for this session, retrying...z=%sReasoning-effort recovery: dropping reasoning config for %s)Úis_reasoning_required_rejection)Úrefresh_reasoning_caps_async)ÚREASONING_FLOOR_EFFORTu+    cannot disable reasoning â€” using effort=z for this session, retrying...z@%sReasoning-disable recovery: stepping reasoning up to %s for %suX    rejects disabling reasoning â€” using the route's default for this session, retrying...z?%sReasoning-disable recovery: dropping reasoning disable for %szPimage-corrupt recovery: no image parts found to strip; surfacing original error.r¼   Ú_oauth_1m_beta_disabledui   ðŸ”• OAuth subscription doesn't support the 1M-context beta â€” disabled for this session and retrying...)TF)NÚnone);rÜ   r_  r8  rB  rÈ   rI  r(   r)   r  r   r=  r`   r’   Ú'nous_paid_entitlement_refresh_attemptedrˆ   rQ   Ú_recover_with_credential_poolra  rN  rc  Úimage_too_largeÚimage_shrink_retry_attemptedÚ#_try_shrink_image_parts_in_messagesr   rÂ   r.  Ú#multimodal_tool_content_unsupportedÚ'multimodal_tool_content_retry_attemptedÚ)_try_strip_image_parts_from_tool_messagesÚreasoning_mandatoryÚ#reasoning_mandatory_retry_attemptedr�   r‘   Ú_reasoning_effort_rejectedrÁ   rÃ   rN   Ú_reasoning_disable_rejectedÚagent.error_classifierrg  rH   Ú_reasoning_floor_requiredÚ hermes_cli.models_reasoning_capsrh  rº   rh   Úagent.auxiliary_reasoning_floorri  Úimage_corruptr²   Ú!oauth_long_context_beta_forbiddenÚ_is_anthropic_oauthÚoauth_1m_beta_retry_attemptedrj  Ú_anthropic_clientÚcloseÚ_rebuild_anthropic_clientr  r!  )rF   r›   r	  rð   rµ   r'  rœ   rž   r_  Úrecovered_with_poolÚsentrg  rh  ri  s   &&&&$$$$      r4   Úrecover_after_classificationr…  …  s<  € õ Aô
 ˜U°×7Ò7Ô;VØ˜*÷<ò <à
�.‰.Ð-Ô
-Ô2CÀE×2UÒ2UØÐô ˜u×0Ò0Ô5SØ�x÷6ò 6ð Ðð 	×Ñœ^×3Ñ3Ô3ä˜ _°dÓ;×AÐA¸r×FÑFÀ~×VÒVÙ$Ü�E˜: rÓ*×0Ð0¨b´'¸%ÀÈRÓ2P×2VÐ2VÐTV÷
ò 
ð ×>×>Ð>à9=ˆÔ6Ü9¸%×@Ò@Ü�EÐuÔvØÐà27×2UÑ2UØ×1GÑ1GØ$×+Ñ+Ô;NÈuÐboÓ;pØ%×8Ñ8ð 3Vó 3Ñ/ÐÔ/÷
 ØÐ(Ð(Ð(ð ×ÑœN×:Ñ:Ô:À6×Cf×CfÐCfØ.2ˆÔ+Ø×4Ñ4ØÔ(BÀ9Ó(M×(UÐ(UÐQUð 5÷ 
ò 
ô �EÐbÔcØÐ,Ð,Ð,Ü�‰ðFô	
ð 	×Ñœ^×OÑOÔOØ×>×>Ð>à9=ˆÔ6Ø×:Ñ:¸<×HÒHÜ�EÐ}Ô~ØÐ,Ð,Ð,Ü�‰ðIô	
ð 	×Ñœ^×?Ñ?Õ?Ø×:×:Ñ:à59ˆÔ2Ü�uÐ6¸Ó=ˆÜ�dœD×!Ò! d§h¡h¨yÓ&9ÀÓ&FÈ4Ï8É8ÐT\ÓK]ÐesÔKsð 04ˆEÔ,Ü�E˜X e§k¡k ]Ð2LÈTÐRZÍ^ÐL\ð  ]Yð  Zô  [Ü�N‰NÐZÐ\a×\lÑ\lÐns×nyÑnyÔzØÐ,Ð,Ð,Ø,0ˆÔ)õ
 	KÙ*IÌ#ÈiË.Ó*YˆÔ'ð	ÝUÙ(¨¯©Ô8ð ×*×*Ð*ÝNÜ�E˜X e§k¡k ]Ð2]Ð^tÐ]uð  vTð  Uô  VÜ�N‰NÐ]Ø ×+Ñ+Ð-CÇ[Á[ôRð
 Ð(Ð(Ð(ô �E˜X e§k¡k ]ð  3Kð  Lô  MÜ�N‰NÐ\Ð^c×^nÑ^nÐpu×p{Ñp{Ô|ØÐ(Ð(Ð(ð
 ×ÑœN×8Ñ8Ô8Ü*¨5×?Ò?ØÐ,Ð,Ð,Ü�‰ÐfÔgð 	×Ñœ^×MÑMÔMØ�N‰NÐ2Ô2Ø×%×%Ð%Ø×4×4Ð4à/3ˆÔ,Ü�uÐ7¸×?Ò?Ø,0ˆEÔ)ðØ×'Ñ'×-Ñ-Ô/ð ×+Ñ+Ô-Ü�Eð  Gô  HØÐ,Ð,Ð,ä% e¸×LÒLØÐ(Ð(Ð(ä˜e°
ÀH×[Ò[ØÐ(Ð(Ð(ØÐ%Ð%Ð%øô] ô 	Úð	ûôF ô Ùðús$   ÎU2 ÔV Õ2VÖ VÖVÖVc          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r/   Úfinal_responserH   rœ   r   Úapi_call_countrw   rg   r0   údict[str, Any]r2   )r3   s   "r4   r5   r5   &  s1   € ÷ ñ ¨ð °sð ÈCð ÐX[ð Ð`nñ r6   c                ó   € RV RVRVRRRRRV/# )	z>Base failed-turn result dict shared by the two terminal paths.r‡  rœ   Ú	api_callsÚ	completedFÚfailedTrg   r2   )r‡  rœ   rˆ  rg   s   &&&&r4   Ú_failed_turn_resultrŽ  &  s(   € ð 	˜.¨*°hÀÈ^Ø�U˜H d¨G°Uðð r6   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r/   rF   r   rœ   Úcurrent_turn_user_idxr0   rH   r2   )r3   s   "r4   r5   r5   .  s)   € ÷ ñ  Cð °3ð Èsð ÐWZñ r6   c                óæ   € ^ RI Hp V! WVRR7      p\        V RR4      p\        V\        4      '       d=   VP                  4       '       d'   ^ RIHp V! W4      P                  4       ;'       g    T# V# )a©  Visible text already delivered this turn ("" when none), collapsing any continuation
trail first so the terminal persist never keeps a dangling synthetic nudge (#119001).

``build_api_request`` resets ``_current_streamed_assistant_text`` per attempt, so after a
mid-stream death + continuation + pre-stream error the live accumulator is empty and the
fragment rows (now collapsed into one assistant row) are the only record.
)Úcollapse_continuation_trailrg   )Úfinish_reasonÚ _current_streamed_assistant_textrŽ   )Ústrip_think_blocks)Úagent.turn_truncationr’  r`   r�   rH   r?   Úagent.agent_runtime_helpersr•  )rF   rœ   r�  r’  Ú	collapsedÚliver•  s   &&&    r4   Úsettle_delivered_partialrš  .  sg   € õ BÙ+ØÐ.¸gô€Iô �5Ð<¸bÓA€DÜ�$œ×Ò §¡§¢ÝBÙ! %Ó.×4Ñ4Ó6×CÐC¸)ÐCØÐr6   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r/   r‡  rH   Úerror_summaryÚ	deliveredr0   Útupler2   )r3   s   "r4   r5   r5   A  s*   € ÷ 5ñ 5¨Cð 5Àð 5ÐPSð 5ÐX]ñ 5r6   c                óœ   € T;'       g    RP                  4       pV'       d   Y1;'       g    RP                  4       8X  d   V R3# V RV  2R3# )uq  Prepend delivered partial text to a terminal error body ("" unchanged).

Returns ``(final_response, keep_partial)``; callers set ``result["partial"]``
when ``keep_partial`` so the gateway emits ``payload.partial`` and surfaces
retain the bubble instead of clearing it. ``final_response`` must stay
distinct from ``error`` â€” that inequality is the retention contract.
rŽ   Fú

T)r?   )r‡  rœ  r�  Ú
_delivereds   &&& r4   Ú_with_delivered_partialr¢  A  sS   € ð —/�/˜r×(Ñ(Ó*€Jß˜×(;Ð(;¸×'BÑ'BÓ'DÔDØ˜uÐ$Ð$Øˆ\˜˜nÐ-Ð.°Ð4Ð4r6   c               ó$   € V ^8„  d   QhRRRRRR/# )r/   rF   r   r›   rh   r0   zOptional[float]r2   )r3   s   "r4   r5   r5   O  s!   € ÷ ñ ˜Sð ¨Yð ¸?ñ r6   c                ó€   € ^ RI Hp  V! V P                  V4      P                  R4      4      #   \         d     R# i ; i)uµ   Epoch seconds when the provider says its limit lifts (Retry-After header, ``resets_at`` /
``retry_after`` body fields, "try again in N" text) â€” the same datum the backoff honours.©Ú_parse_absolute_timestamprV  N)Úagent.credential_poolr¦  Ú_extract_api_error_contextr’   rh   )rF   r›   r¦  s   && r4   Úlimit_reset_epochr©  O  sA   € õ @ðÙ(¨×)IÑ)IÈ)Ó)T×)XÑ)XÐYcÓ)dÓeÐeøÜô Úðús   ˆ%. ®=¼=c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r/   Úresultr‰  rF   r   r›   rh   r	  r0   rI   r2   )r3   s   "r4   r5   r5   ^  s8   € ÷ 
Kñ 
K˜~ð 
K°cð 
KÀið 
KÐ]`ð 
KÐeiñ 
Kr6   c                óª   € VP                   \        9  d   R# \        W4      pVf   R# W@R&   \        V4      ;p'       d   V R,           RV 2V R&   R# R# )z¼``failure_resets_at`` for structured clients (Desktop card: "Limit resets at HH:mm") and the
same sentence appended to the chat text every plain surface (CLI/TUI/gateway) renders (#98852).NÚfailure_resets_atr‡  r   )r  Ú_LIMIT_REASONSr©  r"   )r«  rF   r›   r	  Ú	resets_atrP   s   &&&&  r4   Ú_stamp_limit_resetr°  ^  sc   € ð ×Ñ¤Ô.ÙÜ! %Ó3€IØÒÙØ"+ÐÑÜ 	Ó*Ð*€tÖ*Ø&,Ð-=Õ&>Ð%?¸tÀDÀ6Ð#JˆÐÓ ñ +r6   c               ó4   € V ^8„  d   QhRRRRRRRRRRRRR	R
/# )r/   rF   r   r	  rµ   ri   rº   r`  rÁ   r0   rI   r2   )r3   s   "r4   r5   r5   k  sM   € ÷ >Zñ >ZØð>ZØð>ZØ1>ð>ZØJMð>ZØY\ð>ZØehð>Zà	ñ>Zr6   c          	     óz  € \        VRR4      ;'       g    / P                  R4      '       d   R# ^ RIHpHp VP
                  \        P                  8X  d)   V! V RV\        V4      WQP                  R7      '       d   R# VR8X  d   V! V R4      '       d   R# VR'9   d™   VR8X  d’   VR	8X  d!   ^ RI
Hp \        V RRRV! V4       R24       R# VR
8X  d   \        V RR4       R# \        V RRRR4       \        V\        4      '       d.   VP                  R4      '       d   \        V RV R2RRV R24       R# ^ RIHp	 VR8X  d?   T	! \        T;'       g    R4      4      e"   ^ RI
Hp \        V RV R V! V4       R24       R# \        V R!R"R#V R$24       \#        \        V4      R%4      '       d   \        V R&4       R# R# )(z8Actionable guidance for a terminal auth / billing error.r'  NrL  )Ú&_print_billing_or_entitlement_guidancerÕ   úmodel access©Ú
capabilityrº   r`  rÁ   Ú
unverifiedrú   rÚ   rü   rõ   ró   )Úoauth_relogin_commanduK      ðŸ’¡ Codex OAuth token was rejected (HTTP 401). Your token may have beenzQ      refreshed by another client (Codex CLI, VS Code) or another Hermes profile.z#      Sign this profile in again: `Ú`u8      ðŸ’¡ xAI OAuth token was rejected (HTTP 401). To fix:zU      re-authenticate with xAI Grok OAuth (SuperGrok / Premium+) from `hermes model`.uJ      ðŸ’¡ Nous Portal OAuth token was rejected (HTTP 401). Your token may bezF      expired, revoked, or your account may be out of credits. To fix:z'      1. Re-authenticate: hermes portalzC      2. Check your portal account: https://portal.nousresearch.comz:freeu         âš ï¸�  Note: `z1` looks like an OpenRouter slug (`:free` suffix).zH         Nous Portal won't recognize that model name. Either switch to az7         Nous catalog model, or run `/model openrouter:z` to use OpenRouter.)Úplugin_refresh_hookrŽ   õ      ðŸ’¡ z2 sign-in was rejected (HTTP 401). Sign in again: `u9      ðŸ’¡ Your API key was rejected by the provider. Check:u-         â€¢ Is the key valid? Run: hermes setupu+         â€¢ Does your account have access to Ú?zopenrouter.aiu?         â€¢ Check credits: https://openrouter.ai/settings/credits>   rú   rõ   rü   )r`   r’   rÜ   r³  rÕ   r  r   r=  rH   rc  Úagent.turn_failure_copyr¸  rQ   r�   ÚendswithÚ hermes_cli.auth_plugin_providersrº  r,   )
rF   r	  rµ   rº   r`  rÁ   r³  rÕ   r¸  rº  s
   &&$$$$    r4   Ú!_print_nonretryable_auth_guidancerÀ  k  sÙ  € ô 	�
˜O¨TÓ2×8Ð8°b×=Ñ=¸n×MÒMÙßpà×ÑœN×2Ñ2Ô2Ñ7]Ø˜.°8ÄcÈ(ÃmØ× =Ñ =÷8ó 8ñ 	Ø�6ÔÑ>¸uÐFY×ZÒZÙØÐ8Ô8¸[ÈCÔ=OØ�~Ô%ÝEäØØ]ØcØ5Ñ6KÈHÓ6UÐ5VÐVWÐXô	ñ: 	ð/ ˜Ô$ÜØØJØgôñ, 	ô! ØØ\ØXØ9ØUôô ˜%¤×%Ò%¨%¯.©.¸×*AÒ*AÜØØ+¨E¨7Ð2cÐdØ^ØMÈeÈWÐThÐiô	ñ 	ÝDØ�cÔÑ1´#°h·n°nÀ"Ó2EÓFÒRåAÜ�˜ ( Ð+]Ñ^sÐt|Ó^}Ð]~Ð~ð  Aô  	BÙÜØØCØ7Ø
5°e°W¸AÐ>ô	ô œS ›]¨O×<Ò<Ü�ÐXÖYñ =r6   ÚdoorTc          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r/   r	  r   rÁ   Úin_chatr1   rÁ  r0   rH   r2   )r3   s   "r4   r5   r5   ¬  s8   € ÷ 
Nñ 
N sð 
N°cð 
NÀDð 
NÐPTð 
NÐ`cñ 
Nr6   c               ó  € \        V RR4      ;'       g    / pVP                  R4      VP                  R4      reV'       g   V'       g   R# ^ RIHpHp V'       d   T! T\        T;'       g    R4      W#R7      # V! \        V4      W#R7      # )	z”Copy for a Nous free-tier refusal the classifier parsed (``welcome_refusal`` /
``welcome_route`` in ``error_context``); empty for every other error.r'  Nr(  r+  rŽ   )Úwelcome_refusal_copyÚwelcome_route_refusal_copy©rÁ   rÃ  rÁ  )rÃ  rÁ  )r`   r’   rÞ   rÅ  rÆ  rH   )	r	  rÁ   rÃ  rÁ  r1  r2  r6  rÅ  rÆ  s	   &$$$     r4   Ú_welcome_tier_guidancerÈ  ¬  sm   € ô �*˜o¨tÓ
4×
:Ð
:¸€CØ—W‘WÐ.Ó/°·±¸Ó1IˆUßŸ5ÙßUßÙ# G´3°u·{°{ÀÓ3CÈWÔ`Ð`Ù%¤c¨%£j¸'ÔMÐMr6   Úrate_limitedÚat_capacityÚadmission_closedr)  Úfeature_not_freec               ó    € V ^8„  d   QhRRRR/# )r/   r	  r   r0   rH   r2   )r3   s   "r4   r5   r5   Á  s   € ÷ $ñ $ cð $¨cñ $r6   c                ó¾  € \        V RR4      ;'       g    / p\        V\        4      '       d   VP                  R4      MRp\        V\        4      '       d9   \        P                  \        VP                  R4      ;'       g    R4      R4      # \        V\        4      '       d   VP                  R4      MRpVR8X  d   R	# VR
8X  d   R# VR8X  d   R# V'       d   R# R# )zªThe free-tier failure kind a client renders its card from (``error_surface`` code
``free_tier_<kind>``): the welcome refusal's reason, or the route refusal; "" otherwise.r'  Nr(  r  rŽ   Úrefusedr+  Útier_disabledÚdisabledr$  Úoutager#  r6  )r`   r�   r‘   r’   Ú_WELCOME_SURFACE_KINDSrH   )r	  r1  r2  r6  s   &   r4   Ú_welcome_surface_kindrÔ  Á  s¹   € ô �*˜o¨tÓ
4×
:Ð
:¸€CÜ,6°s¼D×,AÒ,Aˆc�g‰gÐ'Ô(Àt€GÜ�'œ4× Ò Ü%×)Ñ)¬#¨g¯k©k¸(Ó.C×.IÐ.IÀrÓ*JÈIÓVÐVÜ(2°3¼×(=Ò(=ˆC�G‰G�OÔ$À4€EØ�ÔÙàÐ!Ô!ÙàÐ'Ô'Ùßˆ7Ð# Ð#r6   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r/   r«  r‰  ÚkindrH   rk   r0   r2   )r3   s   "r4   r5   r5   Ô  s(   € ÷ ñ ˜^ð °3ð Àð Èñ r6   c                ó,   € RT;'       g    RRV/V R&   V # )z´Structured free-tier failure block: ``error_surface`` keys its code on ``kind`` and a client
shows ``message`` (the chat sentence) as the card body instead of its own generic copy.rÖ  rÏ  rk   Ú	free_tierr2   )r«  rÖ  rk   s   &&&r4   Ú_stamp_free_tierrÙ  Ô  s$   € ð " 4×#4Ð#4¨9°iÀÐI€Fˆ;ÑØ€Mr6   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r/   rF   r   r`  r	  r0   rH   r2   )r3   s   "r4   r5   r5   Û  s(   € ÷ 
ñ 
 ð 
¨sð 
Àð 
Èñ 
r6   c                ó²   € ^ RI HpHp V! W4      '       dA   VP                  \        P
                  \        P                  \        P                  39   d   V# R# )a  On the Nous free tier, a transport / server failure that outlived every retry reads as one
plain sentence (the free model is having trouble) rather than the technical summary. Empty
for every other route and for rate limits / billing, which have their own copy.)ÚFREE_TIER_OUTAGE_COPYÚon_free_modelrŽ   )rÞ   rÜ  rÝ  r  r   ÚtimeoutÚ
overloadedÚserver_error)rF   r`  r	  rÜ  rÝ  s   &&&  r4   Ú_welcome_outage_copyrá  Û  sL   € ÷ Jñ �U×%Ò%¨*×*;Ñ*;Ü×"Ñ"¤N×$=Ñ$=¼~×?ZÑ?Zð@\ô +\à$Ð$Ùr6   z1The provider's safety filter refused this requestz<A firewall/CDN in front of the provider blocked this requestz9The provider's security certificate could not be verifiedzGRequest still exceeded the provider's size limit after shrinking imagesc               ó(   € V ^8„  d   QhRRRRRRRR/# )r/   r›   rh   rº   r   rÁ   r0   zOptional[str]r2   )r3   s   "r4   r5   r5   ò  s*   € ÷ 	ñ 	°ð 	Àcð 	ÐRUð 	ÐZgñ 	r6   c                óº   € \        V RR4      R8w  d   R#  ^ RIHp T! \        T;'       g    R4      \        T;'       g    R4      4      #   \         d     R# i ; i)zYPrefixed catalogue id when a bare 404 most likely means ``vendor/model`` lost its prefix.rµ   Ni”  )Úsuggest_prefixed_model_idrŽ   )r`   Úhermes_cli.model_normalizerä  rH   rh   )r›   rº   rÁ   rä  s   &&& r4   Ú!_missing_vendor_prefix_suggestionræ  ò  sS   € äˆy˜-¨Ó.°#Ô5ÙðÝHá(¬¨X¯^¨^¸Ó)<¼cÀ%Ç+À+È2Ó>NÓOÐOøÜô Úðús   –A ¬A Á 
A ÁAÁAr�  rŽ   c               óT   € V ^8„  d   QhRRRRRRRRRRR	RR
RRRRRRRRRRRRRRRRR/# )r/   rF   r   r›   rh   r	  rµ   ri   rŸ   rž   rœ   r�   Úconversation_historyrˆ  rw   Úapprox_tokensrº   r`  rÁ   r�  rH   r0   r‰  r2   )r3   s   "r4   r5   r5   þ  s§   € ÷ Añ AØðAØ$ðAØ25ðAØGTðAàðAà#&ðAà2FðAà^aðAð ðAð ),ðAð 8;ðAð GJðAð SVðAð ð	Að
 ñAr6   c               óš  € ^ RI HpHpHp Ve   V P	                  VRVR7       V P                  4        V P                  V4      p\        V
4      p\        P                  VP                  V R24      pV P                  RV RV 24       \        V RR4      '       d   \        V R	V
 R
V RV R2RV 24       \        W,RR7      p\        WV4      pV'       d   \        V RV 24       M¸VP                   '       g    VP                  \"        P$                  8X  d   \'        WW:W¼R7       MxVP                  \"        P(                  8X  d-   \        V RV RV R24       V'       d   \        V RV R24       M-VP                  \        9  d   \        V R\+        4        R24       VP                  \"        P,                  8X  d   \        V RRRR4       VP                  \"        P.                  8X  d   \        V R\0         2R4       VP                  \"        P2                  8X  d   \        V RRRR R!R"R#R$4	       \4        P7                  R%V P8                  V4       VR&8X  d%   V	R'8”  g   \;        V4      ^P8”  d   \        V R(4       MV P=                  Wg4       VP                  \"        P.                  8X  d   V! WhR)\?        VVR*7      ,           VR+7      # VP                  \"        P$                  8X  d   V! VVVWŠW¼V! WV4      R,7      # V'       d   \        W,R-R7      pM\A        W*VVVR.7      p\C        VVV4      w  pp\E        VWhV4      pVPG                  R/VP                  PH                  R0\K        VPL                  4      /4       V'       d   R-VR1&   \O        VWV4       V'       d-   \Q        V4      ;p'       d   \S        VV\        W,R-RR27      4       V# )3a  Terminal path for a non-retryable 4xx once fallback is exhausted: debug dump, flush
the retry trace, print auth / billing / content-policy / TLS guidance, persist (skipped
for likely context-overflow 400s so the failure does not grow the session), build result.)Ú_billing_failure_resultÚ_content_policy_blocked_resultÚ_usage_window_refusalÚnon_retryable_client_error©r  rg   z- rejected the request and retrying won't helpu   â�Œ ú: Úverbose_loggingFu      ðŸ”Œ Provider: ú	  Model: z  (HTTP Ú)õ      ðŸŒ� Endpoint: ©rÁ   rÃ  r»  )rµ   rº   r`  rÁ   õ      ðŸ’¡ Model 'z' isn't available on z. Pick another with /model.ú      Did you mean 'z.'? It looks like the vendor prefix is missing.u4      ðŸ’¡ Fix: pick another model (/model), or check `z/logs/agent.log`.u`      ðŸ’¡ The endpoint's firewall/CDN blocked the request before it reached the model â€” your keyz[      and model access are probably fine. Relays often reject the SDK's default User-Agent:zW      set `extra_headers: {User-Agent: HermesAgent/1.0}` on the custom_providers entry,z4      or check the proxy/WAF rules and your network.zS      To route future blocks to another provider automatically: hermes fallback adduW      ðŸ’¡ Hermes couldn't verify the provider's security certificate. This fails the sameuA         way on every retry â€” fix the environment, then try again:uK         â€¢ Corporate TLS-inspecting proxy? Ask your administrator to installzA        its root certificate in the operating system trust store.uJ         â€¢ Missing/stale system CA store? Refresh the OS certificate store.zG        A provider-specific CA can also be configured with ssl_ca_cert.uN         â€¢ Self-signed local endpoint (llama.cpp, LM Studio, vLLM)? Use http://zD        for localhost, or add the server's cert to your trust store.z %sNon-retryable client error: %sr¶   iPÃ  uU   âš ï¸�  Skipping session persistence for large failed session to prevent growth loop.u   âš ï¸� )ÚlabelÚsummary)r‡  Úerror_detail)r	  rù  rœ   rˆ  rº   r`  rÁ   rL  T)rº   rÁ   rù  Úprefix_suggestionÚfailure_reasonÚfailure_retryableÚpartialrÇ  )*rÜ   rë  rì  rí  Ú_dump_api_request_debugÚ_flush_status_bufferÚ_summarize_api_errorr$   Ú_NONRETRYABLE_LABELSr’   r  Ú_emit_diagnostic_statusr`   rQ   rÈ  ræ  Úis_authr   r=  rÀ  Úmodel_not_foundr+   Úupstream_blockedÚcontent_policy_blockedr   Ússl_cert_verificationrÂ   rg   rN   rë   Ú_persist_sessionr    r#   r¢  rŽ  Úupdater{   r1   Ú	retryabler°  rÔ  rÙ  )rF   r›   r	  rµ   rŸ   rž   rœ   rè  rˆ  ré  rº   r`  rÁ   r�  rë  rì  rí  Ú_nonretryable_summaryÚ_plabelr  Ú_welcome_hintÚ_prefix_suggestionÚ_final_responseÚ_keep_partialr«  Ú_kinds   &&&$$$$$$$$$$$            r4   Ú nonretryable_client_error_resultr  þ  sÐ  € ÷ñ ð ÒØ×%Ñ% jÐ9UÐ]fÐ%Ôgà	×ÑÔ ð "×6Ñ6°yÓAÐÜ  Ó*€GÜ!×%Ñ% j×&7Ñ&7¸G¸9ÐDqÐ9rÓs€FØ	×!Ñ! D¨¨°Ð3HÐ2IÐ"JÔKäˆuÐ'¨×/Ò/ÜØØ   
¨)°E°7¸(À;À-ÈqÐQØ   
Ð+ô	
ô
 +¨:ÈEÔR€MÜ:¸9ÐPUÓVÐßô 	�˜ - Ð1Õ2Ø	×	×	Ð	˜z×0Ñ0´N×4JÑ4JÔJÜ)Ø¨;ÐT\ö	
ð 
×	Ñ	œn×<Ñ<Ô	<Ü�˜¨¨Ð/DÀWÀIÐMhÐiÔjßÜ�EÐ1Ð2DÐ1EÐEsÐtÔuøØ	×	Ñ	Ô"6Ô	6Ü�ÐMÔNaÓNcÐMdÐduÐvÔwð ×ÑœN×;Ñ;Ô;ÜØØnØiØeØBô	
ð ×ÑœN×AÑAÔAÜØØÔ0Ð1Ð2Øaô	
ð ×ÑœN×@Ñ@Ô@ÜØØeØOØYØOØXØUØ\ØRô
	
ô ‡L�LÐ3°U×5EÑ5EÀyÔQð
 �cÔ˜}¨uÔ4¼¸LÓ8IÈBÔ8NÜ�ÐnÕoà×Ñ˜xÔ>Ø×ÑœN×AÑAÔAÙ-ØØ$Ô':ÀÐRgÔ'hÕhØ.ô
ð 	
ð ×ÑœN×2Ñ2Ô2Ù&Ø!Ð+@È8Ø)ÀxÙ.¨uÀ,ÓOô
ð 	
÷
 ô 1°ÐRVÔW‰ô ,Ø°Ð@UØ0ô
ˆô &=ØÐ.°	ó&Ñ"€O�]ô ! °(ÐLaÓb€FØ
‡M�MØ˜*×+Ñ+×1Ñ1ØœT *×"6Ñ"6Ó7ðô ÷ Ø ˆˆyÑÜ�v˜u°Ô<ßÔ#8¸Ó#DÐD˜%ÖDä˜ Ü/°
ÐQUÐ\aÔbô	dà€Mr6   c          "     ó\   € V ^8„  d   QhRRRRRRRRRR	R
RRRRRRRRRRRRRRRRRRRRRRR/# )r/   rF   r   r›   rh   r	  Úattemptsrw   Úis_rate_limitedr1   Ú	error_msgrH   rŸ   rž   rœ   r�   rè  rˆ  ré  rº   r`  rÁ   r�  r0   r‰  r2   )r3   s   "r4   r5   r5   ˆ  s»   € ÷ Lñ LØðLØ$ðLØ25ðLØDGðLØZ^ðLàðLà #ðLà36ðLàBVðLð ðLð 03ðLð DGðLð SVðLð ð	Lð ð	Lð +.ð	Lð
 ñLr6   c               óš  a€ ^ RI HpHpHpHp V P                  4        V P                  V4      pRpVP                  \        P                  8H  pV'       dœ   VP                  '       d   V P                  RV 24       MV P                  RV 24       \        RV\        V4      VVP                  R7      pVP                  ;'       g    / P                  R4      '       g   V! R-/ VB pV! V 3/ VB  M^V'       d@   \!        V4      pT P                  RT R	V^8X  d   R
MR RT V'       d   RV R2MR 24       MV P                  RV RV 24       \#        V RV 24       \%        W.RR7      pV'       d   \#        V RV 24       \'        VRR4      '       * ;'       dC    \(        ;QJ d#    V3R l\*         4       F  '       g   K   RM	  RM! V3R l\*         4       4      pV'       d   \#        V RR4       \-        W.S4      pV'       d(   \#        V R\/        WÎR7      P1                  4        24       \2        P5                  RV P6                  VVWÎ\9        V4      VR 4       Ve   V P;                  VRVR7       V P=                  W‰4       RpRpRpV'       d7   VP                  pV! VV4      pV'       d   VR V 2,          pV! WÍVVVR!7      pM¥VP                  P                  R"4      p \?        VP                  P@                  \C        V4      TTV '       d   V \D        PD                  ! 4       ,
          MRR#7      pV'       d   \%        W.RR7      p\G        V4      pM\I        WV4      ;p!'       d   T!R$ppV'       d   VR \/        WÎR7      ,           ,          pMV'       d
   VR%,          p\K        VWŠV4      p"V"PM                  R&VP                  P@                  R'\O        VPP                  4      R(VR)V/4       \S        VVV4      w  pp#V#'       d   VV"R*&   RV"R+&   \U        V"WV4       V'       d$   \W        T"TV'       d   \%        W.RRR,7      MT4       V"# ).a)  Terminal path once retries, transport recovery and fallback all failed: flush the
trace, emit the billing / rate-limit / generic status, print stream-drop or thinking-timeout
guidance (the latter wins), persist, build the result with ``failure_reason`` /
``failure_retryable`` / ``billing_block``.)Ú_billing_block_dictÚ_billing_or_entitlement_messageÚ_billing_terminal_labelr³  rŽ   ue   â�Œ Provider reported usage/credit exhaustion (unverified â€” may be a content-filter rejection) â€” u%   â�Œ Billing or credits exhausted â€” r´  rµ  rL  u   â�Œ Rate limited after rm   ÚattemptÚretriesu    â€” z (resets in ró  u   â�Œ API failed after u    retries â€” u      ðŸ’€ Final error: Frõ  r»  rµ   Nc              3  ó,   <"  € T F	  qS9   x € K  	  R # 5irV   r2   )Ú.0Úpr  s   & €r4   Ú	<genexpr>Ú/max_retries_exhausted_result.<locals>.<genexpr>¾  s   øé € Ð=Ñ(< 1�Y–Ó(<ùs   ƒTu’      ðŸ’¡ The provider's stream connection keeps dropping. This often happens when the model tries to write a very large file in a single tool call.z~      Try asking the model to use execute_code with Python's open() for large files, or to write the file in smaller sections.©rº   rÁ   zP%sAPI call failed after %s retries. %s | provider=%s model=%s msgs=%s tokens=~%sr<  Úmax_retries_exhaustedrï  r   )r·  rV  )rø  r  rù  Úreset_secondsrÒ  uÖ   

The connection kept dropping while the model was writing â€” this often happens when it writes a very large file in one go. Ask me to write the file in smaller sections (or via execute_code with Python's open()).rü  rý  rc  Úbilling_blockr‡  rþ  rÇ  r2   ),rÜ   r  r  r  r³  r   r  r  r   r=  rc  r  r‘   rH   r'  r’   Ú
reset_hintrQ   rÈ  r`   ÚanyÚ_STREAM_DROP_MARKERSr   r   r?   rÂ   rg   rN   rë   rÿ  r	  r!   r{   r$   ÚtimerÔ  rá  rŽ  r
  r1   r  r¢  r°  rÙ  )$rF   r›   r	  r  r  r  rŸ   rž   rœ   rè  rˆ  ré  rº   r`  rÁ   r�  r  r  r  r³  Ú_final_summaryÚ_billing_guidanceÚ_is_billingÚ_billing_kwÚ_resetr  Ú_is_stream_dropÚ_is_thinking_timeoutÚ_billing_blockÚ_billing_unverifiedÚ_free_tier_kindr  Ú	_reset_atÚ_outager«  r  s$   &&&$$d$$$$$$$$$$                    r4   Úmax_retries_exhausted_resultr7  ˆ  s@  ø€ ÷ó ð
 
×ÑÔ Ø×/Ñ/°	Ó:€NØÐØ×#Ñ#¤~×'=Ñ'=Ñ=€KßØ×(×(Ð(à×)Ñ)ðJØJXÐIYð[õð
 ×)Ñ)Ð,QÐR`ÐQaÐ*bÔcÜØ%°Ä3ÀxÃ=ÐX]Ø!×4Ñ4ô
ˆð
 ×(Ñ(×.Ð.¨B×3Ñ3°N×CÒCÙ ?Ñ NÀ+Ñ NÐÙ2°5ÑH¸KÒHøß	Ü˜IÓ&ˆØ×%Ñ%Ø% h Z¨q¸hÈ!¼m±ÐQZÐ0[Ð[`ÐaoÐ`pß+1�˜f˜X QÑ'°rÐ:ð<õ	
ð
 	×%Ñ%Ð(=¸h¸ZÀ}ÐUcÐTdÐ&eÔfÜˆEÐ*¨>Ð*:Ð;Ô<Ü*¨:ÈEÔR€MßÜ�˜ - Ð1Ô2ô
 �I˜}¨dÓ3Ô3÷ 	>ð 	>ß‹CÔ=Õ(<Ó=�C�CŠCÔ=Õ(<Ó=Ó=ð ÷ ÜØðUðEô		
ô /¨zÀ)ÓLÐßÜ�˜Ô"AÈ8Ô"a×"gÑ"gÓ"iÐ!jÐkÔlä
‡L�LØZØ×Ñ˜( NØœ˜\Ó*¨}¸QÐ.?ôð
 ÒØ×%Ñ% jÐ9PÐXaÐ%ÔbØ	×Ñ˜8Ô:Ø€NØÐØ€OßØ(×;Ñ;ÐÙ1°.ÐBUÓVˆßØ Ð&7Ð%8Ð9Õ9ˆOá,Ø Ð'8ÐEXô
‰ð ×,Ñ,×0Ñ0°Ó<ˆ	Ü(Ø×Ñ×#Ñ#Ô+=¸hÓ+GÐRZØ"ÏY°)¼d¿iºi»kÖ2IÐ\`ô
ˆ÷ Ü4°ZÐVZÔ[ˆOÜ3°JÓ?‰OÜ,¨U¸jÓIÐIˆWÖIØ/6¸˜_ˆOßð 	˜6Ô$CÈXÔ$cÕcÕc‰ß	ØðKõ	
ˆô
 ! °(ÈNÓ[€FØ
‡M�Mð 	˜*×+Ñ+×1Ñ1àœT *×"6Ñ"6Ó7àÐ1à˜ð
ô 
ô &=Ø˜¨ó&Ñ"€O�]÷ Ø#2ˆÐÑ Ø ˆˆyÑÜ�v˜u°Ô<ßÜ˜ çô # :ÀDÈuÕUØ"1ô	4ð €Mr6   r  c               ó@   € V ^8„  d   QhRRRRRRRRRR	R
RRRRRRRRR/
# )r/   rF   r   r›   rh   Úretry_countrw   Úmax_retriesrµ   ri   Úelapsed_timerZ  rž   ré  r  r1   r0   ztuple[str, str, Any, Any, Any]r2   )r3   s   "r4   r5   r5     s`   € ÷ <;ñ <;Øð<;Ø$ð<;Ø69ð<;ØHKð<;àð<;à.3ð<;àCFð<;àWZð<;ð ð<;ð $ñ	<;r6   c          
     óB  € \        V4      P                  p	\        V4      P                  4       p
V P	                  V4      pRV RV 2V'       d   RMR,           p\
        P                  RWÉV P                  4       V4       \        V RR4      p\        V RR4      p\        V R	R4      p\        V R
V^ ,          P                  4        VR,           RV 24       \        V RR4      '       dœ   V'       d   RV R2MRp\        V RV	 V RV RV 2RV 24       V'       dH   VR8  dA   \        VRR4      pV'       d   \        V4      R,          MRpV'       d   \        V RV 24       \        V RVR R\        V4       RVR R24       V P                  4       '       dW   R V
9   dP   \        V R!V R"24       ^ R#IHp V! V 4      P                  R$4      '       d   \        V R%R&4       \        V R'V 24       \!        WV4      pV'       d   \        V R(V R)V R*2R+V R,24       WšWÞV3# )-aß  Log one failed API attempt (warning + buffered retry trace, OpenRouter "no tool
endpoints" hint, bare-404 missing-vendor-prefix hint); the buffer only surfaces if every
retry+fallback exhausts. Returns ``(error_type, error_msg, provider, base_url, model)``.

``retryable=False`` (the classifier's verdict, e.g. a 401 on a static-key route) is
named on the line: a bare ``attempt 1/3`` promises a second attempt that never comes
and sends readers hunting for a retry bug (#73237).zattempt Ú/rŽ   z, not retryablez0API call failed (%s) error_type=%s %s summary=%srº   Úunknownr`  rÁ   r¸   :é   NNz	 failed: rñ  Fz [HTTP Ú]u      ðŸ”Œ z  Provider: rò  rô  r·   rl   N:Ni,  Nu      ðŸ“‹ Details: u      â�±ï¸�  Elapsed: z.2fzs  Context: z msgs, ~r<  ú tokenszsupport tool useu$      ðŸ’¡ No OpenRouter providers for z1 support tool calling with your current settings.)Ú_provider_preferences_for_agentÚonlyzU      Your provider_routing.only restriction is filtering out tool-capable providers.zY      Try removing the restriction or adding providers that support tools for this model.zH      Check which providers support tools: https://openrouter.ai/models/rö  z!' is not a valid id for provider u%    â€” it is missing its vendor prefix.r÷  z'?  Re-pick it with /model.)ÚtypeÚ__name__rH   r@   r  rÂ   rÃ   Ú_client_log_contextr`   re   Úupperrë   Ú_is_openrouter_urlÚagent.chat_completion_helpersrB  r’   ræ  )rF   r›   r9  r:  rµ   r;  rž   ré  r  Ú
error_typer  Ú_error_summaryÚ_attemptÚ	_providerÚ_baseÚ_modelÚ_status_code_strrÊ   Ú_err_body_strrB  Ú_suggestions   &&$$$$$$$            r4   Úlog_api_error_attemptrS    sM  € ô �i“×)Ñ)€JÜ�I“×$Ñ$Ó&€IØ×/Ñ/°	Ó:€NØ˜+˜ a¨ }Ð5¿y¹ÐN_Õ`€HÜ
‡N�NØ:Ø˜e×7Ñ7Ó9¸>ôô
 ˜˜z¨9Ó5€IÜ�E˜: yÓ1€EÜ�U˜G YÓ/€FÜˆE�X˜h q�k×/Ñ/Ó1Ð2°8¸Bµ<°.À	È.ÐIYÐZÔ[äˆuÐ'¨×/Ò/ß7B˜W [ M°Ñ3ÈÐÜØØ�z�lÐ#3Ð"4°LÀÀÈ9ÐU[ÐT\Ð]Ø   Ð(ô	
÷
 ˜;¨Ô,Ü 	¨6°4Ó8ˆIß4=œC 	›N¨4Ö0À4ˆMßÜ˜Ð!2°=°/ÐBÔCÜ�Ð-¨l¸3Ð-?¸|ÌCÐP\ÓL]ÐK^Ð^fÐgtÐuvÐfwÐw~Ðô  	Aà×Ñ×!Ò!Ð&8¸IÔ&EÜ�Ð=¸f¸XÐEvÐwÔxÝQÙ*¨5Ó1×5Ñ5°f×=Ò=ÜØØgØkôô
 	�ÐaÐbhÐaiÐjÔkô 4°IÈ&ÓQ€KßÜØØ˜f˜XÐ%FÀyÀkÐQvÐwØ" ; -Ð/JÐKô	
ð
  )°FÐ:Ð:r6   c               ó4   € V ^8„  d   QhRRRRRRRRRR	R
R	RR/# )r/   rF   r   rœ   r�   rè  rˆ  rw   Úabort_messagerH   Úinterrupt_textr0   r‰  r2   )r3   s   "r4   r5   r5   V  sF   € ÷ ñ ØðØ.ðØFIðØ[^ðàðà(+ðð ñr6   c          
     ó¶   € \        V RV 24       V P                  V4       \        W4       V P                  W4       V P	                  RR7       RVRVRVRRR	R/# )
zšAnnounce ``abort_message``, close any open tool sequence with ``interrupt_text``,
persist, clear the interrupt and return the ``interrupted`` result dict.u   âš¡ T)Úhard_cancelr‡  rœ   r‹  rŒ  FÚinterrupted)rQ   Ú)_drop_trailing_empty_response_scaffoldingr   r	  Úclear_interrupt)rF   rœ   rè  rˆ  rU  rV  s   &&&&$$r4   Úabort_turn_on_interruptr\  V  sn   € ô ˆE�T˜-˜Ð)Ô*ð 
×3Ñ3°HÔ=Ü# HÔ=Ø	×Ñ˜8Ô:ð 
×Ñ dÐÔ+à˜.¨*°hÀÈ^Ø�U˜M¨4ðð r6   c               ó@   € V ^8„  d   QhRRRRRRRRR	RR
RRRRRRRRR/
# )r/   rF   r   Ú	wait_timerZ  rð   zOptional[TurnRetryState]rœ   r�   rè  rˆ  rw   rU  rH   rV  Úactivity_labelr0   úOptional[dict[str, Any]]r2   )r3   s   "r4   r5   r5   l  se   € ÷ ñ ØðØ ðØ*Bðà"ðà:=ðàORðð ðð ),ðð >Aðð ñ	r6   c          	     óö  € \         P                   ! 4       V,           p	^ p
\         P                   ! 4       V	8  d±   V P                  '       d4   Ve"   V P                  RR7      '       d
   RVn        R# \	        WWEWgR7      # \         P
                  ! R4       V
^,          p
V
^–,          ^ 8X  g   KŽ  V P                  V R\        V	\         P                   ! 4       ,
          4       R24       KÊ  V P                  4        R# )a¦  Sleep ``wait_time`` in 200 ms slices so interrupts are honoured promptly, touching
activity every ~30 s so the gateway's inactivity monitor knows we are alive.

On interrupt with ``_retry`` given and a redirect pending: preserve the redirect, arm
``_retry.restart_with_redirected_messages`` and return ``None`` (caller rebuilds the
turn). Otherwise return the ``interrupted`` result dict. ``None`` when the wait completed.NT)Úpreserve_redirect)rU  rV  gš™™™™™É?r¹   zs remaining)	r*  Ú_interrupt_requestedr[  Ú restart_with_redirected_messagesr\  ÚsleepÚ_touch_activityrw   Ú_adopt_nous_key_before_expiry)rF   r^  rð   rœ   rè  rˆ  rU  rV  r_  Ú	sleep_endÚ_touch_counters   &&&$$$$$$  r4   Úinterruptible_backoff_sleeprj  l  sÐ   € ô —	’	“˜iÕ'€IØ€NÜ
�)Š)‹+˜	Ô
!Ø×%×%Ð%ØÒ! e×&;Ñ&;ÈdÐ&;×&SÒ&SØ:>�Ô7ÙÜ*ØÐ!5Ø+ôð ô 	�
Š
�3ŒØ˜!ÕˆØ˜CÕ 1Ö$Ø×!Ñ! ^Ð$4°B´s¸9ÄtÇyÂyÃ{Õ;RÓ7SÐ6TÐT_Ð"`Öað 
×'Ñ'Ô)Ùr6   Úzai_coding_overload_longz- (Z.AI Coding overload adaptive long backoff)Úzai_coding_overload_shortz# (Z.AI Coding overload short retry)c               ó    € V ^8„  d   QhRRRR/# )r/   r›   rh   r0   rH   r2   )r3   s   "r4   r5   r5   ’  s   € ÷ Nñ N˜)ð N¨ñ Nr6   c                óà   € ^ RI Hp ^ RIHp ^ RIHp V! V 4      P                  R4      pVf   R# V! V4      ;'       g    R\        P                  ! 4       ,
          pV^8¼  d   RV! V4       2# R# )a  ``"~13m"`` until the ``reset_at`` parsed from *api_error* (epoch s/ms or ISO-8601), else ``""``.

A bare "Rate limited. Waiting 60s" hides the one fact that decides whether to wait or switch
models (#26889): a per-minute throttle and a 13-minute plan window look identical without it.)Úextract_api_error_contextr¥  )Úformat_duration_compactrV  rŽ   g        Ú~)r—  ro  r§  r¦  Úagent.usage_pricingrp  r’   r*  )r›   ro  r¦  rp  rV  Ú	remainings   &     r4   r'  r'  ’  sh   € õ
 FÝ?Ý;Ù(¨Ó3×7Ñ7¸
ÓC€HØÒÙÙ*¨8Ó4×;Ð;¸¼t¿yºy»{ÕJ€IØ7@ÀA´~ˆQÑ& yÓ1Ð2Ð3ÐMÈ2ÐMr6   c               ó<   € V ^8„  d   QhRRRRRRRRRR	R
R	RRRRRR/	# )r/   rF   r   r›   rh   r9  rw   r:  r  r1   Úis_zai_coding_overloadr`  rÁ   r0   rZ  r2   )r3   s   "r4   r5   r5   ¡  sa   € ÷ @ñ @Øð@Ø$ð@Ø69ð@ØHKð@Ø^bð@à ð@à,/ð@à8;ð@ð ñ@r6   c               ó¤  € ^ RI HpHp	Hp
HpHp ^ RIHp V! V4      pVe   \        Wé4      pVe   TM
V! VRRR7      pRpT;'       g    TpV'       d   Vf   V
! V\        V4      WqVR7      w  ppV'       d   \        V4      MRpT;'       d	    V! W4      pV'       d   R	MV'       d   V'       g   R
MRpV'       dR   \        P                  T;'       g    RR4      pRT RV'       d   RV R2MR RVR RV^,            RV RV R2pVR8H  pMRVR RV RV R2pVRJ;'       d    Wè8„  pV'       d   V P                  V4       MV P                  V4       V'       d   VP                  4        RV R2pMV'       d   RMRpV P!                  RV RVR RV RV R2	4       \"        P%                  RYòY0P'                  4       T;'       g    R V4       V# )!a¤  Pick the wait before the next API retry and announce it. Retry-After wins for
rate limits and any other retryable error (capped at ``RETRY_AFTER_CAP_S``); otherwise
jittered backoff, replaced by the adaptive policy for 429s / Z.AI overloads. Retries are
buffered (replayed only if every retry fails); a long Z.AI Coding wait or a non-rate-limit
``Retry-After`` over ``LIVE_RETRY_WAIT_CAP_S`` is announced when it starts.)ÚLIVE_RETRY_WAIT_CAP_SÚRETRY_AFTER_CAP_SÚadaptive_rate_limit_backoffÚjittered_backoffÚprovider_retry_after_seconds©rÝ  Ng       @g      N@)Ú
base_delayÚ	max_delay)r`  rÁ   rg   Údefault_waitrŽ   zThe free model is busyzProvider overloadedzRate limitedu   â�±ï¸� Ú.z Resets in z	 Waiting ú.1fzs (attempt r=  ró  rè   rk  u   â�³ Retrying in z)...u    â€” resets in r<  u   the free model is busy â€”u   waiting on provider â€”u   â�³ z retrying in ú.0fz>Retrying API call in %ss (attempt %s/%s) %s policy=%s error=%sÚdefault)Úagent.retry_utilsrw  rx  ry  rz  r{  rÞ   rÝ  ÚminrH   r'  Ú_ZAI_POLICY_NOTESr’   r  Ú_buffer_diagnostic_statusr@   Ú_emit_diagnostic_waitrÂ   rÃ   rF  )rF   r›   r9  r:  r  ru  r`  rÁ   rw  rx  ry  rz  r{  rÝ  Ú_retry_afterr^  Ú_backoff_policyÚ	_adaptiver/  Ú
_free_busyÚ_wait_reasonÚ_policy_noteÚ_statusÚ_announce_nowÚ_live_reasons   &&$$$$$$                 r4   Úcompute_error_backoffr’  ¡  s  € ÷õ õ 3ñ 0°	Ó:€LØÒÜ˜<Ó;ˆØ ,Ò 8‘Ñ>NÈ{ÐgjÐvzÔ>{€IØ€OØ×9Ð9Ð#9€Iß�\Ò)Ù%@Ø¤# h£-°uÐ\eô&
Ñ"ˆ	�?÷ '0ŒZ˜	Ô"°R€FØ ×CÐC¡]°5Ó%C€Jß0:Ñ,ß2H×Q`Ñ.Ðftð çÜ(×,Ñ,¨_×-BÐ-BÀÀBÓGˆØ˜\˜N¨!Çv¨k¸&¸ÀÑ,CÐSUÐ+VÐV_Ð`iÐjmÐ_nð oØ*¨Q�Ð/¨q°°¸Q¸|¸nÈCðQˆà'Ð+EÑE‰à$ Y¨s O°;¸{¸mÈ1È[ÈMÐY]Ð^ˆà$¨DÐ0×YÐY°\Ñ5YˆßØ×%Ñ% gÕ.à×'Ñ'¨Ô0÷
 Ø&×,Ñ,Ó.Ð/¨¸v¸hÀaÐH‰ç7AÑ3ÐG`ˆØ	×ÑØ
ˆ|ˆn˜M¨)°C¨¸ÀKÀ=ÐPQÐR]ÐQ^Ð^_Ð`ôô ‡N�NØHØ ×-FÑ-FÓ-HØ×$Ð$˜9 iôð
 Ðr6   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r/   rF   r   r›   rh   r`  r0   r1   r2   )r3   s   "r4   r5   r5   ä  s/   € ÷ Eñ E¨ð E¸	ð EÈSð EÐUYñ Er6   c                ó–   € ^ RI HpHp ^ RIHp ^ RIHp V! W4      '       d   V! V 4      '       g   R# V! V4      pVRJ;'       d    Ws8„  # )aÿ  True when an attended session on the free model meets a cooldown longer than a person
sits through. The free tier's pause is service-wide: a 600 s retry met a second 429 while its
1069 s window ran, so the caller ends the attempt cycle now (fallback, or the reset time and
the sign-in / model doors). Every other provider, and every unattended run (cron, messaging,
``hermes chat -q``), waits out its ``Retry-After``: a paid bucket reopens on time, and
``fallback.min_switch_reset_seconds`` relies on that wait.)rw  r{  )Úis_attendedr|  FN)r„  rw  r{  Úagent.session_sourcer•  rÞ   rÝ  )rF   r›   r`  rw  r{  r•  rÝ  Úcooldowns   &&&     r4   Úfree_tier_cooldown_ends_turnr˜  ä  sF   € ÷ VÝ0Ý2Ù˜%×*Ò*©{¸5×/AÒ/AÙÙ+¨IÓ6€HØ˜4Ð×DÐD HÑ$DÐDr6   c               ó    € V ^8„  d   QhRRRR/# )r/   rÖ   r   r0   r‰  r2   )r3   s   "r4   r5   r5   ô  s   € ÷ Qñ Q¨ð Q°ñ Qr6   c                ó²  € \        V RR4      pV'       g   / # \        V\        4      '       d   TpMN\        VR4      '       g   \        VR4      '       d   R\        VRR4      R\        VRR4      /pMR\	        V4      /pVP                  4        UUu/ uF7  w  r4\        V\        4      '       g   K  VP                  4       '       g   K5  W4bK9  	  upp# u uppi )z½``response.error`` of a Codex ``failed``/``cancelled`` Response as ``{"code", "message"}``
(the SDK types it as ``ResponseError``; the raw-SSE assembler keeps the dict); ``{}`` when absent.rg   NÚcoderk   )r`   r�   r‘   r“   rH   Úitemsr?   )rÖ   Ú	error_objÚfieldsÚkÚvs   &    r4   Ú_codex_soft_failure_errorr¡  ô  s¬   € ô ˜ '¨4Ó0€IßØˆ	Ü�)œT×"Ò"Ø‰Ü	�˜F×	#Ò	#¤w¨y¸)×'DÒ'DØœ' )¨V°TÓ:¸IÄwÈyÐZcÐeiÓGjÐk‰àœS ›^Ð,ˆØ#Ÿ\™\œ^ÔP™^‘T�Q¬z¸!¼S×/AŒDÀaÇgÁgÇiŒDˆAŠD™^ÒPÐPùÓPs   ÂCÂ1CÃ	Cc                  ó2   a € ] tR tRtRtR V 3R lltRtV ;t# )Ú_CodexSoftFailurei  z¨A Codex HTTP-200 ``status=failed`` Response reshaped so ``classify_api_error`` and
``extract_api_error_context`` read ``response.error`` exactly like an SDK error body.c               ó    € V ^8„  d   QhRRRR/# )r/   rg   r‰  r0   rI   r2   )r3   s   "r4   r5   Ú_CodexSoftFailure.__annotate__  s   € ÷ %ñ %˜nð %°ñ %r6   c                	ój   <€ \         ST `  VP                  R 4      ;'       g    R4       RV/V n        R# )rk   rŽ   rg   N)ÚsuperÚ__init__r’   rl   )Úselfrg   Ú	__class__s   &&€r4   r¨  Ú_CodexSoftFailure.__init__  s-   ø€ Ü‰Ñ˜Ÿ™ 9Ó-×3Ð3°Ô4Ø˜eÐ$ˆŽ	r6   )rl   )rE  Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r¨  Ú__static_attributes__Ú__classcell__)rª  s   @r4   r£  r£    s   ø† ñ]÷%ö %r6   r£  c               ó$   € V ^8„  d   QhRRRRRR/# )r/   rF   r   rÖ   r0   ztuple[Any, dict[str, Any]]r2   )r3   s   "r4   r5   r5     s"   € ÷ =ñ = sð =°cð =Ð>Xñ =r6   c                óÈ  € V P                   R8w  d   R/ 3# \        \        VRR4      ;'       g    R4      P                  4       P	                  4       R
9  d   R/ 3# \        \        V4      4      p\        T\        V RR4      ;'       g    R\        V RR4      ;'       g    R\        \        V RR4      ;'       g    R4      \        V RR4      R	7      pW0P                  V4      3# )a  ``(classified, error_context)`` for a Codex ``failed``/``cancelled`` Response, or
``(None, {})`` when it is not one. The SDK never raises on these HTTP-200 soft failures,
so this is the only place their quota/billing/auth semantics reach the credential pool.rô   NÚstatusrŽ   rº   rÁ   r`  r�   )rº   rÁ   r`  r�   >   r�  Ú	cancelled)	rÈ   rH   r`   r?   r@   r£  r¡  r   r¨  )rF   rÖ   Úexcr	  s   &&  r4   Úclassify_codex_soft_failurer·    sÖ   € ð ‡~�~Ð*Ô*Ø�RˆxˆÜ
Œ7�8˜X rÓ*×0Ð0¨bÓ1×7Ñ7Ó9×?Ñ?ÓAÐI`Ô`Ø�RˆxˆÜ
Ô5°hÓ?Ó
@€CÜ#Ø”g˜e Z°Ó4×:Ð:¸Ä'È%ÐQXÐZ\ÓB]×BcÐBcÐacÜ”W˜U J°Ó3×9Ð9°rÓ:ÄGÈEÐS\Ð^bÓDcô€Jð ×7Ñ7¸Ó<Ð<Ð<r6   c               ó$   € V ^8„  d   QhRRRRRR/# )r/   rF   r   rÖ   r0   ztuple[bool, list[str]]r2   )r3   s   "r4   r5   r5     s"   € ÷ 1ñ 1 3ð 1°#ð 1Ð:Pñ 1r6   c           
     óÜ  € V P                  4       P                  V4      '       d   R. 3# Vf   RR.3# V P                  R8X  EdU   \        \	        VRR4      ;'       g    R4      P                  4       P                  4       pVR9   dY   \        V4      P                  R4      ;'       g    R	V R
2p\        P                  RW#V P                  4       4       RRV RV 2.3# \	        VRR4      p\        V\        4      '       d   VP                  4       MRpV'       d$   \        P                  R\        V4      4       R. 3# \        P                  R\	        VRR4      \	        VRR4      \	        VRR4      RV P                   RV P                   24       RR.3# V P                  R8X  d   RpM<V P                  R8X  d   RpM(\!        VR4      '       g   RpMVP"                  f   RpMRpRV.3# )a  Validate the raw provider response via the transport; ``(response_invalid,
error_details)``. A Codex ``failed``/``cancelled`` status (e.g. quota exhaustion) is
invalid so the fallback chain triggers; an empty Codex ``output`` with non-empty
``output_text`` is deferred to normalization.FNTzresponse is Nonerô   r´  rŽ   rk   zResponses API returned status 'Ú'z>Codex response status='%s' (error=%s). Routing to fallback. %szresponse.status=rð  Úoutput_textzaCodex response.output is empty but output_text is present (%d chars); deferring to normalization.zeCodex response.output is empty after stream backfill (status=%s, incomplete_details=%s, model=%s). %sÚincomplete_detailsrÁ   z	api_mode=z
 provider=zresponse.output is emptyr¼   z/response.content invalid (not a non-empty list)r¾   z/Bedrock response invalid (no output or choices)Úchoicesz#response has no 'choices' attributezresponse.choices is Nonezresponse.choices is empty>   r�  rµ  )rF  Úvalidate_responserÈ   rH   r`   r?   r@   r¡  r’   rÂ   rÃ   rF  r�   rY  rë   rº   r“   r½  )rF   rÖ   Ú_codex_resp_statusÚ_codex_error_msgÚ	_out_textÚ_out_text_strippedr  s   &&     r4   Úvalidate_response_shaperÃ    s   € ð
 ×ÑÓ×/Ñ/°×9Ò9Ø�bˆyÐØÒØÐ(Ð)Ð)Ð)Ø‡~�~Ð*Õ*Ü ¤¨°8¸RÓ!@×!FÐ!FÀBÓG×MÑMÓO×UÑUÓWÐØÐ!8Ô8ä)¨(Ó3×7Ñ7¸	ÓB÷ Kð KØ4Ð5GÐ4HÈÐJð ô �N‰NØPØ"°e×6OÑ6OÓ6Qôð Ð,Ð-?Ð,@ÀÐCSÐBTÐUÐVÐVÐVä˜H m°TÓ:ˆ	Ü2<¸YÌ×2LÒ2L˜YŸ_™_Ô.ÐRTÐßÜ�L‰Lð:äÐ&Ó'ôð
 ˜"�9ÐÜ�‰ð?ä�H˜h¨Ó-¬w°xÐAUÐW[Ó/\Ü�H˜g tÓ,Ø˜Ÿ™Ð' z°%·.±.Ð1AÐBô	
ð Ð0Ð1Ð1Ð1Ø‡~�~Ð-Ô-ØB‰Ø	�‰Ð-Ô	-ØB‰Ü�X˜y×)Ò)Ø6‰Ø	×	Ñ	Ò	!Ø+‰à,ˆØ�&�ˆ>Ðr6   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r/   rF   r   rÖ   Úapi_durationrZ  r0   ztuple[str, str, str]r2   )r3   s   "r4   r5   r5   P  s/   € ÷ #Wñ #W Sð #W°Cð #WÀuð #WÐQeñ #Wr6   c                ó  € RpRp\        T;'       d!    \        VR4      ;'       d    VP                  4      pV'       d—   \        V4      P	                  R4      ;'       g    \        VP                  4      p\        VP                  R4      '       dC   VP                  P                  '       d'   VP                  P                  P	                  RR4      pMAV'       d:   \        VR4      '       d(   VP                  '       d   \        VP                  4      pVR8X  d<   V'       d4   \        VR4      '       d"   VP                  '       d   RVP                   2pVR8X  dŠ   V'       d‚   \        V4      P                  4        UUu/ uF1  w  rgVP                  R4      '       d   K  V\        V4      R	,          bK3  	  pppV P                  '       d   \        P                  ! R
V 24       Rp	V'       dg   \        VP                  RR4      p
V
f<   \!        VP                  \"        4      '       d   VP                  P	                  R4      p
V
e    \%        V
4      p	W4\+        W’4      3# u uppi   \&        \(        3 d     L&i ; i)zßDiagnostics for an empty/malformed response: ``(error_msg, provider_name,
failure_hint)``. The hint is derived from the provider error code (524/504/429/
5xx) and the response time, instead of always assuming rate limiting.ÚUnknownrg   rk   ÚmetadataÚprovider_namerÁ   zmodel=r8   :Néd   Nz*Response attributes for invalid response: Nr›  )r1   r“   rg   r¡  r’   rH   rÈ  rk   rÁ   Úvarsrœ  Ú
startswithrñ  ÚloggingrY  r`   r�   r‘   rw   Ú	TypeErrorry   Ú_failure_hint_for)rF   rÖ   rÅ  r  rÉ  Ú
_has_errorrŸ  r   Ú
resp_attrsÚ_resp_error_codeÚ	_code_raws   &&&        r4   Údescribe_invalid_responserÔ  P  sñ  € ð €IØ€MÜ�h×PÐP¤7¨8°WÓ#=×PÐPÀ(Ç.Á.ÓQ€Jßä-¨hÓ7×;Ñ;¸IÓF×]Ð]Ì#ÈhÏnÉnÓJ]ˆ	Ü�8—>‘> :×.Ò.°8·>±>×3J×3JÐ3JØ$ŸN™N×3Ñ3×7Ñ7¸ÈÓSˆMøß	”g˜h¨	×2Ò2°x×7G×7GÐ7GÜ˜×(Ñ(Ó)ˆ	ð ˜	Ô!§h´7¸8ÀW×3MÒ3MÐRZ×R`×R`ÐR`Ø  §¡Ð 0Ð1ˆà˜	Ô!§hÜ26°x³.×2FÑ2FÔ2HÔbÑ2H©$¨!ÐPQ×P\ÑP\Ð]`×Pa”o�aœ˜Q› �’oÑ2Hˆ
ÑbØ× × Ð Ü�MŠMÐFÀzÀlÐSÔTàÐßÜ˜HŸN™N¨F°DÓ9ˆ	ØÒ¤¨H¯N©N¼D×!AÒ!AØ Ÿ™×*Ñ*¨6Ó2ˆIØÒ ðÜ#& y£>Ð ð Ô%6Ð7GÓ%VÐVÐVùó cøô œzÐ*ô Ùðús   ÆI&Æ$I&ÉI, É,J É?J c               ó$   € V ^8„  d   QhRRRRRR/# )r/   r›  ri   rÅ  rZ  r0   rH   r2   )r3   s   "r4   r5   r5   v  s!   € ÷ 0ñ 0˜Mð 0¸ð 0À3ñ 0r6   c                óê   € V R8X  d   RVR R2# V R8X  d   RVR R2# V R8X  d   R# V R9   d   R	V  R
VR R2# V R9   d   RV  R2# V e   RV  R
VR R2# V^
8  d   RVR R2# V^<8”  d   RVR R2# RVR R2# )zCHuman-readable hint from the provider error code and response time.i  z-upstream provider timed out (Cloudflare 524, r‚  zs)iø  zupstream gateway timeout (504, i­  z'rate limited by upstream provider (429)zupstream server error (r¹   zupstream provider overloaded (ró  zupstream error (code zfast response (r�  u   s) â€” likely rate limitedzslow response (u   s) â€” likely upstream timeoutzresponse time Ús>   r·   éö  >   é  é÷  r2   )r›  rÅ  s   &&r4   rÏ  rÏ  v  sÜ   € àˆs„{Ø>¸|ÈCÐ>PÐPRÐSÐSØˆs„{Ø0°¸cÐ0BÀ"ÐEÐEØˆs„{Ù8ØˆzÔØ(¨¨¨b°¸cÐ0BÀ"ÐEÐEØˆzÔØ/°¨v°QÐ7Ð7ØÒØ& t f¨B¨|¸CÐ.@ÀÐCÐCØ�bÔØ  ¨cÐ 2Ð2LÐMÐMØ�bÔØ  ¨cÐ 2Ð2PÐQÐQØ˜L¨Ð-¨QÐ/Ð/r6   c                  óž   € ] tR tRt$ RtR]R&   R]R&   R]R&   R	]R
&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   RtR# )ÚClassifiedErrorVerdicti‹  aN  Outcome of ``route_classified_error``. ``action``: ``"return"`` (terminal result),
``"break"`` (restart armed on ``_retry``), ``"continue"`` (re-enter the retry loop; Nous
guard re-check) or ``"fallthrough"`` (proceed to overflow / client-error / backoff
handling). The remaining fields are loop locals the router rebound or computed.rH   Úactionr`  r«  ri   rµ   r�   rœ   r   r    rè  rw   r9  r:  Úcompression_attemptsr1   Ú"provider_overflow_recovery_pendingr  Úwrapped_output_cap_budgetru  r2   N)rE  r¬  r­  r®  r¯  Ú__annotations__r°  r2   r6   r4   rÜ  rÜ  ‹  sW   ‡ ñWð
 ƒKØ$Ó$ØÓØ"Ó"ØÓØÓØÓØÓØÓØ(,Ó,ØÓØ,Ó,Ø × r6   rÜ  i@ c               ó    € V ^8„  d   QhRRRR/# )r/   rF   r   r0   rw   r2   )r3   s   "r4   r5   r5   ­  s   € ÷ ñ  #ð ¨#ñ r6   c           
     ód  € V P                   pVP                  pV\        8”  d�   VP                  V P                  \        V P
                  \        V RR4      V P                  V P                  R7       \        VR4      '       d   RVn
        RVn        V P                  RVR R	\        R R
24       V# )zlCap the compressor's context window at the long-context tier limit; returns the
previous ``context_length``.r�   rŽ   )rÁ   Úcontext_lengthr`  r�   rº   rÈ   Ú_context_probedTFuO   âš ï¸�  Anthropic long-context tier requires extra usage â€” reducing context: r<  u    â†’ rA  )Úcontext_compressorrä  Ú_LONG_CONTEXT_TIER_CAPÚupdate_modelrÁ   r`  r`   rº   rÈ   r“   rå  Ú_context_probe_persistablerd   )rF   Ú
compressorÚold_ctxs   &  r4   Ú_cap_long_context_tierrì  ­  s´   € ð ×)Ñ)€JØ×'Ñ'€GØÔ'Ô'Ø×ÑØ—+‘+Ô.DÈuÏ~É~Ü˜E 9¨bÓ1¸E¿N¹NÐUZ×UcÑUcð 	 ô 	
ô �:Ð0×1Ò1Ø)-ˆJÔ&Ø49ˆJÔ1Ø×Ñð:à�qˆk˜Ô5°aÐ8¸ðAô	
ð
 €Nr6   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r/   r	  r   Úis_upstreamr1   Úis_transport_failurer0   rH   r2   )r3   s   "r4   r5   r5   Å  s0   € ÷ Gñ G sð G¸ð GÐUYð GÐ^añ Gr6   c                óî   € V'       d-   V P                   ;'       g    / P                  RR4      pRV R2# V P                  \        P                  8X  d   V P
                  '       d    R# R# V'       d   R# R# )	z0Status line announcing an eager fallback switch.Úupstream_providerÚ
aggregatoru   âš ï¸� Upstream u0    rate-limited â€” switching to fallback model...u‰   âš ï¸� Provider reported usage/credit exhaustion (unverified â€” may be a content-filter rejection) â€” switching to fallback provider...uI   âš ï¸� Billing or credits exhausted â€” switching to fallback provider...uA   âš ï¸� Provider unreachable â€” switching to fallback provider...u9   âš ï¸� Rate limited â€” switching to fallback provider...)r'  r’   r  r   r=  rc  )r	  rî  rï  Ú_upstream_names   &&& r4   Ú_eager_fallback_statusrô  Å  sq   € çØ$×2Ñ2×8Ð8°b×=Ñ=Ð>QÐS_Ó`ˆØ! .Ð!1Ð1aÐbÐbØ×ÑœN×2Ñ2Ô2Ø×(×(Ð(ð8ññ
 [ßÙRÙFr6   c               ó$   € V ^8„  d   QhRRRRRR/# )r/   rF   r   r«  r‰  r0   r1   r2   )r3   s   "r4   r5   r5   Ø  s&   € ÷ Hñ H¨cð H¸>ð HÈdñ Hr6   c           	     ó
  € VP                  R4      pV'       d.   VP                  R4      '       g   V P                  4       '       g   R# \        \        \	        V4      4      \        V RR4      ;'       g    R\        V RR4      ;'       g    RR7      pVP                  \        9  d   R# V P                  \        W3P                  \        P                  8H  R4      4       \        V P                  VP                  R7      4      # )	aV  The codex app-server runtime reports a failed turn as ``result["error"]`` text instead of
raising, so the generic classify -> ``fallback_providers`` chain never saw it (#71633).
Classify that text; on a billing / rate-limit verdict activate the configured fallback and
return True so the caller re-runs the same user turn on the generic loop.rg   rY  Frº   rŽ   rÁ   r#  ©r  )r’   Ú_has_pending_fallbackr   rÇ   rH   r`   r  Ú_RATE_LIMIT_REASONSr‡  rô  r   Úupstream_rate_limitr1   Ú_try_activate_fallback)rF   r«  rg   r	  s   &&  r4   Ú"activate_codex_app_server_fallbackrü  Ø  sÓ   € ð
 �J‰J�wÓ€Eß�F—J‘J˜}×-Ò-°U×5PÑ5P×5RÒ5RÙÜ#Ü”S˜“ZÓ ¬7°5¸*ÀbÓ+I×+OÐ+OÈRÔW^Ð_dÐfmÐoqÓWr×WxÐWxÐvxô€Jð ×ÑÔ 3Ô3ÙØ	×#Ñ#Ü˜z×+<Ñ+<Ä×@bÑ@bÑ+bÐdiÓjôlä�×,Ñ,°J×4EÑ4EÐ,ÓFÓGÐGr6   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r/   rF   r   r›   rh   r'  r	  r0   r1   r2   )r3   s   "r4   r5   r5   ê  s2   € ÷ "ñ " sð "°yð "ÐQTð "Ðbeð "Ðquñ "r6   c                óÀ  € Rp ^ RI HpHpHp \	        VRR4      pV'       d   \	        VRR4      MRp	^ RIHp
 V
! V 4      p\	        VRR4      ;'       g    / pT;'       d    V! V4      ;'       g    V! W�P                  R7      pV'       d+   / \        V\        4      '       d   TM/ CVCpV! W�VR	7       V# \        P                  R
4        V#   \         d     T# i ; i)aâ  Record a genuine account-level Nous 429 to the cross-session breaker; upstream
capacity 429s (no exhausted bucket in headers or last-known state) are left alone.

*error_context* is the turn's (``extract_api_error_context``); *classified* brings the
classifier's own context, where a welcome-tier ``rate_limited`` refusal and its ``reset_at``
live. A long welcome reset is an exhausted allowance whatever the headers say, and the one
place the user is told that signing in lifts it.F)Úis_genuine_nous_rate_limitÚis_long_welcome_rate_limitÚrecord_nous_rate_limitrÖ   NÚheadersrØ   r'  )r  Úlast_known_state)r  r'  Ú	anonymousz�Nous 429 looks like upstream capacity (no exhausted bucket in headers or last-known state) -- not tripping cross-session breaker.)Úagent.nous_rate_guardrÿ  r   r  r`   rÞ   rÙ   Ú_rate_limit_stater�   r‘   rÂ   r.  rh   )rF   r›   r'  r	  Ú_genuinerÿ  r   r  Ú	_err_respÚ	_err_hdrsrÙ   r  Ú_classified_ctxÚ_mergeds   &&&&          r4   Ú_is_genuine_nous_rate_limitr  ê  sø   € ð €Hð÷	\ñ 	\ä˜I z°4Ó8ˆ	ß;D”G˜I y°$Ô7È$ˆ	Ý;Ù& uÓ-ˆ	Ü! *¨o¸tÓD×JÐJÈˆð ×FÐFÑ5°oÓF÷ gð gÙ)°)×NeÑNeÔfð 	÷ Øg¬:°mÄT×+JÒ+J™-ÐPRÐgÐWfÐgˆGÙ"¨9ÐW`Õað €Oô �K‰Kð)õð €Oøô ô ØØ€Oðús0   „AC ÁC Á C Á0C Â(C Â6C ÃCÃCc          *     ól   € V ^8„  d   QhRRRRRRRRRR	R
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR/# )r/   rF   r   r›   rh   r	  rð   r'   r  rH   r'  rƒ  r1   r`  rÁ   rœ   r�   rž   Úsystem_messager    rè  r9  rw   r:  rÞ  Úmax_compression_attemptsrˆ  Úeffective_task_idr0   rÜ  r2   )r3   s   "r4   r5   r5     së   € ÷ k#ñ k#Øðk#Ø$ðk#Ø25ðk#Ø?Mðk#Ø]`ðk#àðk#à-1ðk#à=@ðk#àILðk#ð #ðk#ð 36ðk#ð HKðk#ð ð	k#ð 69ð	k#ð HKð	k#ð Z]ð	k#ð
 ðk#ð
 :=ðk#ð
 ORðk#ð ðk#ð ñk#r6   c               ó:
  a aa	a
aaaaaa!a"a#a$a%a&a'€ ^ RI Hp ^ RIHo!Hp ^ RIHp Ro#Ro&Ro%Ro"\        VRR4      o'R,R V"V#V%VVVV&VV	VV'3R lllo$R	 V!VV$VV V
VV3R
 llp\        V4      ;'       g    \        V4      RJpVP                  \        9   d¿   \        S RR4      '       g¬   V'       g¤   S P                  4        \        S RR4       \        P                  S P                    RVP                  P"                   R24       S P%                  S	S4       \'        RS P(                  R7      pS$! R\+        RVRS	RRRVRVRRRRRR/RR4      4      # VP                  \,        P.                  8X  dè   \1        S 4      pS^,          oSV8:  dÍ   \3        S	4      pS P5                  S	TT! S
S P6                  ;'       g    RR7      VRVP                  P"                  R7      w  o	oV! S S	S4      o\3        S	4      V8  g   V\8        8”  dS   S P;                  \<        P>                  ! \8        VR 7      4       \@        PB                  ! ^4       Ro#RSn"        S$! R!4      # VP                  \F        9   o&VP                  \,        PH                  8X  d   \        V4      MRo%VP                  \J        9   p\M        \O        V4      W�R"7      o"S"'       d   \Q        S\S        4       4      oS&;'       d    S%RJ ;'       g    T;'       d9    S^8¬  ;'       d,    \        VR#R4      ;'       g    / PU                  R$4      '       * pV'       dã   S PV                  \3        S PX                  4      8  d¿   VP                  \,        PZ                  8H  pV'       d   RMV! 4       P]                  S P^                  4      pV'       gp   S P;                  \a        VVV4      4       \c        V\d        4      '       d   VPU                  R%4      MRp S Pg                  VP                  V R&7      '       d   V! 4       # VPh                  '       dx   SPj                  '       gf   S PV                  \3        S PX                  4      8  dB   RSn5        S P;                  R'4       S Pg                  VP                  R(7      '       d   V! 4       # S&'       dg   S Pl                  R)8X  dV   VP                  \,        PH                  8X  d7   V'       g/   \o        S WV4      '       d   \Q        ^ S^,
          4      oS$! R*4      # S$! R+4      # )-u  Ordered (load-bearing) recovery steps between classification and overflow handling:
compaction-disabled overflow â†’ terminal error (output-cap errors exempt); Anthropic
long-context tier 429 â†’ cap at 200k and compress; eager fallback for rate-limit/billing
(immediately) and transport failures (after 1 retry) unless credential-pool rotation may
still recover (upstream-aggregator 429s always fall back); persistent 401/403 â†’ fallback
chain once; genuine Nous 429 â†’ cross-session breaker + re-enter the loop exactly once.)Ú&conversation_history_after_compression)Ú_arm_fallback_restartÚ_ra)Úestimate_request_tokens_roughFNrµ   c               ó$   € V ^8„  d   QhRRRRRR/# )r/   rÝ  rH   r«  r`  r0   rÜ  r2   )r3   s   "r4   r5   Ú,route_classified_error.<locals>.__annotate__'  s#   € ÷ 	
ñ 	
˜ð 	
Ð&>ð 	
ÐJ`ñ 	
r6   c                ó2   <€ \        WSS
SSSS	SSSSSR 7      # ))rÝ  r«  rµ   rœ   r    rè  r9  r:  rÞ  rß  r  rà  ru  )rÜ  )rÝ  r«  Ú_is_zai_coding_overloadÚ#_provider_overflow_recovery_pendingÚ_wrapped_output_cap_budgetr    rÞ  rè  r  r:  rœ   r9  rµ   s   &&€€€€€€€€€€€r4   Ú_verdictÚ(route_classified_error.<locals>._verdict'  s1   ø€ Ü%Ø°kÈHØ!5ÐL`Ø#°Ø!5Ø/RØ+ÐGaØ#:ô
ð 	
r6   c               ó   € V ^8„  d   QhRR/# )r/   r0   rÜ  r2   )r3   s   "r4   r5   r  2  s   € ÷ !ñ !Ð3ñ !r6   c                 ó2   <€ S ! SSSS4      o^ o^ oS! R4      # )é    Úbreakr2   )r  rð   r  r    rF   rž   rÞ  r9  s   €€€€€€€€r4   Ú_fallback_breakÚ/route_classified_error.<locals>._fallback_break2  s,   ø€ á4°U¸LÐJ^Ð`fÓgÐØˆØ ÐÙ˜Ó Ð r6   Úcompression_enabledTuk   â�Œ The conversation is too long for the model and automatic shrinking is off (compression.enabled: false).u~      ðŸ’¡ Run /compress to shrink it now, /new to start fresh, pick a model with a bigger context window, or remove attachments.zContext overflow (u4   ) with auto-compaction disabled â€” not compressing.Úcompression_disabled)rÁ   r0   r‡  rœ   rŒ  r‹  rg   rþ  r�  Úcompaction_disabledÚcontext_overflow)r  Úoverflow)ré  Útask_idÚtriggerÚoverflow_reason)Únew_ctxrë  r!  )r`  rÁ   rg   r'  rL  rV  )r  rV  u[   ðŸ”� Authentication failed and could not be refreshed â€” switching to fallback provider...r÷  rú   ÚcontinueÚfallthroughrV   )8Úagent.conversation_compressionr  rÜ   r  r  Úagent.model_metadatar  r`   r   r   r  Ú_OVERFLOW_REASONSr   rQ   rÂ   rg   rN   r{   r	  r%   rÁ   r&   r   Úlong_context_tierrì  rë   Ú_compress_contextr  rç  r‡  r	   r3   r*  re  Ú restart_with_compressed_messagesrù  Ú
rate_limitÚ_TRANSPORT_FAILURE_REASONSr   rH   Úmaxr   r’   Ú_fallback_indexÚ_fallback_chainrú  Ú!_pool_may_recover_from_rate_limitÚ_credential_poolrô  r�   r‘   rû  r  Úauth_failover_attemptedrº   r  )(rF   r›   r	  rð   r  r'  rƒ  r`  rÁ   rœ   rž   r  r    rè  r9  r:  rÞ  r  rˆ  r  r  r  r  r"  Ú_is_output_cap_errorr  rë  Úoriginal_lenÚ_is_transport_failureÚ_should_fallbackÚ_is_upstreamÚpool_may_recoverrV  r  r  r  r  r  r  rµ   s(   f&&f$$$$$dd$ddddd$$$             @@@@@@@r4   Úroute_classified_errorrC    s½  ÿÿ€ õ VßBÝBà*/Ð'Ø€OØ!%ÐØ#ÐÜ˜) ]°DÓ9€K÷	
÷ 	
ô 	
÷!÷ !ô 	˜IÓ&×iÐiÔ*RÐS\Ó*]ÐeiÐ*ið ð 	×ÑÔ.Ô.Ü˜Ð4°d×;Ò;ß$à×"Ñ"Ô$ÜØØyðPô	
ô 	�‰Ø×ÑÐ Ð 2°:×3DÑ3D×3JÑ3JÐ2Kð L<ð =ô	
ð 	×Ñ˜xÐ)=Ô>Ü#Ð$:À%Ç+Á+ÔNˆÙ˜¤-Ø˜o¨z¸8À[ÐRWØ˜¨°/À9ÈdÐT\Ð^bØ! 4ð1
ð ˜uó	#&ó 'ð 	'ð ×ÑœN×<Ñ<Ô<Ü(¨Ó/ˆØ Õ!ÐØÐ#;Ô;Ü˜x›=ˆLð .3×-DÑ-Dð ˜.Ù;¸LÐPU×P[ÑP[×PcÐPcÐ_cÔdØ)°:Èz×O`ÑO`×OfÑOfð .Eó .Ñ*ˆHÐ*ñ $JÈ%ÐQYÐ[oÓ#pÐ Ü�8‹}˜|Ô+¨wÔ9OÔ/OØ×/Ñ/ÜE×LÒLÜ 6Àôôô
 —
’
˜1”ð 7;Ð3Ø:>�Ô7Ù Ó(Ð(ð
 !×'Ñ'Ô+>Ñ>€Oð ×Ñ¤× 9Ñ 9Ô9ô 	1°Ô;Ø?Cð ð '×-Ñ-Ô1KÑKÐô ;ÄCÈÃMÐY^ÔpÐßÜ˜+Ô'HÓ'JÓKˆà	×	?Ð	?Ð7¸4Ð?÷ 	8ð 	8Ø!÷Uà6 k°QÑ&6÷Uð Uô �z ?°DÓ9×?Ð?¸R×DÑDÀ^ÓTÔ
Tð ÷ ˜E×1Ñ1´C¸×8MÑ8MÓ4NÔNð "×(Ñ(¬N×,NÑ,NÑNˆç!‰E¡s£u×'NÑ'NÈu×OeÑOeÓ'fð 	÷  Ø×+Ñ+Ô,BÀ:È|Ð]rÓ,sÔtÜ8BÀ=ÔRV×8WÒ8W�}×(Ñ(¨Ô4Ð]aˆHØ×+Ñ+°:×3DÑ3DÈxÐ+×XÒXÙ&Ó(Ð(ð
 	××ÐØ×.×.Ð.Ø×!Ñ!¤C¨×(=Ñ(=Ó$>Ô>à)-ˆÔ&Ø×'Ñ'ð0ô	
ð ×'Ñ'¨z×/@Ñ/@Ð'×AÒAÙ"Ó$Ð$÷
 	Ø�N‰N˜fÔ$Ø×Ñ¤×!:Ñ!:Ô:ß#Ü'¨¨yÈ×TÒTô ˜!˜[¨1�_Ó-ˆÙ˜
Ó#Ð#á�MÓ"Ð"r6   )zconnection lostzconnection resetzconnection closedznetwork connectionznetwork errorÚ
terminatedrV   )�r¯  Ú
__future__r   rÍ  r=   ru   rs   r*  Údataclassesr   Útypingr   r   r   r   r   r/  r	   Úagent.fast_moder
   r   r0  r   r   r„  r   r   rx  r   r   Úagent.message_sanitizationr   r   r   r   r   r   r   r   r   r   Úagent.thinking_timeout_guidancer   r   Úagent.vision_message_prepr   r½  r   r    r!   r"   r#   r$   r%   r&   Úagent.turn_retry_stater'   Úagent.turn_recovery_codexr(   r)   rÝ   r+   Úutilsr,   Ú	getLoggerrÂ   rC   rQ   ra   re   r   rˆ   r˜   r¯   r²   rÒ   rá   rî   r  r!  r/  r8  rB  rI  rN  rM  r…  rŽ  rš  r¢  r©  Ú	frozensetr5  rú  r=  r®  r°  rÀ  rÈ  rÓ  rÔ  rÙ  rá  r  r  r  rn  r  ræ  r  r)  r7  rS  r\  rj  r†  r'  r’  r˜  r¡  rh   r£  r·  rÃ  rÔ  rÏ  rÜ  r2  Úpayload_too_larger'  r1  rù  rÞ  rß  r6  rç  rì  rô  rü  r  rC  r2   r6   r4   Ú<module>rR     s"  ðñõ #ã Û Û Û 	Û Ý !ß 3Õ 3å \ß Oß ^ß ]ß E÷÷ ÷ ÷
 aÝ 9÷÷ ó õ 2ß ]Ý 0Ý 'à	×	Ò	Ð4Ó	5€õ?õPõBõ#õCõB	õõ>J&õZõZ'õz"õJ!õH2õjWðv ÐEØÐLØÐBðÐ õ(õVõ*Bõ
2õkõ ^&õBõõ&5õñ ˜N×5Ñ5°~×7YÑ7YÐ[i×[qÑ[qÐrÓs€õ
Kõ>ZðB
NÐW[÷ 
Nð  �N M°=ÐBTÐVcØÐ&Ð(:Ð<LðÐ õ$õ&õ
ð ×)Ñ)Ð+^Ø×#Ñ#Ð%cØ×(Ñ(Ð*eà×"Ñ"Ð$mðÐ õ	ðAð ÷	AðHÐ ðLð 13÷	Lð^<;ð ÷<;õ~õ,ðB Ð OØÐ!FðÐ õNõ@õFEõ Qô%˜	ô %õ=õ 1õh#WõL0ð* ÷!ð !ó ð!ñ* Ø×$Ñ$ n×&FÒ&FÈ×HgÒHgðó Ð ñ  Ø×Ñ˜~×5Ñ5°~×7YÑ7Yð!ó Ð ñ '¨×(>Ò(>À×@YÒ@YÐ'ZÓ[Ð ð  Ð õõ0Gõ&H÷$"÷Jk#r6   