+
    .pÐ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                  óF   € ] tR t^tRtRR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   "Ú//opt/hermes/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               ó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   &   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   r   )r   s   "r   r   ÚGGatewaySessionEndMixin._finalize_session_off_loop.<locals>.__annotate__/   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# )é    )Úfinalize_sessionÚsession_end_messagesr+   r"   r,   Nr   )Úhermes_cli.lifecycler3   r4   Úextend)r3   r4   r-   r   r"   r,   r+   s     €€€€€r   Ú_callÚ@GatewaySessionEndMixin._finalize_session_off_loop.<locals>._call/   s8   ø€ ßSØ�O‰OÑ0Ù Ñb¨JÐbÀÐbÐRXÐbÐ\aÑbódö er   )ÚtimeoutNz‘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) failedT)Úexc_infor   )ÚasyncioÚwait_forÚ_run_housekeeping_in_executorÚ_run_release_in_profile_scopeÚ_FINALIZE_TIMEOUT_SÚTimeoutErrorr   ÚwarningÚ	ExceptionÚdebugÚlist)r$   r+   r"   r,   r	   r-   r7   r   s   &ddd$l @r   Ú_finalize_session_off_loopÚ1GatewaySessionEndMixin._finalize_session_off_loop&   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(   rE   Ú__static_attributes__r   r   r   r   r      s/   † Ùað]Ø48ð]ØW[÷]ð(Ø[_÷ó r   r   )rK   Ú
__future__r   r;   ÚloggingÚtypingr   r   r   Ú	getLoggerr   r   r   r   r   Ú<module>rQ      s5   ðñõ
 #ã Û ß &Ñ &à	×	Ò	˜=Ó	)€÷1ó 1r   