+
    lHàj$ ã                  ó”  € R t ^ RIHt ^ RIt^RIHtHt ]! 4       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/R R lltRRRR/R R llt]P                   ! RR7       ! R R4      4       tR R ltR R ltR R  ltR! R" ltRXR# R$ lltR% R& ltR' R( ltR)RR*R/R+ R, lltR- R. lt]P                   ! RR7       ! R/ R04      4       tR1 R2 ltR3 R4 ltR5 R6 ltR7 R8 ltR9 R: lt RYR; R< llt!R= R> lt"R? R@ lt#RA RB lt$RC RD lt%RE RF lt&RG RH lt'RIt(RJ RK lt)RL RM lt*RNRRORRPRRQRRRRRSRRR/RT RU llt+RV RW lt,R# )ZaØ  The prompt turn: ``_run_prompt_submit`` and the per-phase helpers it drives.

Bodies are rebound onto server.py's globals at install time (method_ctx.bind_module),
so they reference server.py globals bare.  Turn shape (one fresh daemon thread):
admit -> crash marker -> bind scopes -> resolve message -> run_conversation ->
commit history / message.complete -> goal & loop hooks -> release scopes ->
post-turn follow-ups (queued prompt, goal continuation, notifications).
)ÚannotationsN)ÚHandlerRegistryÚbind_modulec               ó$   € V ^8„  d   QhRRRRRR/# )é   ÚresponseÚAnyÚ
successfulÚboolÚreturn© )Úformats   "Ú</home/ubuntu/.hermes/hermes-agent/tui_gateway/prompt_turn.pyÚ__annotate__r      s&   € ÷ 	Xñ 	X cð 	X¸$ð 	XÀ3ñ 	Xó    c               óB   € ^ RI Hp V'       d   V! V 4      '       d   R# T # )a@  Return the text Bot Mode may render or relay after a completed turn.

The gateway owns the canonical marker set.  Keep the row and completion
event intact, but make a successful bare marker invisible at every Bot
Mode delivery boundary.  Failed turns intentionally fail open so their
diagnostic text is never swallowed.
)Úis_intentional_silence_responseÚ )Úgateway.response_filtersr   )r   r	   r   s   &$ r   Ú_bot_mode_delivery_textr      s    € õ IßÑ ?À× IÒ Iˆ2ÐWÈxÐWr   c               ó    € V ^8„  d   QhRRRR/# ©r   ÚsessionÚdictr   r
   r   )r   s   "r   r   r      s   € ÷ Xñ X $ð X¨4ñ Xr   c                óÐ   € ^ RI Hp \        \        V P	                  R4      RR4      ;'       g    R4      P                  4       pV'       d   W!8H  # \        V \        V 4      4      V8H  # )a	  Whether this completion belongs to the canonical Bot Chat surface.

Same resolution as the system-prompt gate: the agent's title hint first (the DB
title lands after turn 1 and ``pending_title`` is cleared once it does), then the
live title from the session store.
)ÚBOT_CHAT_TITLEÚagentÚ_session_title_hintr   )Útools.bot_mode_prober   ÚstrÚgetattrÚgetÚstripÚ_session_live_titleÚ_session_lookup_key)r   r   Úhints   &  r   Ú_is_bot_mode_sessionr&      sY   € õ 4ÜŒw�w—{‘{ 7Ó+Ð-BÀBÓG×MÐMÈ2ÓN×TÑTÓV€DßØÑ%Ð%Ü˜wÔ(;¸GÓ(DÓEÈÑWÐWr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úwhatr   ÚexcÚBaseExceptionr   ÚNoner   )r   s   "r   r   r   -   s&   € ÷ Xñ X˜ð X -ð X°Dñ Xr   c                ót   € \        R V  R\        V4      P                   RV 2\        P                  R7       R# )z[tui_gateway] z	 failed: ú: ©ÚfileN)ÚprintÚtypeÚ__name__ÚsysÚstderr)r(   r)   s   &&r   Ú_hook_failurer5   -   s.   € Ü	ˆN˜4˜& 	¬$¨s«)×*<Ñ*<Ð)=¸RÀ¸uÐ
EÌCÏJÉJ×Wr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úresultr   Ústatusr   Úrawr   r
   r   )r   s   "r   r   r   1   s.   € ÷ Tñ T Sð T°#ð T¸Cð TÀDñ Tr   c                óN  € ^ RI Hp VR8w  g-   \        V\        4      '       d   VP	                  4       '       g   R# \        V \
        4      '       g   R# V P                  R4      '       g   V P                  R4      '       d   R# V P                  R4      RJ;'       g	    V! V 4      # )aB  Whether a turn produced a real response the goal judge can use.

A non-failed ``max_iterations_reached(...)`` handoff is a resumable turn boundary, not a
failure: its summary must reach the judge so an active goal continues (#102213). Failed,
interrupted and other ``completed is False`` turns still stay out (cf. #63180).)Úis_max_iteration_handoffÚcompleteFTÚfailedÚinterruptedÚ	completed)Úagent.turn_failure_copyr;   Ú
isinstancer   r"   r   r!   )r7   r8   r9   r;   s   &&& r   Ú_is_successful_goal_turnrB   1   s{   € õ AØ�Ô¤:¨c´3×#7Ò#7¸s¿y¹y¿{º{ÙÜ�fœd×#Ò#ÙØ‡z�z�(×Ò˜vŸz™z¨-×8Ò8ÙØ�:‰:�kÓ"¨%Ð/×SÐSÑ3KÈFÓ3SÐSr   c               ó   € V ^8„  d   QhRR/# ©r   r   r   r   )r   s   "r   r   r   A   s   € ÷ 	6ñ 	6 $ñ 	6r   c                óN  € ^ RI Hp  \        \        4       P	                  R4      ;'       g    / P	                  R^4      ;'       g    ^4      pT! \        V P	                  R4      ;'       g    R4      VR7      pVP                  4       '       d   V# R#   \
         d    ^p LUi ; i)z;The session's GoalManager when a goal is active, else None.)ÚGoalManagerÚgoalsÚ	max_turnsÚsession_keyr   )Ú
session_idÚdefault_max_turnsN)Úhermes_cli.goalsrF   ÚintÚ	_load_cfgr!   Ú	Exceptionr   Ú	is_active)r   rF   rH   Úgoal_mgrs   &   r   Ú_active_goal_managerrR   A   s”   € å,ðÜœ›Ÿ™¨Ó1×7Ð7°R×<Ñ<¸[È"ÓM×SÐSÐQSÓTˆ	ñ Ü�w—{‘{ =Ó1×7Ð7°RÓ8ÈIôW€Hà×)Ñ)×+Ò+ˆ8Ð5°Ð5øô	 ô ØŠ	ðús   ˆ$B ­B ÁB ÂB$Â#B$c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   r   r   r7   r   r8   r   r9   r   ztuple[str | None, str | None]r   )r   s   "r   r   r   M   s4   € ÷ $9ñ $9Øð$9Øð$9Ø+.ð$9Ø58ð$9Ø=Zñ$9r   c               ó&  € \        V\        4      '       d   VP                  R4      '       g+   \        WV4      '       d   V P	                  \
        R4       R# \        V P                  R4      ;'       g    R4      '       g   R# \        V 4      ;pf   V P	                  \
        R4       R# \        \        VP                  RR4      ;'       g    R4      p\        VP                  RR4      pV P                  \
        4      p^ p\        V\        4      '       d�   VP                  R4      V8X  dk   VP                  R4      V8X  dU   \        P                  \        \        4      ;_uu_ 4        \        VP                  R	^ 4      ;'       g    ^ 4      pRRR4       VP!                  4       p	V\"        8  d#   V	'       d   RVRVR	V^,           /V \
        &   V	R
3# VP%                  RR7       V P	                  \
        R4       R#   + '       g   i     Lw; i)zùBounded active-goal retry after compression exhaustion: ``(continuation, notice)``.
Exhaustion is a failed turn (never judge input, never a spent goal turn); one fresh
continuation is allowed, a second exhaustion pauses the goal instead of spinning.Úcompression_exhaustedNrI   r   Ú
created_atg        ÚgoalÚgoal_created_atÚattemptszAContext compression was exhausted. Retrying the active goal once.z1context compression exhausted twice consecutively©Úreason©NN)NzhGoal paused after context compression was exhausted twice. Run /compress, then /goal resume to continue.)rA   r   r!   rB   ÚpopÚ#_GOAL_COMPRESSION_RECOVERY_ATTEMPTSr   rR   Úfloatr    ÚstateÚ
contextlibÚsuppressÚ	TypeErrorÚ
ValueErrorrM   Únext_continuation_promptÚ _GOAL_COMPRESSION_RECOVERY_LIMITÚpause)
r   r7   r8   r9   rQ   rX   Ú	goal_textÚrecovery_staterY   Úcontinuation_prompts
   &&$$      r   Ú_plan_goal_compression_recoveryrk   M   s»  € ô
 �vœt×$Ò$¨¯©Ð4K×)LÒ)LÜ# F°C×8Ò8Ø�K‰KÔ;¸TÔBØÐÜˆw�{‰{˜=Ó)×/Ð/¨R×0Ò0ØÐÜ(¨Ó1Ð1ˆÒ:Ø�‰Ô7¸Ô>ØÐÜœG H§N¡N°LÀ#ÓF×MÐMÈ#ÓN€OÜ˜Ÿ™¨°Ó3€IØ—[‘[Ô!DÓE€NØ€Hä�>¤4×(Ò(Ø×ÑÐ0Ó1°_ÔDØ×Ñ˜vÓ&¨)Ô3Ü× Ñ ¤¬J×7Õ7Ü˜>×-Ñ-¨j¸!Ó<×AÐAÀÓBˆH÷ 8à"×;Ñ;Ó=ÐØÔ2Ô2×7Jà˜°¸	À:ÈxÐZ[Í|ð8]ˆÔ3Ñ4ð  ØOðQð 	Qð ‡N�NÐM€NÔNà‡K�KÔ3°TÔ:ð9ð 9÷ 8×7ús   Å+&H È H	Úreport_ownership_refusalTc               ó<   € V ^8„  d   QhRRRRRRRRR	R
RRRRRRRR/	# )r   Úsidr   r   r   Útextr   Úimage_pathsúlist[str] | NoneÚqueued_prompt_generationú
int | NoneÚdisplay_kindú
str | NoneÚdisplay_metadataúdict | Nonerl   r
   r   ztuple[list[str], Any] | Noner   )r   s   "r   r   r   t   s^   € ÷ ;ñ ;Ø	ð;Øð;Ø#&ð;Ø5Eð;à(ð;à8Bð;ð "ð;ð AEð;ð Qmñ;r   c               óÌ  € VP                  R4      pVP                  R4      '       g¨   \        W4      ;p	e™   \        P                  RVP                  R4      ;'       g    T \	        V	RR4      ;'       g    R4       VR,          ;_uu_ 4        R	VR
&   VP                  RR4       RRR4       V'       d   \        RV R\        V	4      /4       R# VR,          ;_uu_ 4        VP                  R4      '       g%   Vez   \        VP                  R^ 4      4      V8w  dZ   R	VR
&   VP                  RR4       VP                  R4      '       d!   VP                  R4      VJd   \        V4        RRR4       R# \        Vf   VP                  R. 4      MT4      p
Vf   . VR&   VP                  R4      p\        V\        4      '       d   VP                  R4      R8X  d   \        WWVR7       VR,          pVf   R	VR
&   M:\        P                  \         4      ;_uu_ 4        VP#                  4        RRR4       RRR4       Xff   VP                  R4      ;'       g    \$        p\        P                  RVP                  R4      ;'       g    T V4       \'        WVRRRRRR/R7       R# X
V3#   + '       g   i     EL; i  + '       g   i     L™; i  + '       g   i     L¤; i)ué   Ownership + liveness gate every turn source must cross; ``(images, agent)`` or None.
Synthesized turns (auto-continue, wake-ups) call ``_run_prompt_submit`` directly â€” the
bypass that once let a second backend run a duplicate turn.Úactive_session_leaseÚ_closingNz6Refusing turn for session %s at _run_prompt_submit: %srI   r[   ÚrefusedÚhistory_lockFÚrunningÚ_submit_user_rowÚerrorÚmessageÚ_queued_prompt_generationÚattached_imagesÚinflight_turnr8   )rt   rv   r   Úagent_errorz4Refusing turn for session %s: no agent attached (%s)ÚlayerÚruntimeÚcodeÚagent_init_failedÚ	retryableT©Úerror_surface)r!   Ú_ensure_active_session_slotÚloggerÚinfor    r]   Ú_emitr   rM   Ú_release_active_session_slotÚlistrA   r   Ú_start_inflight_turnra   rb   rO   Úclear_interruptÚAGENT_MISSING_FOR_TURNÚ_emit_terminal_turn_error)rn   r   ro   rp   rr   rt   rv   rl   Ú
held_leaseÚownership_refusalÚimagesÚinflightr   r[   s   &&&&&&&$      r   Ú_admit_prompt_turnrš   t   s  € ð —‘Ð3Ó4€Jà�;‰;�z×"Ò"Ô=XÐY\Ó=fÐ(fÐ(9Ò'sÜ�‰ØDØ�K‰K˜Ó&×-Ð-¨#ÜÐ% x°Ó6×CÐC¸)ô	Eð �^×$×$Ø!&ˆG�IÑØ�K‰KÐ*¨DÔ1÷ %÷ $Ü�'˜3 ¬CÐ0AÓ,BÐ CÔDÙØ	�×	 ×	 Ø�;‰;�z×"Ò"Ø$Ò0Ü�G—K‘KÐ ;¸QÓ?Ó@ÐD\Ô\Ø!&ˆG�IÑØ�K‰KÐ*¨DÔ1Ø�{‰{˜:×&Ò&¨7¯;©;Ð7MÓ+NÐV`Ó+`ô -¨WÔ5Ø÷ 
!Ñ	 ô ¸KÒ<O�g—k‘kÐ"3°RÔ8ÐU`ÓaˆØÒØ)+ˆGÐ%Ñ&Ø—;‘;˜Ó/ˆô ˜(¤D×)Ò)¨X¯\©\¸(Ó-CÀwÔ-NÜ Ø¨Lõ]à˜Õ ˆØŠ=Ø!&ˆG�IÒä×$Ñ$¤Y×/Õ/Ø×%Ñ%Ô'÷ 0÷3 
!ð6 ‚}ð —‘˜]Ó+×EÐEÔ/EˆÜ�‰ÐJÈGÏKÉKÐXeÓLf×LmÐLmÐjmÐouÔvÜ!Ø˜&Ø" I¨vÐ7JÈKÐY]Ð^õ	`ñ Ø�5ˆ=Ð÷[ %×$Ð$ú÷> 0×/ú÷3 
!×	 ús>   ÂJ,Ã!A)KÅ!KÅ6B(KÈK 	È/KÊ,J=	Ë KËKËK#	Úauto_continueÚnotification_categoryc          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   r   r   ro   r   r›   r
   rœ   ru   r   r   r   )r   s   "r   r   r   ²   s1   € ÷ ñ  ð ¨Sð ÀDð Ø/9ðØEHñr   c               óŒ  € \        V 4      p\        V P                  R4      ;'       g    R4      p\        V P	                  R^ 4      ;'       g    ^ 4      pV P	                  RR4      ;'       g    Tp\        V\        4      '       d˜   VP                  4       '       d‚   V R,          ;_uu_ 4        WPR&   RRR4       \        WEV3RVR	V/VR
8X  d   RR
/M/ B  V R,          ;_uu_ 4        \        V P                  R4      4      pRRR4       X'       d   \        WE4       V#   + '       g   i     Lu; i  + '       g   i     L8; i)a[  Write the durable crash marker; returns the session key it was written under (compression
can rotate session_key mid-turn).  A surviving marker means the process died mid-turn.
The key is published before the disk write so an interrupt racing startup can retire
it; the post-write cancel check closes the inverse race (Stop landed first, no file).rI   r   Ú_auto_continue_attemptÚ_auto_continue_promptNr|   Ú_active_turn_marker_keyrY   r›   Ú
diagnosticrœ   Ú_turn_cancel_requested)
Ú_session_homer   r!   rM   r]   rA   r"   Úrecord_turn_startr
   Úclear_turn_marker)	r   ro   r›   rœ   Úmarker_homeÚ
marker_keyÚmarker_attemptÚmarker_textÚmarker_cancelleds	   &&$$     r   Ú_record_turn_markerr¬   ²   s  € ô   Ó(€KÜ�W—[‘[ Ó/×5Ð5°2Ó6€JÜ˜Ÿ™Ð%=¸qÓA×FÐFÀQÓG€NØ—+‘+Ð5°tÓ<×DÐDÀ€KÜ�+œs×#Ò#¨×(9Ñ(9×(;Ò(;Ø�^×$×$Ø1;Ð-Ñ.÷ %ä˜+°;ñ 	PÈð 	PØ(5ð	Pð !6¸Ô Eð 6°|ÑDØKMò	Pð �^×$×$Ü# G§K¡KÐ0HÓ$IÓJÐ÷ %çÜ˜kÔ6ØÐ÷ %×$ú÷ %×$ús   Â.D Ã(D3Ä D0	Ä3E	)Úslotsc                  ó„   € ] tR t^Êt$ RtRtR]R&   ]P                  ! ]	R7      t
R]R&   RtR]R&   RtR]R	&   RtR]R
&   RtR# )Ú_TurnScopeszOReset tokens for the thread/context scopes a turn binds (filled incrementally).Nr   Úapproval©Údefault_factoryr‘   Úsession_tokensÚhomeÚsecretÚterminalr   )r2   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r°   Ú__annotations__ÚdataclassesÚfieldr‘   r³   r´   rµ   r¶   Ú__static_attributes__r   r   r   r¯   r¯   Ê   sB   ‡ áYà€HˆcÓØ&×,Ò,¸TÔB€N�DÓBØ€Dˆ#ÓØ€FˆCÓØ€Hˆc×r   r¯   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úpromptr   r˜   ú	list[str]r   r   )r   s   "r   r   r   Õ   s!   € ÷ 4ñ 4 cð 4°9ð 4Àñ 4r   c           
     óž  €  ^ RI HpHp ^ RIHp \        V 4      w  rgV! WgV! 4       \        V RR4      R7      p\        V RR4      R8X  d   RpTR8w  d   \        Y4      #  X! Y4      w  r«T'       d)   \        R\        T4       R2\        P                  R
7       \        ;QJ d    R T
 4       F  '       g   K   RM	  RM! R T
 4       4      '       d   T
#  \        Y4      #   \         d+   p	\        R	T	 2\        P                  R
7       Rp Rp	?	LÅRp	?	ii ; i  \         d)   p	\        RT	 2\        P                  R
7        Rp	?	LqRp	?	ii ; i)zÊRun message for a turn with attached images: "native" content parts, or "text" path
references the agent analyzes in-loop (never blocking submit on vision calls).
Decision table: agent/image_routing.py.)Úbuild_native_content_partsÚdecide_image_input_mode©Úload_configÚrequested_providerr   )rÇ   Úapi_modeÚcodex_app_serverro   zA[tui_gateway] image_routing decision failed, defaulting to text: r.   NÚnativez.[tui_gateway] native image attachment skipped z unreadable path(s)c              3  óH   "  € T F  qP                  R 4      R8H  x € K  	  R# 5i)r1   Ú	image_urlN©r!   )Ú.0Úps   & r   Ú	<genexpr>Ú%_route_turn_images.<locals>.<genexpr>î   s   é € Ð;±U°�u‰u�V‹} Ö+³Uùs   ‚ "TFz:[tui_gateway] native attach failed, falling back to text: )Úagent.image_routingrÃ   rÄ   Úhermes_cli.configrÆ   Ú_active_image_routing_identityr    rO   r0   r3   r4   Ú_build_image_ref_messageÚlenÚany)r   rÀ   r˜   rÃ   rÄ   Ú_tui_load_configÚ	_providerÚ_modelÚmodeÚ_img_excÚpartsÚskippeds   &&&         r   Ú_route_turn_imagesrß   Õ   s8  € ðß[ÝEÜ:¸5ÓAÑˆ	Ù&ØÑ/Ó1Ü& uÐ.BÀBÓGôIˆô �5˜* bÓ)Ð-?Ô?ØˆDð
 ˆxÔÜ'¨Ó7Ð7ð
Ù3°FÓC‰ˆßÜØ@ÄÀWÃÀÐNaÐbÜ—Z‘Zõ!÷ ‹3Ñ;±UÓ;�3�3Š3Ñ;±UÓ;×;Ò;ØˆLð <ô
 $ FÓ3Ð3øô# ô ÜÐQÐRZÐQ[Ð\Ü—:‘:õ	à�ûðûô ô ÜÐJÈ8È*ÐUÜ—:‘:÷	ò 	ûðúsC   ‚A
C! ÁAD Â$D Â8D ÃD Ã!DÃ, DÄDÄEÄ$EÅEc               ó   € V ^8„  d   QhRR/# )r   r   ztuple[Any, bool]r   )r   s   "r   r   r   ö   s   € ÷  ñ  Ð+ñ  r   c                 óö   a€ \        4       p \        4       '       g   V R3# \        4       P                  RR4      '       d   \	        4         ^ RIHoHp R V3R llpW! VR7      3#   \         d    T R3u # i ; i)z×Arm voice-mode turn audio; ``(tts_queue, thinking_started)``.  ``_tts_stream_begin``
goes first: cutting a still-speaking previous turn IS this turn's barge-in, so it must
latch before the caller consumes the latch.FÚbarge_inT)Úis_audio_output_activeÚstart_thinking_soundc               ó   € V ^8„  d   QhRR/# ©r   r   r
   r   )r   s   "r   r   Ú'_start_turn_voice.<locals>.__annotate__  s   € ÷ 	ñ 	 tñ 	r   c                 ól   <€ S! 4       '       d   R #  ^ RI Hp  V ! 4       '       * #   \         d     R# i ; i)F)Úis_continuous_activeT)Úhermes_cli.voiceré   rO   )ré   rã   s    €r   Ú_thinking_should_playÚ0_start_turn_voice.<locals>._thinking_should_play  s5   ø€ Ù%×'Ò'ÙðÝAÙ/Ó1Ô1Ð1øÜô Úðús   ’$ ¤3²3)Úshould_play)	Ú_tts_stream_beginÚ_voice_mode_enabledÚ_voice_cfg_dictr!   Ú_arm_full_duplex_listenerÚtools.voice_moderã   rä   rO   )Ú	tts_queuerä   rë   rã   s      @r   Ú_start_turn_voicerô   ö   s}   ø€ ô "Ó#€IÜ× Ò Ø˜%ÐÐÜÓ×Ñ˜Z¨×.Ò.Ü!Ô#ð ßQ÷	ð 	ð Ð.Ð;PÔQÐQÐQøÜô  Ø˜%ÐÒð ús   ÁA& Á&A8Á7A8c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   r   r   r7   Úhistoryr‘   Úhistory_versionrM   r   ru   r   )r   s   "r   r   r     s4   € ÷ %5ñ %5Øð%5Øð%5Ø*.ð%5ØADð%5ØISñ%5r   c           	     ó4  € V R,          ;_uu_ 4        \        V P                  R^ 4      4      pWC8X  d$   VR,          V R&   V^,           V R&    RRR4       R# \        V R,          4      pV Uu. uF  p\        V4      '       d   K  VNK  	  ppV Uu. uF  p\        V4      '       d   K  VNK  	  ppW‡8X  d˜   \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d^   VR,          p	\        V	4      \        V4      8”  d   V	\        V4      R M
\        V	4      p
WZ,           V R&   V^,           V R&    RRR4       R# \        R	V R
V R2\        P                  R7         RRR4       R# u upi u upi   + '       g   i     R# ; i)aC  Write the agent's messages back to session history; returns a client warning or None.
If history_version moved mid-turn, the only tolerated mutation is a gateway-inserted
pivot marker (compare content, not indices: ``_append_model_switch_marker`` strips prior
markers in place); any other desync is surfaced, never dropped.r|   r÷   Úmessagesrö   Nc              3  ó8   "  € T F  p\        V4      x € K  	  R # 5i©N)Ú_is_pivot_marker)rÎ   Úes   & r   rÐ   Ú'_commit_turn_history.<locals>.<genexpr>%  s   é € ð <>Ù-<¨Ô  ×#Ð#«_ùs   ‚TFz@[tui_gateway] prompt.submit: history_version mismatch (expected=z	 current=u1   ) â€” agent output NOT written to session historyr.   uh   History changed during this turn â€” the response above is visible but was not saved to session history.)	rM   r!   r‘   rü   r×   rÖ   r0   r3   r4   )r   r7   rö   r÷   Úcurrent_versionÚcurrent_historyrý   Úhistory_no_markersÚcurrent_no_markersÚmsgsÚnew_messagess   &&&&       r   Ú_commit_turn_historyr    sŒ  € ð 
�×	 ×	 Ü˜gŸk™kÐ*;¸QÓ?Ó@ˆØÔ-Ø!'¨
Õ!3ˆG�IÑØ)8¸1Õ)<ˆGÐ%Ñ&Ø÷ 
!Ñ	 ô ˜w yÕ1Ó2ˆÙ)0ÓL© AÔ8HÈ×8KŸa˜a©ÐÐLÙ)8ÓT© AÔ@PÐQR×@SŸa˜a©ÐÐTØÔ3¿»ñ <>Ù-<ó<>¿¿ºñ <>Ù-<ó<>÷ 9>ò 9>ð ˜*Õ%ˆDÜ25°d³)¼cÀ'»lÔ2J˜4¤ G£ Ñ.ÔPTÐUYÓPZˆLØ!0Õ!?ˆG�IÑØ)8¸1Õ)<ˆGÐ%Ñ&Ø÷/ 
!Ñ	 ô0 	ðØ(Ð)¨°?Ð2Cð D:ð;ô —‘õ		ð4ð	5÷; 
!Ñ	 ùò MùÚT÷ 
!×	 Ð	 úsT   ’;FÁFÁ-E<ÂE<ÂFÂFÂ)FÂ/FÃFÃFÃ1AFÅ$FÅ<
FÆF	c               ó    € V ^8„  d   QhRRRR/# )r   r7   r   r   r   r   )r   s   "r   r   r   7  s   € ÷ =ñ =˜4ð = Cñ =r   c                ój   € V P                  R 4      '       d   R # V P                  R4      '       d   R# R# )r>   r   r<   rÍ   )r7   s   &r   Ú_result_statusr  7  s6   € àŸ™ M×2Ò2ˆð=àŸ
™
 7×+Ò+ˆWð=à1;ð=r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r7   r   r‹   rw   r   ztuple[Any, str, str | None]r   )r   s   "r   r   r   =  s"   € ÷ 'ñ '˜#ð '¨kð 'ÐE`ñ 'r   c                óŠ  € \        V \        4      '       g   \        V 4      RR3# V P                  RR4      p\	        V 4      pV'       ga   V P                  R4      '       dJ   V P                  R4      '       g   V P                  R4      '       d   \        V P                  R4      V4      pVR8X  dB   \        V\        4      '       d,   VP                  4       P                  \        4      '       d   RpV P                  R	4      p\        V\        4      '       d'   VP                  4       '       d   VP                  4       MRpW#V3# )
zKReduce a run_conversation result to ``(raw_text, status, last_reasoning)``.r<   NÚfinal_responser   r   r=   Úpartialr>   Úlast_reasoning)	rA   r   r   r!   r  Úturn_error_textr"   Ú
startswithÚ"INTERRUPT_WAITING_FOR_MODEL_PREFIX)r7   r‹   r9   r8   Úlrr  s   &&    r   Ú_turn_outcomer  =  só   € ä�fœd×#Ò#Ü�6‹{˜J¨Ð,Ð,Ø
�*‰*Ð% rÓ
*€CÜ˜FÓ#€F÷ �V—Z‘Z ×(Ò(¨f¯j©j¸×.BÒ.BÀfÇjÁjÐQZ×F[ÒF[Ü˜fŸj™j¨Ó1°=ÓAˆð �Ô¤:¨c´3×#7Ò#7¸C¿I¹I»K×<RÑ<RÜ.÷=0ò =0àˆØ	�‰Ð$Ó	%€BÜ#-¨b´#×#6Ò#6¸2¿8¹8¿:º:�R—X‘X”ZÈ4€NØ˜Ð&Ð&r   c               ó0   € V ^8„  d   QhRRRRRRRRRRR	R
/# )r   rn   r   r   r   r7   r   r8   r9   r   ru   r   )r   s   "r   r   r   U  s<   € ÷ (ñ (Ø	ð(Øð(Ø%(ð(Ø25ð(Ø<?ð(ØDNñ(r   c           	     ó  a a€ Rp\        \        V\        4      ;'       d    VP                  R4      4      p \	        WW4R7      w  poS'       d1   ^ RIHp V! VV 3R lR\        VP                  R4      RR4      R	7       T;'       g    RpV'       g   \        W#V4      '       g   V#  VP                  R4      '       dã   \        V4      ;p
eÔ   ^ p ^ RIHpHp T! VP                  R4      ;'       g    RR7      pV! \        VP                  R4      RR4      4      pV
P                  VRWëR7      pVP                  R4      ;'       g    R;p'       d   \!        RS RRRV/4       VP                  R4      '       d&   VP                  R4      ;'       g    R;p'       d   TpV#   \         d   p	\        R
T	4        Rp	?	EL5Rp	?	ii ; i  \         d    Rp Lºi ; i  \         d   p\        RT4        Rp?T# Rp?ii ; i)zø/goal continuation (mirrors gateway/run._post_turn_goal_continuation): the prompt to
chain once ``running`` is released, or None.  Compression failures are never judge
input: the error text is not work toward the goal, and judging it spends a turn.NrU   )r8   r9   )Úrender_notificationc                 ó&   <€ \        R SRRRS /4      # )ústatus.updateÚkindrW   ro   ©r�   )Úrecovery_noticern   s   €€r   Ú<lambda>Ú+_goal_followup_after_turn.<locals>.<lambda>b  s   ø€ œ˜o¨s°V¸VÀVÈ_Ð4]Ô^r   Útuir   Ú_notification_config)ÚplatformÚuser_configzgoal compression recoveryrI   )Úcount_active_delegationsÚgather_background_processes)Úowner_task_idrJ   T)Úuser_initiatedÚbackground_processesÚactive_delegationsr€   r   r  r  rW   ro   Úshould_continuerj   zgoal continuation hook)r
   rA   r   r!   rk   Úgateway.warning_notificationsr  r    rO   r5   rB   rR   rL   r!  r"  Úevaluate_after_turnr�   )rn   r   r7   r8   r9   Úgoal_followuprU   Úrecovery_promptr  Ú_goal_recovery_excrQ   Ú_active_delegr!  Ú
_gather_bgÚ	_bg_procsÚdecisionÚverdict_msgÚcont_promptÚ	_goal_excr  s   f&&&&              @r   Ú_goal_followup_after_turnr4  U  sî  ù€ ð
 €MÜ ¤¨F´DÓ!9×!aÐ!a¸f¿j¹jÐI`Ó>aÓbÐð
GÜ+JØ Fô,5Ñ(ˆ˜çÝIÙÝ^Ø¬G°G·K±KÀÓ4HÐJ`ÐbfÓ,gõið (×/Ð/¨4ˆ÷ Ô$<¸VÈS×$QÒ$QØÐð;Ø�;‰;�}×%Ò%Ô7KÈGÓ7TÐ+T¨8Ò*aØˆMð!ßpñ '°W·[±[ÀÓ5O×5WÐ5WÐSWÔX�	Ù 8¼ÀÇÁÈWÓAUÐWcÐeiÓ9jÓ k�ð  ×3Ñ3Ø D¸yð 4ó lˆHà&Ÿl™l¨9Ó5×;Ð;¸Ð;ˆ{Ö;Ü�o s¨V°V¸VÀ[Ð,QÔRØ�|‰|Ð-×.Ò.Ø'Ÿ|™|Ð,AÓB×HÐHÀbÐH�ÖHØ +�ð Ðøô1 ô GÜÐ1Ð3E×FÒFûðGûô ô !Ø ’	ð!ûô ô ;ÜÐ.°	×:Ð:ØÐûð;ús„   ¸AF$ Â	F$ Â)G Ã G Ã!G	 Ã4*G	 Ä+G Å

G Å'G Å=G Æ
G Æ G Æ$GÆ/GÇGÇ	GÇG ÇGÇG ÇG>Ç'G9Ç9G>c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   rn   r   r   r   ÚstÚ_TurnRunr9   r   r   r+   r   )r   s   "r   r   r   €  s/   € ÷ #?ñ #?˜cð #?¨Dð #?°hð #?ÀSð #?ÈTñ #?r   c                óà  €  ^ RI Hp VP                  R4      ;'       g    RpV'       d‰   V! VR7      pVP                  pVep   VP                  '       d^   TP                  \        V\        4      '       d   TMR4      pVP                  R4      ;'       g    R;p	'       d   \        RV RR	R
V	/4       TP                  R4      ;p'       d]   TP                  R4      ;'       g    T p \        T4      ;_uu_ 4       pT'       d   TP                  YË4      '       d   RTR&   RRR4       TP                   fq   \        T\        4      '       dY   TP#                  4       '       dA   \%        4       '       d/    \&        P)                  \*        T3RR7      P-                  4        R# R# R# R# R#   \         d   p
\        RT
4        Rp
?
ELRp
?
ii ; i  + '       g   i     Lµ; i  \         d&   pRTR&   \        P                  RYÎ4        Rp?LãRp?i\         d     Lói ; i  \.         d    \        P1                  R4        R# \         d"   p\        P1                  RT4        Rp?R# Rp?ii ; i)zTHooks for a ``complete`` turn: /loop tick evaluation, pending title, voice fallback.)ÚLoopManagerrI   r   )rJ   Nr€   r  r  Úloopro   zloop completion hookÚpending_titlez)Dropping pending title for session %s: %sT)ÚtargetÚargsÚdaemonz/voice TTS skipped: hermes_cli.voice unavailablezvoice TTS dispatch failed: %s)Úhermes_cli.loopsr9  r!   r`   Úawaiting_responseÚcomplete_tickrA   r   r�   rO   r5   Ú_session_dbÚset_session_titlerd   r�   rŽ   ró   r"   Ú_voice_tts_enabledÚ	threadingÚThreadÚ_speak_text_with_bargeÚstartÚImportErrorÚwarning)rn   r   r6  r9   r9  Úloop_sid_keyÚloop_mgrÚ
loop_stateÚloop_decisionÚloop_msgÚ	_loop_excÚ_pendingÚ_session_keyÚ_pdbr)   rý   s   &&&&            r   Ú_after_complete_turnrT  €  sõ  € ð9Ý0Ø—{‘{ =Ó1×7Ð7°RˆßÙ"¨lÔ;ˆHØ!Ÿ™ˆJØÒ%¨*×*F×*FÐ*FØ (× 6Ñ 6¼jÈÌc×>RÒ>R±sÐXZÓ [�Ø,×0Ñ0°Ó;×AÐA¸rÐA�8ÖAÜ˜/¨3°¸ÀÈÐ0RÔSð —;‘;˜Ó/Ð/€xÖ/Ø—{‘{ =Ó1×8Ð8°Sˆð		Ü˜W×%Ô%¨ß˜D×2Ñ2°<×JÒJØ/3�G˜OÑ,÷ &ð 
‡|�|Ò¤
¨3´× 4Ò 4¸¿¹¿ºÔI[×I]ÒI]ð	?Ü×ÑÔ$:À#ÀÐPTÐÓU×[Ñ[Ö]ñ J^¹Ñ 4Ñøô# ô 9ÜÐ,¨i×8Ò8ûð9ú÷ &×%ûô ô 	Xà'+ˆG�OÑ$Ü�K‰KÐCÀ\×WÑWûÜô 	Ùð	ûô ô 	NÜ�N‰NÐL×MÜô 	?Ü�N‰NÐ:¸A×>Ò>ûð	?úsš   ‚F(  
F( «*F( ÁA F( Â
F( Â"F( Ã(G  Ã;%GÄ G  Å3+H Æ(G
Æ3GÇG
ÇG	ÇG  ÇG  Ç HÇ+HÈHÈHÈHÈ I-ÉI-ÉI-ÉI(É(I-Úon_doneÚon_errorc          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   rn   r   r   r   rÀ   r   r(   r   r+   r   )r   s   "r   r   r   ¦  s0   € ÷ 'ñ ' cð '°Dð 'À#ð 'ÈSð 'Ø<@ñ'r   c               ó  €  \        RV4       \        WW#4       Ve
   V! 4        R# R#   \         dY   pTe   T! 4        \        YG4       TR,          ;_uu_ 4        RTR&   RRR4        Rp?R#   + '       g   i      Rp?R# ; iRp?ii ; i)ziChain one follow-up turn (caller set ``running``); on failure run ``on_error``, log,
release ``running``.úmessage.startNr|   Fr}   )r�   Ú_run_prompt_submitrO   r5   )Úridrn   r   rÀ   r(   rU  rV  r)   s   &&&&&$$ r   Ú_dispatch_followup_turnr\  ¦  st   € ð
'Üˆo˜sÔ#Ü˜3 WÔ5ØÒÙŽIñ øäô 'ØÒÙŒJÜ�dÔ Ø�^×$×$Ø!&ˆG�IÑ÷ %×$×$×$Ò$þð	'ús2   ‚#) ©B´'BÁA/Á!BÁ/BÁ:BÂBÂBc          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   rn   r   r   r   r7   r   r*  ru   r   r+   r   )r   s   "r   r   r   ·  s4   € ÷ +<ñ +<Øð+<Ø ð+<Ø*-ð+<Ø>Hð+<ØMQñ+<r   c                óò  aaaa€ \        V\        4      '       d   VP                  R4      MRp\        V\        4      '       dM   VP	                  4       '       d7   SR,          ;_uu_ 4        \        SVSP                  R4      4       RRR4       \        V SS4      '       d   R# V'       d}   \        S4      ;_uu_ 4       pV'       d   SP                  R4      '       d    RRR4       R# SP                  R4      '       d    RRR4       R# RSR&   RRR4       \        V SSVR4        ^ R	I	H
o ^ R
IHp ^ RIHpHp	 SP                  RR4      oVVVV3R lp
\!        S4      ;_uu_ 4        V! SV
4      ;_uu_ 4       p. p\#        SSV Uu. uF  qÙ! V4      '       g   K  VNK  	  upSP%                  R\'        4       4      SWŒRR7       V F  pSP(                  P+                  V4       K   	  RRR4       RRR4       R#   + '       g   i     EL�; i  + '       g   i     EL; iu upi   + '       g   i     LG; i  + '       g   i     R# ; i  \,         d   p\/        RT4        Rp?R# Rp?ii ; i)a<  Chain whatever should run after ``running`` was released.  Order: a mid-turn user
prompt wins over every auto follow-up (drain it, skip the rest); a leftover /steer is
requeued first so it isn't dropped; then goal continuation, then completion
notifications.  Each nested submit re-checks ``running`` under the lock.Úpending_steerNr|   Ú	transportr}   r£   Tzgoal continuation dispatch)Úprocess_registry)Údrained_for)Úformat_process_notificationÚshould_surface_notificationrI   r   c                óZ   <€ SP                  V SVV3R  lV P                  R4      R8H  4      # )c                ó   <€ \        SSV 4      # rû   )Ú _session_owns_notification_event)Úevtr   rn   s   &€€r   r  Ú<_run_post_turn_followups.<locals>.<lambda>.<locals>.<lambda>Ö  s   ø€ Ô @ÀÀgÈsÔ Sr   r1   Úasync_delegation)Ú_owns_eventr!   )rý   Úkeyra  r   rn   s   &€€€€r   r  Ú*_run_post_turn_followups.<locals>.<lambda>Õ  s/   ø€ Ð)×5Ñ5ØˆsÕSÐUV×UZÑUZÐ[aÓUbÐfxÑUxôzr   Ú_notification_emitted)Úownedzcompletion queue drain)rA   r   r!   r   r"   Ú_enqueue_promptÚ_drain_queued_promptÚ_session_turn_admissionr\  Útools.process_registryra  Útools.process_registry_awaitingrb  Ú$tools.process_registry_notificationsrc  rd  Ú_session_profile_runtime_scopeÚ_notif_handle_readyÚ
setdefaultÚsetÚcompletion_queueÚputrO   r5   )r[  rn   r   r7   r*  ÚsteerÚadmittedrb  rc  rd  ÚownsÚmineÚdeferredrh  ÚeventÚ
_drain_excrl  ra  s   &ff&&           @@r   Ú_run_post_turn_followupsrƒ  ·  sé  û€ ô ,6°f¼d×+CÒ+CˆF�J‰J�Ô'È€EÜ�%œ×Ò %§+¡+§-¢-Ø�^×$×$Ü˜G U¨G¯K©K¸Ó,DÔE÷ %ä˜C  g×.Ò.ÙßÜ$ W×-Ô-°ß˜wŸ{™{¨9×5Ò5Ø÷ .Ñ-ð �{‰{Ð3×4Ò4Ø÷	 .Ñ-ð
 "&ˆG�IÑ÷ .ô 	   S¨'°=ÐB^Ô_ð<Ý;õ 	@ßqØ�k‰k˜-¨Ó,ˆ÷zˆô ,¨G×4Õ4±kÐBRÐTX×6YÔ6YÐ]aØˆHÜØ�W©dÓW©d sÐ6QÐRU×6VŸs˜s©dÑWØ×"Ñ"Ð#:¼C»EÓBÐDTØ+¸TõCó "�Ø ×1Ñ1×5Ñ5°eÖ<ñ "÷ 7Z×4Ñ4÷5 %×$Ð$ú÷
 .×-Ð-üò0 X÷ 7Z×6Yú×4×4Ð4ûô ô <ÜÐ.°
×;Ò;ûð<ús˜   Á+H Ã HÃ HÃ+HÄHÄHÄ*AI Å,I Å>H-	ÆH(Æ H(Æ&AH-	Ç.I Ç6I È H	ÈH%	È(H-	È-H=È8I É I	ÉI ÉI ÉI6ÉI1É1I6c                  ó>  € ] tR tRt$ RtR]R&   R]R&   R]R&   R]R&   ]P                  ! ]R	7      t	R
]R&   Rt
R]R&   RtR]R&   RtR]R&   ]P                  ! ]R	7      tR]R&   ^ tR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR# ) r7  iå  zôShared state of one turn thread.  ``agent`` is bound eagerly so except/finally always
have one; ``error_retained`` makes the finally keep the failed inflight snapshot for
resume replay; ``error_detail`` is the "tui turn finished" failure cause.r   r   Úone_turn_restoreÚterminal_callbackr
   Úreceipt_committedr±   r¯   ÚscopesNr7   ró   FÚthinking_startedr‘   rö   rM   r÷   rs   Úcompression_countÚ
run_kwargsÚerror_retainedr   r   Úerror_detailÚprompt_textr¨   Úreceipt_attemptedr   )r2   r·   r¸   r¹   rº   r»   r¼   r½   r¯   rˆ  r7   ró   r‰  r‘   rö   r÷   rŠ  r‹  rŒ  r�  rŽ  r¨   r�  r¾   r   r   r   r7  r7  å  s¼   ‡ ñQð ƒJØÓØÓØÓØ%×+Ò+¸KÔH€FˆKÓHØ€FˆCÓØ€IˆsÓØ"Ð�dÓ"Ø×%Ò%°dÔ;€GˆTÓ;Ø€O�SÓØ$(Ð�zÓ(Ø€J�ÓØ €N�DÓ Ø€L�#ÓØ€K�ÓØ€J�ÓØ#Ð�t×#r   r7  c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   r+   r   )r   s   "r   r   r   þ  s   € ÷ 11ñ 11 dð 11¨tñ 11r   c           
     óR  aaaa€ V R,          ;_uu_ 4        \        V P                  R4      ;'       g    R4      \        V P                  R^ 4      4      r!RRR4       \        V3R lX 4       RR7      o\	        V P                  R4      ;'       g    / 4      oR V3R	 lloSf   \        WXS4       R# R
 VV3R llp\        V 4      ;_uu_ 4       p Ve   VP                  \        V 4      SR7      M. p RRR4       X Uu. uF#  qc! TP                  R4      4      '       g   K!  TNK%  	  ppT'       g   R# \        ;QJ d    R T 4       F  '       g   K   RM	  RM! R T 4       4      p\        YR7      ;'       g    . pT'       d   SMTp	\        T U
u. uF  q©! \	        T
4      4      '       g   K  T
NK  	  up
4      pT'       g   R# T R,          ;_uu_ 4        \        T P                  R^ 4      4      X8w  d    RRR4       R# T'       d   TMY,           T R&   T^,           T R&   RRR4       R#   + '       g   i     ELæ; i  \         d$    \        P                  RRR7        RRR4       R# i ; i  + '       g   i     ELŠ; iu upi u up
i   + '       g   i     R# ; i)uG  Fold turns another surface appended to this session (Telegram reply, cron run) into the model-facing
history before the turn snapshots it. The desktop already repaints them from the DB (#86588); without
this the next prompt still ran on the in-memory history and the model never saw them (#42962).
Foreign rows are the active rows between the highest ``_row_id`` the agent's own flushes stamped onto
the in-memory messages (``sync_flushed_message_markers``; a local compaction re-stamps them too) and
this turn's own user row, which ``_persist_submit_user_row`` already wrote (#111868). When a foreign
row is a compaction summary the other surface rewrote the transcript under us, so the in-memory history
is stale from the root and is re-hydrated from the DB the way ``session.resume`` does. Nothing stamped
yet (seeded branch before its first turn) means nothing to adopt; a cold resume arrives stamped â€” but a
record whose list was rebuilt from provider-format messages carries no stamp at all, so the row-id
boundary cannot key on anything and the store-ahead fallback takes over (#81951).r|   rö   r÷   Nc              3  óz   <"  € T F0  p\        V\        4      '       g   K  \        V4      ;of   K,  Sx € K2  	  R # 5irû   )rA   r   Ú_message_row_id)rÎ   Úmr[  s   & €r   rÐ   Ú+_adopt_out_of_band_turns.<locals>.<genexpr>  s+   øé € Ðh™W˜¬
°1´d×(;”ÌÐXYÓHZÐAZÀ—’›Wùs   ƒ; ;±
;)Údefaultr~   c               ó   € V ^8„  d   QhRR/# ræ   r   )r   s   "r   r   Ú._adopt_out_of_band_turns.<locals>.__annotate__  s   € ÷ Kñ K˜tñ Kr   c                óV   <€ \        V \        4      ;'       d    SR J ;'       g    V S8  # rû   )rA   rM   )r[  Úceilings   &€r   Ú_below_ceilingÚ0_adopt_out_of_band_turns.<locals>._below_ceiling  s(   ø€ Ü˜#œsÓ#×JÐJ¨°D¨×)IÐ)I¸CÀ'¹MÐJr   c               ó   € V ^8„  d   QhRR/# ræ   r   )r   s   "r   r   r˜    s   € ÷ 2ñ 2˜ñ 2r   c                ó.   <€ S! V 4      ;'       d    V S8„  # rû   r   )r[  r›  Úseens   &€€r   Ú_foreignÚ*_adopt_out_of_band_turns.<locals>._foreign  s   ø€ Ù˜cÓ"×1Ð1 s¨T¡zÐ1r   )Úafter_idzDout-of-band history probe failed; turn runs on the in-memory historyT©Úexc_infoÚidc              3  óB   "  € T F  qP                  R 4      x € K  	  R# 5i)Ú_compressed_summaryNrÍ   )rÎ   Úrows   & r   rÐ   r•  %  s   é € ÐD¹e°s—G‘GÐ1×2Ð2»eùs   ‚F©Úrepair_alternationr   )r‘   r!   rM   Úmaxr“  Ú!_adopt_store_tail_without_row_idsrB  Úget_messagesÚ_submit_row_target_keyrO   r�   Údebugr×   Ú _load_durable_truncation_historyÚcanonicalize_replay_history)r   rö   Úversionr   ÚdbÚnewerr¨  Ú	rewrittenÚrowsÚkeepr”  Útailr›  rš  r[  rŸ  s   &           @@@@r   Ú_adopt_out_of_band_turnsr¹  þ  s#  û€ ð 
�×	 ×	 Ü §¡¨IÓ 6× <Ð <¸"Ó=¼sÀ7Ç;Á;ÐO`ÐbcÓCdÓ?e�÷ 
!äÔh™WÓhØô€Dä˜gŸk™kÐ*<Ó=×CÐCÀÓD€G÷Kð Kà‚|Ü)¨'¸GÀ^ÔTÙ÷2ñ 2ô 
�W×	Ô	 ð	ØWYÒWe�B—O‘OÔ$:¸7Ó$CÈd�OÔSÐkm‰E÷ 
ñ "Ó=™E�S X¨c¯g©g°d«m×%<�SˆS™E€EÐ=ßÙß“ÑD¹eÓD——’ÑD¹eÓDÓD€IÜ+¨GÔR×XÐXÐVX€Dß&‰>¨H€DÜ&±4Ó'T±4¨a¸4ÄÐPQÓ@R×;S¯¨±4Ñ'TÓU€DßÙØ	�×	 ×	 Üˆw�{‰{Ð,¨aÓ0Ó1°WÔ<Ø÷ 
!Ñ	 ÷ &/™T°GµNˆ�	ÑØ%,¨q¥[ˆÐ!Ñ"÷	 
!Ñ	 ÷C 
!×	 Ð	 ûô* ô 	Ü�L‰LÐ_ÐjnˆLÔoØ÷ 
Ñ	ð	ú÷ 
×	Ð	üò >ùò (U÷ 
!×	 Ð	 úse   –?H2ÃI7Ã"IÄJÄ%JÆJÆ3JÇ"JÈJÈJÈ2I	É"I4É(I7É3I4É4I7É7J	ÊJ&	c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r   r   rö   r‘   r²  rM   r   r+   r   )r   s   "r   r   r   2  s)   € ÷ .1ñ .1¨tð .1¸dð .1ÈSð .1Ðdhñ .1r   c                ó¬  a€ \        V RR7      ;'       g    .  Uu. uF  pV! \        V4      4      '       g   K  VNK   	  ppV'       g   R# V Uu0 uFE  p\        V\        4      '       g   K  VP	                  R4      '       g   K4  VP	                  R4      kKG  	  upo\
        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       d`   \        V4      pV R,          ;_uu_ 4        V'       d1   \        V P	                  R	^ 4      4      V8X  d   W`R
&   V^,           V R	&   RRR4       R# \        V4      \        V4      8:  d   R# \        ;QJ d%    R \        W4       4       F  '       d   K   RM	  RM! R \        W4       4       4      '       g   R# \        V\        V4      R 4      pV'       g   R# V R,          ;_uu_ 4        \        V P	                  R	^ 4      4      V8w  d    RRR4       R# W,           V R
&   V^,           V R	&   RRR4       R# u upi u upi   + '       g   i     R# ; i  + '       g   i     R# ; i)u­  Catch a live record up with the store when its in-memory messages carry NO durable ``_row_id``.

``_adopt_out_of_band_turns`` keys off the highest ``_row_id`` in memory; a record whose list was
rebuilt from provider-format messages (the unstamped shape ``_resolve_truncate_row_id`` heals for
rewind â€” #82959) carries none. A writer in ANOTHER process (the messaging gateway appending to the
same session while the desktop's serve record holds it) was then silently dropped and the next
provider request truncated to the early snapshot while the UI showed the full transcript (#81951).

With no row ids there is no boundary to key on, so adoption is gated on proof instead: the durable
lineage (below this turn's own user row, which ``_persist_submit_user_row`` already wrote and the turn
appends itself) must be STRICTLY longer and its head must equal the in-memory view entry for entry.
A diverged view (prefix mismatch, e.g. a rewind that has not landed locally), a store that is not
ahead (an unflushed local tail is the fresher record) and an empty in-memory history (no head to
prove against) are left alone.

A compaction by another surface is the one rewrite that is NOT an append: the store then holds a
``_compressed_summary`` row the in-memory view has never seen, so the view is stale from the root and
is re-hydrated from the DB like the stamped path does â€” a positional check alone would keep it because
the compacted store is shorter.
Tr©  Nr§  Úcontentc              3  ó|   <"  € T F1  qP                  R 4      ;'       d    VP                  R4      S9  x € K3  	  R# 5i)r§  r¼  NrÍ   )rÎ   r”  Úknowns   & €r   rÐ   Ú4_adopt_store_tail_without_row_ids.<locals>.<genexpr>L  s4   øé € Ð
XÑSWÈa�5‰5Ð&Ó'×IÐI¨A¯E©E°)Ó,<ÀEÑ,IÔIÓSWùs   ƒ<Ÿ<Fr|   r÷   rö   c              3  óò   "  € T Fm  w  r\        V\        4      ;'       dO    VP                  R 4      VP                  R 4      8H  ;'       d$    VP                  R4      VP                  R4      8H  x € Ko  	  R# 5i)Úroler¼  N)rA   r   r!   )rÎ   ÚmemÚstoreds   &  r   rÐ   r¿  U  sk   é € ð 6á"4‘;�3ô ˜#œtÓ$÷ ?ð ?¨¯©°«¸F¿J¹JÀvÓ<NÑ)N÷ ?ð ?Ø—7‘7˜9Ó%¨¯©°IÓ)>Ñ>ô?ã"4ùs   ‚A7 *A7Á,A7)r°  r“  rA   r   r!   r×   r±  rM   rÖ   ÚallÚzip)r   rö   r²  Úbelow_ceilingr”  r¶  r¸  r¾  s   &&&&   @r   r¬  r¬  2  sÜ  ø€ ô* 8¸ÐTXÔY×_Ð_Ð]_Ð_ó 2Ñ_�!Ùœ_¨QÓ/×0÷ ˆAÑ_€Dð 2çÙÙ'.Óg¡w !´*¸QÄ×2EÔÈ!Ï%É%ÐPe×JfÔˆQ�U‰U�9Ö¡wÑg€Eß
ƒsÔ
XÑSWÓ
X‡s‡s‚sÔ
XÑSWÓ
X×XÒXÜ*¨4Ó0ˆØ�^×$×$ßœ˜GŸK™KÐ(9¸1Ó=Ó>À'ÔIØ%)˜	Ñ"Ø-4°q­[�Ð)Ñ*÷ %ñ 	Ü
ˆ4ƒy”C˜“LÔ Ùß‹3ñ 6ä"% gÔ"4ó6�3�3Š3ñ 6ä"% gÔ"4ó6÷ 6ò 6ñ 	Ü& t¬C°«L¨MÐ':Ó;€DßÙØ	�×	 ×	 Üˆw�{‰{Ð,¨aÓ0Ó1°WÔ<Ø÷ 
!Ñ	 ð %�^ˆ�	ÑØ%,¨q¥[ˆÐ!Ñ"÷	 
!Ñ	 ùò+2ùò h÷ %Ö$ñ 	ú÷ 
!×	 Ð	 ús:   ›H$¹H$ÁH)Á,H)ÂH)Ã99H.Ç"IÈIÈ.H?	ÉI	c               ó    € V ^8„  d   QhRRRR/# r   r   )r   s   "r   r   r   c  s   € ÷ ñ ¨ð °$ñ r   c                óô   €  \        V 4      ;_uu_ 4       pVRJ;'       d    VP                  ^4      uuRRR4       #   + '       g   i     R# ; i  \         d    \        P	                  RRR7        R# i ; i)aT  True when this install already has session rows beyond the current one.

Mirrors ``gateway.session.SessionStore.has_any_sessions`` (the messaging
first-contact gate): ``_run_prompt_submit`` persists the session's own row
before the turn runs (``_ensure_session_db_row``), so a fresh install on
its first-ever message holds exactly one row.
Nz2session count probe failed for first-contact checkTr£  F)rB  Úsession_count_gerO   r�   r¯  )r   r³  s   & r   Ú_install_has_prior_sessionsrÊ  c  s`   € ðÜ˜×!Ô! RØ˜T�>×<Ð< b×&9Ñ&9¸!Ó&<÷ "×!×!Ó!ûäô Ü�‰ÐIÐTXˆÔYÚðús+   ‚A •=²
A ½A	ÁA ÁA Á"A7Á6A7c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   Úhistory_emptyr
   r   r+   r   )r   s   "r   r   r   s  s'   € ÷ Lñ L°$ð LÈdð LÐW[ñ Lr   c                ó~  €  ^ RI Hp ^ RIHp ^ RIHp T! V! 4       ;'       g    / V! 4       R,          T\        V 4      R\        VRR4      ;'       g    R9   R7      pV'       g   R# \        VR	R
4      ;'       g    R
pV'       d   V RV 2MTVn        R#   \         d    \        P                  RRR7        R# i ; i)u³  Stage the install's first-message onboarding note for THIS turn (#82750).

The messaging gateway appends the consent-gated profile-build directive to
the very first message ever (``_hmwa_first_contact_notes``); the
TUI/Desktop surface never did, so a fresh install's first Desktop chat
skipped the opt-in profile flow entirely. Stage the same note through
``agent._gateway_turn_context_notes`` â€” consumed by
``agent.turn_context`` on the user message â€” never the ephemeral system
prompt, which must stay byte-stable for the conversation (prompt-cache
invariant). Fires at most once per install: the directive path persists
``onboarding.seen.profile_build_offered`` before the turn runs.
)Úfirst_contact_turn_noterÅ   )Úget_hermes_homezconfig.yamlÚ
setup_beatÚvalid_tool_namesN)Úsession_history_emptyÚinstall_has_prior_sessionsÚonboarding_run_activeÚ_gateway_turn_context_notesr   z

z$first-contact onboarding note failedTr£  r   )Úagent.onboardingrÎ  rÓ   rÆ   Úhermes_constantsrÏ  rÊ  r    rÕ  rO   r�   r¯  )r   r   rÌ  rÎ  Ú_load_onboarding_configrÏ  ÚnoteÚpriors   &&&     r   Ú$_stage_first_contact_onboarding_noterÛ  s  s³   € ðLÝ<ÝLÝ4á&Ù#Ó%×+Ð+¨ÙÓ Õ-Ø"/Ü'BÀ7Ó'KØ".´7¸5ÐBTÐVZÓ3[×3aÐ3aÐ_aÑ"bô
ˆ÷ ÙÜ˜Ð<¸bÓA×GÐGÀRˆßDI¨u¨g°T¸$¸Ñ,@ÈtˆÖ)øÜô LÜ�‰Ð;Àdˆ×KðLús.   ‚!B ¤.B ÁB Á'B Á;
B ÂB Â"B<Â;B<c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   rn   r   r   r   r6  r7  ro   r   r˜   rÁ   r   )r   s   "r   r   r   ”  s>   € ÷ MZñ MZ˜Sð MZ¨4ð MZ°Xð MZÀSð MZÐR[ñ MZr   c                ó2  € ^ RI Hp VP                  pV! VR,          4      Vn        \	        VR,          V R7      Vn        \        VP                  R4      4      pVe5   VP                  VP                  VP                  uVn        Vn	        Vn
        \        V 4       VP                  '       g"   \        W4       \        W4       \        W4       \!        W4       \#        W4       \%        V4       VR,          ;Vn        pVR,          ;_uu_ 4        \)        VR,          4      Vn        \-        VP                  R	^ 4      4      Vn        RRR4       \1        WVP*                  '       * 4       \3        WVP*                  '       * 4       \5        V4      p	\7        V4       VP                  R
^P4      p
\9        V
4      pTp\;        V\<        4      '       dä   RV9   dÝ   ^ RIH p ^ RI!H"p T! \G        VRR4      ;'       g    \I        4       \G        VRR4      ;'       g    R\G        VRR4      ;'       g    R\G        VRR4      ;'       g    R\G        VRR4      R7      pV! WÉWŸR7      pVPJ                  '       d5   \M        RT RRPO                  VPP                  4      ;'       g    R/4       R# VPR                  p\;        V\<        4      '       d   TMRVn*        V'       d   \W        WŒV4      MTp^ RI,H-p V! RV 4      '       g   \]        4       w  Vn/        Vn0        ^ RI1H2pH3p V! 4       '       d   \i        VV4      p\i        V\k        V4      4      p\m        VPo                  RR4      4      Vn8        V\i        V\s        V4      4      W«3#   + '       g   i     ELD; i)a3  Bind scopes, sync the agent, snapshot history, build the run message; returns
``(prompt, run_message, cols, streamer)`` or None when @-expansion was refused.
Scopes fill field by field so a failure midway still leaves every bound token for the
finally; the profile's terminal policy is bound too (a failed install leaves a
fail-closed refusal scope).  The config-model sync is skipped under a /model --once
override (not pinned as model_override, the sync would clobber it); a model picked
mid-turn is applied first so the explicit pick wins over a config change.)Úset_current_session_keyrI   )Úui_session_idÚprofile_homeNr   r|   rö   r÷   ÚcolsÚ@)Úpreprocess_context_references)Úget_model_context_lengthÚmodelr   Úbase_urlÚapi_keyÚproviderÚ_config_context_length)ræ  rç  rè  Úconfig_context_length)ÚcwdÚallowed_rootÚcontext_lengthr   r€   Ú
úContext injection refused.)Úevent_presentation_mutedúmessage.delta)ÚSPEECH_INTERRUPTED_NOTEÚtake_speech_interruptedÚ
voice_turnF):Útools.approval_contextrÞ  rˆ  r°   Ú_set_session_contextr³   Ú_profile_runtime_scope_tokensr!   r´   rµ   r¶   Ú_wire_callbacksr…  Ú_apply_pending_model_switchÚ_sync_agent_model_with_configÚ#_sync_agent_compression_with_configÚ _sync_agent_fallback_with_configÚ_sync_bot_capabilitiesr¹  r   r‘   rö   rM   r÷   rÛ  Ú_stage_onboarding_turn_noteÚ_session_cwdÚ_register_session_cwdÚmake_stream_rendererrA   r   Úagent.context_referencesrã  Úagent.model_metadatarä  r    Ú_resolve_modelÚblockedr�   ÚjoinÚwarningsr€   rŽ  rß   Úagent.notification_presentationrð  rô   ró   r‰  Útools.tts_streamingrò  ró  Ú_prepend_noteÚ_pending_reaction_notesr
   r]   Ú_voice_turn_pendingÚ_hud_surface_note)rn   r   r6  ro   r˜   rÞ  rˆ  Úboundr   rë  rá  ÚstreamerrÀ   rã  rä  Úctx_lenÚctxÚrun_messagerð  rò  ró  s   &&&&&                r   Ú_prepare_turn_inputr  ”  sè  € õ ?Ø�Y‰Y€FÙ-¨g°mÕ.DÓE€F„OÜ0°¸Õ1GÐWZÔ[€FÔô *¨'¯+©+°nÓ*EÓF€EØÒØ6;·j±jÀ%Ç,Á,ÐPU×P^ÑP^Ð3ˆŒ�V”] F¤Oô �CÔØ××Ðô 	$ CÔ1Ü% cÔ3Ü+¨CÔ9Ü$ SÔ2Ü˜3Ô(Ü˜WÔ%Ø˜wÕ'Ð'€B„Hˆuà	�×	 ×	 Ü˜' )Õ,Ó-ˆŒ
Ü  §¡Ð->ÀÓ!BÓCˆÔ÷ 
!ô
 )¨¸R¿Z¹Z¼ÔHÜ °·
±
¬NÔ;Ü
�wÓ
€CÜ˜'Ô"Ø�;‰;�v˜rÓ"€DÜ# DÓ)€HØ€FÜ�&œ#×Ò 3¨&¤=ÝJÝAÙ*Ü�E˜7 BÓ'×;Ð;¬>Ó+;Ü˜U J°Ó3×9Ð9°rÜ˜E 9¨bÓ1×7Ð7°RÜ˜U J°Ó3×9Ð9°rÜ")¨%Ð1IÈ4Ó"PôRˆñ ,Ø¨#ôGˆà�;�;ˆ;ÜØ˜˜y¨$¯)©)°C·L±LÓ*A×*aÐ*aÐEaÐbôdáØ—‘ˆÜ)¨&´#×6Ò6‘V¸B€B„NßDJÔ)¨%¸Ô@ÐPV€KÝHÙ# O°S×9Ò9Ü,=Ó,?Ñ)ˆŒ�bÔ)÷ UÙ× Ò Ü# KÐ1HÓIˆÜ Ô-DÀWÓ-MÓN€KÜ $ W§[¡[°¸uÓ%EÓ F€EÔØ”= Ô.?ÀÓ.HÓIÈ4ÐYÐY÷Q 
!×	 Ð	 ús   Ä8NÎN	c               óD   € 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   rn   r   r   r   r6  r7  rÀ   r   r  r˜   rÁ   rt   ru   rv   rw   Úturn_authorro   r   r+   r   )r   s   "r   r   r   ä  sw   € ÷ Nñ NØ	ðNØðNØ!)ðNØ36ðNØEHðNàðNà%/ðNàCNðNð ðNð ,/ðNð ;?ñNr   c           
     ó¾  a aaaaa€ SP                   o\        \        SRR4      RR4      Sn        \        S4      '       d   RRRR/MRoVVVV VV3R lpRR	/R
 VV 3R lllp\	        4       '       d   TMRSn        R\        SP                  4      RTRV'       d   \        W6V4      MT/;Sn	        p \        P                  SP                  4      P                  pRV9   d   SR,          VR&   V'       d   RV9   d   W}R&   V'       d   RV9   d   W�R&   V	'       d   RV9   d   W�R&   RV9   d#   ^ RIHp V! SSP                  4      pVe   VVR&   \%        SSVR,          V
4       SP'                  R4      ;'       g    S pV3V 3R llSn        \+        S S4      w  pp ^ RIHpHp V! SV! RS 4      S R7      ;_uu_ 4        SP                  ! V3/ SP                  B Sn        RRR4       VP5                  4        VP7                  4        R#   \        \        3 d    / p ELHi ; i  + '       g   i     LL; i  TP5                  4        TP7                  4        i ; i)z�Wire the streaming callbacks and run the conversation into ``st.result``.
``text`` is the turn's raw submit, matched against the row staged by prompt.submit.Úcontext_compressorNrŠ  Úbufr   Úheldc                ót  <€ \        SR R4      '       d   R# Set   \        V \        4      '       d^   ^ RIHp SR;;,          V ,          uu&   V! SR,          4      '       d   SR;;,          V ,          uu&   R# SR,          V ,           Rup SR&   SR,          ;_uu_ 4        \        SV 4       RRR4       RV /pS	'       d   S	P                  V 4      ;pe   W2R	&   SP                  e2   \        V \        4      '       d   SP                  P                  V 4       \        R
SV4       R#   + '       g   i     Lƒ; i)Ú_mute_notification_replyFN)Úis_partial_silence_markerr  r  r   r|   ro   Úrenderedrñ  )
r    rA   r   r   r  Ú_append_inflight_deltaÚfeedró   r{  r�   )
Údeltar  ÚpayloadÚrr   Úholdr   rn   r6  r  s
   &   €€€€€€r   Ú_streamÚ_invoke_agent.<locals>._streamñ  sð   ø€ Ü�5Ð4°e×<Ò<ÙØÒ¤
¨5´#× 6Ò 6ÝJØ��K˜5Õ ‹KÙ(¨¨e­×5Ò5Ø�V— Õ%“ÙØ"& v¥,°Õ"6¸ÐˆE�4˜‘<Ø�^×$×$Ü" 7¨EÔ2÷ %à˜5�/ˆß˜hŸm™m¨EÓ2Ð2˜Ò?Ø"#�JÑØ�<‰<Ò#¬
°5¼#×(>Ò(>Ø�L‰L×Ñ˜UÔ#Üˆo˜s GÖ,÷ %×$ús   ÂD'Ä'D7	Úalready_streamedFc               ó$   € V ^8„  d   QhRRRRRR/# )r   ro   r   r&  r
   r   r+   r   )r   s   "r   r   Ú#_invoke_agent.<locals>.__annotate__  s&   € ÷ \ñ \ Cð \¸dð \Ètñ \r   c               óT   <€ \        SR R4      '       d   R# \        RSRV RV/4       R# )r  FNzmessage.interimro   r&  )r    r�   )ro   r&  r   rn   s   &$€€r   Ú_interim_assistant_cbÚ,_invoke_agent.<locals>._interim_assistant_cb  s.   ø€ Ü�5Ð4°e×<Ò<ÙÜÐ  v¨tÐ5GÐIYÐ&ZÖ[r   Úconversation_historyÚstream_callbackÚpersist_user_messageÚtask_idrI   Úpersist_user_display_kindÚpersist_user_display_metadatar  Úprelude)Úonboarding_preludec                ó&   <€ \        R SRVRV /4      # )zsession.titlerJ   Útitler  )ÚtÚ_srcÚ_krn   s   &&&€r   r  Ú_invoke_agent.<locals>.<lambda>'  s   ø€ ¼UØ˜˜|¨R°¸!Ð<ô>>r   )Únotification_turnrð  rñ  ©ÚmutedrJ   )r   r    rŠ  r&   Ú _load_interim_assistant_messagesÚinterim_assistant_callbackr‘   rö   Ú_build_persist_user_messager‹  ÚinspectÚ	signatureÚrun_conversationÚ
parametersrc   rd   Úagent.onboarding_sessionr3  Ú_adopt_submit_user_rowr!   Ú_on_session_titleÚ_start_usage_tickerr  r:  rð  r7   ry  r  )rn   r   r6  rÀ   r  r  r˜   rt   rv   r  ro   r$  r*  r‹  Ú
run_paramsr3  r2  Ú
_title_keyÚ_usage_stopÚ_usage_threadr:  rð  r   r#  s   fff&&f&&&&&           @@r   Ú_invoke_agentrL  ä  s7  ý€ ð �H‰H€EÜ"¤7¨5Ð2FÈÓ#MÐObÐdhÓi€BÔô ';¸7×&CÒ&CˆE�2�v˜rÑ"È€D÷-ò -ð*\ÀU÷ \ó \ô
 "B×!CÒ!CÑÈð 
Ô$ð
 	¤ R§Z¡ZÓ 0Ø˜7ØßHNÔ'¨¸ÔDÐTZð	"]ð ]€B„M�Jð
Ü×&Ñ& u×'=Ñ'=Ó>×IÑIˆ
ð �JÔØ '¨Õ 6ˆ
�9ÑßÐ3°zÔAØ2>Ð.Ñ/ßÐ;¸zÔIØ6FÐ2Ñ3ß�}¨
Ô2Ø$/�=Ñ!Ø�JÔÝ?Ù$ U¨B¯J©JÓ7ˆØÒØ$+ˆJ�yÑ!Ü˜7 E¨:Ð6LÕ+MÈtÔTà—‘˜]Ó+×2Ð2¨s€JØ1;ö >€EÔä!4°S¸%Ó!@Ñ€K�ðß_Ù˜uÑ,DÀ_ÐVYÓ,ZÐgj×kÖkØ×.Ò.¨{ÑL¸b¿m¹mÑLˆBŒI÷ lð
 	�‰ÔØ×ÑÖøô; ”zÐ"ô Ø‹
ðú÷. l×kûð
 	�‰ÔØ×ÑÕús6   Â2)H Æ"H: Ç #H'Ç#H: ÈH$È#H$È'H7	È2H: È:"Ic               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR
/# )r   rn   r   r   r   r6  r7  ro   r   rt   ru   r   r   )r   s   "r   r   r   5  s<   € ÷ <ñ <Ø	ð<Øð<Ø!)ð<Ø14ð<ØDNð<àñ<r   c           
     óT  € VP                   VP                  rvV'       dø   \        V\        4      '       dâ   \	        VRR4      p\	        VRR4      ;'       g    VP                  R4      p	Ve    VP                  V	RW4VR7       \        V\        4      '       d   \        VP                  R
4      \        4      '       dZ   \        VR
,          4       FC  p
V
P                  R4      R8X  g   K  V
P                  R4      V8X  g   K3  WJR&   V'       d   WZR&    M	  RV9   dÈ   VP                  RR4      p\        V\        4      '       d…   VP                  R4      pVP                  R4      pVP                  R4      pVf   VP                  RR4       MWÁR&   V'       d.   V'       d   V RV 2MTp \        WVR\        V4      RRR7       MMVf   VP                  RR4       MW±R&   Rp\        V\        4      '       dU   \        VP                  R
4      \        4      '       d"   \#        WVP$                  VP&                  4      p\)        WRRR7       V#   \         d    \        P                  RRR	7        ELõi ; i  \         d!   p\        P!                  RT4        Rp?L½Rp?ii ; i)zZStamp, restore /moa, commit history, re-sync the session key; returns the history warning.rB  NrJ   rI   Úuser)rÁ  r¼  rt   rv   z&failed to stamp synthetic display kindTr£  rù   rÁ  r¼  rt   rv   Úmoa_one_shot_restoreÚoverriderå  rè  Úmodel_overridez --provider F)Úconfirm_expensive_modelÚpin_session_overrideÚpersist_overrideÚcount_switchz%MoA one-shot model restore failed: %s)Úclear_pending_titleÚrestart_slash_worker)r7   r   rA   r   r    r!   Ú(set_latest_matching_message_display_kindrO   r�   r¯  r   r‘   Úreversedr]   Ú_apply_model_switchr
   rJ  r  rö   r÷   Ú _sync_session_key_after_compress)rn   r   r6  ro   rt   rv   r7   r   r³  Úcurrent_session_idr€   Ú_restoreÚ_prev_overrideÚ_prev_modelÚ_prev_providerÚ_rawÚ_moa_restore_excÚstatus_notes   &&&&&&            r   Ú_absorb_turn_resultre  5  sb  € ð —I‘I˜rŸx™xˆEßœ
 4¬×-Ò-ä�U˜M¨4Ó0ˆÜ$ U¨L¸$Ó?×]Ð]À7Ç;Á;È}ÓC]ÐØŠ>ðVØ×;Ñ;Ø&¨V¸TØ%5ð <ô 7ô
 �fœd×#Ò#¬
°6·:±:¸jÓ3IÌ4×(PÒ(PÜ# F¨:Õ$6Ö7�Ø—;‘;˜vÓ&¨&Ö0°W·[±[ÀÓ5KÈtÖ5SØ.:˜NÑ+ß'Ø6FÐ 2Ñ3Ùñ 8ð  Ô(ð —;‘;Ð5°tÓ<ˆä�h¤×%Ò%Ø%Ÿ\™\¨*Ó5ˆNØ"Ÿ,™, wÓ/ˆKØ%Ÿ\™\¨*Ó5ˆNØÒ%Ø—‘Ð,¨dÕ3à,:Ð(Ñ)ßçDR�{�m <°Ð/?Ñ@ÐXcð ð^Ü'Ø dÀEÜ-1°.Ó-AØ).¸UöDð	 ð ÒØ�K‰KÐ(¨$Õ/à(0Ð$Ñ%Ø€KÜ�&œ$×ÒÜ�f—j‘j Ó,¬d×3Ò3Ü.¨wÀÇ
Á
ÈB×L^ÑL^Ó_ˆKô
 	)Ø¨eÈ$õ	PàÐøô] ô VÜ—‘ÐEÐPT�×UðVûô< !ô ^Ü—N‘NÐ#JÐL\×]Ñ]ûð^ús*   Á.I Æ.I< É"I9É8I9É<J'ÊJ"Ê"J'c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r6  r7  r9   r   r8   r   r   rw   r   )r   s   "r   r   r   t  s.   € ÷ kñ k ð k¨sð k¸Cð kÀKñ kr   c                ó|  a€ ^ RI HoHp V P                  P	                  R4      p\        V\        4      '       g   R# T! T\        V P                  RR4      V P                  Y\        V P                  4      \        J ;'       d0    V P                  \        \        V P                  RR4      RR4      8H  V3R lR7      # )	z›Committed row addresses of this turn (``agent.persisted_turn_receipt``); the pre-turn
prefix is unchanged when every history row kept its committed row id.)Úcommitted_row_idÚpersisted_turn_receiptrù   NÚ_persist_user_message_idxr  rŠ  c                óJ   <€ S! V 4      R J;'       d    S! V 4      S! V4      8H  # rû   r   )ÚbeforeÚafterrh  s   &&€r   r  Ú)_persisted_turn_receipt.<locals>.<lambda>�  s-   ø€ Ù˜VÓ$¨DÐ0×hÐhÑ5EÀfÓ5MÑQaÐbgÓQhÑ5hÐhr   )Úcompression_unchangedÚprefix_row_matches)Úagent.persisted_turn_receiptrh  ri  r7   r!   rA   r‘   r    r   rö   r1   rŠ  rM   )r6  r9   r8   ri  rù   rh  s   &&&  @r   Ú_persisted_turn_receiptrr  t  s«   ø€ ÷ Và�y‰y�}‰}˜ZÓ(€HÜ�h¤×%Ò%ÙÙ!Ø”'˜"Ÿ(™(Ð$?ÀÓFÈÏ
É
ØÜ" 2×#7Ñ#7Ó8¼CÐ?÷ Vð VÀB×DXÑDXÔ\cÜ�B—H‘HÐ2°DÓ9Ð;NÐPTó]Vñ EVôjôkð kr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r   r   r6  r7  rd  ru   rá  rM   r   )r   s   "r   r   r   …  s/   € ÷ N ñ N  Dð N ¨hð N ÀZð N ÐWZñ N r   c                óF  € VP                   VP                  rTRp\        V4      R8X  dO    ^ RIHp T! T\        \        VRR4      ;'       g    R4      \        \        VRR4      ;'       g    R4      R7      p\        WF4      w  r‰p
\        V 4      '       d   \        W‰R8H  R	7      pR
VR\        V4      RV	/p\        WV	4      ;p'       d   WËR&   V
'       d   W«R&   V'       d   W+R&   \        VRR4      pVP                  R4      '       g   \        V4      '       d   V! V4      RJ d   RVR&   V'       d   VP                  R4      '       d   RVR&   VP                  R4      '       d   RVR&   VP                  R4      ;p'       d   WëR&   VP                  R4      VR&   \        Wƒ4      ;p'       d   WûR&   VP                  R4      pVP                  R4      p\!        VP                  R4      ;'       de    \#        V\
        4      ;'       dM    VP%                  4       ;'       d5    VP%                  4       \        T;'       g    R4      P%                  4       8g  4      pV R,          ;_uu_ 4        V	R8X  d…   V'       d<   V P                  R4      ;'       g    / P                  R4      '       g   \'        W4       \)        V VVR7       RVn        \-        VVP                  R4      VP.                  4      Vn        M\3        V 4       RRR4       V	R8X  d7   \        T;'       g    T4      VR&   RVR&   V'       d   RVR&   V'       d   WkR &   VP4                  ey   RVn        TP5                  RR!R"RR#/P                  V	R$4      R
\#        V\
        4      '       d   TM
\        V4      /V	R8X  d   R\        T;'       g    T4      /M/ C4       RVn        VP8                  '       d   \;        WP<                  4       W¸V	3#   \         d    Rp EL“i ; i  + '       g   i     EL; i)%z``(payload, raw, status)`` for message.complete; retains/clears the inflight turn and
settles the hosted-room terminal receipt.Nr   )Úbuild_error_surface_from_resultrè  r   rå  )rè  rå  r<   )r	   ro   Úusager8   Úpersisted_turnÚ	reasoningrJ  Ú_interim_text_was_deliveredÚresponse_previewedTÚresponse_reusedÚresponse_transformedÚbilling_blockÚbillingÚfailure_reasonr  r  r  r|   rƒ   Ú	assistantrŠ   Úrecoverabler‹   r>   Ú	cancelledr=   Úsettled)r7   r   r  Úagent.error_surfaceru  r   r    rO   r  r&   r   Ú
_get_usagerr  r!   ÚcallableÚrender_messager
   rA   r"   r  Ú_fail_inflight_turnrŒ  Ú_turn_failure_detailrŽ  r�  Ú_clear_inflight_turnr†  r�  r‡  Ú_retire_turn_markerr¨   )r   r6  rd  rá  r7   r   Ú_error_surfaceru  r9   r8   r  r!  ÚreceiptÚwas_deliveredÚ_billing_blockr  Úerror_valueÚ
final_textÚhas_partial_texts   &&&&               r   Ú_complete_turn_payloadr“  …  sÛ  € ð —I‘I˜rŸx™xˆEð €NÜ�fÓ Ô(ð	"ÝKÙ<Ø¤¤W¨U°JÀÓ%C×%IÐ%IÀrÓ!JÜœ' %¨°"Ó5×;Ð;¸Ó<ô>ˆNô
 #0°Ó"GÑ€C�Ü˜G×$Ò$Ü% cÀ
Ñ6JÔKˆØ�s˜G¤Z°Ó%6¸À&ÐI€GÜ)¨"°6Ó:Ð:€wÖ:Ø$+Ð Ñ!ßØ-�ÑßØ(�	Ñô ˜EÐ#@À$ÓG€MØ‡z�zÐ&×'Ò'¬H°]×,CÒ,CÉÐVYÓHZÐ^bÓHbØ(,ˆÐ$Ñ%ç
ˆv�z‰zÐ+×,Ò,Ø%)ˆÐ!Ñ"ð ‡z�zÐ(×)Ò)Ø*.ˆÐ&Ñ'àŸ™ OÓ4Ð4€~Ö4Ø+�	ÑØ$*§J¡JÐ/?Ó$@ˆÐ Ñ!Ü! #Ó,Ð,€xÖ,Ø&�
ÑØ—*‘*˜WÓ%€KØ—‘Ð,Ó-€JÜØ�
‰
�9Ó÷ 	Xð 	X¤*¨Z¼Ó"=÷ 	Xð 	XØ×ÑÓ÷	Xð 	XØ#-×#3Ñ#3Ó#5¼¸[×=NÐ=NÈBÓ9O×9UÑ9UÓ9WÑ#WóYÐð 
�×	 ×	 Ø�WÔ÷  ¨¯©°_Ó)E×)KÐ)KÈ×(PÑ(PÐQ\×(]Ò(]ä& wÔ4Ü ¨ÀNÕSØ $ˆBÔÜ2Ø˜VŸZ™ZÐ(8Ó9¸2¿>¹>óKˆB�Oô ! Ô)÷ 
!ð �ÔÜ˜{×1Ð1¨cÓ2ˆ�ÑØ!%ˆ�ÑçØ!%ˆG�IÑßØ'5�OÑ$Ø	×ÑÒ'Ø#ˆÔØ
×ÑØ�} k°7¸HÐE×IÑIÈ&ÐR[Ó\Øœ: c¬3×/Ò/‘C´S¸³XðQð 6<¸wÔ5F�œ˜[×/Ð/¨CÓ0Ñ1ÈBðQô 	Rð  $ˆÔØ	××ÐÜ˜G§]¡]Ô3Ø˜ÐÐøôC ô 	"Ø!‹Nð	"ú÷F 
!×	 Ð	 ús<   «!O; ÁO; Á,O; É.PÉ>PÊPÊ.APÏ;PÐPÐP 	c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   rn   r   r   r   r6  r7  rý   r*   r   r+   r   )r   s   "r   r   r   Ö  s0   € ÷ 1ñ 1 ð 1¨tð 1¸ð 1Àmð 1ÐX\ñ 1r   c                óâ  € ^ RI p\        P                  \        4      ;_uu_ 4        \        P                  \        P                  P                  \        4      RR7       \        \        RRR7      ;_uu_ 4       pVP                  R\        P                  R4       R	V  R
24       VP                  VP                  4       4       RRR4       RRR4       \        R\        V4      P                    RV 2\"        P$                  RR7       \'        WP(                  4       VP*                  eB   VP,                  '       g0   RVn         VP+                  RRRRR\/        V4      /4       RVn         \7        WW2P0                  R7       RVn        \;        V\        V4      P                   VP<                  4      Vn        R#   + '       g   i     EL; i  + '       g   i     EL; i  \         d    \2        P5                  R4        Lši ; i  \         dY   p\        R\        T4      P                    RT 2\"        P$                  RR7       \A        RT R\/        T4      /4        Rp?R# Rp?ii ; i)zJExcept-path of the turn: crash log, history restore, terminal error frame.NT)Úexist_okÚazutf-8)Úencodingu"   
=== turn-dispatcher exception Â· z%Y-%m-%d %H:%M:%Su    Â· sid=z ===
z[gateway-turn] r-   )r/   Úflushr8   r=   ro   r   r   z*hosted room terminal receipt commit failed)Úretire_markerz+[gateway-turn] terminal error emit failed: r€   )!Ú	tracebackra   rb   rO   ÚosÚmakedirsÚpathÚdirnameÚ
_CRASH_LOGÚopenÚwriteÚtimeÚstrftimeÚ
format_excr0   r1   r2   r3   r4   Ú'_restore_agent_history_after_turn_errorr   r†  r�  r   r‡  r�   Ú	exceptionr•   rŒ  r‰  rŽ  r�  r�   )rn   r   r6  rý   r›  ÚfÚemit_excs   &&&&   r   Ú_recover_turn_exceptionrª  Ö  sã  € ãÜ	×	Ñ	œY×	'Õ	'Ü
�‰”B—G‘G—O‘O¤JÓ/¸$ˆÔ?Ü”*˜c¨G×4Õ4¸Ø�G‰GØ5Ü—=‘=Ð!4Ó5Ð6°h¸s¸eÀ6ðKôLð �G‰G�I×(Ñ(Ó*Ô+÷	 5÷ 
(ô 
ˆOœD ›G×,Ñ,Ð-¨R°¨sÐ
3¼#¿*¹*ÈDÕQä+¨G·X±XÔ>Ø	×ÑÒ'°×0D×0DÐ0DØ#ˆÔð	KØ× Ñ  (¨H°f¸bÀ'Ì3ÈqË6Ð!RÔSØ#'ˆBÔ ð	1ä! #°×AUÑAUÕVØ ˆÔÜ.¨q´$°q³'×2BÑ2BÀBÇNÁNÓSˆŽ÷' 5×4Ð4ú÷ 
(×	'Ð	'ûô ô 	KÜ×ÑÐIÖJð	Kûô ô 1ÜØ9¼$¸x».×:QÑ:QÐ9RÐRTÐU]ÐT^Ð_Ü—‘ 4õ	)ô 	ˆg�s˜Y¬¨A«Ð/×0Ò0ûð	1úsQ   ¦AGÁ9AF=	ÃGÅ'G% Å.AH Æ=GÇ	GÇG"	Ç% HÈHÈI.ÈAI)É)I.c               ó(   € V ^8„  d   QhRRRRRRRR/# ©	r   rn   r   r   r   r6  r7  r   r+   r   )r   s   "r   r   r   ö  s(   € ÷  2ñ  2˜cð  2¨Dð  2°hð  2À4ñ  2r   c                ó>  € VP                   VP                  rCVP                  4        \        V\        4      '       d   VP                  4        VP
                  '       d8   \        P                  \        4      ;_uu_ 4        ^ RI	H
p V! 4        RRR4       VP                  e   VP                  P                  R4       VP                  '       dC    \        VP                  VP                  4       \!        W4       \#        V4       \%        V4       VP*                  p\        P                  \        4      ;_uu_ 4        VP,                  e   ^ RIHp V! VP,                  4       RRR4       VP2                  e   \5        VP2                  4       VP6                  e   ^ RIHp V! VP6                  4       \=        VP>                  4       R#   + '       g   i     ELJ; i  \         d    \&        P)                  RRR7        Lôi ; i  + '       g   i     L¬; i)zpFinally-path, before settlement: drop snapshots, end turn audio, undo a one-turn model, reset scopes (not home).)Ústop_thinking_soundNz!TUI one-turn model restore failedTr£  )Úreset_current_session_key)Úreset_terminal_scope) rö   r‹  ÚclearrA   r   r‰  ra   rb   rO   rò   r®  ró   r{  r…  Ú_restore_agent_model_runtimer   Ú_restart_slash_workerÚ_persist_live_session_runtimeÚ#_persist_live_session_system_promptr�   r¯  rˆ  r°   rõ  r¯  rµ   Úreset_secret_scoper¶   Útools.terminal_scoper°  Ú_clear_session_contextr³   )	rn   r   r6  rö   r‹  r®  rˆ  r¯  r°  s	   &&&      r   Ú_release_turn_scopesr¹  ö  sm  € ð Ÿ*™* b§m¡mˆZØ‡M�M„OÜ�*œd×#Ò#Ø×ÑÔØ	××ÐÜ× Ñ ¤×+Õ+Ý<ÙÔ!÷ ,ð 
‡|�|ÒØ
�‰×Ñ˜ÔØ	××Ðð	MÜ(¨¯©°2×3FÑ3FÔGÜ! #Ô/Ü)¨'Ô2Ü/°Ô8ð �Y‰Y€FÜ	×	Ñ	œY×	'Õ	'Ø�?‰?Ò&ÝHÙ% f§o¡oÔ6÷ 
(ð ‡}�}Ò Ü˜6Ÿ=™=Ô)Ø‡�Ò"Ý=Ù˜VŸ_™_Ô-Ü˜6×0Ñ0Ö1÷/ ,×+Ð+ûô ô 	MÜ�L‰LÐ<ÀtˆLÖLð	Mú÷ 
(×	'ús+   ÂGÃAG$ Å'HÇG!	Ç$"H	ÈH	ÈH	c               ó(   € V ^8„  d   QhRRRRRRRR/# r¬  r   )r   s   "r   r   r     s(   € ÷ 
3ñ 
3 ð 
3¨tð 
3¸ð 
3Àdñ 
3r   c                ó  €  ^ RI Hp \        V R7      '       d
   V! RR7       TP                  P                  e"   \        TP                  P                  4       R# R#   \         d    \        P                  RRR7        L_i ; i)	zYBest-effort tail AFTER the turn settled: a slow trim must not hold the bookend (#131740).)Útrim_memory)Úexcludeztui turn completionrZ   zpost-turn memory trim failedTr£  N)	Úhermes_cli.mem_trimr¼  Ú_sessions_quiescentrO   r�   r¯  rˆ  r´   Úreset_hermes_home_override)rn   r   r6  r¼  s   &&& r   Ú_post_turn_housekeepingrÁ    sh   € ðDÝ3ä s×+Ó+ÙÐ4Õ5ð 
‡y�y‡~�~Ò!Ü" 2§9¡9§>¡>Ö2ñ "øô ô DÜ�‰Ð3¸dˆÖCðDús   ‚!A Á"BÂBg      à?c               ó   € V ^8„  d   QhRR/# rD   r   )r   s   "r   r   r   *  s   € ÷ ,ñ , Dñ ,r   c                ó”   €  \        V 4      #   \         d0    \        P                  RRR7       \        P                  R4      u # i ; i)zZThe session's own SessionDB for :func:`_reopen_routed_session_row`, or a ``None`` context.z7could not resolve the session db for routing provenanceTr£  N)rB  rO   r�   r¯  ra   Únullcontext)r   s   &r   Ú_routing_provenance_dbrÅ  *  sD   € ð,Ü˜7Ó#Ð#øÜô ,Ü�‰ÐNÐY]ˆÔ^Ü×%Ñ% dÓ+Ò+ð,ús   ‚
 �7AÁAc               ó$   € V ^8„  d   QhRRRRRR/# )r   rn   r   r   r   r   r+   r   )r   s   "r   r   r   3  s&   € ÷ [ñ [¨ð [°dð [¸tñ [r   c                óè   € \        VP                  R4      RR4      pV e	   V'       g   R#  V P                  VRV R2\        R7       R#   \         d    \
        P                  RTRR	7        R# i ; i)
aA  Routing provenance for #106459, called under ``_sessions_lock`` while this backend still has the
session registered and is about to start a turn for it: an explicit-close stamp on its row missed a
live conversation, so it is cleared (the gateway's #54878 stale-route self-heal, which this backend
lacked). ``_pop_session_by_id`` claims teardown under the same lock and sets ``_closing`` before
``_finalize_session`` stamps, so a close of THIS session is either not written yet or already stops
the turn -- it is never cleared here. Best-effort: a failure never blocks the turn.r   rJ   NzTUI session z) is still registered and accepting a turn)Ú
provenanceÚ
patience_sz'routing-provenance reopen failed for %sTr£  )r    r!   Úreopen_if_explicitly_closedÚ_ROUTING_REOPEN_PATIENCE_SrO   r�   r¯  )r³  rn   r   rJ   s   &&& r   Ú_reopen_routed_session_rowrÌ  3  sw   € ô ˜Ÿ™ WÓ-¨|¸TÓB€JØ	‚zŸÙð[Ø
×&Ñ&Ø \°#°Ð6_Ð#`Ü1ð 	'ö 	3øô ô [Ü�‰Ð>À
ÐUYˆ×Zð[ús   ¬A
 Á
#A1Á0A1rt   rv   rp   rr   r†  r  c               óD   € 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   rn   r   r   r   ro   r   rt   ru   rv   rw   rp   rq   rr   rs   r†  z'Callable[[dict[str, Any]], None] | Noner  rl   r
   r   r   )r   s   "r   r   r   E  s   € ÷ Rñ RØðRØ ðRØ(+ðRØ>HðRà!ðRà7GðRð )ðRð ?ð	Rð
 ðRð
 @DðRð
 PTñRr   c               ó  a aaaaaaa	aaaaaa€ \        S4      R J d0   \        P                  RSP                  R4      ;'       g    S4       \	        SSSWgSSV
R7      pVf   R # Tw  oo^ RIHp ^ RIHp \        S4      ;_uu_ 4        V! 4       oV! SRS4      oRRR4       S'       d   Ro\        P                  4       o\        P                  R	SSP                  R4      ;'       g    R
\        SRR
4      ;'       g    R
S;'       g    R\        S\        4      '       d   \!        S4      MR\!        S4      4       S'       g   \#        RS4       VVVVVVVVV	3	R loVVVV VVV3R lp\%        S4      ;_uu_ 4       p\&        ;_uu_ 4        \(        P                  S4      pSP                  R4      '       * ;'       d    VRJ ;'       g    VSJ pV'       d'   VSJ d   \+        VSS4       \-        VRS 2SR7      RJpRRR4       RRR4       X'       g"   SR,          ;_uu_ 4        R SR&   RRR4       V# V#   + '       g   i     EL©; i  + '       g   i     LW; i  + '       g   i     Lb; i  + '       g   i     T# ; i)FuO   prompt dispatch: session store unavailable for %s â€” this turn may not persistrI   )rl   N)Údiagnostic_turn_muted)Únotification_config_snapshotr  Úhiddenz`tui prompt accepted: ui_session=%s session_key=%s agent_session_id=%s kind=%s chars=%s images=%dr   rJ   rO  Ú-rY  c                 ó:  <	€ \        SP                  R 4      4      p \        P                  S4      p\	        SR,          SP                  RR4      SSRJ R7      p\        SSSRJ S;'       g    / P                  R4      R7      Vn        Rp \        SSVSS4      pVEf€   VP                  e8   VP                  '       g&   RVn
        VP                  RR	R
RRR/4       RVn         \        SSV4        \        P                  V4       \        V 4       RVP                  n        SR,          ;_uu_ 4        RSR&   \"        P#                  4       SR&   SP                  RR4       VP$                  '       g   \'        S4       \)        S4       RRR4       \+        VP,                  \.        4      '       d   \1        VP,                  4      pMVP$                  '       d   RMRp\2        P5                  RSSP                  R4      ;'       g    R\7        VP                  RR4      ;'       g    RWRP$                  \"        P9                  4       S,
          VP:                  4       VP                  '       du   \=        SVP                  4       SR,          ;_uu_ 4        SP                  R4      VP                  8X  d   SP                  RR4       SP                  RR4       RRR4       SP                  RR4       \?        SSVP                  4       \A        SSV4       R# Vw  rgr‰\C        SSW&WySSSSS4       \E        SSVSSS4      p
\G        SW*V4      w  r¼pVR8X  d&   ^ RI$H%p V! SVP,                  VP                  S4       \M        RSV4       \O        SSVP,                  W\4      pVR8X  d   \Q        SSW,4       \S        SSRR7       \        SSV4        \        P                  V4       \        V 4       RVP                  n        SR,          ;_uu_ 4        RSR&   \"        P#                  4       SR&   SP                  RR4       VP$                  '       g   \'        S4       \)        S4       RRR4       \+        VP,                  \.        4      '       d   \1        VP,                  4      pMVP$                  '       d   RMRp\2        P5                  RSSP                  R4      ;'       g    R\7        VP                  RR4      ;'       g    RWRP$                  \"        P9                  4       S,
          VP:                  4       VP                  '       du   \=        SVP                  4       SR,          ;_uu_ 4        SP                  R4      VP                  8X  d   SP                  RR4       SP                  RR4       RRR4       SP                  RR4       \?        SSVP                  4       \A        SSV4       TP,                  T3#   + '       g   i     EL‹; i  + '       g   i     ELM; i  \A        SST4       i ; i  \T         d   p\W        SSY.4        Rp?EL�Rp?ii ; i  + '       g   i     EL; i  + '       g   i     LÈ; i  \A        SST4       i ; i  \        SST4        \        P                  T4       \        T 4       RTP                  n        SR,          ;_uu_ 4        RSR&   \"        P#                  4       SR&   SP                  RR4       TP$                  '       g   \'        S4       \)        S4       RRR4       M  + '       g   i     M; i\+        TP,                  \.        4      '       d   \1        TP,                  4      pMTP$                  '       d   RMRp\2        P5                  RSSP                  R4      ;'       g    R\7        TP                  RR4      ;'       g    RYRP$                  \"        P9                  4       S,
          TP:                  4       TP                  '       d‰   \=        STP                  4       SR,          ;_uu_ 4        SP                  R4      TP                  8X  d   SP                  RR4       SP                  RR4       RRR4       M  + '       g   i     M; iSP                  RR4       \?        SSTP                  4       \A        SST4       i   \A        SST4       i ; i; i)r`  r   Úone_turn_model_restoreN)r‡  rœ   )r›   rœ   Tr8   r=   ro   r   r   rï  r|   Fr}   Úlast_activeÚ_turn_user_inputr<   zptui turn finished: ui_session=%s session_key=%s agent_session_id=%s status=%s error_retained=%s duration=%.1fs%srI   rJ   r¡   Ú_hosted_room_taskÚ_auto_continue_scheduled)Únote_task_donezmessage.complete)Úonly_if_present),Úbind_transportr!   Ú_current_runtime_session_recordry  r7  r]   r¬   r¨   r  r†  r�  r‡  r¹  ÚresetÚreset_transportr   r>  r£  rŒ  rŠ  Ú_release_hosted_room_turn_slotrA   r7   r   r  r�   rŽ   r    Ú	monotonicr�  r‹  Ú_emit_settled_session_inforÁ  rL  re  r“  Útui_gateway.free_tier_task_donerÙ  r�   r4  rT  Ú!_publish_session_control_snapshotrO   rª  )Útransport_tokenÚruntime_session_tokenr6  r*  Úpreparedr8   rÀ   r  rá  r  rd  r!  r9   rÙ  rý   Ú_turn_started_monotonicrt   rv   r˜   r   rn   r†  ro   r  s                  €€€€€€€€€r   Úrun_bodyÚ$_run_prompt_submit.<locals>.run_bodyq  sO  ø€ ô )¨¯©°[Ó)AÓBˆÜ ?× CÑ CÀGÓ LÐÜØ�GÕ˜gŸk™kÐ*BÀDÓIÐK\Ø/°4Ð7ô9ˆô ,¨G°TÐIZÐ^bÐIbØ#3×#9Ð#9°r×">Ñ">Ð?VÓ"WôYˆŒàˆðB	:Ü*¨3°¸¸TÀ6ÓJˆHØÓØ×'Ñ'Ò3¸B×<P×<PÐ<PØ+/�BÔ(Ø×(Ñ(Ø  (¨F°B¸ÐA]ð*_ô `à+/�BÔ(Øô, !  g¨rÔ2ð#:Ü/×5Ñ5Ð6KÔLÜ Ô0à6:�—‘Ô3Ø˜^×,×,Ø).�G˜IÑ&Ü-1¯Y©Y«[�G˜MÑ*Ø—K‘KÐ 2°DÔ9Ø×,×,Ð,Ü,¨WÔ5Ü2°7Ô;÷ -ô ˜bŸi™i¬×.Ò.Ü+¨B¯I©IÓ6‘Fà(*×(9×(9Ð(9™W¸z�FÜ—‘ð9à˜Ÿ™ ]Ó3×9Ð9°r¼7À2Ç8Á8È\Ð[]Ó;^×;dÐ;dÐbdØ×-Ñ-¬t¯~©~Ó/?ÐBYÕ/YØ—O‘Oô%ð ×'×'Ð'Ü'¨°·±Ô?Ø  ×0×0Ø"Ÿ;™;Ð'@ÓAÀRÇ]Á]ÔRØ#ŸK™KÐ(AÀ4ÔHØŸ™Ð$7¸Ô>÷ 1ð —‘Ð6¸Ô=Ü*¨3°¸¿¹ÔBä'¨¨W°bÖ9ðs 3;Ñ/ˆF ÜØ�W˜b¨+ÀÈØ  +¨tô5ô .Ø�W˜b $¨Ð6FóHˆKä#9¸'À2ÐTXÓ#YÑ ˆG˜&Ø˜Ô#åJÙ˜w¨¯	©	°2·8±8¸\ÔJÜÐ$ c¨7Ô3Ü5°c¸7ÀBÇIÁIÈvÓ[ˆMØ˜Ô#Ü$ S¨'°2Ô;ô .¨c°7ÈDÕQô !  g¨rÔ2ð#:Ü/×5Ñ5Ð6KÔLÜ Ô0à6:�—‘Ô3Ø˜^×,×,Ø).�G˜IÑ&Ü-1¯Y©Y«[�G˜MÑ*Ø—K‘KÐ 2°DÔ9Ø×,×,Ð,Ü,¨WÔ5Ü2°7Ô;÷ -ô ˜bŸi™i¬×.Ò.Ü+¨B¯I©IÓ6‘Fà(*×(9×(9Ð(9™W¸z�FÜ—‘ð9à˜Ÿ™ ]Ó3×9Ð9°r¼7À2Ç8Á8È\Ð[]Ó;^×;dÐ;dÐbdØ×-Ñ-¬t¯~©~Ó/?ÐBYÕ/YØ—O‘Oô%ð ×'×'Ð'Ü'¨°·±Ô?Ø  ×0×0Ø"Ÿ;™;Ð'@ÓAÀRÇ]Á]ÔRØ#ŸK™KÐ(AÀ4ÔHØŸ™Ð$7¸Ô>÷ 1ð —‘Ð6¸Ô=Ü*¨3°¸¿¹ÔBä'¨¨W°bÔ9Ø�y‰y˜-Ð'Ð'÷? -×,Ð,ú÷. 1×0Ð0ûô (¨¨W°bÕ9ûôO ô 	9Ü# C¨°"×8Ò8ûð	9ú÷ -×,Ð,ú÷. 1×0ûô (¨¨W°bÕ9ûôI !  g¨rÔ2ð#:Ü/×5Ñ5Ð6KÔLÜ Ô0à6:�—‘Ô3Ø˜^×,×,Ø).�G˜IÑ&Ü-1¯Y©Y«[�G˜MÑ*Ø—K‘KÐ 2°DÔ9Ø×,×,Ð,Ü,¨WÔ5Ü2°7Ô;÷ -×,×,Ð,úô ˜bŸi™i¬×.Ò.Ü+¨B¯I©IÓ6‘Fà(*×(9×(9Ð(9™W¸z�FÜ—‘ð9à˜Ÿ™ ]Ó3×9Ð9°r¼7À2Ç8Á8È\Ð[]Ó;^×;dÐ;dÐbdØ×-Ñ-¬t¯~©~Ó/?ÐBYÕ/YØ—O‘Oô%ð ×'×'Ð'Ü'¨°·±Ô?Ø  ×0×0Ø"Ÿ;™;Ð'@ÓAÀRÇ]Á]ÔRØ#ŸK™KÐ(AÀ4ÔHØŸ™Ð$7¸Ô>÷ 1×0×0Ð0úð —‘Ð6¸Ô=Ü*¨3°¸¿¹ÔBä'¨¨W°bÕ9øÔ'¨¨W°bÕ9ýs<  Â3Y Â?%Y Ã3AX6 Ä5AXÆAX6 Ç,X6 È	X6 È)A0X6 ÊAX"Ë1X6 ÌB+Y ÏAZ ÐAY.Ñ0AZ Ó ,Z Ó-Z ÔA0Z Õ=AZ×1Z ØX	Ø	X6 Ø"X3	Ø-	X6 Ø6YÙY+ÙY&Ù Z' Ù&Y+Ù+Z' Ù.Y?	Ù9	Z ÚZ	ÚZ ÚZ$Ú'dÚ6AdÛ8A]	Ý	dÝ](Ý#AdÞ3,dß dà A0dá0Ab>	â5	dâ>cã	1dã:dädädc            	     ó  <€ ^ RI Hp  ^ RI Hp V! SRS4      ;_uu_ 4        V ! SSS	R7      ;_uu_ 4        S! 4       pRRR4       RRR4       Xe   \        SS	S.VO5!   R# R#   + '       g   i     L/; i  + '       g   i     L:; i)é    )r:  )Únotification_policy_snapshotr  r;  N)r  r:  rì  rƒ  )
r:  rì  Úfollowupr   r<  Únotification_configr[  rè  r   rn   s
      €€€€€€€r   ÚrunÚ_run_prompt_submit.<locals>.runÀ  s}   ø€ ÝEõ 	QÙ)¨%°Ð8K×LÕLÑN_Ð`eÐmrð  @C÷  ODö  ODÙ“zˆH÷ OD×LàÒÜ$ S¨#¨wÐB¸ÖBñ  ÷ OD÷  ODú×L×Lús!    A6´A#	¼A6Á#A3Á.A6Á6B	rz   zprompt-turn-)Únamer   r|   r}   )Ú_ensure_session_db_rowr�   rJ  r!   rš   r(  rÏ  r  rÐ  rv  r£  rà  rŽ   r    rA   r   rÖ   r�   rÅ  Ú_sessions_lockÚ	_sessionsrÌ  Ú_start_session_work)r[  rn   r   ro   rt   rv   rp   rr   r†  r  rl   r}  rÏ  rÐ  rï  Ú
routing_dbÚ
registeredÚ	can_startrç  r   r˜   r<  rî  rè  s   ffffdd$$dd$       @@@@@@r   rZ  rZ  E  s  ÿý€ ô ˜gÓ&¨%Ó/Ü�‰Ø]Ø�K‰K˜Ó&×-Ð-¨#ô	/ô "ØˆW�d˜KÀ<ÐQaØ!9ô;€Hð ÒÙØ�M€FˆEÝCÝLÜ	'¨×	0Õ	0Ù:Ó<ÐÙ%Ð&6¸Ð?RÓSˆ÷ 
1÷ Øˆô #Ÿn™nÓ.ÐÜ
‡K�Kð	%àˆW�[‰[˜Ó'×-Ð-¨2¬w°u¸lÈBÓ/O×/UÐ/UÐSUØ×Ð˜¬Z¸¼c×-BÒ-B¤ D¤	ÈÌSÐQWË[ô
Z÷ Üˆo˜sÔ#÷N(õ N(÷^Có Cô 
  ×	(Ô	(¨J¿¾Ü—]‘] 3Ó'ˆ
ØŸ™ JÓ/Ô/×aÐa°ZÀ4Ð5G×5`Ð5`È:ÐY`ÐK`ˆ	ßð ˜WÓ$Ü*¨:°s¸GÔDÜ+¨C¸ÀSÀEÐ6JÐT[Ô\ÐdhÐhˆI÷ 9G×	(÷ Ø�^×$×$Ø!&ˆG�IÑ÷ %àÐˆ9Ð÷y 
1×	0Ð	0ú÷` 9G¿ú×	(×	(ú÷ %Ö$àÐúsH   Â	H;Å?I"Æ>I	ÇI	Ç&I	È I"È)I5È;I	ÉIÉI"É"I2	É5J	c               ó   € V ^8„  d   QhRR/# )r   r   r+   r   )r   s   "r   r   r   Ú  s   € ÷ 0ñ 0˜ñ 0r   c                ó2   € \        \        4       V RR7       R# )zFPublish this module's helpers onto ``server``, rebound to its globals.)ÚskipN)Ú_)r   Úglobals)Úservers   &r   Úregisterrÿ  Ú  s   € ä”“	˜6¨×/r   rû   r\   )-rº   Ú
__future__r   r¼   Ú
method_ctxr   r   Ú	_registryr   r&   r5   rB   rR   rk   rš   r¬   Ú	dataclassr¯   rß   rô   r  r  r  r4  rT  r\  rƒ  r7  r¹  r¬  rÊ  rÛ  r  rL  re  rr  r“  rª  r¹  rÁ  rË  rÅ  rÌ  rZ  rÿ  r   r   r   Ú<module>r     s¥  ðñõ #ã ç 4áÓ€	õ	XõXõXõTõ 	6õ$9ðN;ð HL÷;ð|È4ð Ø<@÷ð0 ×Ò˜TÔ"÷ð ó #ðõ4õB õ2%5õP=÷'õ0(õV#?ðL'Ø$(ð'Ø37÷'õ"+<ð\ ×Ò˜TÔ"÷$ð $ó #ð$õ011õh.1õbõ LõBMZ÷`Nõb<õ~kõ"N õb1õ@ 2õF
3ð !Ð õ,õ[ð$RØKOðRà$(ðRàJNðRð ,0ðRð BFð	Rð
  $ðRð
 GK÷R÷j0r   