+
    jHàj�k  ã                   ó”  a € R$ t/0 t R t^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHt ]P                   ! ]4      t]! RRR	7      t]! R
RR	7      t]! RRR	7      t] ^ k ]! RRR	7      t]! RRR	7      t]! 0 R%m4      tRtR tR tR&tR tR tR t R t!R t"R t#R t$R t%R t&R t'R t(R t)R t*R t+R  t,R!R/R" lt-R# t.R# )'zLTrusted messaging admission and the existing TurnRunner invocation boundary.N)Ú
ContextVar)Únullcontext)Úreplace)ÚMessageEvent)Úrestore_native)ÚRuntimeStoreErrorÚadmission_author)ÚdefaultÚexecuting_admissionFÚviewer_turnÚbusy_acceptanceÚbusy_commituh   â�³ Too many messages are already waiting in this conversation; send this again after the current reply.c              ƒ   óò  "  € ^ RI Hp \        P                  4       \        P                  4       rC\        P                  R4       \        P                  R4       TP                  Vf   RMT4      p V P                  V4      G Rj  x€L
 pVe(   VP                  4       '       g   VP                  R4       TP                  T4       TP                  R8X  d   R# T P                   P#                  TP$                  4       T P&                  P)                  TP$                  \*        P,                  ! 4       P/                  4       4      p	\1        T 4      p
\3        TRR4      '       d   YTP$                  &   ^ RIHp T! T P8                  TP$                  R7      pTf   RMTR,          pTR9   d°   T P                   P;                  TP$                  4       T P&                  P                  TP$                  4      T	J d   T P&                  TP$                   T
P                  TP$                  4      TJ d   Y¦P$                   TR8X  d   R# \=        YP>                  R4      # Te(   TP                  4       '       g   TP                  R4        \*        P@                  ! T	4      G Rj  x€L
 T
P                  TP$                  4      TJ d   Y¦P$                   # #  ELK  \         dè   pTP                  R8X  d)   TP                  R8X  d    Rp?TP                  T4       R# TP                  R8X  dk   TP                  '       dY   TP                  \        9   d   TP                   RTP                   2MTP                  pRT R	2u Rp?TP                  T4       # TP                  R
8w  d   h \        u Rp?TP                  T4       # Rp?ii ; i  TP                  T4       i ; i EL?  \         dW   p\=        YP>                  TP                  4      u Rp?T
P                  TP$                  4      TJ d   Y¦P$                   # # Rp?ii ; i  T
P                  TP$                  4      TJ d   Y¦P$                   i i ; i5i)é    )Úmessaging_admissionNTÚstale_generationÚrouteÚinvalid_paramsz: u$   âš ï¸� Hermes refused this message (zJ), so it was not saved or answered. Ask the operator to check gateway.log.Ú
queue_fullÚterminalÚ_turn_marker_handoffF)Úget_session_admission)Úadmission_idÚstatusÚunknown_execution)r   Úunknown)!Úgateway.session_authorityr   r   Úgetr   ÚsetÚadmit_nativeÚdoneÚ
set_resultr   ÚreasonÚfieldÚresetÚ_CONTENT_CLAUSESÚQUEUE_FULL_REPLYr   Únative_waitersÚaddr   ÚwaitersÚ
setdefaultÚasyncioÚget_running_loopÚcreate_futureÚ_marker_adoptersÚgetattrÚhermes_state_runtimer   ÚdbÚdiscardÚpause_noticeÚrefÚshield)Ú	authorityÚeventr   ÚacceptedÚ	committedÚingressÚreceiptÚexcÚnamedÚwaiterÚadoptersr   Úrowr   s   &&            Ú</home/ubuntu/.hermes/hermes-agent/gateway/session_ingress.pyÚadmit_messagerB   #   sŸ  é € Ý=Ü)×-Ñ-Ó/´·±Ó1BˆiÜ×Ñ˜ÔÜ‡O�O�DÔØ!×%Ñ%¨hÒ.>¡dÀHÓM€Gð+Ø!×.Ñ.¨uÓ5×5ˆØÒ ¨¯©×)9Ò)9Ø× Ñ  Ô&ð  	×!Ñ! 'Ô*Ø‡~�~˜Ô#Ùà×Ñ× Ñ  ×!5Ñ!5Ô6Ø×Ñ×)Ñ)¨'×*>Ñ*>Ä×@XÒ@XÓ@Z×@hÑ@hÓ@jÓk€FÜ 	Ó*€HÜˆuÐ,¨e×4Ò4ð */�×%Ñ%Ñ&õ ;Ù
 	§¡¸7×;OÑ;OÔ
P€CØš;‰Z¨C°­M€FØÐ(Ô(Ø× Ñ ×(Ñ(¨×)=Ñ)=Ô>Ø×Ñ× Ñ  ×!5Ñ!5Ó6¸&Ó@Ø×!Ñ! '×"6Ñ"6Ð7Ø�<‰<˜×,Ñ,Ó-°Ó6Ø×-Ñ-Ð.Ø Ô+ˆtÐj´¸iÏÉÐViÓ1jÐjØÒ H§M¡M§O¢OØ×Ñ˜DÔ!ð/Ü—^’^ FÓ+×+ð �<‰<˜×,Ñ,Ó-°Ó6Ø×-Ñ-Ñ.ð 7òa 6øô ô  Ø�:‰:Ð+Ô+°·	±	¸WÔ0DÛð 	×!Ñ! 'Ö*ð �:‰:Ð)Ô)¨c¯i¯i¨ið 58·I±IÔAQÔ4Q�s—z‘z�l " S§Y¡Y KÑ0ÐWZ×WaÑWaˆEØ:¸5¸'ð BJð Jô Kð 	×!Ñ! 'Õ*ð �:‰:˜Ô%ØäÔà×!Ñ! 'Õ*ûð ûð 	×!Ñ! 'Õ*úò4 ,øÜô @Ü˜I§{¡{°C·J±JÓ?Ô?à�<‰<˜×,Ñ,Ó-°Ó6Ø×-Ñ-Ñ.ð 7ûð@ûð �<‰<˜×,Ñ,Ó-°Ó6Ø×-Ñ-Ñ.ð 7üsì   ‚A/Q7Á2K ÂKÂK Â%K Â6F>Q7É5Q7ÊO" Ê OÊ!O" Ê$-Q7ËK ËOË"OÌO	 ÌQ7Ì"OÌ;AOÍ<OÍ=O	 ÎQ7ÎOÎ*OÎ+O	 Î/Q7ÏOÏO	 Ï	OÏQ7ÏO" Ï"QÏ-P>ÐQÐQ Ð-Q7Ð>QÑQ Ñ.Q4Ñ4Q7c                 ó8   € \        V R R4      pVf	   / ;qn        V# )Úmarker_adoptersN)r/   rD   )r6   r?   s   & rA   r.   r.   ^   s'   € Ü�yÐ"3°TÓ:€HØÒØ/1Ð1ˆÔ,Ø€Oó    c              ƒ  óÎ   "  € \        V 4      P                  V4      pVe   \        W#4       R# WP                  9   d   V\	        V 4      V&   R# \        W4      G Rj  x€L
  R#  L5i)a   The executed turn's durable active-turn marker outlives the handler, as the in-process
turn's does on main, and is released only once its reply is in the delivery ledger (or nothing
is owed). A kill between the terminal commit and that ledger write then leaves a marked turn
whose persisted reply the next unclean boot ledgers and sends once, without new inference,
instead of a settled answer nobody owes. The waiting adapter lifecycle adopts it; a recovered
no-waiter reply keeps it until ``deliver_settled``; any other turn releases it here.N)r.   r   Ú_move_markerÚpending_deliveriesÚ_held_markersÚ_release_turn_marker)r6   r   r7   Úadopters   &&& rA   Ú_hand_over_turn_markerrL   h   sY   é € ô ˜yÓ)×-Ñ-¨lÓ;€GØÒÜ�UÔ$ÙØ×3Ñ3Ô3à16Œ�iÓ  Ñ.ÙÜ
˜yÓ
0×0Ô0ùs   ‚AA%ÁA#ÁA%c           	      ó†   € \          F6  p\        W4      '       g   K  \        W\        W4      4       \	        W4       K8  	  R # ©N)Ú_MARKER_FIELDSÚhasattrÚsetattrr/   Údelattr)ÚsourceÚtargetÚnames   && rA   rG   rG   z   s.   € ßˆÜ�6× Ô Ü�F¤'¨&Ó"7Ô8Ü�FÖ!ó rE   c                 ó8   € \        V R R4      pVf	   / ;qn        V# )Úheld_turn_markersN)r/   rW   )r6   Úhelds   & rA   rI   rI   �   s&   € Ü�9Ð1°4Ó8€DØ‚|Ø-/Ð/ˆÔ*Ø€KrE   c                 óB   € \        WR 4      pVf   / p\        WV4       V# rN   )r/   rQ   )r6   rU   Úfounds   && rA   Ú	_registryr[   ˆ   s'   € Ü�I TÓ*€EØ‚}ØˆÜ�	 Ô'Ø€LrE   c                ó   € \        V R4      # )z¤admission -> the reply a live native waiter is about to send, kept only until the drain
settles the turn, so a turn fenced ``unknown`` can still owe it to the chat.Úwaiter_replies)r[   )r6   s   &rA   r]   r]   �   s   € ô �YÐ 0Ó1Ð1rE   c                ó2  € \        V 4      P                  VR4      pVeG   \        V 4      P                  V4      pVe(   \	        W2^,          4       V^,          \        V 4      V&   MV P                  P                  VR4      pVe   V\        V R4      V&   R# R# )a!  Settlement could not commit and the turn is fenced ``unknown``, but this owner keeps its
captured answer for Discard (``resolve_unknown``). The reply stays owed to its destination,
and so does the turn's crash marker: the live waiter is released with a pause notice, so the
marker is taken back from it. Restart while unknown clears the marker (no answer is owed,
``release_unknown_turn_markers``); a Discard that commits the captured answer makes it owed,
sent once by ``deliver_resolved`` or, after a kill before that send, by the boot ledger.NÚunsettled_deliveries)r]   Úpopr.   r   rG   rI   rH   r[   )r6   r   ÚdeliveryrK   s   &&  rA   Úretain_unsettled_deliveryrb   –   s‘   € ô ˜iÓ(×,Ñ,¨\¸4Ó@€HØÒÜ" 9Ó-×1Ñ1°,Ó?ˆØÒÜ˜¨1¥+Ô.Ø5=¸aµ[ŒM˜)Ó$ \Ñ2øà×/Ñ/×3Ñ3°LÀ$ÓGˆØÒØEMŒ	�)Ð3Ó4°\ÓBñ rE   c             ƒ  ó¨   "  € \        V R4      P                  VR4      pVf   R# V'       d   W0P                  V&   \        W4      G Rj  x€L
  R#  L5i)a  After a Discard committed: send the retained reply when its captured answer committed with
the resolution (``owed``), else release its marker and drop it. Popped first, so a repeated
resolution never sends twice; a turn the drain still owns is delivered by the drain.r_   N)r[   r`   rH   Údeliver_settled)r6   r   Úowedra   s   &&$ rA   Údeliver_resolvedrf   ©   sI   é € ô ˜Ð$:Ó;×?Ñ?ÀÈdÓS€HØÒÙßØ5=×$Ñ$ \Ñ2Ü
˜)Ó
2×2Ô2ùs   ‚*A­AÁ	AÁ
Ac              ƒ   ó‚   "  € \        VR R4      '       d&   V P                  P                  V4      G Rj  x€L
  R# R#  L5i)Ú_gateway_active_turn_tokenN)r/   ÚrunnerÚ_clear_durable_active_turn)r6   r7   s   &&rA   rJ   rJ   µ   s7   é € ÜˆuÐ2°D×9Ò9Ø×Ñ×9Ñ9¸%Ó@×@Ò@ñ :Ù@ùs   ‚2?´=µ	?c                ó*  € V P                   VP                  ,          pVP                  '       d   R# RVn        VR8X  d   R# VR8X  d   R# VR8X  d8   \        \        VP                  RR4      R	R4      R
8H  pV'       d   RMRpRV R2# RV R2pRV R2# )a  The committed input stays queued behind a paused FIFO (a turn lost across an owner
restart, or a head the preflight refused). Tell the platform user once per pause episode
through the ordinary reply path; later messages onto the same pause are admitted silently.NTÚruntime_draininguX   â�³ Hermes is restarting â€” your message is saved and will be answered when it is back.Úsession_busyuc   â�³ Your message is saved and will be answered when the work running in this conversation finishes.r   ÚplatformÚvalueÚslackz/hermes discardz/discardu¢   â�¸ï¸� This conversation is paused: a previous turn did not finish when Hermes restarted, and only you know whether to send it again. Your message is saved. Send z` to drop the lost turn and continue (it is not re-run), or /reset to start a fresh conversation.z-a queued message could not be re-authorized (Ú)u$   â�¸ï¸� This conversation is paused: z‰. Your message is saved but will not be answered here. Send /reset to start a fresh conversation, or ask the operator to resume this one.)ÚsessionsÚ
session_idÚpause_notifiedr/   rS   )r6   r4   r"   Úliverp   r2   Úcauses   &&&    rA   r3   r3   º   sÄ   € ð ×Ñ˜cŸn™nÕ-€DØ××ÐÙØ€DÔØÐ#Ô#áiØ�ÔátØÐ$Ô$ô œ §¡¨Z¸Ó>ÀÈÓNÐRYÑYˆß',Ñ#°*ˆð[Ø[bÐZcð djðjð 	kð <¸F¸8À1ÐE€EØ2°5°'ð :að að brE   c                ó¦   € VR,          pR F5  pVP                  V4      ;'       g    / P                  R4      pVf   K3  Vu # 	  ^ RIHp V! V 4      # )z¯Who wrote the admitted input, for memory attribution only: the producer's stamp when it
left one, else the forwarded peer bound into the session policy; never grants anything.ÚpayloadÚturn_author)Úforward_author)Úlocal_automation_v1Úapi_turn_v1Úcli_turn_v1)r   Úgateway.session_a2arz   )Úpolicyr@   rx   ÚkeyÚauthorrz   s   &&    rA   Úrow_turn_authorr‚   Ö   sT   € ð �)�n€GÛDˆØ—+‘+˜cÓ"×(Ð( b×-Ñ-¨mÓ<ˆØÔØŠMñ Eõ 3Ù˜&Ó!Ð!rE   c              ƒ   óš  "  € ^ RI Hp V! WV4      G Rj  x€L
 pVe   V# ^ RIHp V! V P                  V P
                  VP                  ,          P                  4      pVe)   VP                  R8X  d   ^ RIH	p V! WW&4      G Rj  x€L
 # Tp^ RI
Hp	Hp
 V	! W4      pVe   V
! WW&4      G Rj  x€L
 # V P
                  VP                  ,          pVR,          V P                  9   pV P                  P                  VR,          4       RVR	,          9   d   \        VR	,          V P                  4      pM`^ R
IHp \%        R+RVR	,          R,          RVP                  RVR,          /V! VR	,          4      B pRVR	,          9   d   ^ RIHp V! WV4      pVP*                  '       dQ   RVP,                  9   d@   RVR	,          9   d   V P/                  V4      MVP,                  R,          VP,                  R&   VR	,          P1                  R/ 4      P1                  R4      pRpVe%   ^ RIHp V! V P                  VP                  V4      p^ RIHp ^ RIHpHp ^ RI H!p VP                  PD                  VPF                  8H  pVP*                  '       gH   V'       g@   VP                  PD                  VPH                  8X  g   VP                  VR,          3Vn%        VP,                  P1                  R4      p\L        PO                  Ve   TM
\Q        W‚4      4      p^ RI)H*p \V        PO                  V! V4      '       d   TMR4      pVPO                  R4      p/ pVPO                  V4      p\X        PO                  R4      pRVn-        Rp  \]        V V4      G Rj  x€L
 ;_uu_ 4        V'       dt   V! WVR	,          4      p!VPO                  V!4       \_        VP`                  \b        4      '       d%   RPe                  R V!R,           4       4      Vn0        RVn3        RVn        V P                  Pi                  V4      G Rj  x€L
 p"VP1                  RVP1                  R 4      4      p#V#fa   R!T";'       g    R"R#. /p#V'       g3   VR	,          P1                  R$4      RJ d-   VPk                  4       '       g   R!R"R#. R%RR&RR'T";'       g    R(/p#R V#R)VP1                  R)/ 4      /R*V9   d   R*VR*,          /M/ CV Pl                  VR,          &   V'       gv   V"'       dn   V P                  Po                  VP                  4      p$V$eE   V$WÛPp                  V"V3p%V'       d   V%\s        V 4      VR,          &   MV%V Pt                  VR,          &   Rp \w        WR,          V4      G Rj  x€L
  T"uuRRR4       V '       g   \y        W4      G Rj  x€L
  \X        P{                  V4       VP{                  V4       VP{                  V4       \L        P{                  V4       \V        P{                  V4       #  EL EL¡ EL} ELš ELö L› Lw  + '       g   i     M; i T '       g   \y        Y4      G Rj  x€L 
  \X        P{                  T4       TP{                  T4       TP{                  T4       \L        P{                  T4       \V        P{                  T4       R#   T '       g   \y        Y4      G Rj  x€L 
  \X        P{                  T4       TP{                  T4       TP{                  T4       \L        P{                  T4       \V        P{                  T4       i ; i5i),r   )Únote_if_unviewedN)Úpolicy_for_sourceÚcron)Úexecute)Úmanaged_policyÚadmit_managedr   Únative_text_v1rx   )Úrestore_attachmentsÚtextrS   Ú
message_idr{   )Úrestore_local_automationÚgateway_session_idÚgateway_proven_session_idÚ
provenance)Úrestore_provenance)ÚPlatform)Úapi_executionÚprepare_api_execution)Úexecution_resultÚ
generationry   )Úis_viewer_inputTFÚ
c              3   ób   "  € T F%  qP                  R 4      R8X  g   K  VR,          x € K'  	  R# 5i)ÚtyperŒ   N)r   )Ú.0Úparts   & rA   Ú	<genexpr>Ú$execute_admission.<locals>.<genexpr>#  s,   é € Ð*vÑDW¸D×[cÑ[cÐdjÓ[kÐouÑ[u¬<¨4°¯<ª<ÓDWùs   ‚/ž/ÚcontentÚterminal_resultÚresultÚfinal_responseÚ ÚmessagesÚfiniteÚfailedÚ	completedÚerrorzThe admitted turn failed.ÚusageÚsession_usage© )>Ú gateway.session_completion_notesr„   Úgateway.session_policyr…   ri   rr   rs   rS   Úgateway.session_cronr‡   Úgateway.session_managed_workerrˆ   r‰   r'   r2   r   Úgateway.session_ingress_mediar‹   r   Úgateway.session_automationrŽ   ÚinternalÚmetadataÚphysical_targetr   Úgateway.session_ingress_contextr’   Úgateway.configr“   Úgateway.session_api_turnr”   r•   Úgateway.session_resultsr–   rn   Ú
API_SERVERÚLOCALÚ_claimed_ownerr   r   r‚   Úgateway.session_operatorr˜   r   r
   r   Ú_execution_scopeÚ
isinstancerŒ   ÚlistÚjoinÚallow_gateway_controlÚ_handle_messageÚget_commandÚpending_resultsÚ_adapter_for_sourcer   r]   rH   rL   rJ   r$   )&r6   r4   r@   r„   Únotedr…   r   r‡   Úlocal_policyrˆ   r‰   ru   Únativer7   r‹   rŽ   r‘   Úhomer’   r“   r”   r•   r–   Úis_apir�   Úauthor_tokenr˜   Úviewer_tokenÚ	api_tokenÚcapturedÚresult_tokenÚtokenÚhandedÚpreparedÚresponser¢   Úadapterra   s&   &&&                                   rA   Úexecute_admissionrÖ   â   s  é € ÝAÙ" 9°3Ó7×7€EØÒØˆÝ8Ù˜y×/Ñ/°×1CÑ1CÀCÇNÁNÕ1S×1ZÑ1ZÓ[€FØÒ˜fŸm™m¨vÔ5Ý0Ù˜Y¨SÓ9×9Ð9Ø€LßLÙ˜IÓ+€FØÒÙ" 9°3Ó?×?Ð?Ø×Ñ˜cŸn™nÕ-€DØ�Õ  I×$<Ñ$<Ñ<€FØ×Ñ×$Ñ$ S¨Õ%8Ô9Ø˜3˜y�>Ô)Ü˜s 9�~¨y×/?Ñ/?Ó@‰åEÜñ d # i¥.°Õ"8ð dÀÇÁð dØ(+¨NÕ(;ðdÙ?RÐSVÐW`ÕSaÓ?bñdˆà  C¨	¥NÔ2ÝKÙ,¨Y¸SÓAˆEØ‡~‡~€~Ð.°%·.±.Ô@ð /?À#ÀiÅ.Ô.PˆI×%Ñ% cÔ*ÐV[×VdÑVdÐeyÕVzð 	�‰Ð2Ñ3à�Y•×#Ñ#Ð$4°bÓ9×=Ñ=¸lÓK€JØ€DØÒÝFÙ! )×"2Ñ"2°E·L±LÀ*ÓMˆÝ'ßMÝ8Ø�[‰[×!Ñ! X×%8Ñ%8Ñ8€FØ�N�NˆNŸf¨¯©×(<Ñ(<ÀÇÁÔ(Nð !$§¡°°LÕ0AÐBˆÔØ�^‰^×Ñ Ó.€FÜ#×'Ñ'°&Ò2D©Ì/ÐZfÓJlÓm€LÝ8Ü—?‘?©?¸3×+?Ò+?¡4ÀTÓJ€LØ×!Ñ! $Ó'€IØ€HØ#×'Ñ'¨Ó1€LÜ×#Ñ# DÓ)€Eà!%€EÔØ€Fð5(Ü# I¨tÓ4×4×4Ñ4ßá0°ÀÀYÅÓP�Ø×!Ñ! (Ô+Ü˜eŸj™j¬$×/Ò/ð "&§¡Ñ*vÀHÈYÖDWÓ*vÓ!v�E”JØ.3�Ô+Ø!%�”Ø&×-Ñ-×=Ñ=¸eÓD×DˆHØ—\‘\Ð"3°X·\±\À(Ó5KÓLˆFØŠ~ð +¨H¯N¨N¸¸JÈÐK�ß˜c )�n×0Ñ0°Ó:¸dÓBÈ5×K\ÑK\×K^ÒK^Ø.°°JÀÀHÈdÐT_ÐafØ% x×'NÐ'NÐ3NðP�Fð
 ˜& '¨8¯<©<¸ÀÓ+Dð>iàCRÐV^ÔC^�O X¨oÕ%>Ñ?Ðdfð>iˆI×%Ñ% c¨.Õ&9Ñ:÷ ŸhØ#×*Ñ*×>Ñ>¸u¿|¹|ÓL�ØÒ&ð
 !(¨·
±
¸HÀdÐK�HßØIQœ yÓ1°#°nÕ2EÒFàLT˜	×4Ñ4°S¸Õ5HÑIØˆFÜ(¨¸Õ4GÈÓO×OÐOØ÷Y 5Ñ4÷\ Ü& yÓ8×8Ð8Ü×!Ñ! %Ô(Ø×Ñ˜|Ô,Ø×Ñ˜IÔ&Ü×Ñ˜|Ô,Ü×Ñ˜,Õ'òW 8ò :ò
 @òV 5ò Eñ@ Pñ 9÷_ 5×4úÐ4÷\ Ü& yÓ8×8Ñ8Ü×!Ñ! %Ô(Ø×Ñ˜|Ô,Ø×Ñ˜IÔ&Ü×Ñ˜|Ô,Ü×Ñ˜,Ö'ø÷ Ü& yÓ8×8Ñ8Ü×!Ñ! %Ô(Ø×Ñ˜|Ô,Ø×Ñ˜IÔ&Ü×Ñ˜|Ô,Ü×Ñ˜,Õ'üs  ‚]•X#–A/]ÂX&Â&]Â,X)Â-C6]Æ$C*]Ê]ÊB ]Ì8A
]Î[	 ÎX,Î[	 ÎBX6Ð9X/Ð:2X6Ñ-X6Ñ;1X6Ò-X6Ò?A	X6Ô	X6ÔBX6ÖX2ÖX6Ö
[	 Ö&]Ö<X4Ö=A']Ø&]Ø)]Ø,[	 Ø/X6Ø2X6Ø4]Ø6Y	Ù[	 Ù
]Ù]Ù Y#Ù!A(]Û	]Û [#Û!A']Ý]c                óÆ   € ^ RI Hp ^ RIHp V! \	        V P
                  4      4      pVP                  4       '       d   V! V4      '       g   \        4       # ^ RIH	p V! 4       # )a  A standalone owner's turn binds nothing, but the launch profile's is marked at entry: a second
profile switching this gateway to multiplexing mid-turn must not fail its later credential reads
closed. Any other owner (a hosted named profile) stays unmarked, never reading the launch env.©ÚPath)Ú_is_process_home)Úlaunch_body)
ÚpathlibrÙ   Úagent.secret_scoperÚ   ÚstrÚ
profile_idÚis_absoluter   Ú!tui_gateway.launch_profile_policyrÛ   )r6   rÙ   rÚ   ÚownerrÛ   s   &    rA   Ú_launch_body_if_launch_ownerrã   R  sL   € õ Ý3Ù”�Y×)Ñ)Ó*Ó+€EØ×Ñ×ÒÑ&6°u×&=Ò&=Ü‹}ÐÝ=Ù‹=ÐrE   c              ƒ  ó  a aa"  € \        \        S P                  RR4      RR4      pSf   V'       g   \        S 4      # ^ RIHoHp VV V3R lp\        P                  ! V4      G Rj  x€L
 w  rVVf   \        4       # V! WV4      #  L5i)ag  Under multiplex, owner-side execution runs under the OWNING profile's home (agent build,
config, secrets, state.db), never the launch profile's ambient scope; native provenance
(``home``) refines it. A single-profile gateway keeps its ambient scope byte-for-byte.
Secret sources (external CLIs) hydrate off the loop, as main's per-message scope does (#99519).ÚconfigNÚmultiplex_profilesF)Ú_load_profile_secret_scopeÚ_profile_runtime_scopec                  óØ   <€ ^ RI Hp  SpVfL   V ! \        SP                  4      4      pVP	                  4       '       d   VP                  4       '       d   TMRpY;'       d	    S! V4      3# )r   rØ   N)rÜ   rÙ   rÞ   rß   rà   Úis_dir)rÙ   Ú
scope_homerâ   rç   r6   rÊ   s      €€€rA   ÚloadÚ_execution_scope.<locals>.loadi  s\   ø€ Ý Øˆ
ØÒÙœ˜Y×1Ñ1Ó2Ó3ˆEØ"'×"3Ñ"3×"5Ò"5¸%¿,¹,¿.º.™ÈdˆJØ×PÐPÑ*DÀZÓ*PÐPÐPrE   )	r/   ri   rã   Úgateway.runrç   rè   r+   Ú	to_threadr   )r6   rÊ   Ú	multiplexrè   rì   rë   Úsecretsrç   s   ff     @rA   r¾   r¾   _  sw   úé € ô
 œ 	× 0Ñ 0°(¸DÓAÐCWÐY^Ó_€IØ‚|ŸIÜ+¨IÓ6Ð6ßN÷Qô !(× 1Ò 1°$Ó 7×7Ñ€JØ&Ò.Œ;‹=Ð_Ñ4JÈ:Ó4_Ð_ñ 8ùs   ….B´4BÁ(BÁ)Bc              ƒ  ót  "  € \        V 4      P                  VR4      pV P                  P                  V4      pVex   WP                  9   dh   V P                  P                  V4       V P                  P                  V4       \        V 4      P                  V4      pVe   Ve   \        W$4       RpRpVf   Ve   \        W4      G Rj  x€L
  R# Vw  rVrxp	 \        W	4      G Rj  x€L
 ;_uu_ 4        \        WVWx4      G Rj  x€L
  RRR4       T P                  P                  TR4       \        Y4      G Rj  x€L
  R#  Lv L\ LA  + '       g   i     LG; i  \         d    \        P                  RT4        Lmi ; i LF  T P                  P                  TR4       \        Y4      G Rj  x€L 
  i ; i5i)z§Send a recovered no-waiter turn's reply after its terminal outcome committed. A send
failure cannot rewrite that outcome; it is logged, and inference never runs again.Nz'Delivery of settled admission %s failed)rI   r`   rH   r   r'   r2   r.   rG   rJ   r¾   Údeliver_responseÚ	ExceptionÚloggerÚ	exception)
r6   r   rX   ra   rK   rÕ   r7   Úsession_keyrÔ   rÊ   s
   &&        rA   rd   rd   u  s~  é € ô ˜Ó#×'Ñ'¨°dÓ;€DØ×+Ñ+×/Ñ/°Ó=€HØÒ ×0HÑ0HÔ Hð 	× Ñ ×(Ñ(¨Ô6Ø×$Ñ$×(Ñ(¨Ô6Ü" 9Ó-×1Ñ1°,Ó?ˆØÒ Ò 3Ü˜Ô'ØˆDØˆØÒØÒä& yÓ7×7Ð7ÙØ2:Ñ/€G�K¨4ð	5Ü# IÓ4×4×4Ñ4Ü" 7°;ÓI×IÐI÷ 5ð 	×$Ñ$×(Ñ(¨°tÔ<ä" 9Ó4×4Ò4ñ 8ñ 5ÙI÷ 5×4ûäô RÜ×ÑÐBÀLÖQðRúñ 	5øð 	×$Ñ$×(Ñ(¨°tÔ<ä" 9Ó4×4Ò4üs¨   ‚CF8Ã
EÃF8ÃE Ã&EÃ'E Ã3EÄEÄEÄE Ä*F8Ä:FÄ;F8ÅE ÅEÅE	ÅE ÅF ÅE Å!E>Å;F Å=E>Å>F ÆF8Æ+F5Æ.F1Æ/F5Æ5F8c           	   ƒ   óª  "  € ^ RI HpHp V P                  V4      w  rgV'       g   R# V P	                  WaW'^ 8„  R7      G Rj  x€L
 pV! V! V4      4      p	. p
VP
                  '       d4   V P                  WVP
                  W—^ 8„  WzP                  4      G Rj  x€L
  V P                  WV	\        V
4      V
P                  R7      G Rj  x€L
  R#  L‹ L8 L
5i)r   )Ú_thread_metadata_for_eventÚ_mark_notify_metadataN)Úis_ephemeral_response)Úanything_sentÚrecord_delivery)
Úgateway.platforms.baserù   rú   Ú_unwrap_ephemeralÚ_extract_response_contentÚtext_contentÚ_send_final_textÚappendÚ_deliver_attachmentsÚbool)rÕ   r7   r÷   rÔ   rù   rú   rŒ   ÚttlÚ	extractedr´   Úresultss   &&&&       rA   ró   ró   –  s×   é € ßXØ×)Ñ)¨(Ó3�I€DßÙØ×7Ñ7¸À[ÐnoÑhoÐ7Óp×p€IÙ$Ñ%?ÀÓ%FÓG€HØ€GØ××ÐØ×&Ñ& u¸9×;QÑ;QØ'/°q±¸#¿~¹~óO÷ 	Oð 	Oà
×
&Ñ
& u¸ÔQUÐV]ÓQ^Ø7>·~±~ð 'ó G÷ Gò Gñ qñ	OñGùs;   ‚?CÁCÁ%CÁ(.CÂCÂ/CÃCÃCÃCÃCÚdurablec             ƒ  óÐ  a aaa	a
"  € \        S\        SP                  4      R7      o
\        P                  ! 4       P	                  4       o	\        P                  ! 4       P	                  4       pV	V V
VV3R lp\
        P                  S	4      \        P                  V4      rv \        P                  ! V! 4       4      p\
        P                  V4       \        P                  V4       S P                  P                  V4       VP                  S P                  P                  4        \        P                  ! S	V0\        P                  R7      G Rj  x€L
  V'       dF   VP!                  4       '       g0   \        P                  ! WH0\        P                  R7      G Rj  x€L
  TP!                  4       '       d   TP'                  4        R# TP!                  4       '       g   \)        S YH4       R# R#   \
        P                  T4       \        P                  T4       i ; i LÎ Lƒ  \        P"                   d)    S	P!                  4       '       g   TP%                  4        h i ; i5i)a2  Serial receive loops (IRC, Signal) await this before reading their next frame, so return
once the follow-up is committed to the FIFO, or queued behind an earlier input of its chat still
capturing (its position is then fixed; acceptance still waits for the commit); a tracked
observer delivers its one reply. *durable*: return only once the row is committed (or the input
was refused, fenced or answered), never on the earlier position release: a busy burst's commit
task, which a command barrier (``/restart`` closing admission) waits on. Otherwise an input
released before its commit is held until it commits or its handler ends, and a serial reader's
next command waits for that too (``burst_gate``): a non-burst busy input (a second video, a voice
note, text outside queue mode) has no burst commit task to wait on.)rS   c               “   ó’  <"  € \        SR R4      RJSn         SP                  S4      G Rj  x€L
 p \        SS4       SP                  Sn        \	        SSSV 4      G Rj  x€L
  SP                  S4      G Rj  x€L
  SP                  S4      G Rj  x€L
  R#  Lk L:  \
         d`   pSP                  4       '       g   h \        P                  RSP                  TRR7       SP                  ST4      G Rj  x€L 
   Rp?L�Rp?ii ; i L� Ly  SP                  S4      G Rj  x€L 
  SP                  S4      G Rj  x€L 
  i ; i5i)Úgateway_runnerNz%[%s] Queued busy follow-up failed: %sT)Úexc_info)r/   r   Ú_message_handlerrG   ró   rô   r    rõ   r©   rU   Ú_notify_turn_errorrJ   )rÔ   r<   r8   rÕ   Údelivery_eventr7   r÷   s     €€€€€rA   ÚobserveÚ%dispatch_shared_busy.<locals>.observe³  s  øé € ô &-¨WÐ6FÈÓ%MÐUYÐ%YˆÔ"ð	6Ø$×5Ñ5°eÓ<×<ˆHä˜ Ô/Ø27×2LÑ2LˆNÔ/Ü" 7¨N¸KÈÓR×RÐRð ×.Ñ.¨~Ó>×>Ð>Ø×.Ñ.¨uÓ5×5Ò5ñ =ñ SøÜô 	BØ—=‘=—?’?ØÜ�L‰LÐ@À'Ç,Á,ÐPSÐ^bˆLÔcØ×,Ñ,¨^¸SÓA×AÖAûð		Búñ ?Ù5øð ×.Ñ.¨~Ó>×>Ñ>Ø×.Ñ.¨uÓ5×5Ò5üs¥   ƒE™B ­B®2B Á BÁ!B Á%EÁ9D
Á:EÂDÂEÂB ÂB ÂDÂ(ADÃ7C:Ã8DÃ=D ÄDÄD Ä
EÄEÄEÄ#D&Ä$EÄ=E Ä>EÅE)Úreturn_whenN)r   rS   r+   r,   r-   r   r   r   Úcreate_taskr$   Ú_background_tasksr(   Úadd_done_callbackr2   ÚwaitÚFIRST_COMPLETEDr    ÚCancelledErrorÚcancelr¢   Ú_hold_until_committed)rÕ   r7   r÷   r	  r9   r  rÑ   Úcommit_tokenÚtaskr8   r  s   fff$     @@rA   Údispatch_shared_busyr  ¥  s§  üé € ô ˜U¬7°5·<±<Ó+@ÔA€NÜ×'Ò'Ó)×7Ñ7Ó9€HÜ×(Ò(Ó*×8Ñ8Ó:€I÷6ñ 6ô* *×-Ñ-¨hÓ7¼¿¹ÈÓ9Sˆ<ð(Ü×"Ò"¡7£9Ó-ˆä×Ñ˜eÔ$Ü×Ñ˜,Ô'Ø×Ñ×!Ñ! $Ô'Ø×Ñ˜7×4Ñ4×<Ñ<Ô=ðÜ�lŠl˜H dÐ+¼×9PÑ9PÔQ×QÐQß˜4Ÿ9™9Ÿ;š;Ü—,’, 	Ð0¼g×>UÑ>UÔV×VÐVð
 ‡y�y‡{‚{Ø�‰ŽØ�^‰^×ÒÜ˜g yÖ7ñ øô 	×Ñ˜eÔ$Ü×Ñ˜,Õ'úñ 	RáVøÜ×!Ñ!ô Ø�}‰}�ŠØ�K‰KŒMØðüsy   ‡BI&Â"G3 Â=A*I&Ä(+H& ÅH"ÅH& Å H& Å6*H& Æ H$Æ!H& Æ%I&Æ;'I&Ç#I&Ç3,HÈI&È"H& È$H& È&*I#ÉI#É#I&c                ó>  a€ \         P                  ! 4       P                  4       oV3R lpVP                  V4       VP                  V4       V P                  P                  R\        4       4      pVP                  S4       SP                  VP                  4       R# )a  Released before its commit: the reader reads on, but this input is not durable yet. A serial
reader's next command waits for its commit or its handler's end (``burst_gate``), so /restart never
closes admission, and /new never cancels the chat's rows, before it lands.c                 óZ   <€ SP                  4       '       g   SP                  R 4       R # R # rN   )r    r!   )Ú_Úsettleds   &€rA   ÚsettleÚ%_hold_until_committed.<locals>.settleä  s!   ø€ Ø�|‰|�~Š~Ø×Ñ˜tÖ$ñ rE   Ú_uncommitted_inputsN)	r+   r,   r-   r  Ú__dict__r*   r   r(   r2   )rÕ   r9   r  r#  rX   r"  s   &&&  @rA   r  r  Þ  sx   ø€ ô ×&Ò&Ó(×6Ñ6Ó8€Gõ%ð ×Ñ Ô'Ø×Ñ˜6Ô"Ø×Ñ×&Ñ&Ð'<¼c»eÓD€DØ‡H�HˆWÔØ×Ñ˜dŸl™lÖ+rE   c                ó@   € V ^8„  d   Qh/ ^ \         9   d
   \        ;R&   # )é   r   )Ú__conditional_annotations__r   )Úformats   "rA   Ú__annotate__r+     s   € × RÑ R÷  BÒ AŒZÑ Aò! SrE   >
   rŒ   Ú
auto_skillÚ
media_urlsÚmedia_typesÚchannel_promptÚreply_expectedÚchannel_contextÚmedia_text_inlinedÚmedia_types_lengthÚmedia_text_inlined_length)Ú _gateway_active_turn_session_keyrh   )0r)  Ú__doc__r+   ÚloggingÚcontextvarsr   Ú
contextlibr   Údataclassesr   Úgateway.platforms.eventr   Úgateway.session_enveloper   r0   r   Ú	getLoggerÚ__name__rõ   r   r
   r   r   r   Ú	frozensetr%   r&   rB   r.   rO   rL   rG   rI   r[   r]   rb   rf   rJ   r3   r‚   rÖ   rã   r¾   rd   ró   r  r  r+  )r)  s   @rA   Ú<module>r@     s  øðÞ RÛ Û Ý "Ý "Ý å 0Ý 3Ý 2à	×	Ò	˜8Ó	$€áÐ0¸$Ô?Ð Ù Ð!6ÀÔFÐ á$ ]¸DÔA€Ó AáÐ.¸Ô=€ñ ˜°Ô5€áò ó Ð ð?Ð ò8/òvð T€ò1ò$"òòò2òNò&	3òAò
bò8	"òm(ò`
ò`ò,5òBGð68Àuô 68ôr,rE   