+
    lHàjã  ã                  óø  a € 0 t $ R t^ RIHt ^ RIt^ RIHt RtRtRt	Rt
RtR	tR
tRtRtRtRtRtRtRt]! ]]]	]
]]]]]]]]]]04      tRt]! ]]	]]04      tR R ltRtRtRtR R ltRt];QJ d9    . R R]3R] R2]3] R2]3] R 2]3] R!2]3R"]3R#]3R$]33 4       F  NK  	  5M2! R R]3R] R2]3] R2]3] R 2]3] R!2]3R"]3R#]3R$]33 4       4      t R%]!R&&   R' R( lt"R) R* lt#R+ R, lt$R- R. lt%R# )/u  Typed failure-reason codes for bot turns and relay replies.

A closed vocabulary of machine-readable reason codes carried ALONGSIDE the
free-text ``error`` fields (additive â€” old consumers keep working). Platform-side
codes are assigned by the transport/relay layer; agent-side codes are derived
from raw agent/provider error text via ``classify_agent_error``. Classifier
precedence is the order of ``_RULES``: auth outranks quota by design â€” real
provider 401 bodies (e.g. Anthropic) say "invalid, blocked or out of funds".
)ÚannotationsN)ÚAnyÚruntime_offlineÚqueued_expiredÚdelivery_timeoutÚagent_blockedÚ	cancelledÚprovider_auth_or_accessÚprovider_quota_limitÚprovider_rate_limitÚprovider_server_errorÚcontext_overflowÚmissing_configÚmodel_unavailableÚtarget_scope_unresolvedÚunknownÚruntime_coordination_requiredc               ó    € V ^8„  d   QhRRRR/# )é   ÚreasonÚstrÚreturnÚbool© )Úformats   "Ú>/home/ubuntu/.hermes/hermes-agent/tools/bot_failure_reasons.pyÚ__annotate__r   3   s   € ÷ $ñ $˜cð $ dñ $ó    c                ó   € V \         9   # ©N)ÚAUTO_RETRYABLE©r   s   &r   Úis_auto_retryabler"   3   s   € Ø”^Ñ#Ð#r   ÚresumeÚcompress_then_resumeÚnonec               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   r   )r   s   "r   r   r   B   s   € ÷ ñ ˜ð  ñ r   c                óR   € V \         9   d   \        # V \        8X  d   \        # \        # )zEMap a failure reason to the bot-turn retry action (see policy above).)r    ÚRETRY_RESUMEÚCONTEXT_OVERFLOWÚRETRY_COMPRESS_THEN_RESUMEÚ
RETRY_NONEr!   s   &r   Úretry_actionr,   B   s%   € à”ÔÜÐØÔ!Ô!Ü)Ð)ÜÐr   z3(?:error code:?\s*|status(?:\s*code)?:?\s*|http\s*)c              #  ót   "  € T F.  w  r\         P                  ! V\         P                  4      V3x € K0  	  R # 5ir   )ÚreÚcompileÚ
IGNORECASE)Ú.0ÚpatÚcodes   &  r   Ú	<genexpr>r4   N   s1   é € ð 8ñ‰	ˆô ‡Z‚Z�”R—]‘]Ó# TÕ*óùs   ‚68zycould not read this profile's [^(]+\(an internal profile-scoping bug|served_profile_child_env\(inherit_credentials=true\)z%authentication_error|invalid api key|z(?:401|403)\bz 402\b|out of funds|quota|balancez429\b|rate.?limitz$5\d{2}\b|server[ _]?error|overloadedz/context length|context_overflow|maximum contextz9no llm provider configured|missing config|no access tokenz2model .*(not found|does not exist)|model_not_foundz'tuple[tuple[re.Pattern[str], str], ...]Ú_RULESc               ó$   € V ^8„  d   QhRRRRRR/# )r   Ústdoutz
str | NoneÚstderrr   r   r   )r   s   "r   r   r   d   s&   € ÷ 	Yñ 	Y˜jð 	Y°*ð 	YÀñ 	Yr   c                ó4   € RP                  R W3 4       4      # )u5  The error text of a failed ``hermes â€¦ -Q`` delivery turn: both streams, in the order the CLI
writes them. The provider prose is the turn's final_response and lands on STDOUT; stderr carries
session bookkeeping (``session_id: â€¦``) on every run, so ``stderr or stdout`` only ever saw the
banner and every transient failure classified as ``unknown``.

The in-process lanes hand over the same two pieces of prose as an agent result dict
(``error`` + ``failure_reason``); ``result_retry_action`` joins them here too, so one classifier
sees every lane's failure text.Ú
c              3  ó„   "  € T F6  q'       g   K  VP                  4       '       g   K$  VP                  4       x € K8  	  R # 5ir   )Ústrip)r1   Útexts   & r   r4   Ú$turn_failure_text.<locals>.<genexpr>m   s(   é € ÐXÑ.> dÃ$”\È4Ï:É:Ï<”\�T—Z‘Z—\�\Ó.>ùs   ‚	A �A ¨A )Újoin)r7   r8   s   &&r   Úturn_failure_textr@   d   s   € ð �9‰9ÑX¨vÑ.>ÓXÓXÐXr   c               ó    € V ^8„  d   QhRRRR/# )r   Úresultr   r   r   r   )r   s   "r   r   r   p   s   € ÷ Oñ O ð O¨ñ Or   c           
     óà   € \        V \        4      '       d   V P                  R4      '       g   \        # \	        \        \        V P                  R4      V P                  R4      4      4      4      # )u~  The retry action for a finished IN-PROCESS turn (an ``_run_agent`` result dict).

The transport-agnostic twin of the child-process lanes' ``retry_action(classify_agent_error(
turn_failure_text(stdout, stderr)))``: same policy, the failure text just arrives as result fields
instead of two streams â€” ``error`` carries the raw provider summary (status codes included) and
``failure_reason`` the turn loop's own typed verdict, which is what names an overflow the copy only
describes in prose. ``RETRY_NONE`` for anything that did not fail (and for a non-dict result), so a
successful turn whose text happens to mention 429 is never re-run.ÚfailedÚerrorÚfailure_reason)Ú
isinstanceÚdictÚgetr+   r,   Úclassify_agent_errorr@   )rB   s   &r   Úresult_retry_actionrK   p   sZ   € ô �fœd×#Ò#¨6¯:©:°h×+?Ò+?ÜÐÜÔ,Ü˜&Ÿ*™* WÓ-¨v¯z©zÐ:JÓ/KÓLóNó Oð Or   c               ó    € V ^8„  d   QhRRRR/# )r   r=   r   r   r   )r   s   "r   r   r      s   € ÷ ñ ˜sð  sñ r   c                ó¸   € \        T ;'       g    R4      pVP                  4       '       d+   \         F   w  r#VP                  V4      '       g   K  Vu # 	  \        # )z]Map raw agent/provider error text to a closed reason code (``unknown`` when unmatched/empty).Ú )r   r<   r5   ÚsearchÚUNKNOWN)r=   ÚrawÚpatternr3   s   &   r   rJ   rJ      sC   € ä
ˆd�jˆj�b‹/€CØ
‡y�y‡{‚{ß#‰MˆGØ�~‰~˜c×"Ô"Ø’ñ $ô €Nr   c               ó    € V ^8„  d   QhRRRR/# )r   rE   ÚBaseExceptionr   r   r   )r   s   "r   r   r   ‰   s   € ÷ ,ñ , =ð ,°Sñ ,r   c                ó®   € \        \        V RR4      ;'       g    R4      P                  4       pVR8X  g   V\        9   d   V# \	        \        V 4      4      # )a  The typed reason for a delivery refusal, kept inside the documented vocabulary.

An exception's own ``reason`` is trusted only when it names a real code: ``TurnBusyError``
carries ``target_busy``, but ``reason`` is also a stdlib attribute on ``ssl.SSLError`` and
``urllib.error.URLError``, and forwarding one of those would put free text where consumers
expect a closed set. Anything else is classified like every other failure. Shared by the
relay lane (``bot_relay.deliver``) and the local runner (``bot_mode_dm --run-delivery``).
r   rN   Útarget_busy)r   Úgetattrr<   ÚALL_REASONSrJ   )rE   Úsupplieds   & r   Údelivery_failure_reasonrZ   ‰   sK   € ô ”7˜5 (¨BÓ/×5Ð5°2Ó6×<Ñ<Ó>€HØ�=Ô  H´Ô$;ØˆÜ¤ E£
Ó+Ð+r   )&Ú__conditional_annotations__Ú__doc__Ú
__future__r   r.   Útypingr   ÚRUNTIME_OFFLINEÚQUEUED_EXPIREDÚDELIVERY_TIMEOUTÚAGENT_BLOCKEDÚ	CANCELLEDÚPROVIDER_AUTH_OR_ACCESSÚPROVIDER_QUOTA_LIMITÚPROVIDER_RATE_LIMITÚPROVIDER_SERVER_ERRORr)   ÚMISSING_CONFIGÚMODEL_UNAVAILABLEÚTARGET_SCOPE_UNRESOLVEDrP   Ú	frozensetrX   ÚHELD_NOT_SENTr    r"   r(   r*   r+   r,   Ú_STATUSÚtupler5   Ú__annotations__r@   rK   rJ   rZ   )r[   s   @r   Ú<module>rp      s  øðôõ #ã 	Ý ð $€Ø!€Ø%Ð Ø€Ø€	ð 4Ð Ø-Ð Ø+Ð Ø/Ð Ø%Ð Ø!€Ø'Ð à3Ð Ø
€áØ�^Ð%5°}ÀiØÐ1Ð3FØÐ+¨^Ð=NØ˜Wð	ó €ð 0€ñ ˜OÐ-=Ð?RÐTiÐjÓk€õ$ð €Ø3Ð Ø€
õð A€÷ 38°%ñ 8ð
BØCZð	\à1°'°¸-Ð	HÐJaÐbØˆIÐ5Ð	6Ð8LÐMØˆIÐ&Ð	'Ð)<Ð=ð ˆIÐ;Ð	<Ð>SÐTØ	;Ð=MÐNØ	EÀ~ÐVØ	>Ð@QÐRñó8·%±%ñ 8ð
BØCZð	\à1°'°¸-Ð	HÐJaÐbØˆIÐ5Ð	6Ð8LÐMØˆIÐ&Ð	'Ð)<Ð=ð ˆIÐ;Ð	<Ð>SÐTØ	;Ð=MÐNØ	EÀ~ÐVØ	>Ð@QÐRñó8ó 3€Ð/ó õ,	YõOõ÷,r   