+
    jHàj•  ã                  óÆ   € R t ^ RIHt ^ RIHtHtHt ^ RIHt ^ RIH	t	H
t
Ht RtRtRtRtR]]3R]]33tR	tR
 R ltR R ltR R ltR R ltR R ltRRR/R R llltR# )u½  Memory status rollup for ``/api/status``.

Read side for signals the gateway already persists: the 30s ``state/gateway.heartbeat``
(RSS + MemAvailable/MemTotal + swap) and the lifecycle sentinel's ``suspected_oom``
flag â€” two small file reads, no IPC.  ``/api/status`` is unauthenticated, so only
coarse numbers (MB), enums and booleans.  A missing/corrupt file degrades to
``pressure="unknown"`` rather than raising into the status endpoint.
)Úannotations)ÚdatetimeÚtimezoneÚUTC)ÚPath)ÚAnyÚDictÚOptionalgš™™™™™©?g333333Ã?ÚcriticalÚelevatedg     Àb@c               ó    € V ^8„  d   QhRRRR/# )é   Úvaluer   ÚreturnúOptional[int]© )Úformats   "Ú:/home/ubuntu/.hermes/hermes-agent/gateway/memory_status.pyÚ__annotate__r   !   s   € ÷ dñ d�sð d˜}ñ dó    c                óp   € \        V \        4      '       d    \        V \        4      '       g
   V ^ 8¼  d   V # R# )zGReturn *value* if it is a non-negative int (bools rejected), else None.N)Ú
isinstanceÚintÚbool)r   s   &r   Ú_nonneg_intr   !   s-   € ä˜u¤c×*Ò*´:¸eÄT×3JÒ3JÈuÐXYÌzˆ5ÐcÐ_cÐcr   c               ó    € V ^8„  d   QhRRRR/# )r   Úkibr   r   r   r   )r   s   "r   r   r   &   s   € ÷ =ñ =ˆSð =�]ñ =r   c                ó2   € \        V 4      f   R # V R,          # )Ni   )r   )r   s   &r   Ú_mbr   &   s   € Ü˜sÓ#Ò+ˆ4Ð<°¸µÐ<r   c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   úOptional[datetime]r   )r   s   "r   r   r   *   s   € ÷ bñ b�cð bÐ0ñ br   c                óè   €  \        V \        4      '       d   V '       d   \        P                  ! V 4      MR pTe%   TP
                  f   TP                  \        R7      # T#   \         d     R # i ; i)N)Útzinfo)r   Ústrr   ÚfromisoformatÚ
ValueErrorr"   Úreplacer   )r   Úparseds   & r   Ú
_parse_isor(   *   sc   € ðÜ2<¸UÄC×2HÒ2HÏU”×'Ò'¨Ô.ÐX\ˆð *0Ò);ÀÇÁÒ@Uˆ6�>‰>¤ˆ>Ó%ÐaÐ[aÐaøô ô Úðús   ‚A"  A" Á"A1Á0A1c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úavailable_kibr   Ú	total_kibr   r#   r   )r   s   "r   r   r   2   s!   € ÷ 
ñ 
 Sð 
°Sð 
¸Sñ 
r   c                ó¬   € \        V 4      \        V4      r2Vf   R# V'       d	   W#,          MRp\         F  w  rVpW&8  g   Vf   K  WG8  g   K  Vu # 	  R# )u    ``ok``/``elevated``/``critical`` from MemAvailable/MemTotal; ``unknown`` when the
sample is missing/malformed â€” "could not read it" must never read as "fine".NÚunknownÚok)r   Ú_PRESSURE_TIERS)r*   r+   Ú	availableÚtotalÚfractionÚlevelÚ	kib_floorÚ
frac_floors   &&      r   Úclassify_pressurer6   2   sS   € ô # =Ó1´;¸yÓ3IˆuØÒÙß$)ˆyÖ ¨t€Hß(7Ñ$ˆ˜*ØÔ  XÔ%9¸hÖ>SØŠLñ )8ñ r   c               ó    € V ^8„  d   QhRRRR/# )r   ÚhomeúOptional[Path]r   Útupler   )r   s   "r   r   r   ?   s   € ÷ ñ ˜Nð ¨uñ r   c                ó~   €  ^ RI HpHp ^ RIHp V! V! V 4      4      V! V! V 4      4      3#   \
         d    Ru # i ; i)z?``(heartbeat, sentinel)`` dicts, each ``None`` when unreadable.)Ú
_read_jsonÚget_lifecycle_sentinel_path)Úget_loop_heartbeat_path)NN)Úgateway.lifecycle_ledgerr<   r=   Úgateway.shutdown_watchdogr>   Ú	Exception)r8   r<   r=   r>   s   &   r   Ú_read_state_filesrB   ?   sD   € ðßTÝEáÑ1°$Ó7Ó8¹*ÑE`ÐaeÓEfÓ:gÐgÐgøÜô ØÒðús   ‚), ¬<»<NÚnowc               ó$   € V ^8„  d   QhRRRRRR/# )r   r8   r9   rC   r    r   zdict[str, Any]r   )r   s   "r   r   r   J   s(   € ÷ &ñ &Ø
ð&ð 
ð&ð ñ	&r   c               ó:  € T;'       g    \         P                  ! \        4      pRRRRRRRRRRRRR	R
RR
RR/	p\        V 4      w  rEV'       dÖ   \	        VP                  R4      4      VP                  R4      rv\        V\        4      '       d–   R F!  w  r‰\        VP                  V	4      4      W8&   K#  	  Vek   VP                  4       VR&   ^ W&,
          P                  4       u;8:  d   \        8:  d1   M M-\        VP                  R4      VP                  R4      4      VR&   V'       dq   \        VP                  R4      4      VR	&   \        VP                  R4      4      VR&   VP                  R4      p
\        V
\        4      '       d   V
'       d   T
MRVR&   V# )uæ   ``memory`` block for ``/api/status``; ``home`` scopes to a profile (``None`` =
active), ``now`` is injectable.  Never raises â€” a down gateway or corrupt files
yield ``pressure="unknown"`` plus whatever fields could be recovered.Úpressurer-   Úgateway_rss_mbNÚsystem_total_mbÚsystem_available_mbÚswap_used_mbÚ
sampled_atÚlast_boot_uncleanFÚlast_boot_suspected_oomÚboot_idÚ
updated_atÚmemÚmem_total_kibÚmem_available_kibÚprior_unclean_exitÚprior_suspected_oomÚ
started_at))rG   Úrss_kib)rH   rQ   )rI   rR   )rJ   Úswap_used_kib)r   rC   r   rB   r(   Úgetr   Údictr   Ú	isoformatÚtotal_secondsÚ_HEARTBEAT_FRESH_TTL_Sr6   r   r#   )r8   rC   ÚmomentÚstatusÚ	heartbeatÚsentinelrK   rP   ÚdstÚsrcrU   s   &$         r   Úcollect_memory_statusrc   J   sw  € ð ×%Ð%”H—L’L¤Ó%€Fà�IÐ/°Ð7HÈ$ÐPeÐgkØ˜˜l¨DÐ2EÀuÐNgÐinð 	�4ð€Fô ,¨DÓ1Ñ€IßÜ$ Y§]¡]°<Ó%@ÓAÀ9Ç=Á=ÐQVÓCW�CÜ�cœ4× Ò ón‘�ä! #§'¡'¨#£,Ó/�“ñnð Ò%Ø'1×';Ñ';Ó'=��|Ñ$ð ˜Õ,×;Ñ;Ó=ÖWÔAW×WÜ):¸3¿7¹7ÐCVÓ;WÐY\×Y`ÑY`ÐapÓYqÓ)r�F˜:Ñ&çÜ&*¨8¯<©<Ð8LÓ+MÓ&NˆÐ"Ñ#Ü,0°·±Ð>SÓ1TÓ,UˆÐ(Ñ)Ø—\‘\ ,Ó/ˆ
Ü*4°ZÄ×*EÒ*EÏ*™JÐZ^ˆˆyÑà€Mr   i   i   )N)Ú__doc__Ú
__future__r   r   r   r   Úpathlibr   Útypingr   r   r	   Ú_CRITICAL_AVAILABLE_KIBÚ_CRITICAL_AVAILABLE_FRACTIONÚ_ELEVATED_AVAILABLE_KIBÚ_ELEVATED_AVAILABLE_FRACTIONr/   r\   r   r   r(   r6   rB   rc   r   r   r   Ú<module>rl      sŽ   ðñõ #ç ,Ñ ,Ý ß &Ñ &ð
 $Ð Ø#Ð Ø$Ð Ø#Ð àÐ(Ð*FÐGØÐ(Ð*FÐGð€ð Ð õdõ
=õbõ
õñ&ð #÷&ò &r   