+
    lHàj’  ã                  óV  € R t ^ RIHt ^ RIt^ RIt^RIHt ^tR R ltR R lt	R R	 lt
R
 R ltR R ltR R ltR2R R lltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR3R  R! lltR4R" R# lltR$ R% ltR& R' ltR5R(R)/R* R+ llltR, R- ltR. R/ ltR0 R1 ltR# )6zòAuto-continue: resume a turn killed by a process/machine death, plus queued-prompt drain and
busy-submit handling. Bodies are rebound onto server.py's globals at install time
(method_ctx.bind_module), so they reference server.py globals bare.)ÚannotationsN)Úbind_modulec               ó   € V ^8„  d   QhRR/# )é   Úreturnztuple[bool, float, int]© )Úformats   "ÚF/home/ubuntu/.hermes/hermes-agent/tui_gateway/session_auto_continue.pyÚ__annotate__r
      s   € ÷ 
Oñ 
OÐ6ñ 
Oó    c                 óÜ  € \        4       P                  R4      p \        V \        4      '       d   V P                  R4      MRp\        V\        4      '       d   TM/ p \	        VP                  R\
        4      4      p\        VP                  R4      RR7      \        RV4      R	,          \        VP                  R
4      ^^ R7      3#   \        \        3 d    \	        \
        4      p Lmi ; i)zc(enabled, freshness window in seconds, max attempts) from ``desktop.auto_continue`` in config.yaml.ÚdesktopÚauto_continueNÚfreshness_minutesÚenabledT)Údefaultg        g      N@Úmax_attempts)Ú	min_value)Ú	_load_cfgÚgetÚ
isinstanceÚdictÚfloatÚ(_AUTO_CONTINUE_FRESHNESS_MINUTES_DEFAULTÚ	TypeErrorÚ
ValueErrorÚis_truthy_valueÚmaxÚ_coerce_int_config_value)r   ÚcfgÚminutess      r	   Ú_auto_continue_configr!      sÆ   € ä‹k�o‰o˜iÓ(€GÜ*4°W¼d×*CÒ*Cˆ'�+‰+�oÔ
&È€CÜ˜C¤×&Ò&‰#¨B€CðBÜ˜Ÿ™Ð 3Ô5]Ó^Ó_ˆô ˜CŸG™G IÓ.¸Ô=¼sÀ3ÈÓ?PÐSWÕ?WÜ$ S§W¡W¨^Ó%<¸aÈ1ÔMðOð Oøô ”zÐ"ô BÜÔ@ÓAŠðBús   ÁC Ã C+Ã*C+c               ó    € V ^8„  d   QhRRRR/# )r   Úsessionr   r   ÚPathr   )r   s   "r	   r
   r
   #   s   € ÷ =ñ =˜4ð = Dñ =r   c                óR   € \        V P                  R4      ;'       g    \        4      # )zEThe HERMES_HOME the session's durable state lives in (profile-aware).Úprofile_home)r$   r   Ú_hermes_home)r#   s   &r	   Ú_session_homer(   #   s   € ä�—‘˜NÓ+×;Ð;¬|Ó<Ð<r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r#   r   ÚkeysÚstrr   ÚNoner   )r   s   "r	   r
   r
   (   s!   € ÷ )ñ ) ð )¨cð )°dñ )r   c                óÌ   € \        V 4      p\        P                  . VO\        V P	                  R4      ;'       g    R4      N54       F  pV'       g   K  \        W#4       K  	  R# )a  Drop the crash marker right before the terminal frame (not at turn-thread end: post-turn work outlives the
client's answer, and quitting in that window would leave a marker that re-runs a finished turn). Extra ``keys``
cover a session_key that compression rotated mid-turn.Úsession_keyÚ N)r(   r   Úfromkeysr+   r   Úclear_turn_marker)r#   r*   ÚhomeÚkeys   &*  r	   Ú_retire_turn_markerr4   (   sP   € ô ˜Ó!€DÜ�}‰}ÐK˜tÐK¤S¨¯©°]Ó)C×)IÐ)IÀrÓ%JÑKÖLˆß‰3Ü˜dÖ(ó Mr   c               ó    € V ^8„  d   QhRRRR/# )r   Úpromptr+   r   r   )r   s   "r	   r
   r
   2   s   € ÷ Kñ K ð K¨ñ Kr   c                ó   € \          R V  2# )uÚ    â€” the app or its backend process stopped before the turn could finish. Some of the work may already be complete; check the current state before redoing anything, then finish the task. The interrupted request was:]

)Ú_AUTO_CONTINUE_NOTE_PREFIX)r6   s   &r	   Ú_auto_continue_noter9   2   s!   € ô *Ð*ð +AàAGÀðJð Kr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úsidr+   r#   r   r.   r   údict | Noner   )r   s   "r	   r
   r
   :   s5   € ÷ QHñ QH sð QH°Tð QHÈð QHÐP[ñ QHr   c           
     ó°  a aaa
aa€ SP                  R4      R8X  d   R# \        S4      p\        VS4      ;of   R# SP                  RR4      '       g   R# \        S4      pVR8X  df   SP                  R4      \        P
                  ! 4       8w  d=   \        P                  RSSP                  R4      \        P
                  ! 4       4       R# \        4       w  rVp\        P                  4       SR	,          ,
          pV'       d   W†8”  g   SR
,          V8¼  d   \        VS4       R# SP                  R4      '       d   R# RSR&   SR
,          ^,           \        SR,          4      uo
oR V
VVVV V3R llp	\        V	RS  2R7      f   RSR&   R# \        P                  RSS
VSP                  R4      V\        P
                  ! 4       4       RS
RSR	,          /# )a(  Kick off a continuation turn for a crash-interrupted session (session.resume cold paths). Returns a descriptor
for the resume payload when scheduled, else None. The turn runs on a background thread after the deferred agent
build via _run_prompt_submit, so the client that just resumed streams it.ÚsourceÚbot_roomNr   TÚaliveÚ
writer_pidz�auto-continue for %s held back: marker writer pid %s is still alive (reader pid %s); the marker is ownership evidence and the owner clears itÚ
started_atÚattemptsÚ_auto_continue_scheduledr6   c               ó   € V ^8„  d   QhRR/# ©r   r   r,   r   )r   s   "r	   r
   Ú3_maybe_schedule_auto_continue.<locals>.__annotate__Z   s   € ÷ +)ñ +)�Tñ +)r   c            	     óØ  <€ R \        \        P                  4       R,          4       2p  \        S
S4       \        SV RR7      pV'       d   R
SR&   R# SR,          ;_uu_ 4        SP                  R4      '       g/   SP                  R4      '       g   SP                  R4      '       d   R
SR&    RRR4       R# RSR&   \        P                  4       SR&   RRR4       \        S
S4      e=   \
        P                  RS	4       SR,          ;_uu_ 4        R
SR&   R
SR&   RRR4       R# SR,          ;_uu_ 4        SSR,          uSR&   SR&   RRR4        ^ RI
Hp SP                  R4      R8H  p\        S4      ;_uu_ 4        V
3R lpV! VRVR7       \        V S
SS3RR/V'       d   RRR//M/ B  RRR4       R#   \         d#    \
        P                  RS
RR7       RRR	//p EL¥i ; i  + '       g   i     EL ; i  + '       g   i     R# ; i  + '       g   i     LÑ; i  + '       g   i     R# ; i  \         d#   p\        RT4       \        S4        Rp?R# Rp?ii ; i) Ú__auto_continue__iè  g      ^@)Útimeoutz'auto-continue agent build failed for %sT©Úexc_infoÚerrorÚmessagezagent build failedFrD   NÚhistory_lockÚrunningÚ_turn_cancel_requestedÚ
_finalizedÚlast_activez<auto-continue for %s refused: session has another live ownerr6   Ú_auto_continue_attemptÚ_auto_continue_prompt)Úrender_notificationÚnotification_categoryÚ
diagnosticc                 óB   <€ \        R S RRRR/4       \        RS 4       R# )zstatus.updateÚkindÚprocessÚtextu   Resuming interrupted turnâ€¦zmessage.startN)Ú_emit)r;   s   €r	   ÚannounceÚ@_maybe_schedule_auto_continue.<locals>.kickoff.<locals>.announce}   s#   ø€ Ü˜/¨3°¸ÀFÐLjÐ0kÔlÜ˜/¨3Ö/r   Útui)ÚplatformrX   Údisplay_kindr   Údisplay_metadatazauto-continue dispatch failed)ÚintÚtimeÚ_start_agent_buildÚ_wait_agentÚ	ExceptionÚloggerÚwarningr   Ú_ensure_active_session_slotÚinfoÚgateway.warning_notificationsrV   Ú_session_profile_runtime_scopeÚ_run_prompt_submitÚ_notif_log_failureÚ_notif_release_turn)ÚridÚerrrV   rX   r^   ÚexcÚattemptÚmarkerr#   r.   r;   r\   s         €€€€€€r	   ÚkickoffÚ._maybe_schedule_auto_continue.<locals>.kickoffZ   s<  ø€ Ø!¤#¤d§i¡i£k°DÕ&8Ó"9Ð!:Ð;ˆð	?Ü˜s GÔ,Ü˜g s°EÔ:ˆC÷ Ø27ˆGÐ.Ñ/ÙØ�^×$×$Ø�{‰{˜9×%Ò%¨¯©Ð5M×)NÒ)NÐRY×R]ÑR]Ð^j×RkÒRkØ6;�Ð2Ñ3Ø÷ %Ñ$ð "&ˆG�IÑÜ%)§Y¡Y£[ˆG�MÑ"÷ %ô ' s¨GÓ4Ò@Ü�K‰KÐVÐXcÔdØ˜×(×(Ø%*�˜	Ñ"Ø6;�Ð2Ñ3÷ )ñ Ø�^×$×$ð SZÐ[aÐbjÕ[kÐOˆGÐ,Ñ-¨wÐ7NÑ/O÷ %ð	)ÝIØŸ™Ð$;Ó<ÀÑLˆJÜ/°×8Õ8õ0ñ $ H°uÈÕTÜ" 3¨¨W°dñ mÈð mßXbÐ*Ð-DÀlÐ,SÑTÐhjòm÷ 9Ñ8øô; ô 	?Ü�N‰NÐDÀcÐTXˆNÔYØ˜YÐ(<Ð=Ð>‹Cð	?ú÷ %×$Ð$ú÷ )Ö(ñ úß$×$ú÷ 9×8Ð8ûô ô 	)ÜÐ>ÀÔDÜ ×(Ò(ûð	)ús}   ªF= Á$.G-ÂG-Â*G-Â:G-ÄHÄ9HÅ-H< Æ1H(Æ3H< Æ=)G*Ç)G*Ç-G>	ÈH	ÈH%	È(H9	È3H< È9H< È<I)ÉI$É$I)zauto-continue-)ÚnameFzlauto-continue scheduled for session %s (attempt %d, interrupted %.0fs ago, writer pid %s: %s, reader pid %s)ru   Úinterrupted_at)r   r(   Úread_turn_markerÚmarker_writer_stateÚosÚgetpidri   rl   r!   re   r1   r9   Ú_start_session_work)r;   r#   r.   r2   Úwriter_stater   Úfreshness_secsr   Úagerw   ru   rv   r\   s   fff       @@@r	   Ú_maybe_schedule_auto_continuerƒ   :   sœ  ý€ ð ‡{�{�8Ó 
Ô*ÙÜ˜Ó!€DÜ" 4¨Ó5Ð5ˆÒ>ÙØ�:‰:�o t×,Ò,Ùô ' vÓ.€LØ�wÔ 6§:¡:¨lÓ#;¼r¿yºy»{Ô#JÜ�‰ð KØLWØ—J‘J˜|Ó,¬b¯iªi«kô	;ñ Ü,AÓ,CÑ)€G˜\Ü
�)‰)‹+˜˜|Õ,Õ
,€Cß�cÔ*¨f°ZÕ.@ÀLÔ.PÜ˜$ Ô,ÙØ‡{�{Ð-×.Ò.ÙØ*.€GÐ&Ñ'Ø˜:Õ&¨Õ*Ô,?ÀÀxÕ@PÓ,Q€M€GˆT÷+)õ +)ôX ˜7¨>¸#¸Ð)?Ô@ÒHØ.3ˆÐ*Ñ+ÙÜ
‡K�Kð !Ø"-¨w¸¸V¿Z¹ZÈÓ=UÐWcÔeg×enÒenÓepôrà�wÐ 0°&¸Õ2FÐGÐGr   c               ó    € V ^8„  d   QhRRRR/# )r   r#   r   r   r+   r   )r   s   "r	   r
   r
   Ž   s   € ÷ Qñ Q 4ð Q¨Cñ Qr   c                ó¸   € V P                  R 4      p\        V\        4      '       d3   \        VP                  R4      ;'       g    R4      P	                  4       # R# )Úinflight_turnÚuserr/   )r   r   r   r+   Ústrip)r#   Úturns   & r	   Ú_ac_inflight_originalrŠ   Ž   sF   € Ø�;‰;�Ó'€DÜ2<¸TÄ4×2HÒ2HŒ3ˆt�x‰x˜Ó×%Ð% 2Ó&×,Ñ,Ó.ÐPÈbÐPr   c               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R	/# )r   r#   r   r\   ÚAnyÚ	transportÚimage_pathszlist[str] | NoneÚturn_authorr<   r   r   )r   s   "r	   r
   r
   “   s9   € ÷ ñ ˜Tð ¨ð ¸ð ÐK[ð Ø!,ðØ8Cñr   c                ó"  € \        T;'       g    . 4      p\        V 4       V'       * ;'       d    \        V\        4      pV'       d3   V'       g+   VP	                  4       \        V 4      u;8X  d
   R8w  d    R#  RVRV/V'       d   RV/M/ CV'       d   RV/M/ CpV P                  R4      pV'       d¬   V'       d¤   V'       gœ   \        VP                  R4      \        4      '       dw   VP                  R4      '       g`   VP                  R4      '       gI   V P                  R4      '       g2   VR,          pV'       d   V'       d   V R	V 2MT;'       g    TVR&   V# V'       d$   V P                  R. 4      P                  V4       V# W`R&   V# )
aì  Queue a message for the next turn. Text-only arrivals share a slot and merge losslessly (like the
consecutive-user merge in ``repair_message_sequence``); image-bearing and authored ones stay separate
envelopes so attachment chronology and the sender survive. ``transport`` is pinned so the drained turn
streams to its sender. Returns the envelope dict the text landed in (the merged head on a merge)
so the caller can attach durable state to it; None when the text was dropped as a duplicate.r/   Nr\   r�   rŽ   r�   Úqueued_promptÚqueued_promptsú

)	ÚlistÚ(_drop_queued_duplicates_of_inflight_userr   r+   rˆ   rŠ   r   Ú
setdefaultÚappend)	r#   r\   r�   rŽ   r�   Ú	text_onlyÚqueuedÚexistingÚprevs	   &&&&&    r	   Ú_enqueue_promptrœ   “   sP  € ô �{×(Ð( bÓ)€Kô -¨WÔ5Ø”×9Ð9¤J¨t´SÓ$9€IçŸ¨¯©«Ô9NÈwÓ9WÖ)]Ð[]Õ)]Ùð *^à�d˜K¨ð G×Wb¸À{Ñ7SÐhjð Gß1<�- Ñ-À"ðG€Fà�{‰{˜?Ó+€Hß—Y§{´zÀ(Ç,Á,ÈvÓBVÔX[×7\Ò7\Ø—L‘L ×/Ò/¸¿¹À]×8SÒ8SØ—K‘KÐ 0×1Ò1Ø˜Õˆß26¿4˜d˜V 4¨ vÑ.ÀdÇlÀlÈdˆ�ÑØˆßØ×ÑÐ+¨RÓ0×7Ñ7¸Ô?ð €Mð $*�Ñ Ø€Mr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚentryrŒ   Úoriginalr+   r   r<   r   )r   s   "r	   r
   r
   ³   s&   € ÷ rñ r°3ð rÀ#ð rÈ+ñ rr   c                óž  aa€ \        V \        4      '       g   R# V P                  R4      oS'       dE   V P                  R4      '       g.   V P                  R4      '       g   \        S\        4      '       g   V # \	        VV3R lR 4       S4      P                  4       pV'       d   VS8X  d   R# VSP                  4       8X  d   V # / V CRV/C# )a>  Drop (``None``) a text-only self-duplicate of the live user text, or rewrite a merged slot
``"{original}\n\n{later}"`` to ``later`` so the correction survives without re-firing the original. Image-bearing
and authored envelopes are left alone: chronology and the sender's own words are kept.

Returns ``None`` to drop the envelope, or a (possibly rewritten) dict to keep. A merged slot
``"{original}\n\n{later}"`` (from ``_enqueue_prompt``'s consecutive text merge) is rewritten to just
``later`` so a later correction is not lost and the original is not re-fired (#84417).
Nr\   rŽ   r�   c              3  óŽ   <"  € T F:  pSP                  SV,           4      '       g   K#  S\        SV,           4      R  x € K<  	  R # 5i©N)Ú
startswithÚlen)Ú.0ÚseprŸ   r\   s   & €€r	   Ú	<genexpr>Ú:_sanitize_queued_entry_vs_inflight_user.<locals>.<genexpr>Â   s7   øé € Ði±~°ÈÏÉÐYaÐdgÕYg×IhÔ+�”c˜( S�.Ó)Ð*Õ+³~ùs
   ƒ A¨A)r“   Ú
)r   r   r   r+   Únextrˆ   )rž   rŸ   Úrestr\   s   &f @r	   Ú'_sanitize_queued_entry_vs_inflight_userr¬   ³   s¨   ù€ ô �eœT×"Ò"ÙØ�9‰9�VÓ€Dß�u—y‘y ×/Ò/°5·9±9¸]×3KÒ3KÔS]Ð^bÔdg×ShÒShØˆäÕi±~ÓiÐkoÓp×vÑvÓx€Dß˜t xÔ/ˆ4Ðq¸tÀtÇzÁzÃ|Ô?S°eÐqÐYpÐ\aÐYpÐciÐkoÑYpÐqr   c               ó    € V ^8„  d   QhRRRR/# )r   r#   r   r   r,   r   )r   s   "r	   r
   r
   Æ   s   € ÷ Bñ B°dð B¸tñ Br   c                ó  a€ \        V 4      ;o'       g   R# V P                  R4      pV3R lV'       d   V.M. \        V P                  R4      ;'       g    . 4      ,            4       p\        Y Uu. uF
  q3f   K  VNK  	  up4       R# u upi )uT  Remove server-queue copies of the live turn's original user text: a mid-turn ``prompt.submit`` of the same text
queued while redirect was unavailable must not drain and restart the original.

A mid-turn ``prompt.submit`` of the same text can land in ``queued_prompt`` when redirect is not yet
available (model not active, build window, tool boundary). If the user then corrects the turn with a
different prompt via redirect, that stale self-duplicate must not ``_drain_queued_prompt`` after the
redirected turn completes â€” otherwise the original prompt restarts as a fresh agent turn (#84417).
Nr‘   c              3  ó<   <"  € T F  p\        VS4      x € K  	  R # 5ir¢   )r¬   )r¥   ÚerŸ   s   & €r	   r§   Ú;_drop_queued_duplicates_of_inflight_user.<locals>.<genexpr>Ò   s#   øé € ð ^Ù\�1ô 7°q¸(×CÐCÛ\ùs   ƒr’   )rŠ   r   r”   Ú_ac_set_queue)r#   ÚheadÚcleanedÚcrŸ   s   &   @r	   r•   r•   Æ   sx   ø€ ô .¨gÓ6Ð6ˆHÖ6ÙØ�;‰;�Ó'€Dô^ß#'˜$™¨R´4¸¿¹ÐDTÓ8U×8[Ð8[ÐY[Ó3\Ö\ó^€Gä�' wÓ@¡w !ŸA˜A¡wÑ@ÖAùÒ@s   Á1B

Á;B

c               ó$   € V ^8„  d   QhRRRRRR/# )r   r#   r   Úentriesr”   r   r,   r   )r   s   "r	   r
   r
   ×   s!   € ÷ ,ñ ,˜4ð ,¨$ð ,°4ñ ,r   c                ó’   € V'       d
   V^ ,          MRV R&   \        V4      ^8”  d   VR,          V R&   R# V P                  RR4       R# )zGWrite ``entries`` back as queued_prompt (head) + queued_prompts (rest).Nr‘   :é   NNr’   )r¤   Úpop)r#   r·   s   &&r	   r²   r²   ×   s>   € ç-4˜w qžz¸$€GˆOÑÜ
ˆ7ƒ|�aÔØ$+¨B¥KˆÐ Ó!à�‰Ð$ dÖ+r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r;   r+   r#   r   ÚagentrŒ   r   r,   r   )r   s   "r	   r
   r
   à   s.   € ÷ Zñ Z ð Z¨tð Z¸Cð ZÀDñ Zr   c                ó†  a aaa€ SRJ;'       d    \        SR4      oS'       g   \        S4      '       g   R# SR,          ;_uu_ 4        SP                  R4      '       d    RRR4       R# RSR&   RRR4       R VVV V3R llp\        P	                  VRRS  2R	7      P                  4        R#   + '       g   i     LG; i)
a
  Interrupt a busy turn on a worker thread, never under ``history_lock`` (some providers can't apply ``interrupt()``
until a blocking call returns; inline it stalled ``session.resume``). At most one interrupt worker per session so
repeated steering can't leak threads.NÚ	interruptrO   Ú_busy_interrupt_pendingTc               ó   € V ^8„  d   QhRR/# rF   r   )r   s   "r	   r
   Ú-_interrupt_busy_session.<locals>.__annotate__ì   s   € ÷ ;ñ ;�tñ ;r   c            	     ó¼  <€  \         P                  ! \        4      ;_uu_ 4        S'       d   S P                  4       M\	        4       P                  S4       R R R 4       SR,          ;_uu_ 4        RSR&   R R R 4       R #   + '       g   i     L1; i  + '       g   i     R # ; i  SR,          ;_uu_ 4        RSR&   R R R 4       i   + '       g   i     i ; i; i)NrO   Fr¿   )Ú
contextlibÚsuppressrh   r¾   Ú_get_compute_host_supervisor)r¼   r#   r;   Ú	use_agents   €€€€r	   r¾   Ú*_interrupt_busy_session.<locals>.interruptì   s–   ø€ ð	;Ü×$Ò$¤Y×/Õ/ß%.�—‘Ô!Ô4PÓ4R×4\Ñ4\Ð]`Ó4aø÷ 0ð ˜×(×(Ø5:�Ð1Ñ2÷ )Ñ(÷ 0×/ú÷ )×(Ð(û�˜×(×(Ø5:�Ð1Ñ2÷ )×(×(Ð(ýsF   ƒ"B' ¥2B ÁB' Á0BÂ B	ÂB' ÂB$	Â'CÂ9C	Â?	CÃCÃCzbusy-interrupt-)ÚtargetÚdaemonry   )ÚhasattrÚ_session_uses_compute_hostr   Ú	threadingÚThreadÚstart)r;   r#   r¼   r¾   rÆ   s   fff @r	   Ú_interrupt_busy_sessionrÏ   à   s¡   û€ ð ˜TÐ!×AÐA¤g¨e°[Ó&A€IßÔ7¸×@Ò@ÙØ	�×	 ×	 Ø�;‰;Ð0×1Ò1Ø÷ 
!Ñ	 ð .2ˆÐ)Ñ*÷ 
!÷
;ó ;ô ×Ñ˜I¨d¸?È3È%Ð9PÐÓQ×WÑWÖY÷ 
!×	 ús   Á	B0Á,B0Â0C 	c               ó0   € V ^8„  d   QhRRRRRRRRRRR	R
/# )r   r#   r   r¼   rŒ   Úmethodr+   Ú
plain_textÚstatusr   r<   r   )r   s   "r	   r
   r
   ö   s9   € ÷ (ñ ( Tð (°#ð (¸sð (ÐPSð (Ð]`ð (Ðepñ (r   c                ó,  €  \        W#4      ! V4      '       g   R#  TR,          ;_uu_ 4        \        Y4       \        T4       \        P	                  4       TR&   RRR4       \        T RT/4      #   \         d     R# i ; i  + '       g   i     L0; i)u  Apply ``agent.<method>(plain_text)`` (steer/redirect); on acceptance record the correction, scrub stale
self-duplicates so the live turn's original text is not re-fired after settle, and return the ``status`` reply.
None â†’ caller falls through to the queue path.NrO   rS   rÓ   )Úgetattrrh   Ú_record_inflight_correctionr•   re   Ú_ok)rr   r#   r¼   rÑ   rÒ   rÓ   s   &&&&&&r	   Ú_ac_try_correctionrØ   ö   s€   € ðÜ�uÔ% j×1Ò1Ùð 2ð 
�×	 ×	 Ü# GÔ8Ü0°Ô9Ü!%§¡£ˆ�Ñ÷ 
!ô ˆs�X˜vÐ&Ó'Ð'øô ô Úðúç	 ×	 ús   ‚A1 ­.BÁ1B Á?B ÂB	c               ó    € V ^8„  d   QhRRRR/# ©r   r#   r   r   Úboolr   )r   s   "r	   r
   r
     s   € ÷ 4ñ 4¨Dð 4°Tñ 4r   c                ó^  € V P                  R4      '       d   R# V P                  R4      p\        \        VRR4      ;'       g    R4      ;'       g%    \        V P                  R4      ;'       g    R4      pV'       g   R#  \        V 4      ;_uu_ 4       p\        VRR	4      p\	        V4      '       g    R	R	R	4       R# V! V4      pR	R	R	4       \        X\        4      ;'       d    \        T4      #   + '       g   i     L3; i  \
         d    \        P                  R
TRR7        R# i ; i)u5  True when a compression lock is held for this session's durable id.

Context compression is interrupt-protected (#23975), but a correction that reaches the
provider mid-compression still aborts it with ``explicit_interrupt`` â€” the user's
follow-up kills the very turn that would answer it (#61042). The channel-side busy
path demotes interruptâ†’queue for the same reason (gateway/run_busy.py
``_session_has_compression_in_flight``, #56391); this is the local-RPC twin. Both
blocking reads run off the event loop so a large state.db never freezes the dispatcher.
Ú_manual_compress_activeTr¼   Ú
session_idr/   r.   FÚget_compression_lock_holderNz1compression in-flight check failed for session %srK   )
r   r+   rÕ   Ú_session_dbÚcallablerh   ri   Údebugr   rÛ   )r#   r¼   r;   ÚdbÚ
get_holderÚholders   &     r	   Ú_session_compression_in_flightræ     s÷   € ð ‡{�{Ð,×-Ò-ÙØ�K‰K˜Ó €EÜ
Œg�e˜\¨2Ó.×4Ð4°"Ó
5×
^Ð
^¼¸W¿[¹[ÈÓ=W×=]Ð=]Ð[]Ó9^€CßÙðÜ˜×!Ô! RÜ  Ð%BÀDÓIˆJÜ˜J×'Ò'Ø÷ "Ñ!ñ   “_ˆF÷	 "ô �fœcÓ"×3Ð3¤t¨F£|Ð3÷ "×!ûô
 ô Ü�‰ÐHÈ#ÐX\ˆÔ]Úðús<   ÂD Â C2Â5D Â?C2ÃD Ã2D	Ã=D ÄD Ä#D,Ä+D,c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r#   r   Úenveloperb   ú
str | Noner   r,   r   )r   s   "r	   r
   r
   $  s)   € ÷ 7<ñ 7< dð 7<°dð 7<È*ð 7<ÐY]ñ 7<r   c           
     ó‚  € \        V 4      '       d   R# \        V 4       VP                  R4      p\        V\        4      '       dù   \        VP                  R4      \
        4      '       dÔ   VP                  R4      VP                  R4      8w  d­   \        V 4      ;_uu_ 4       pVf    RRR4       R#  \        W04      pVP                  WSR,          4      pVRJ;'       d#    \        VP                  WVVR,          4      4      p RRR4       X'       g   TP                  RR4       R# XTR,          uTR&   TR&   R# ^ R	IHp \#        WP                  R4      VVR/R
7      pVe   W1R&   V'       d   W!R&   R# R# R#   \         d$    \        P                  RRR7        RRR4       R# i ; i  + '       g   i     L°; i)uT  Make a queued prompt durable the moment it is accepted. Writes the user row through the same
#111868 machinery as an idle submit (so a cold ``session.resume`` sees it and a restart cannot lose
it) and attaches the durable dict to the QUEUE ENVELOPE â€” never ``session["_submit_user_row"]``, the
shared slot a possibly-still-staged in-flight turn owns. A text-only merge into an existing envelope
rewrites the already-written row (and the staged dict) to the merged text in place, so cold readers
see the merged text and the drained turn's ``_adopt_submit_user_row`` content match keeps working.
A failed write stages nothing on the envelope; the drained turn then writes its own row as before.
Caller holds ``history_lock`` (the durable row, the envelope text and the queue must move together â€”
a drain cannot claim between the merge and the write).NÚ_submit_user_rowÚ_row_idÚcontentr\   z%queued-prompt row merge update failedTrK   ©ÚQUEUED_PROMPT_METADATA_KEY©Úaccept_metadataÚ_queued_display_kind)rË   Ú_ensure_session_db_rowr   r   r   rd   rà   Ú_submit_row_owner_keyÚresolve_active_row_idrÛ   Úset_user_message_contentrh   ri   râ   rº   Úhermes_state_commonrï   Ú_write_submit_user_row)	r#   rè   rb   Ústagedrã   r3   Úlive_idÚupdatedrï   s	   &&&      r	   Ú_persist_queued_user_rowrü   $  sš  € ô " '×*Ò*ÙÜ˜7Ô#Ø�\‰\Ð,Ó-€FÜ�&œ$×Ò¤J¨v¯z©z¸)Ó/DÄc×$JÒ$Jà�:‰:�iÓ  H§L¡L°Ó$8Ô8Ü˜W×%Ô%¨Ø’:Ø÷ &Ñ%ðô 0°Ó@�CØ ×6Ñ6°sÀ9Õ<MÓN�GØ%¨TÐ1÷ Uð U´dØ×3Ñ3°CÀ(È6ÕBRÓSó7U‘G÷ &÷  ð —‘Ð/°Ô6ÙØ3:¸HÀVÕ<LÐ0ˆF�9Ñ˜v iÑ0Ùõ ?Ü#Ø—‘˜fÓ% |Ø3°TÐ:ô<€Fð ÒØ'-Ð#Ñ$ßØ/;Ð+Ó,ñ ñ øô# !ô Ü—L‘LÐ!HÐSW�LÔXØ÷ &Ñ%ðú÷ &×%ús+   Â#F.Â4AE=Å="F+ÆF.Æ*F+Æ+F.Æ.F>	c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r#   r   r™   Úis_dispatchingrÛ   r   r<   r   )r   s   "r	   r
   r
   ^  s*   € ÷ /ñ /¨tð /¸Tð /ÐSWð /Ðdoñ /r   c                óT  € VP                  R4      p\        V\        4      '       d&   \        VP                  R4      \        4      '       g   R# V'       d,   \	        WP                  R4      VP                  R4      4       M4^ RIHp \	        WP                  R4      VP                  R4      VR/R7       V P                  R4      p\        V\        4      '       d&   \        VP                  R4      \        4      '       g   R# WQR&   \        V 4      ;_uu_ 4       pVf    RRR4       R#  \        W04      pVP                  WsR,          4      pVe   VP                  Wx4       RRR4       T#   \         d    \        P                  R	RR
7        L.i ; i  + '       g   i     T# ; i)uò  Re-place a queued prompt's accept-time row at the transcript END before dispatching its turn.

The accept-time write lands BEFORE the in-flight turn's assistant rows (raw ``[uA, uB, aA]``), and
``repair_alternation`` would glue the two user turns into one. So on drain: write an identical row
with a fresh timestamp at the end via the normal ``_persist_submit_user_row`` â€” it slots
``session["_submit_user_row"]``, so the turn's ``_adopt_submit_user_row`` adopts it and the flush
writes no second row (the exact existing contract) â€” then deactivate the early row (durable
history, never deleted). Steady-state raw order: ``[uA, aA, uB, aB]``. Caller holds
``history_lock`` so a concurrent submit cannot interleave its own row between the two writes.
rë   rì   Nr\   rò   rî   Trð   z0queued-prompt row re-placement deactivate failedrK   )r   r   r   rd   Ú_persist_submit_user_rowr÷   rï   rà   rô   rõ   Údeactivate_messagerh   ri   râ   )	r#   r™   rþ   Úearlyrï   Úfreshrã   r3   rú   s	   &&&      r	   Ú!_replace_queued_user_row_for_turnr  ^  s]  € ð �J‰JÐ)Ó*€EÜ�uœd×#Ò#¬
°5·9±9¸YÓ3GÌ×(MÒ(MÙ÷ Ü  ¯*©*°VÓ*<¸f¿j¹jÐI_Ó>`ÕaåBÜ  ¯*©*°VÓ*<¸f¿j¹jÐI_Ó>`Ø2LÈdÐ1Sõ	Uà�K‰KÐ*Ó+€EÜ�uœd×#Ò#¬
°5·9±9¸YÓ3GÌ×(MÒ(MÙØ!&ÐÑÜ	�W×	Ô	 ØŠ:Ø÷ 
Ñ	ð	\ô (¨Ó7ˆCØ×.Ñ.¨s¸)Õ4DÓEˆGØÒ"Ø×%Ñ% cÔ3÷ 
ð$ €Løô	 ô 	\ô �L‰LÐKÐVZˆLÖ[ð	\ú÷ 
Ö	ð$ €Lús*   ÄFÄ,8E.Å."FÆFÆFÆFÆF'	c               ó8   € V ^8„  d   QhRRRRRRRRRR	R
RRRRR/# )r   r;   r+   r#   r   r\   rŒ   r�   r™   rÛ   r�   r<   rb   ré   r   r   )r   s   "r	   r
   r
   �  sH   € ÷ 6*ñ 6* #ð 6*°ð 6*¸Cð 6*ÈCð 6*ÐY]ð 6*Ø%0ð6*ØGQð6*Ø]hñ6*r   c           
     ó”  € V'       d   RM	\        4       pVP                  R4      p	VR9   d   \        V4      '       d   RpVR,          ;_uu_ 4        VP                  R4      '       g    RRR4       R# RVR	&   \        VP                  R
. 4      4      p
V
'       d   . VR
&   RRR4       X
'       g+   \	        V4      '       d   \        V4      P                  4       MRpV'       dw   V	es   R\        V	R4      R\        V	RR4      RJ ;'       d    \        V	R4      /pRRRR/P                  VR4      w  rÞV'       d"   WÈ,          '       d   \        WW�W¾4      ;pe   V# VR,          ;_uu_ 4        VP                  R4      '       g9   V
'       d&   V
\        VP                  R
. 4      4      ,           VR
&    RRR4       R# \        W#WJVR7      pVe   \        VVV4       \        P                  4       VR&   RRR4       VR8X  d   V
'       g   \        WV	4       \        V RR/4      #   + '       g   i     EL‹; i  + '       g   i     LM; i)u“  Apply ``display.busy_input_mode`` to a mid-turn prompt instead of rejecting it (rejection made clients busy-retry
and drop sends): ``interrupt`` (default) â†’ redirect, falling back to hard interrupt + queue; ``queue`` â†’ queue only;
``steer`` â†’ inject after the current atomic action. ``queued=True`` (client queue drain) forces queue mode: a "run
after" message must NEVER become a live correction.Úqueuer¼   Ústeerr¾   rO   rP   NTÚ_turn_user_inputÚattached_imagesr/   Ú_supports_active_turn_redirectFÚredirect)rŽ   r�   rS   rÓ   r™   )r  r¾   )r  Ústeered)r  Ú
redirected©NN)Ú_load_busy_input_moder   ræ   r”   Ú_is_text_only_busy_payloadÚ_coerce_message_textrˆ   rÊ   rÕ   rØ   rœ   rü   re   rÏ   r×   )rr   r;   r#   r\   r�   r™   r�   rb   Úmoder¼   rŽ   rÒ   Ú	supportedrÑ   rÓ   Úresprè   s   &&&&&&&&         r	   Ú_handle_busy_submitr  �  s  € ÷ ‰7Ô"7Ó"9€DØ�K‰K˜Ó €Eð Ð%Ô%Ô*HÈ×*QÒ*QØˆØ	�×	 ×	 Ø�{‰{˜9×%Ò%Ø÷ 
!Ñ	 ð '+ˆÐ"Ñ#Ü˜7Ÿ;™;Ð'8¸"Ó=Ó>ˆßØ)+ˆGÐ%Ñ&÷ 
!÷ <GÔKeÐfj×KkÒKkÔ% dÓ+×1Ñ1Ô3Ðqs€J÷ �eÒ'à”W˜U GÓ,Øœ Ð(HÈ%ÓPÐTXÐX×wÐwÔ]dÐejÐlvÓ]wðyˆ	ð "Ð#7¸ÐF`Ða×eÑeÐfjÐlxÓy‰ˆß�y—”Ü/°¸eÈZÓ`Ð`�TÒmØˆKð 
�×	 ×	 Ø�{‰{˜9×%Ò%ßØ-8¼4ÀÇÁÐL]Ð_aÓ@bÓ;cÕ-c�Ð)Ñ*Ø÷	 
!Ñ	 ô
 # 7°)ÐbmÔnˆð ÒÜ$ W¨h¸ÔEÜ!%§¡£ˆ�Ñ÷ 
!ð$ ˆ{Ô§;Ü ¨eÔ4Üˆs�X˜xÐ(Ó)Ð)÷S 
!×	 Ð	 ú÷* 
!×	 ús*   ÁH#Á4-H#Å,H7Æ&H7Æ<6H7È#H4	È7I	c               ó$   € V ^8„  d   QhRRRRRR/# )r   r;   r+   r#   r   r   rÛ   r   )r   s   "r	   r
   r
   É  s&   € ÷ Dñ D 3ð D°ð D¸$ñ Dr   c           
     óx  € \        V4      ;_uu_ 4       pV'       dH   VP                  R4      '       g1   VP                  R4      ;p'       d   VP                  R4      '       d    RRR4       R# \        VP                  R^ 4      4      p\        Y"P                  R4      ;'       g    . 4       RVR&   VP                  R	4      pVe   \	        V4      '       g   \        W&4       RRR4       \        V4      pVR
,          ;_uu_ 4        \        VP                  R^ 4      4      X8w  dW   VP                  R4      p\        TX.V'       d   V.M. OVP                  R4      ;'       g    . O4       RVR&    RRR4       R#  RRR4       RX/p	XP                  R4      '       d   VR,          V	R&   VR
,          ;_uu_ 4        \        W$RR7      p
VP                  R4      '       d   VR,          .M. \        VP                  R4      ;'       g    . 4      ,           pV F  p\        W,4       K  	  V
e   W¢R&   MVP                  RR4       RRR4       VP                  R4      '       d   RVR,          /M/ pRp V'       g   \        WW$R,          3/ V	BVB  M¡\        WW$R,          3/ V	B ;pP                  R4      '       dw   VR
,          ;_uu_ 4        RVR&   \        V4       RRR4       \        RTR\        VP                  R4      ;'       g    / P                  R4      ;'       g    R4      /4       RpV'       dg   VR
,          ;_uu_ 4        \%        VP                  R4      4      ;'       d    VP                  R4      '       * pRRR4       X'       d   \'        WV4       R#   + '       g   i     ELÍ; i  + '       g   i     ELE; i  + '       g   i     EL�; i  + '       g   i     EL	; i  \         d$   p\!        RT4       \#        T4       Rp Rp?LéRp?ii ; i  + '       g   i     L§; i)z°Fire a queued next-turn prompt if one is waiting and the session is idle. True when dispatched: the caller
skips lower-priority follow-ups this cycle (the user's message wins).Ú_closingr‘   rP   NFÚ_queued_prompt_generationr’   Tr�   rO   Úqueued_prompt_generationrŽ   )rþ   rë   r�   r\   rM   rN   zqueued prompt failedzqueued prompt dispatch failedrQ   )Ú_session_turn_admissionr   rd   r²   Ú_transport_is_deadÚ_attach_session_transportrË   r  r”   rº   ro   Ú_submit_prompt_to_compute_hostÚ_clear_inflight_turnr]   r+   rh   rp   rq   rÛ   Ú_drain_queued_prompt)rr   r;   r#   Úadmittedr™   Úqueue_generationÚqueued_transportÚuse_compute_hostÚadvancedÚkwargsÚdispatch_rowÚstill_queuedrè   Úauthor_kwargsÚdispatch_failedr  rt   Ú
drain_nexts   &&&               r	   r!  r!  É  s�  € ô 
! ×	)Ô	)¨Xß˜7Ÿ;™; z×2Ò2ÀWÇ[Á[ÐQ`ÓEaÐ;a¸6Ö;aÐfm×fqÑfqÐr{×f|Òf|Ø÷ 
*Ñ	)ô ˜wŸ{™{Ð+FÈÓJÓKÐÜ�gŸ{™{Ð+;Ó<×BÐBÀÔCØ!ˆ�	ÑØ!Ÿ:™: kÓ2Ðð
 Ò'Ô0BÐCS×0TÒ0TÜ% gÔ@÷ 
*ô 2°'Ó:ÐØ	�×	 ×	 Üˆw�{‰{Ð6¸Ó:Ó;Ð?OÔOð —{‘{ ?Ó3ˆHÜ˜' FÐ#v¿H¨x©jÈ"Ð#vÐQX×Q\ÑQ\Ð]mÓQn×QtÐQtÐrtÐ#vÔwØ!&ˆG�IÑØ÷ 
!Ñ	 ØO÷ 
!ð /Ð0@ÐA€FØ‡z�z�-× Ò Ø & }Õ 5ˆˆ}Ñð 
�×	 ×	 Ü8¸ÐY]Ô^ˆØ7>·{±{À?×7SÒ7S˜' /Õ2Ñ3ÐY[Ü˜wŸ{™{Ð+;Ó<×BÐBÀÓCõDˆã$ˆHÜ-¨gÖ@ñ %ð Ò#Ø*6Ð&Ò'à�K‰KÐ*¨DÔ1÷ 
!ð ?E¿j¹jÈ×>WÒ>W�] F¨=Õ$9Ñ:Ð]_€MØ€OðßÜ˜s¨¸µ.Ñ\ÀFÐ\ÈmÓ\Ü4°S¸wÈvÍÑaÐZ`ÑaÐaˆd×fÑfÐgn×oÒoØ˜×(×(Ø%*�˜	Ñ"Ü$ WÔ-÷ )ô �'˜3 ¬C°·±¸'Ó1B×1HÐ1HÀb×0MÑ0MÈiÓ0X×0rÐ0rÐ\rÓ,sÐ tÔuØ"ˆO÷
 Ø�^×$×$Ü˜gŸk™k¨/Ó:Ó;×iÐiÀGÇKÁKÐPhÓDiÔ@iˆJ÷ %çÜ  ¨7Ô3Ù÷C 
*×	)Ð	)ú÷ 
!×	 Ð	 ú÷$ 
!×	 Ð	 ú÷& )×(Ð(ûô
 ô ÜÐ:¸CÔ@Ü˜GÔ$Ø�ûðú÷
 %×$ús�   ”N(´N(ÁN(Á$N(Á/A5N(ÄAN<Å'N<Ç AOÈ<OÉ8O8 Ê O8 Ê<O8 ËO$Ë$,O8 ÌO8 Ì*O8 Í9P)Î(N9	Î<O	ÏO!	Ï$O5	Ï/	O8 Ï8P&ÐP!Ð!P&Ð)P9	c               ó    € V ^8„  d   QhRRRR/# ©r   r#   r   r   r<   r   )r   s   "r	   r
   r
     s   € ÷ ñ  ð ¨ñ r   c           	     ó  € V P                  R 4      p\        V\        4      '       g   R# \        VP                  R4      ;'       g    R4      P	                  4       \        VP                  R4      ;'       g    R4      r2\        VP                  R4      4      \        VP                  R4      ;'       g    R4      P	                  4       rTV'       g   V'       g   V'       g   V'       g   R# RVRVRV/p\        VP                  R4      ;p\        4      '       d   V'       d   WvR&   \        VP                  R4      ;p\        4      '       d   \        V4      VR&   VP                  R	4      ;'       g    . p	\        VP                  R
4      ;'       g    . 4       U
Uu. uFK  w  r«\        V4      P	                  4       '       g   K&  \        V4      V
\        V	4      8  d	   Wš,          MR3NKM  	  pp
pV'       dv   V UUu. uF  w  r½VNK	  	  uppVR
&   \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       d#   V UUu. uF  w  rÞ\        V4      NK  	  uppVR	&   V'       d‚   TP                  T\        VP                  R4      ;'       g    R4      \        VP                  R4      4      R7       \        VP                  R4      ;p\        4      '       d   V'       d   WöR&   V# u upp
i u uppi u uppi )r†   Nr‡   r/   Ú	assistantÚ	streamingrM   rb   rc   Úcorrection_offsetsÚcorrectionsc              3  ó`   "  € T F$  w  r\        V\        4      ;'       d    V^ 8¬  x € K&  	  R# 5i)é    N)r   rd   )r¥   Ú_Úoffsets   &  r	   r§   Ú%_inflight_snapshot.<locals>.<genexpr>$  s*   é € ÐYÑHX¹9¸1Œz˜&¤#Ó&×6Ð6¨6°Q©;Ô6ÓHXùs   ‚. .FTrÓ   Úrecoverable)rM   rÓ   r9  Úerror_surface)r   r   r   r+   rˆ   rÛ   Ú	enumerater¤   Úallrd   Úupdate)r#   r‰   r‡   r0  r1  rM   Úsnapshotrb   rc   Úraw_offsetsÚirµ   Úcorrection_pairsr6  r7  Úsurfaces   &               r	   Ú_inflight_snapshotrC    sb  € Ø�;‰;�Ó'€DÜ�dœD×!Ò!ÙÜ˜$Ÿ(™( 6Ó*×0Ð0¨bÓ1×7Ñ7Ó9¼3¸t¿x¹xÈÓ?T×?ZÐ?ZÐXZÓ;[ˆ)Ü˜DŸH™H [Ó1Ó2´C¸¿¹ÀÓ8I×8OÐ8OÈRÓ4P×4VÑ4VÓ4Xˆuß—I§¯eÙØ˜Y¨°YÀÈÐM€HÜ $§(¡(¨>Ó":Ð:�,¼C×@Ò@Ç\Ø#/�Ñ Ü d§h¡hÐ/AÓ&BÐBÐ"ÄD×IÒIÜ'+Ð,<Ó'=ˆÐ#Ñ$Ø—(‘(Ð/Ó0×6Ð6°B€Kä$-¨d¯h©h°}Ó.E×.KÐ.KÈÔ$Lô`Ù$L™D˜AÔPSÐTUÓPV×P\ÑP\×P^ô Sœ˜Q›°1´s¸;Ó7GÔ3G ¦ÈTÓRÙ$Lð ñ `çñ 2BÔ"BÑ1A©¨£1Ñ1AÒ"Bˆ�Ñß‹3ÑYÑHXÓY�3�3Š3ÑYÑHXÓY×YÒYÙK[Ô-\ÑK[¹i¸a¬c°&®kÑK[Ò-\ˆHÐ)Ñ*ßð 	�‰˜e¬C°·±¸Ó0B×0MÐ0MÀgÓ,NÔ\`Ðae×aiÑaiÐjwÓaxÓ\yˆÔzÜ §¡¨/Ó!:Ð:�g¼D×AÒAÇgØ(/�_Ñ%Ø€Oùó`ùó
 #Cùã-\s   Æ#K:Ç)K:Ç?L ÉLÚretire_markerTc               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR/# )r   r;   r+   r#   r   rM   rŒ   r:  zOptional[dict]rD  rÛ   r   r,   r   )r   s   "r	   r
   r
   /  s<   € ÷ ,ñ ,Ø	ð,Øð,Ø$'ð,Ø8Fð,Øaeð,Øquñ,r   c               ó†  € VP                  R4      pVf›   \        V\        4      '       d…   \        P                  ! \
        4      ;_uu_ 4        ^ RIHp T! T\        \        VRR4      ;'       g    R4      \        \        VRR4      ;'       g    R4      \        VRR4      R7      pRRR4       VR	,          ;_uu_ 4        \        WVR
7       VP                  R4      ;'       g    / p\        VP                  R4      ;'       g    R4      \        VP                  R4      ;'       g    R4      r˜\        VP                  R^P4      4      p
RRR4       X	;'       g    \        XV4      pRp\        P                  ! \
        4      ;_uu_ 4        \        VX
4      pRRR4       RTRVe   \        V4      M/ RRRXRR/V'       d   RV/M/ CV	'       d   RR/M/ CV'       d   RV/M/ CpV'       d   \        V4       \!        RW4       R#   + '       g   i     ELj; i  + '       g   i     LÙ; i  + '       g   i     L�; i)a-  Close a failed turn with the same ``status: "error"`` ``message.complete`` frame as the returned-error path,
retaining the turn so a client that missed the frame recovers it from ``session.resume``'s ``inflight``.
``error_surface`` ({layer, code, retryable}) is classified from an exception if absent.r¼   N)Ú"build_error_surface_from_exceptionÚproviderr/   ÚmodelÚapi_key)rH  rI  rJ  rO   )r:  r†   rM   zturn failedr0  Úcolsr\   ÚusagerÓ   r9  Tr:  ÚpartialÚrenderedzmessage.complete)r   r   ÚBaseExceptionrÃ   rÄ   rh   Úagent.error_surfacerG  r+   rÕ   Ú_fail_inflight_turnrd   Úturn_error_textÚrender_messageÚ
_get_usager4   r]   )r;   r#   rM   r:  rD  r¼   rG  r‰   rN   rM  rK  r\   rN  Úpayloads   &&&&$         r	   Ú_emit_terminal_turn_errorrV  /  sà  € ð
 �K‰K˜Ó €EØÒ¤¨E´=×!AÒ!AÜ× Ò ¤×+Õ+ÝNÙ>Ø¤¤G¨E°:¸rÓ$B×$HÐ$HÀbÓ IÔQTÔU\Ð]bÐdkÐmoÓUp×UvÐUvÐtvÓQwÜ  y°$Ó7ô9ˆM÷ ,ð
 
�×	 ×	 Ü˜G¸-ÕHØ�{‰{˜?Ó+×1Ð1¨rˆÜ˜tŸx™x¨Ó0×AÐA°MÓBÄCÈÏÉÐQ\ÓH]×HcÐHcÐacÓDd�Ü�7—;‘;˜v rÓ*Ó+ˆ÷	 
!ð
 ×=Ð=”o g¨}Ó=€DØ€HÜ	×	Ò	œY×	'Õ	'Ü! $¨Ó-ˆ÷ 
(à�t˜W¸5Ò;L¤j°Ô&7ÐRTÐV^Ð`gØ˜ °ðiß]j¸/È=Ñ9YÐprðiç'.�9˜dÑ#°BðiçV^¸ZÈÑ<RÐdfði€G÷ Ü˜GÔ$Ü	Ð
˜cÖ+÷' ,×+Ð+ú÷
 
!×	 ú÷ 
(×	'ús8   ÁAH	ÂH	ÃAHÄ"HÄ*"HÆH0È	H	ÈH-	È0I 	c               ó    € V ^8„  d   QhRRRR/# rÚ   r   )r   s   "r	   r
   r
   L  s   € ÷ 	ñ 	°Tð 	ÀTñ 	r   c                ó  € \        VRR4      p\        V\        4      '       g   R# V R,          ;_uu_ 4        \        V4      V R&   \        V P	                  R^ 4      4      ^,           V R&   RRR4       R#   + '       g   i     R# ; i)z¤Keep a failed turn's working transcript: ``AIAgent`` persists its messages independently, so after a raise the
next prompt must see them, not the pre-turn snapshot.Ú_session_messagesNFrO   ÚhistoryÚhistory_versionT)rÕ   r   r”   rd   r   )r#   r¼   Úagent_messagess   && r	   Ú'_restore_agent_history_after_turn_errorr]  L  sv   € ô ˜UÐ$7¸Ó>€NÜ�n¤d×+Ò+ÙØ	�×	 ×	 Ü! .Ó1ˆ�	ÑÜ%(¨¯©Ð5FÈÓ)JÓ%KÈaÕ%OˆÐ!Ñ"÷ 
!ñ ÷ 
!Ö	 ñ ús   ·4A5Á5B	c               ó    € V ^8„  d   QhRRRR/# r.  r   )r   s   "r	   r
   r
   X  s   € ÷ ,ñ , Tð ,¨kñ ,r   c                ó¤   € V P                  R4      p\        V\        4      '       d   \        VP                  R4      4      MRpV'       d   RV/# R# )z�The accepted next-turn prompt without its transport handle, for the live-session projection (Desktop may
reconnect while it is still queued).r‘   r\   r/   r‡   N)r   r   r   Ú_inflight_text)r#   r™   r‡   s   &  r	   Ú_queued_prompt_snapshotra  X  sD   € ð �[‰[˜Ó)€FÜ1;¸FÄD×1IÒ1IŒ>˜&Ÿ*™* VÓ,Ô-Èr€Dß!ˆF�Dˆ>Ð+ tÐ+r   c               ó   € V ^8„  d   QhRR/# rF   r   )r   s   "r	   r
   r
   `  s   € ÷ 0ñ 0˜ñ 0r   c                ó2   € \        \        4       V RR7       R# )zQPublish this module's helpers + handlers onto ``server``, rebound to its globals.)ÚskipN)r6  )r   Úglobals)Úservers   &r	   Úregisterrg  `  s   € ä”“	˜6¨×/r   r  )F)FNNr¢   )Ú__doc__Ú
__future__r   rÃ   r}   Ú
method_ctxr   r   r!   r(   r4   r9   rƒ   rŠ   rœ   r¬   r•   r²   rÏ   rØ   ræ   rü   r  r  r!  rC  rV  r]  ra  rg  r   r   r	   Ú<module>rk     s«   ðñGõ #ã Û 	å #ð ,.Ð (õ
Oõ=õ
)õKõQHõhQ÷
õ@rõ&Bõ",õZõ,(õ 4õ<7<÷t/÷d6*õrDõNñ>,Øhl÷,ð ,õ:	õ,÷0r   