+
    iHàjY  ã                   ó¬   € R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ]P                  ! ]4      t	]P                  ! 4       tRtR	R R lltR t]R R l4       tR# )
aN  ``context_length_cache.yaml`` writes and their cross-process serialization.

Every agent (CLI, gateway sessions, cron jobs, subagents) persists probed context windows with a
load -> mutate -> write cycle; unserialized, one writer rewrites a stale snapshot and drops the
other's entry (or resurrects an invalidated, too-large length).
N)Úatomic_yaml_writeg      @c                ód   € V ^8„  d   QhR\         \        \        3,          R\         R,          RR/# )é   ÚcacheÚbedrock_confirmedNÚreturn)ÚdictÚstrÚint)Úformats   "Ú?/home/ubuntu/.hermes/hermes-agent/agent/model_metadata_cache.pyÚ__annotate__r      s.   € ÷ ;ñ ;¤¤S¬# X¥ð ;Ä4È$Å;ð ;ÐZ^ñ ;ó    c                óT   € ^ RI Hp RV /pV'       d   WR&   \        V! 4       V4       R# )z¡Atomic write (a truncating write killed mid-dump leaves a partial file that
_load_context_cache() swallows as {}, wiping EVERY cached length). Raises on failure.©Ú_get_context_cache_pathÚcontext_lengthsÚbedrock_confirmed_v1N)Úagent.model_metadatar   r   )r   r   r   Údocuments   &&  r   Ú_write_context_cacher      s+   € õ =Ø! 5Ð)€HßØ+<Ð'Ñ(ÜÑ-Ó/°Ö:r   c                óF   a € \         P                  ! S 4      V 3R l4       pV# )z¼Run ``fn``'s load -> mutate -> write cycle under the cache file's cross-process lock.

The cache is best-effort: when the lock cannot be taken in time the update is skipped, never raised.
c                  ó²  <€ ^ RI Hp ^ RIHp V! 4       pVP	                  VP
                  R,           4      p\        P                  ! 4       ;_uu_ 4       p VP                  V! V\        \        RV R24      4       S! T / TB uuR	R	R	4       #   \        \        3 d$    \        P                  RRR7        R	R	R	4       R	# i ; i  + '       g   i     R	# ; i)
é    r   )Ú
_file_lockz.lockz5Timed out waiting for the context length cache lock (Ú)z$Skipping context length cache updateT©Úexc_infoN)r   r   Úhermes_cli.authr   Ú	with_nameÚnameÚ
contextlibÚ	ExitStackÚenter_contextÚ_CONTEXT_CACHE_LOCK_HOLDERÚ#_CONTEXT_CACHE_LOCK_TIMEOUT_SECONDSÚOSErrorÚTimeoutErrorÚloggerÚdebug)ÚargsÚkwargsr   r   ÚpathÚ	lock_pathÚstackÚfns   *,     €r   ÚwrapperÚ%locked_context_cache.<locals>.wrapper$   sÀ   ø€ å@Ý.Ù&Ó(ˆØ—N‘N 4§9¡9¨wÕ#6Ó7ˆ	Ü×!Ò!×#Ô# uðØ×#Ñ#¡JØÔ9Ô;^ØKÈIÈ;ÐVWÐXó%Zô [ñ �tÐ&˜vÑ&÷ $Ò#øô
 œ\Ð*ô Ü—‘ÐCÈd�ÔSØ÷ $Ñ#ð
ú÷ $×#Ð#ús0   ÁCÁ&BÁ<CÂ(CÂ6CÃCÃCÃC	)Ú	functoolsÚwraps)r/   r0   s   f r   Úlocked_context_cacher4      s'   ø€ ô
 ‡_‚_�RÓô'ó ð'ð €Nr   c                óJ   € V ^8„  d   QhR\         \        ,          R\        RR/# )r   Ú
stale_keysÚlabelr   N)Úsetr	   )r   s   "r   r   r   7   s*   € ÷ añ a¬¬C­ð a¼ð aÀñ ar   c                ó  aa€ ^ RI Hp V! 4       pVP                  R4      ;'       g    / oVP                  R4      ;'       g    / o\        S\        4      '       d   SM/ o\
        ;QJ d     VV3R lV  4       F  '       g   K   RM	  RM! VV3R lV  4       4      '       g   R# V  F'  pSP                  VR4       SP                  VR4       K)  	   \        SS4       R#   \         d    \        P                  RTRR	7        R# i ; i)
z»Remove every key shape of one cached entry (and its Bedrock provenance) under the cache lock.

Only the file update is locked: callers evict their in-process probe caches unconditionally.)Ú_load_context_cache_documentr   r   c              3   óF   <"  € T F  qS9   ;'       g    VS9   x € K  	  R # 5i©N© )Ú.0Úkr   Ú	confirmeds   & €€r   Ú	<genexpr>Ú*drop_context_cache_rows.<locals>.<genexpr>@   s"   øé € Ð@±Z°�E‰z×+Ð+˜Q )™^Ô+³Zùs   ƒ!“!TFNz2Failed to invalidate context length cache entry %sr   )r   r:   ÚgetÚ
isinstancer   ÚanyÚpopr   Ú	Exceptionr(   r)   )r6   r7   r:   r   r?   r   r@   s   &&   @@r   Údrop_context_cache_rowsrH   6   sÑ   ù€ õ
 BÙ+Ó-€HØ�L‰LÐ*Ó+×1Ð1¨r€EØ—‘Ð3Ó4×:Ð:¸€IÜ'¨	´4×8Ò8‘	¸b€Iß‹3Õ@±ZÓ@�3�3Š3Õ@±ZÓ@×@Ò@ÙÛˆØ�	‰	�!�TÔØ�‰�a˜Öñ ðaÜ˜U IÖ.øÜô aÜ�‰ÐIÈ5Ð[_ˆ×`ðaús   ÃC  Ã #DÄDr<   )Ú__doc__r!   r2   ÚloggingÚ	threadingÚutilsr   Ú	getLoggerÚ__name__r(   Úlocalr$   r%   r   r4   rH   r=   r   r   Ú<module>rP      s^   ðñó Û Û Û å #à	×	Ò	˜8Ó	$€à&Ÿ_š_Ó.Ð Ø&)Ð #÷;òð. ôaó òar   