+
    lHàjŠ'  ã                   óÞ   € R t ^RIHtHt ]! 4       t]P
                  tR R ltR R ltR R lt]! R4      R	 R
 l4       t	R R lt
R R lt]! RRRR R4       ]! RRRR R4       R R ltR# )u“  Interrupt / steer / redirect session handlers (``methods_session`` split).

Moved verbatim from ``tui_gateway/methods_session.py`` (file-line ratchet #68779): the
bodies close over server.py globals through ``method_ctx.bind_module`` exactly as before â€”
``@method`` registration, ``_session_arg`` wrapping and module publication all still run
from the parent's ``register()`` via ``HandlerRegistry``.
)ÚHandlerRegistryÚbind_modulec                ó   € V ^8„  d   QhRR/# ©é   ÚreturnN© )Úformats   "ÚJ/home/ubuntu/.hermes/hermes-agent/tui_gateway/methods_session_interrupt.pyÚ__annotate__r      s   € ÷ %ñ % dñ %ó    c                 óV  a€ \         ;_uu_ 4        \        p RRR4       . p\        4       X 3 Fe  oSeA   \        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       d   KI  VP	                  S4       \        S4       Kg  	  R#   + '       g   i     L‰; i)a\  Re-arm a wake lease held by the interrupt caller or a voice capture.

``_wake_resume_if_owner`` no-ops unless that object holds the lease, so an
in-progress capture owned by someone else is not stolen. Interrupt already
silenced TTS before it can return an error; this matches that cut. A
``not_interrupted`` hosted-task mismatch must not call it.
Nc              3   ó,   <"  € T F	  pSVJ x € K  	  R # 5i)Nr   )Ú.0ÚitemÚowners   & €r
   Ú	<genexpr>Ú/_resume_wake_after_interrupt.<locals>.<genexpr>   s   øé € Ð?¹$°$ ¨¥»$ùs   ƒTF)Ú_voice_sid_lockÚ_voice_wake_ownerÚ_caller_transportÚanyÚappendÚ_wake_resume_if_owner)Úvoice_ownerÚseenr   s     @r
   Ú_resume_wake_after_interruptr      so   ø€ ÷ 
ŽÜ'ˆ÷ 
à€DÜ#Ó% {Ó3ˆØŠ=ŸC›CÔ?¹$Ó?ŸCŸCšCÔ?¹$Ó?×?Ò?ÙØ�‰�EÔÜ˜eÖ$ó	 4÷ 
�ús   �BÂB(	c                ó(   € V ^8„  d   QhR\         RR/# )r   Úsessionr   N©Údict)r	   s   "r
   r   r   !   s   € ÷ /ñ /œdð / tñ /r   c                óš   € V R,          ;_uu_ 4        V P                  R4      '       d   RV R&   RRR4       R#   + '       g   i     R# ; i)z�Mark the running turn as touched by the user (also covers compute-host turns, whose agent
flag never reaches this process); popped by the turn's own finally.Úhistory_lockÚrunningTÚ_turn_user_inputN)Úget)r   s   &r
   Ú_note_user_inputr&   !   s8   € ð 
�×	 ×	 Ø�;‰;�y×!Ò!Ø*.ˆGÐ&Ñ'÷ 
!×	 ×	 Ò	 ús	   ’9¹A
	c                ó4   € V ^8„  d   QhR\         R\        RR/# )r   Úsidr   r   N)Ústrr    )r	   s   "r
   r   r   )   s'   € ÷ Sñ S´ð S¼dð SÐ^bñ Sr   c                óè  €  \        4       P                  V 4      pVR,          ;_uu_ 4        RVR&   RVR&   VP                  RR4       \        VP                  R^ 4      4      ^,           VR&   VP                  R	4      pV'       g1   VP                  R
4      '       d   Ve   WRJ d   RVR
&   \        V4       RRR4       \        V 4       \        P                  \        4      ;_uu_ 4        \        VRV R7       ^ RIHp V! VR,          RRR7       RRR4       R#   \         d$   p\        P	                  RY4       Rp Rp?EL*Rp?ii ; i  + '       g   i     Lž; i  + '       g   i     R# ; i)aà  Stop on a compute host that is gone (broken pipe, respawn exhausted, #82603).

The failed dial raised before ``_interrupt_session_turn`` purged the queue, and no ``turn.end`` will ever
clear ``running``, so every later submit would queue forever. Clear the turn only when the supervisor owes
no completion for it and the inflight dict is still the one this Stop saw (a successor turn keeps its own).
The probe runs outside ``history_lock``: compute-host calls never run under it.
zDsession.interrupt: compute-host pending-turn probe failed for %s: %sTNr"   Ú_turn_cancel_requestedÚqueued_promptÚqueued_promptsÚ_queued_prompt_generationÚinflight_turnr#   FÚ	interrupt)Ú
session_id)Úresolve_gateway_approvalÚsession_keyÚdeny)Úresolve_all)Ú_get_compute_host_supervisorÚhas_pending_turnÚ	ExceptionÚloggerÚwarningÚpopÚintr%   Ú_clear_inflight_turnÚ_clear_pendingÚ
contextlibÚsuppressÚ%_announce_cancelled_gateway_approvalsÚtools.approvalr2   )r(   r   Úinflight_at_interruptÚpendingÚexcÚinflight_nowr2   s   &&&    r
   Ú&_recover_unreachable_compute_host_turnrG   )   s.  € ðÜ.Ó0×AÑAÀ#ÓFˆð 
�×	 ×	 Ø,0ˆÐ(Ñ)Ø#'ˆ�Ñ Ø�‰Ð$ dÔ+Ü/2°7·;±;Ð?ZÐ\]Ó3^Ó/_ÐbcÕ/cˆÐ+Ñ,Ø—{‘{ ?Ó3ˆß˜7Ÿ;™; y×1Ò1°lÒ6NÐS_ÓSxØ!&ˆG�IÑÜ  Ô)÷ 
!ô �3ÔÜ	×	Ñ	œY×	'Õ	'Ü-¨g°{ÈsÕSÝ;Ù  ¨Õ!7¸ÈTÕR÷ 
(Ñ	'øô ô Ü�‰Ð]Ð_bÔhØŽûðú÷ 
!×	 ú÷ 
(×	'Ð	'ús5   ‚D ¬A1EÂEÃ+'E ÄE
Ä'EÅE
ÅE	Å E1	zsession.interruptc                ó0   € V ^8„  d   QhR\         R\         /# ©r   Úparamsr   r   )r	   s   "r
   r   r   G   s   € ÷ (Tñ (T”4ð (TœDñ (Tr   c           	      ó¸  € \        4        R p \        W4      w  r4V'       d   TV'       d    \        4        # # \        VR4      ;p'       d    VR,          ;_uu_ 4        VP                  R4      pVP                  R4      '       d-   \        V\        4      '       d   VP                  R4      V8X  g1   Rp\        V R	R
RR/4      uuRRR4       V'       d    \        4        # #  RRR4       \        VP                  R4      ;'       g    R4      p\        V4       \        V4      '       da   VR,          ;_uu_ 4        VP                  R4      pRRR4        \        WsRV  2R7       \        V R	RRR /4      V'       d    \        4        # # \        Ws4       VR,          ;_uu_ 4        \        VP#                  RR4      ;'       g    R4      p
RRR4       \%        VX
4       \        V R	R/4      V'       d    \        4        # #   \         d    \        P                  RR R7        # i ; i  \         d    \        P                  RR R7        # i ; i  + '       g   i     ELy; i  + '       g   i     EL"; i  \         d.   p	\        P                  RYy4       \!        YsX4        Rp	?	ELGRp	?	ii ; i  \         d    \        P                  RR R7        # i ; i  + '       g   i     EL; i  \         d    \        P                  RR R7        # i ; i  T'       d5    \        4        i   \         d    \        P                  RR R7        i i ; ii ; i)Tz$session.interrupt wake resume failed)Úexc_infoÚexpected_hosted_task_idr"   Ú_hosted_room_taskr#   Útask_idFÚstatusÚnot_interruptedÚinterruptedNr1   Ú r/   z
interrupt-)Ú
request_idz;session.interrupt: compute-host interrupt failed for %s: %sÚturn_isolationÚ_active_turn_marker_key)Ú_tts_stream_stopÚ_sess_nowaitr   r8   r9   ÚdebugÚ
_str_paramr%   Ú
isinstancer    Ú_okr)   r&   Ú_session_uses_compute_hostÚ_interrupt_session_turnr:   rG   r;   Ú_retire_turn_marker)ÚridrJ   Úresume_waker   ÚerrÚexpectedÚtaskr(   rC   rE   Úactive_marker_keys   &&         r
   Ú_rf   F   sï  € äÔØ€Kð%TÜ# FÓ0‰ˆßØ÷< ðTÜ,Õ.ð ô; " &Ð*CÓDÐDˆ8ÖDØ˜×(×(Ø—{‘{Ð#6Ó7�ØŸ™ I×.Ò.´:¸dÄD×3IÒ3IÈdÏhÉhÐW`ÓNaÐemÔNmØ"'�KÜ˜s XÐ/@À-ÐQVÐ$WÓX÷	 )Ñ(÷8 ðTÜ,Õ.ð ð5 On÷ )ô
 �&—*‘*˜\Ó*×0Ð0¨bÓ1ˆÜ˜Ô!Ü% g×.Ò.Ø˜×(×(Ø(/¯©°OÓ(DÐ%÷ )ð\Ü'¨À:ÈcÈUÐASÕTô �s˜X }Ð6FÈÐMÓN÷ ðTÜ,Õ.ð ô 	  Ô-ð �^×$×$Ü # G§K¡KÐ0IÈ2Ó$N×$TÐ$TÐRTÓ UÐ÷ %ä˜GÐ%6Ô7Ü�3˜ =Ð1Ó2çðTÜ,Õ.ð øô ô TÜ—‘ÐCÈd�ÖSðTû”9ô TÜ—‘ÐCÈd�ÖSðTú÷? )×(Ð(ú÷ )×(Ð(ûô ô \Ü—‘Ð\Ð^aÔgÜ6°sÐEZ×[Ò[ûð\ûô& ô TÜ—‘ÐCÈd�ÖSðTú÷ %×$Ð$ûô ô TÜ—‘ÐCÈd�ÖSðTû÷ ðTÜ,Õ.øÜô TÜ—‘ÐCÈd�ÖSðTúð ús   ŽL ­
H¹%L ÁA&IÃ
L Ã
H,Ã$$L Ä	4L Ä=I(ÅL ÅI< Å(L Æ 
J7ÆL Æ(&KÇ!L Ç8
K3È"H)È(H)È,"IÉIÉI%	É	L É(I9	É3	L É<J4Ê"J/Ê)L Ê/J4Ê4L Ê7"KËKËK0	Ë*	L Ë3"LÌLÌ	MÌ%
L0Ì/MÌ0"MÍMÍMÍMc          
      óT   € V ^8„  d   QhR\         R\        R\        R\        R\         /# )r   r   ÚverbÚtextÚaccepted_statusr   )r    r)   )r	   s   "r
   r   r   r   s8   € ÷ [ñ [¤Dð [´ð [¼3ð [ÔQTð [ÔY]ñ [r   c                ó‚  €  \        VR,          V4      ! V4      pT'       dH   TR,          ;_uu_ 4        \        Y4       \	        T4       \
        P                  4       TR&   RRR4       \        T RT'       d   TMRR	T/4      #   \         d   p\        T RT RT 24      u Rp?# Rp?ii ; i  + '       g   i     LT; i)
zµ``agent.<verb>(text)``; on acceptance record it on the live turn (mid-turn resume rebuilds the bubble)
and purge queued self-copies so post-turn drain cannot re-fire the old prompt.Úagentiˆ  z	 failed: Nr"   Úlast_activerP   Úrejectedri   )Úgetattrr8   Ú_errÚ_record_inflight_correctionÚ(_drop_queued_duplicates_of_inflight_userÚtimer\   )r`   r   rh   ri   rj   ÚacceptedrE   s   &&&&&  r
   Ú_apply_correctionru   r   s¦   € ð8Ü˜7 7Õ+¨TÔ2°4Ó8ˆ÷ Ø�^×$×$Ü'¨Ô6ô
 5°WÔ=Ü%)§Y¡Y£[ˆG�MÑ"÷ %ô ˆs�X·(™À
ÈFÐTXÐYÓZÐZøô ô 8Ü�C˜ $  y°°Ð6Ó7Õ7ûð8ú÷ %×$ús(   ‚B ´.B.ÂB+ÂB&Â B+Â&B+Â.B>	c                óH   € V ^8„  d   QhR\         R\         R\         R\         /# )r   Únamerh   rj   Úunsupported)r)   )r	   s   "r
   r   r   …   s/   € ÷ !Lñ !LœSð !L¬ð !L¼cð !LÔ[^ñ !Lr   c                óB   aaaa€ \        V 4      R VVVV3R ll4       pR# )z|steer/redirect RPC: ``params.text`` (4002, checked before the session) into a live session;
``supported(agent)`` gates 4010.c                ó0   € V ^8„  d   QhR\         R\         /# rI   r   )r	   s   "r
   r   Ú(_correction_method.<locals>.__annotate__‰   s   € ÷ Lñ L”tð L¤ñ Lr   c                 ó  <€ VP                  R 4      ;'       g    RP                  4       ;p'       g   \        V RR4      # \        W4      w  r4V'       d   V# \	        V4       VP                  R4      pS	R8X  de   Vfa   VP                  R4      '       dJ   \        Y2\        4       ;'       g    \        4       \        P                  4       VR&   \        V RR	R V/4      # \        V4      '       dJ   \        Y2\        4       ;'       g    \        4       \        P                  4       VR&   \        V RR	R V/4      # S! V4      '       g   \        V R
S4      # S	R8X  d(   VP                  R4      '       g   \        V RRR V/4      # \        WS	VS4      # )ri   rS   i¢  ztext is requiredrl   Úredirectr#   rm   rP   Úqueuediª  Ústeerrn   )r%   Ústriprp   rX   r&   Ú_enqueue_promptÚcurrent_transportÚ_stdio_transportrs   r\   Ú_session_compression_in_flightru   )
r`   rJ   ri   r   rb   rl   rj   Ú	supportedrx   rh   s
   &&    €€€€r
   rf   Ú_correction_method.<locals>._ˆ   s]  ø€ àŸ™ FÓ+×1Ð1¨r×8Ñ8Ó:Ð:�Ö:Ü˜˜TÐ#5Ó6Ð6Ü# FÓ0‰ˆßØˆJÜ˜Ô!Ø—‘˜GÓ$ˆð �:Ô %¢-°G·K±KÀ	×4JÒ4JÜ˜GÔ+<Ó+>×+RÐ+RÔBRÔSÜ%)§Y¡Y£[ˆG�MÑ"Ü�s˜X x°¸Ð>Ó?Ð?ô *¨'×2Ò2Ü˜GÔ+<Ó+>×+RÐ+RÔBRÔSÜ%)§Y¡Y£[ˆG�MÑ"Ü�s˜X x°¸Ð>Ó?Ð?Ù˜×ÒÜ˜˜T ;Ó/Ð/ð �7Œ? 7§;¡;¨y×#9Ò#9Ü�s˜X z°6¸4Ð@ÓAÐAÜ  ¨t°T¸?ÓKÐKr   N)Úmethod)rw   rh   rj   r…   rx   rf   s   &ffff r
   Ú_correction_methodrˆ   …   s#   û€ ô ˆDƒ\÷Lò Ló òLr   zsession.steerr   r~   c                 ó   € \        V R 4      # )r   )Úhasattr©rl   s   &r
   Ú<lambda>rŒ   «   s   € ÄWÈUÐT[ÔE\r   zagent does not support steerzsession.redirectr}   Ú
redirectedc                 óH   € \        V R R4      RJ ;'       d    \        V R4      # )Ú_supports_active_turn_redirectFTr}   )ro   rŠ   r‹   s   &r
   rŒ   rŒ   ¯   s.   € ¤¨Ð0PÐRWÓ!XÐ\`Ð!`÷ "2ð "2Ü˜u jÓ1ð"2r   z+agent does not support active-turn redirectc                ó   € V ^8„  d   QhRR/# r   r   )r	   s   "r
   r   r   ³   s   € ÷ 0ñ 0˜ñ 0r   c                ó2   € \        \        4       V RR7       R# )z\Publish this module's helpers onto ``server`` (rebound to its globals) and install handlers.)ÚskipN)rf   )r   Úglobals)Úservers   &r
   Úregisterr•   ³   s   € ä”“	˜6¨×/r   N)Ú__doc__Ú
method_ctxr   r   Ú	_registryr‡   r   r&   rG   rf   ru   rˆ   r•   r   r   r
   Ú<module>r™      s‘   ðñ÷ 5áÓ€	Ø	×	Ñ	€õ%õ&/õSñ: ÐÓô(Tó ð(TõV[õ&!LñL �? G¨XÑ7\Ø1ô3ñ Ð% z°<ñ2Ø3`ôb÷
0r   