+
    jHàjœ  ã                  ór   € R t ^ RIHt ^ RIt^ RIt^ RIHtHtHt ]P                  ! R4      t
 ! R R4      tR# )zËSession finalize dispatch and delivery of plugin ``on_session_finalize`` messages for GatewayRunner.

Split out of ``gateway/run_shutdown.py``; bound onto ``GatewayRunner`` via ``GatewayShutdownMixin``.
)ÚannotationsN)ÚAnyÚListÚOptionalzgateway.runc                  óZ   € ] tR t^tRtRRRR/R R lltRR/R R lltRR/R	 R
 lltRtR# )ÚGatewaySessionEndMixinzWBounded off-loop ``finalize_session`` plus out-of-band delivery of what plugins return.ÚsourceNÚsession_keyc               ó(   € V ^8„  d   QhRRRRRRRR/# )	é   Úmessagesú	list[str]r   r   r	   úOptional[str]ÚreturnÚNone© )Úformats   "ÚE/home/ubuntu/.hermes/hermes-agent/gateway/run_shutdown_session_end.pyÚ__annotate__Ú#GatewaySessionEndMixin.__annotate__   s2   € ÷ ]ñ ]Ø!ð]Ø.1ð]ØGTð]à	ñ]ó    c          
   ƒ  óæ  "  € V'       g   R# Vf5   V'       d-   V P                  V4      G Rj  x€L
 pV'       d
   V^ ,          MRpVe   V P                  V4      MRpVf   \        P                  RV4       R# V P	                  V4      pV F\  pT P                  T\        VP                  4      YrP                  '       d   VP                  P                  MRRVR7      G Rj  x€L
  K^  	  R#  L¿ L5i)u´   Send plugin ``on_session_finalize`` text to the chat that owns the session â€” a plain adapter send,
never an agent turn. No resolvable chat (or no adapter) â†’ logged and dropped.Nz=Session-end plugin message(s) dropped: no chat for session %sÚ z6Failed to send session-end plugin message to %s:%s: %s)Úmetadata)
Ú_shutdown_notification_targetÚ_delivery_adapter_forÚloggerÚinfoÚ_thread_metadata_for_sourceÚ_send_notice_loggedÚstrÚchat_idÚplatformÚvalue)Úselfr   r   r	   ÚtargetÚadapterr   Úmessages   &&$$    r   Ú_deliver_session_end_messagesÚ4GatewaySessionEndMixin._deliver_session_end_messages   sØ   é € ÷
 ÙØŠ>ŸkØ×=Ñ=¸kÓJ×JˆFß"(�V˜A–Y¨dˆFØ8>Ò8J�$×,Ñ,¨VÔ4ÐPTˆØŠ?Ü�K‰KÐWÐYdÔeÙØ×3Ñ3°FÓ;ˆÛˆGØ×*Ñ*Øœ˜VŸ^™^Ó,¨g×P_×P_ÐP_°v·±×7LÒ7LÐegØHÐS[ð +ó ]÷ ]ò ]ó  ñ Kñ]ùs,   ‚C1™C1­C-®C1ºB(C1Ã"C/Ã#C1Ã/C1c               ó$   € V ^8„  d   QhRRRRRR/# )r   r	   r   Úkwargsr   r   r   r   )r   s   "r   r   r   &   s(   € ÷ iñ i¸Mð iÐ\_ð iÐdhñ ir   c             ‹  ó   a"  € R V3R llp \         P                  ! V P                  V P                  VR
V4      V P                  R7      G Rj  x€L
  R#  L  \
         d5    \        P                  RSP                  R4      T P                  4        R# \         d,    \        P                  RSP                  R4      RR	7        R# i ; i5i)z¾Plugin ``on_session_reset`` off-loop under the profile owning ``session_key``, bounded like
finalize: a viewer's ``/new`` resets its conversation on the owner (gateway/session_viewer_close).c               ó   € V ^8„  d   QhRR/# ©r   r   r   r   )r   s   "r   r   ÚDGatewaySessionEndMixin._reset_session_off_loop.<locals>.__annotate__)   s   € ÷ 	6ñ 	6�tñ 	6r   c                 ó$   <€ ^ RI Hp  V ! R/ SB  R# )é    )Úinvoke_hookN)Úon_session_reset)Úhermes_cli.lifecycler2   )r2   r+   s    €r   Ú_callÚ=GatewaySessionEndMixin._reset_session_off_loop.<locals>._call)   s   ø€ Ý8ÙÑ5¨fÔ5r   ©ÚtimeoutNzRSession reset hooks (%s) exceeded %ss; proceeding without blocking the event loop.Úold_session_idzSession reset hooks (%s) failedT©Úexc_infor   )ÚasyncioÚwait_forÚ_run_housekeeping_in_executorÚ_run_release_in_profile_scopeÚ_FINALIZE_TIMEOUT_SÚTimeoutErrorr   ÚwarningÚgetÚ	ExceptionÚdebug)r$   r	   r+   r5   s   &$l r   Ú_reset_session_off_loopÚ.GatewaySessionEndMixin._reset_session_off_loop&   s²   øé € ÷	6ð 	6ð		iÜ×"Ò"Ø×2Ñ2°4×3UÑ3UÐW\Ð^`ÐbmÓnØ×0Ñ0ô÷ ô øô ô 	SÜ�N‰NÐoØ!Ÿ:™:Ð&6Ó7¸×9QÑ9Q÷Säô 	iÜ�L‰LÐ:¸F¿J¹JÐGWÓ<XÐcgˆL×hð	iüsM   ƒ
CŽAA ÁAÁA ÁCÁA Á;CÂCÂCÂ(CÃCÃ
CÃCc               ó0   € V ^8„  d   QhRRRRRRRRRRR	R
/# )r   Ú
session_idr   r"   r    Úreasonr	   r   Úextrar   r   r   )r   s   "r   r   r   8   s<   € ÷ ñ Ø ðØ,/ðØ9<ðØKXðØjmðà	ñr   c             ‹  óŠ  aaaaa"  € . oR VVVVV3R llp \         P                  ! V P                  V P                  VR	V4      V P                  R7      G Rj  x€L
  \        S4      #  L  \
         d&    \        P                  RSST P                  4        L<\         d    \        P                  RSSRR7        Lai ; i5i)
a{  Run hermes_cli.lifecycle.finalize_session off-loop, bounded; on timeout the worker is left alone.
``session_key`` lets an unscoped caller (shutdown) enter the owning profile's scope: plugin
``on_session_finalize`` observers and the Relay coordinator (``current_profile_key``) resolve
profile state at call time. Returns the plugins' user-facing messages (empty on timeout/error).c               ó   € V ^8„  d   QhRR/# r.   r   )r   s   "r   r   ÚGGatewaySessionEndMixin._finalize_session_off_loop.<locals>.__annotate__A   s   € ÷ 	eñ 	e�tñ 	er   c                 ó^   <€ ^ RI Hp Hp SP                  V! V ! RRSRSRS/SB 4      4       R# )r1   )Úfinalize_sessionÚsession_end_messagesrI   r"   rJ   Nr   )r4   rP   rQ   Úextend)rP   rQ   rK   r   r"   rJ   rI   s     €€€€€r   r5   Ú@GatewaySessionEndMixin._finalize_session_off_loop.<locals>._callA   s8   ø€ ßSØ�O‰OÑ0Ù Ñb¨JÐbÀÐbÐRXÐbÐ\aÑbódö er   r7   Nz‘Session finalize hooks (%s, reason=%s) exceeded %ss; proceeding without blocking the event loop (the worker thread is left to finish on its own).z-Session finalize hooks (%s, reason=%s) failedTr:   r   )r<   r=   r>   r?   r@   rA   r   rB   rD   rE   Úlist)r$   rI   r"   rJ   r	   rK   r5   r   s   &ddd$l @r   Ú_finalize_session_off_loopÚ1GatewaySessionEndMixin._finalize_session_off_loop8   sÂ   üé € ð !ˆ÷	eô 	eð
	mÜ×"Ò"Ø×2Ñ2°4×3UÑ3UÐW\Ð^`ÐbmÓnØ×0Ñ0ô÷ ð ô �H‹~Ðñøô ô 	Ü�N‰NðDØEOÐQWÐY]×YqÑYqöô ô 	mÜ�L‰LÐHÈ*ÐV\ÐgkˆLÖlð	müsM   ‡C˜AA+ ÁA)ÁA+ ÁCÁ)A+ Á+-C ÂCÂC Â#C Â=CÂ?C Ã Cr   )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r(   rF   rU   Ú__static_attributes__r   r   r   r   r      s=   † Ùað]Ø48ð]ØW[÷]ð(iÈD÷ ið$Ø[_÷ó r   r   )r[   Ú
__future__r   r<   ÚloggingÚtypingr   r   r   Ú	getLoggerr   r   r   r   r   Ú<module>ra      s7   ðñõ
 #ã Û ß &Ñ &à	×	Ò	˜=Ó	)€÷Có Cr   