+
    jHàjñ
  ã                  ór   € R t ^ RIHt ^ RIt^ RIt^ RIHtHt ^ RIH	t
 R R ltR R ltR	RR
R/R R lltR# )zûScoped-lock ownership and release, split from :mod:`gateway.status` (acquire stays there).

Helpers read status through the module at call time, preserving its patch seams.
The acquire path imports the ownership check lazily to avoid an import cycle.
)ÚannotationsN)ÚAnyÚOptional)Ústatusc               ó$   € V ^8„  d   QhRRRRRR/# )é   Úexistingzdict[str, Any]Úexisting_pidúOptional[int]ÚreturnÚbool© )Úformats   "Ú@/home/ubuntu/.hermes/hermes-agent/gateway/status_scoped_locks.pyÚ__annotate__r      s"   € ÷ 5ñ 5¨>ð 5Èð 5Ð[_ñ 5ó    c                ó>  € Ve   \         P                  ! V4      '       g   R# V P                  R4      p\         P                  ! V4      p\         P                  ! W#4      '       d   R# V P                  R4      p\        V\        4      ;'       d    VP                  R4      R8H  pV'       g]   \         P                  ! V4      '       gA   \         P                  ! V4      e   R# RW#39   d   \         P                  ! V 4      '       g   R# \         P                  ! V4      # )zçRecover dead/reused/stopped owners. Gateway locks also validate gateway argv.

An explicitly process-owned reservation can belong to a dashboard or setup
worker. Unknown identity stays reserved instead of guessing that it is dead.
NTÚ
start_timeÚmetadataÚ
owner_kindÚprocess)Ú_statusÚ_pid_existsÚgetÚ_get_process_start_timeÚ_start_times_conflictÚ
isinstanceÚdictÚ_looks_like_gateway_processÚ_read_process_cmdlineÚ_record_looks_like_gatewayÚ_process_is_stopped)r   r	   Úrecorded_startÚcurrent_startr   Úprocess_owners   &&    r   Ú_scoped_lock_record_is_staler%      s×   € ð Ò¤7×#6Ò#6°|×#DÒ#DÙØ—\‘\ ,Ó/€NÜ×3Ò3°LÓA€MÜ×$Ò$ ^×CÒCÙØ�|‰|˜JÓ'€HÜ˜x¬Ó.×ZÐZ°8·<±<ÀÓ3MÐQZÑ3Z€Mß¤×!DÒ!DÀ\×!RÒ!RÜ×(Ò(¨Ó6ÒBÙØ�NÐ2Ô2¼7×;]Ò;]Ð^f×;gÒ;gÙÜ×&Ò& |Ó4Ð4r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚscopeÚstrÚidentityr   ÚNoner   )r   s   "r   r   r   %   s!   € ÷ +ñ +˜sð +¨cð +°dñ +r   c                óð   € \         P                  ! W4      p\         P                  ! V4      ;'       g    / P                  R4      \        P
                  ! 4       8X  d   \         P                  ! V4       R# R# )z€Release a scope lock owned by this PID. No start_time equality check: on-disk null vs a live
fingerprint would wedge reconnects.ÚpidN)r   Ú_get_scope_lock_pathÚ_read_json_filer   ÚosÚgetpidÚ_unlink_quietly)r'   r)   Ú	lock_paths   && r   Úrelease_scoped_lockr3   %   sT   € ô ×,Ò,¨UÓ=€IÜ×Ò 	Ó*×0Ð0¨b×5Ñ5°eÓ<ÄÇ	Â	ÃÔKÜ×Ò 	Ö*ñ Lr   Ú	owner_pidÚowner_start_timec               ó$   € V ^8„  d   QhRRRRRR/# )r   r4   r
   r5   r   Úintr   )r   s   "r   r   r   -   s$   € ÷ ñ ØðØ:Gðàñr   c                óþ  € \         P                  ! 4       pVP                  4       '       g   ^ # ^ pVP                  R4       F¤  pV eX   \         P                  ! V4      ;'       g    / p\         P
                  ! V4      V 8w  g   Ve   VP                  R4      V8w  d   K^  \        P                  ! \        4      ;_uu_ 4        VP                  RR7       V^,          pRRR4       K¦  	  V#   + '       g   i     K»  ; i)z¬Remove scoped lock files (--replace cleanup); returns the count removed. With ``owner_pid``
only that gateway's records go (``owner_start_time`` narrows against PID reuse).z*.lockNr   T)Ú
missing_ok)r   Ú_get_lock_dirÚexistsÚglobr.   Ú_pid_from_recordr   Ú
contextlibÚsuppressÚOSErrorÚunlink)r4   r5   Úlock_dirÚremovedÚ	lock_fileÚrecords   $$    r   Úrelease_all_scoped_locksrF   -   sË   € ô
 ×$Ò$Ó&€HØ�?‰?×ÒÙØ€GØ—]‘] 8Ö,ˆ	ØÒ Ü×,Ò,¨YÓ7×=Ð=¸2ˆFÜ×'Ò'¨Ó/°9Ô<Ø Ò,°·±¸LÓ1IÐM]Ô1]áÜ× Ò ¤×)Õ)Ø×Ñ¨ÐÔ-Ø�q�LˆG÷ *Ñ)ñ -ð €N÷ *×)Ð)ús   ÃC+Ã+C<)Ú__doc__Ú
__future__r   r>   r/   Útypingr   r   Úgatewayr   r   r%   r3   rF   r   r   r   Ú<module>rK      s?   ðñõ
 #ã Û 	ß  å %õ5õ,+ðØ"&ðØJN÷ñ r   