+
    jHàj?  ã                   ó˜   € R t ^ RIt^ RIt^ RIt^ RIHt ]P                  ! ]4      t]P                  ! 4       t
R R ltR R ltR R ltR# )	a8  Persisted per-session restart-failure counters (``.restart_failure_counts``, #7536).

Every load/mutate/save of the file runs under one lock: session completions clear their
counter from worker threads concurrently, and an unserialized pair rewrites a stale snapshot
that resurrects the other session's counter.
N)ÚPathc                ó0   € V ^8„  d   QhR\         R\        /# )é   ÚpathÚreturn)r   Údict)Úformats   "Ú>/home/ubuntu/.hermes/hermes-agent/gateway/stuck_loop_counts.pyÚ__annotate__r
      s   € ÷ 6ñ 6”tð 6¤ñ 6ó    c                ó¶   €  \         P                  ! V P                  RR7      4      p\        T\        4      '       d   T# / #   \        \        3 d    / u # i ; i)zQParsed counters, or {} when the file is missing, unreadable or not a JSON object.z	utf-8-sig)Úencoding)ÚjsonÚloadsÚ	read_textÚOSErrorÚ
ValueErrorÚ
isinstancer   )r   Úcountss   & r	   Ú_read_countsr      sT   € ðÜ—’˜DŸN™N°K˜NÓ@ÓAˆô   ¬×-Ò-ˆ6Ð5°2Ð5øô ”ZÐ ô ØŠ	ðús   ‚&A ÁAÁAc                ó4   € V ^8„  d   QhR\         R\        RR/# )r   r   Úactive_session_keysr   N)r   Úset)r   s   "r	   r
   r
      s&   € ÷ `ñ `¬4ð `Äcð `Èdñ `r   c                ó>  € ^ RI Hp \        ;_uu_ 4        \        V 4      p T! Y Uu/ uF  qDVP	                  V^ 4      ^,           bK  	  upRR7       RRR4       R# u upi   \
         d    \        P                  RT RR7        L4i ; i  + '       g   i     R# ; i)z\Increment the counters of sessions active at shutdown; drop the rest (their loop is broken).©Úatomic_json_writeN©Úindentz.Could not write restart-failure counters to %sT©Úexc_info)Úutilsr   Ú_COUNTS_LOCKr   ÚgetÚ	ExceptionÚloggerÚdebug)r   r   r   r   Úkeys   &&   r	   Ú increment_restart_failure_countsr'      sˆ   € å'ß	ŽÜ˜dÓ#ˆð	`Ù˜dÐL_Ó$`ÑL_ÀS¨&¯*©*°S¸!Ó*<¸qÕ*@Ò%@ÑL_Ñ$`ÐimÕn÷ 
‰ùò %aøÜô 	`Ü�L‰LÐIÈ4ÐZ^ˆLÖ_ð	`ú÷	 
�ˆús9   •B¢A"¨"AÁ
	A"ÁA"Á"#BÂBÂBÂBÂB	c                ó4   € V ^8„  d   QhR\         R\        RR/# )r   r   Úsession_keyr   N)r   Ústr)r   s   "r	   r
   r
   '   s&   € ÷ _ñ _¤dð _¼ð _Àñ _r   c           	     óD  € ^ RI Hp \        ;_uu_ 4        \        V 4      pW9  d    RRR4       R# W1  V'       d   V! WRR7       MV P	                  RR7        RRR4       R#   \
         d    \        P                  RT RR7        L/i ; i  + '       g   i     R# ; i)z´Drop a completed session's counter; removes the file once no counter is left.

Blocking (``atomic_json_write`` fsyncs): callers on the event loop run it via ``asyncio.to_thread``.
r   Nr   T)Ú
missing_okz-Could not clear restart-failure counter in %sr   )r    r   r!   r   Úunlinkr#   r$   r%   )r   r)   r   r   s   &&  r	   Úclear_restart_failure_countr.   '   s‡   € õ
 (ß	ŽÜ˜dÓ#ˆØÔ$Ø÷ 
‰ð Ðð	_ßÙ! $°tÖ<à—‘ t�Õ,÷ 
‰øô ô 	_Ü�L‰LÐHÈ$ÐY]ˆLÖ^ð	_ú÷ 
�ˆús?   •B²BµA%ÁBÁA%ÁBÁ%#BÂBÂ
BÂBÂB	)Ú__doc__r   ÚloggingÚ	threadingÚpathlibr   Ú	getLoggerÚ__name__r$   ÚLockr!   r   r'   r.   © r   r	   Ú<module>r7      sG   ðñó Û Û Ý à	×	Ò	˜8Ó	$€ð �~Š~Ó€õ6õ`÷_r   