+
    .pÐjëË ã                  óÈ  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
H
t
 ^ RIHt ^ RIHtHtHtHt ^ RIHt ^ RIHtHt ^ R	IHtHt ^ R
IHtHt ^ RIHtHtH t  ^ RI!H"t"H#t#H$t$H%t%H&t& ^ RI'H(t( ]PR                  ! R4      t*R R lt+Rt,R R lt-RR/R R llt.R R lt/0 R$mt0R%t10 R&mt2]3! 0 R'm4      t4RR(RR)RR*RR+/t5Rt6R R lt7R  R! lt8 ! R" R#](4      t9R# ),aL  Process/completion/update notifications, media delivery and async-delegation delivery for GatewayRunner.

Split out of ``gateway/run.py``; bound onto ``GatewayRunner`` via the MRO.
``gateway.run`` internals are imported lazily inside method bodies (import cycle),
so ``patch("gateway.run.X")`` keeps intercepting them at call time.
)ÚannotationsN)Úsuppress)Údatetime)ÚPath)ÚAnyÚDictÚOptionalÚcast©Út)ÚPlatformÚ_BUILTIN_PLATFORM_VALUES)ÚBasePlatformAdapterÚ_mark_notify_metadata)ÚMessageEventÚMessageType)ÚSessionEntryÚSessionSourceÚSessionStore)Ú_delivery_target_keyÚ_log_suppressedÚ_notice_target_keyÚ_send_errorÚ_send_failed)Ú!GatewayNotificationOwnershipMixinzgateway.runc               ó   € V ^8„  d   QhRR/# ©é   ÚreturnÚstr© )Úformats   "Ú(/opt/hermes/gateway/run_notifications.pyÚ__annotate__r#   "   s   € ÷ -ñ -˜sñ -ó    c                 ó   € \        R 4      # )zgateway.update.failed_noticer
   r    r$   r"   Ú_update_failed_noticer&   "   s   € ÜÐ+Ó,Ð,r$   ç      ¬@c               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚprofileúOptional[str]Úplatform_valuer   r   Útupler    )r!   s   "r"   r#   r#   ,   s'   € ÷ bñ b }ð bÀcð bÐbgñ br$   c                ó:   € \        V f   WV4      # V  RV 2W#4      # )a1  Notice-dedupe key for one SERVED profile's home channel.

A secondary uses the ``<profile>:<platform>`` key convention the runtime status already
stamps in ``gateway_state.json``; the launch profile keeps the bare platform value so a
marker written before this change still matches its delivered targets.
Ú:)r   )r)   r+   Úchat_idÚ	thread_ids   &&&&r"   Ú_served_notice_target_keyr1   ,   s:   € ô Ø!š/ˆÐW`óbð bØ29°¸!¸NÐ;KÐ/LÈgóbð br$   r)   c               ó   € V ^8„  d   QhRR/# )r   r)   r*   r    )r!   s   "r"   r#   r#   7   s   € ÷ ñ À]ñ r$   c          
     ó´   € ^ RI Hp  V! WV4      #   \         d<   p\        P	                  RT'       d   T R2MR\        T RT 4      T4        Rp?R# Rp?ii ; i)zç``resolve_delivery_transport`` isolated to one target: ``None`` (logged) on failure.

The fan-out spans every served profile, so one profile's broken adapter must not abort the
pass and starve every profile after it in dict order.
©Úresolve_delivery_transportz/Home-channel transport unavailable for %s%s: %sr.   Ú ÚvalueN)Úgateway.deliveryr5   Ú	ExceptionÚloggerÚdebugÚgetattr)ÚplatformÚconfigÚadaptersr)   r5   Úexcs   &&&$  r"   Ú_safe_delivery_transportrA   7   sY   € õ <ðÙ)¨(¸HÓEÐEøÜô Ü�‰Ø=ß$ˆwˆi�q‰M¨"¬g°hÀÈÓ.RÐTWô	Yõ ûð	ús   ˆ ‘Aœ0AÁAc               ó$   € V ^8„  d   QhRRRRRR/# )r   Úoutputr   ÚlimitÚintr   r    )r!   s   "r"   r#   r#   G   s&   € ÷ Gñ G ð G¨Cð G°Cñ Gr$   c                ó>   € \        V 4      V8:  d   V # RW) R ,           # )zJLast ``limit`` chars of an update log, prefixed with an ellipsis when cut.u   â€¦N)Úlen)rC   rD   s   &&r"   Ú_update_output_tailrH   G   s#   € ä˜“[ EÔ)ˆ6ÐF¨u°v¸f¸g°Õ/FÐFr$   ÚdropÚreleaseÚdeferÚcompleteu´   [INTERNAL NOTIFICATION â€” generated by the Hermes gateway, not written by a human user. Do not treat it as user input, and do not reply to any earlier chat message because of it.]c               ó    € V ^8„  d   QhRRRR/# )r   Útextr   r   r    )r!   s   "r"   r#   r#   c   s   € ÷ 8ñ 8 cð 8¨cñ 8r$   c                ó„   € V P                  4       p V P                  \        4      '       d   V # V R,           \        ,           # )uB  Append unambiguous machine provenance to model-facing notification text (#52694).

A process notification re-enters the conversation as a role=user turn on every wake path
(push ``handle_message`` and the api_server self-post alike); without this footer the model
has read it as something the human said â€” including "replying" to the message the watch
was armed from. Appended, not prepended, so start-anchored consumers (session timeline,
memory gating, desktop notification detection, the SYSTEM prefix) keep matching.
Idempotent so a retried delivery never stacks footers.
ú

)ÚrstripÚendswithÚINTERNAL_NOTIFICATION_FOOTER)rN   s   &r"   Ú_mark_internal_notificationrT   c   s4   € ð �;‰;‹=€DØ‡}�}Ô1×2Ò2ØˆØ�&�=Ô7Õ7Ð7r$   c               ó    € V ^8„  d   QhRRRR/# )r   ÚevtÚdictr   r   r    )r!   s   "r"   r#   r#   s   s   € ÷ Jñ J tð J°ñ Jr$   c                ó4  a € \        S P                  R4      ;'       g    R4      P                  4       p\        S P                  R4      ;'       g    R4      P                  4       P                  4       pVP	                  R4      '       g   VR	9  d   R# V'       gC   \
        ;QJ d    V 3R lR
 4       F  '       g   K   RM	  RM! V 3R lR
 4       4      '       d   R# \        S P                  R4      ;'       g    T;'       g    R4      P                  4       # )zKRecognize API routes, not malformed structured or partial messaging routes.Úsession_keyr6   r=   úagent:c              3  óF   <"  € T F  pSP                  V4      x € K  	  R # 5i©N)Úget©Ú.0ÚfieldrV   s   & €r"   Ú	<genexpr>Ú0_raw_process_event_session_id.<locals>.<genexpr>y   s   øé € Ð^Ñ8]¨u˜CŸG™G EŸN˜NÓ8]ùs   ƒ!TFÚorigin_session_id>   r6   Ú
api_server)r/   Ú	chat_typer0   )r   r]   ÚstripÚlowerÚ
startswithÚany)rV   rY   r=   s   f  r"   Ú_raw_process_event_session_idrj   s   sÆ   ø€ ä�c—g‘g˜mÓ,×2Ð2°Ó3×9Ñ9Ó;€KÜ�3—7‘7˜:Ó&×,Ð,¨"Ó-×3Ñ3Ó5×;Ñ;Ó=€HØ×Ñ˜h×'Ò'¨8Ð;MÔ+MÙßŸ›Ô^Ñ8]Ó^ŸŸšÔ^Ñ8]Ó^×^Ò^ÙÜˆs�w‰wÐ*Ó+×@Ð@¨{×@Ð@¸bÓA×GÑGÓIÐIr$   c                  óÐ  € ] tR t^~t$ RtR•t. R–O]R,          O5t]P                   ! R R4      4       t	]P                   ! R R4      4       t
]P                   ! R R4      4       tR	 R
 ltR—R R lltR˜R R lltR—R R lltR R lt]R R l4       t]R R l4       t]R R l4       tR R ltR R ltR R  lt]R! R" l4       t]R# R$ l4       tR% R& ltR' R( ltR) R* ltR™R+ R, lltR- R. ltR/ R0 lt R1 t!R2 t"R3 t#R4 R5 lt$Rt%R6]&R7&   R8 R9 lt'R:R/R; 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.R—RI RJ llt/RKR/RL RM llt0]RN RO l4       t1RP RQ lt2RRR/RS RT llt3RšRU RV llt4RšRW RX llt5]RY RZ l4       t6R[ R\ lt7R] R^ lt8R_ R` lt9]:Pv                  Ra Rb l4       t<RcR›/Rd Re llt=RcR›/Rf Rg llt>]Rh Ri l4       t?]Rj Rk l4       t@Rl Rm ltARn Ro ltB]Rp Rq l4       tCRr Rs ltDRt Ru ltERv Rw ltFRx Ry ltGRz R{ ltHR| R} ltIR~ R ltJR€ R� ltKRœR‚ Rƒ lltL]R„ R… l4       tMR† R‡ ltNRˆ R‰ ltO]RŠ R‹ l4       tPRŒ R� ltQRŽ R� ltRR� R‘ ltSR’ R“ ltTR”tUR# )�ÚGatewayNotificationsMixinzhProcess/completion/update notifications, media delivery and async-delegation delivery for GatewayRunner.ºé   NNc                  óp   € ] tR t^…t$ RtR]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R	 R
 ltR R ltRtR# )Ú&GatewayNotificationsMixin._UpdatePathszTMarker files ``hermes update --gateway`` and its watcher exchange under HERMES_HOME.r   ÚpendingÚclaimedrC   Ú	exit_codeÚpromptÚresponsec               ó   € V ^8„  d   QhRR/# ©r   r   Úboolr    )r!   s   "r"   r#   Ú3GatewayNotificationsMixin._UpdatePaths.__annotate__�   s   € ÷ 	Bñ 	B ñ 	Br$   c                	óz   € V P                   P                  4       ;'       g    V P                  P                  4       # r\   )rq   Úexistsrr   )Úselfs   &r"   Úany_pendingÚ2GatewayNotificationsMixin._UpdatePaths.any_pending�   s*   € Ø—<‘<×&Ñ&Ó(×AÐA¨D¯L©L×,?Ñ,?Ó,AÐAr$   c               ó   € V ^8„  d   QhRR/# ©r   r   ÚNoner    )r!   s   "r"   r#   ry   “   s   € ÷ 	*ñ 	* ñ 	*r$   c                	óÀ   € V P                   V P                  V P                  V P                  V P                  V P
                  3 F  pVP                  R R7       K  	  R# )T©Ú
missing_okN)rq   rr   rC   rs   rt   ru   Úunlink)r|   Úps   & r"   Ú
unlink_allÚ1GatewayNotificationsMixin._UpdatePaths.unlink_all“   sC   € Ø—l‘l D§L¡L°$·+±+¸t¿~¹~ÈtÏ{É{Ð\`×\iÑ\iÓj�Ø—‘ D�Ö)ó kr$   r    N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r}   r‡   Ú__static_attributes__r    r$   r"   Ú_UpdatePathsrp   …   s3   ‡ ábà‹Ø‹Ø‹Ø‹Ø‹Ø‹õ	B÷	*ñ 	*r$   r�   c                  ó`   € ] tR t^—t$ RtR]R&   R]R&   R]R&   R]R&   R]R&   R	 tR
 R ltRtR# )Ú'GatewayNotificationsMixin._UpdateTargetz5Resolved delivery target for update watcher messages.r   Úadapterr/   r*   rY   Úmetadatar=   c                	óJ   € ^ RI Hp V! V P                  V P                  R7      # )é    ©Ú_non_conversational_metadata©r=   )Úgateway.runr˜   r”   r=   )r|   r˜   s   & r"   Úsend_metadataÚ5GatewayNotificationsMixin._UpdateTarget.send_metadata¡   s   € Ý@Ù/°·±ÈÏÉÔVÐVr$   c               ó   € V ^8„  d   QhRR/# )r   rN   r   r    )r!   s   "r"   r#   Ú4GatewayNotificationsMixin._UpdateTarget.__annotate__¥   s   € ÷ 	^ñ 	^ 3ñ 	^r$   c              ƒ  	óˆ   "  € V P                   P                  V P                  WP                  4       R 7      G Rj  x€L
 #  L5i)©r”   N)r“   Úsendr/   r›   )r|   rN   s   &&r"   r¡   Ú,GatewayNotificationsMixin._UpdateTarget.send¥   s2   é € ØŸ™×*Ñ*¨4¯<©<¸×HZÑHZÓH\Ð*Ó]×]Ð]Ñ]ùs   ‚9A»A ¼Ar    N)	r‰   rŠ   r‹   rŒ   r�   rŽ   r›   r¡   r�   r    r$   r"   Ú_UpdateTargetr’   —   s1   ‡ áCà‹Ø‹Ø"Ó"Ø‹Ø‹ò	W÷	^ñ 	^r$   r£   c                  ó~   € ] tR t^¨t$ Rt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	# )Ú*GatewayNotificationsMixin._CompletionClaimz/Pre-flight outcome for one completion delivery.r6   r   Údelegation_idÚclaim_idTrx   ÚproceedNúOptional[bool]Úearly_resultÚowner_session_idÚproven_session_idFrK   r    )r‰   rŠ   r‹   rŒ   r�   r¦   rŽ   r§   r¨   rª   r«   r¬   rK   r�   r    r$   r"   Ú_CompletionClaimr¥   ¨   sM   ‡ á=àˆ�sÓØˆ�#ÓØˆ�ÓØ'+ˆ�nÓ+Ø "Ð˜#Ó"Ø!#Ð˜3Ó#Øˆˆt×r$   r­   c               ó    € V ^8„  d   QhRRRR/# )r   Úcontentr   r   r�   r    )r!   s   "r"   r#   Ú&GatewayNotificationsMixin.__annotate__´   s   € ÷  Gñ  G¸cð  GÀdñ  Gr$   c           	   ƒ  ó   "  € ^ RI Hp V P                  V4      pV'       g   R# \        V RR4      p\        VRR4      pV'       dH   \        VRR4      \        P
                  8X  d(   V! WVV4      '       d   \        P                  RV4       R# \        VRR4      p\        VRR4      p\        V\        4      '       d*   RV9   d#   ^ R	I
Hp	 V	! VP                  R4      R
R0R
4      p
M7V'       d.   \        VR4      '       d   VP                  VP                  4      MR
p
V P!                  V4      pV
R8X  dœ   \        VRR4      '       d‰   \#        \$        P&                  R\        VRR4      RR7      ;_uu_ 4        VP)                  VP*                  VP,                  W+R7      G Rj  x€L
 p\        VRR4      '       d    RRR4       R#  RRR4       VP/                  VP*                  W+R7      G Rj  x€L
  R#  LR  + '       g   i     L9; i L5i)zIDeliver a setup/operational notice using platform-specific privacy rules.)Ú_is_slack_ignored_channelNr>   r/   r=   z@Skipping Slack platform notice for configured ignored channel %sÚextraÚnotice_delivery)Ú_normalize_choiceÚpublicÚprivateÚget_notice_deliveryÚuser_idz7[%s] send_private_notice failed, falling back to publicÚ?T©Úexc_infor    ÚsuccessF)rš   r²   Ú_delivery_adapter_forr<   r   ÚSLACKr:   ÚinfoÚ
isinstancerW   Úgateway.configrµ   r]   Úhasattrr¸   r=   Ú_thread_metadata_for_sourcer   ÚloggingÚDEBUGÚsend_private_noticer/   r¹   r¡   )r|   Úsourcer¯   r²   r“   r>   r/   Úadapter_configÚadapter_extrarµ   r´   r”   Úresults   &&&          r"   Ú_deliver_platform_noticeÚ2GatewayNotificationsMixin._deliver_platform_notice´   sÐ  é € å9Ø×,Ñ,¨VÓ4ˆßÙÜ˜˜x¨Ó.ˆÜ˜& )¨TÓ2ˆß”g˜f j°$Ó7¼8¿>¹>ÔIÑNgÐhnð  zA÷  OBò  OBÜ�K‰KÐZÐ\cÔdÙô ! ¨(°DÓ9ˆÜ °¸Ó>ˆÜ�m¤T×*Ò*Ð/@ÀMÔ/QÝ8Ù/°×0AÑ0AÐBSÓ0TÐW_ÐajÐVkÐmuÓv‰O÷ @FÌ'ÐRXÐZo×JpÒJp�×*Ñ*¨6¯?©?Ô;Øð ð ×3Ñ3°FÓ;ˆØ˜iÔ'¬G°F¸IÀt×,LÒ,LÜ Ü—‘ÐXÜ˜ 
¨CÓ0¸4÷ö ð  '×:Ñ:¸6¿>¹>È6Ï>É>Ð[bÐ:Óv×v�Ü˜6 9¨e×4Ò4Ø÷ñ ð
 5÷ð �l‰l˜6Ÿ>™>¨7ˆlÓF×FÒFñ w÷	÷ úñ 	GùsI   ‚C+HÃ.B
HÅ8,G9Æ$G7Æ%G9Æ=
HÇ(HÇ0HÇ1HÇ7G9Ç9H		È	HNc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   ru   r   Úeventr   Úthread_metadataúOptional[dict[str, Any]]r   r�   r    )r!   s   "r"   r#   r°   Ö   s2   € ÷ ;bñ ;bØð;bØ$0ð;bØLdð;bà	ñ;br$   c           
   ƒ  óx  a"  € ^ RI Hp \        \        P                  R4      ;_uu_ 4        RV9   o^ RIHpHp VP                  V4      w  r‰VP                  ! V4      pVP                  V	4       Ve   \        V4      M*V P                  VP                  V P                  V4      4      p
VP                  P                  pR V3R llpV UUu. uF  w  rÞV! WÞ4      '       g   K  VNK  	  pppV UUu. uF  w  rÞV! WÞ4      '       d   K  WÞ3NK  	  pppV'       d:    V Uu. uF  pRV! V4       2R	3NK  	  ppVP!                  VVV
R
7      G Rj  x€L
  V F³  w  pp \+        V4      P,                  P/                  4       pV! VP                  P0                  VVR7      '       d    VP3                  VVV
VR7      G Rj  x€L
  Kn  V\4        9   d   VP7                  VVV
R7      G Rj  x€L
  K—  VP9                  VVV
R7      G Rj  x€L
  Kµ  	  RRR4       R# u uppi u uppi u upi  LØ  \"         d-   p\$        P'                  RTP(                  T4        Rp?ELRp?ii ; i L¦ L Lc  \"         d.   p\$        P'                  RTP(                  T4        Rp?EKG  Rp?ii ; i  + '       g   i     R# ; i5i)u-  Deliver explicit MEDIA: tags from an already-streamed response (text already delivered).
EXPLICIT-ONLY, unlike the non-streaming path in ``gateway/platforms/base.py``: a bare local
path in a streamed reply is shown text or stale inspected content, and promoting it sent
files the model never asked for. MEDIA tags are NOT deduped against prior turns (a final-reply
directive is a deliberate attach); stale auto-appended tags are deduped upstream.

Only ``MEDIA:`` directives â€” the explicit attachment contract â€” trigger post-stream uploads. See
#20834.
)Úquotez'Post-stream media extraction failed: %sz[[as_document]])r   Úshould_send_media_as_audioNc               ó$   € V ^8„  d   QhRRRRRR/# )r   Ú
media_pathr   Úis_voicerx   r   r    )r!   s   "r"   r#   ÚLGatewayNotificationsMixin._deliver_media_from_response.<locals>.__annotate__ù   s&   € ÷ ^ñ ^ cð ^°Tð ^¸dñ ^r$   c                ó˜   <€ \        V 4      P                  P                  4       pV\        9   ;'       d    V'       * ;'       d    S'       * # r\   )r   Úsuffixrg   Ú_IMAGE_EXTS)rÖ   r×   ÚextÚforce_document_attachmentss   && €r"   Ú	_is_photoÚIGatewayNotificationsMixin._deliver_media_from_response.<locals>._is_photoù   s=   ø€ Ü˜:Ó&×-Ñ-×3Ñ3Ó5�ØœkÑ)×]Ð]°(¬l×]Ð]ÐC]Ô?]Ð]r$   zfile://r6   )r/   Úimagesr”   z0[%s] Post-stream image batch delivery failed: %s)r×   )r/   Ú
audio_pathr”   r×   )r/   Ú
video_pathr”   )r/   Ú	file_pathr”   z*[%s] Post-stream media delivery failed: %s)Úurllib.parserÓ   r   rÅ   ÚWARNINGÚgateway.platforms.baser   rÔ   Úextract_mediaÚfilter_media_delivery_pathsÚextract_imagesrW   rÄ   rÈ   Ú_reply_anchor_for_eventr/   Úsend_multiple_imagesr9   r:   ÚwarningÚnamer   rÚ   rg   r=   Ú
send_voiceÚ_VIDEO_EXTSÚ
send_videoÚsend_document)r|   ru   rÏ   r“   rÐ   Ú_quoter   rÔ   Úmedia_filesÚcleanedÚ_thread_metar/   rÞ   r†   ÚvÚimage_pathsÚnon_image_mediarà   ÚerÖ   r×   rÜ   rÝ   s   &&&&&                 @r"   Ú_deliver_media_from_responseÚ6GatewayNotificationsMixin._deliver_media_from_responseÖ   s�  øé € õ 	1ÜœWŸ_™_Ð.W×XÕXà):¸hÑ)FÐ&ß^Ø#*×#8Ñ#8¸Ó#BÑ ˆKØ-×IÒIÈ+ÓVˆKð ×"Ñ" 7Ô+ð #Ò.ô �_Ô%à×5Ñ5°e·l±lÀD×D`ÑD`ÐafÓDgÓhð ð
 —l‘l×*Ñ*ˆG÷^ð ^ñ *5ÔH©¡ ¹	À!¿Ÿ1˜1©ˆKÑHÙ2=ÔU±+©$¨!ÁYÈqÇ_œv ›v±+ˆOÑUßðhÙCNÓOÁ;¸a ©°«¨Ð4°bÓ9Á;�FÐOØ!×6Ñ6¸wÈvÐ`lÐ6Óm×mÐmó )8Ñ$�
˜HðbÜ˜zÓ*×1Ñ1×7Ñ7Ó9�CÙ1°%·,±,×2GÑ2GÈÐW_×`Ó`Ø%×0Ñ0Ø$+¸
È\Ðdlð 1ó ÷ ò ð ¤Ô+Ø%×0Ñ0¸ÈZÐbnÐ0Óo×oÒoà%×3Ñ3¸GÈzÐdpÐ3Óq×qÒqñ )8÷E YÑXùó4 IùÛUùò PÙmøÜ ô hÜ—N‘NÐ#UÐW^×WcÑWcÐef×gÒgûðhúññ páqøÜ ô bÜ—N‘NÐ#OÐQX×Q]ÑQ]Ð_`×aÓaûðbú÷[ Y×XÐXüs  ƒ)J:¬B"J&ÃH
Ã%H
Ã+J&Ã3H
Ä
H
ÄJ&ÄH+Ä!H$Ä7H+ÅH)ÅH+ÅJ&ÅA I+Æ>I%
Æ?I+ÇJ&Ç"I+Ç'I'
Ç(I+Ç,J&Ç.I+ÈI)
ÈI+È
J&È
J:ÈJ&È$H+È+I"È6!IÉJ&ÉI"É"J&É%I+É'I+É)I+É+J#	É6!J	ÊJ&ÊJ#	Ê#J&Ê&J7	Ê1	J:Fc               ó<   € V ^8„  d   QhRRRRRRRRR	R
RR
RRRRRR
/	# )r   ru   r   rÈ   r   r”   rÑ   Úevent_message_idr*   Útext_already_deliveredrx   Údeliver_mediarY   Úinbound_message_idr   r    )r!   s   "r"   r#   r°     sl   € ÷ Iñ IØðIØ%2ðIà*ðIàERðIð !%ðIð >BðIð #ð	Ið @Mð	Ið
 
ñIr$   c           	   ƒ  óè  "  € ^ RI Hp V'       gú   V! W4      pV'       dê   Rp\        VRR4      pV'       dš   VR8w  d“   \        VRR4      '       g€    VP                  VP                  WìRR7      G Rj  x€L
 p\        VR	R4      '       d   Rp\
        P                  R
V4       M,^ RIHp V! V4      '       d   \
        P                  R4       R#  V'       g2   V P                  W2WÄWYV
4      G Rj  x€L
 p\        VR	R4      '       g   R# V'       g   R# V P                  V\        RW%R7      VVR7      G Rj  x€L
  R#  LÉ  \         d!   p\
        P                  RT4        Rp?L•Rp?ii ; i L} L85i)u  Deliver a queued response using the normal text+attachment split.

``session_key`` lets the text send record a delivery-ledger obligation like the normal final
send does, keyed on ``inbound_message_id`` (the raw inbound id, distinct from the
``event_message_id`` reply anchor); see ``_send_queued_final_text``. Without a key the send
stays unledgered.

Returns whether the caller may treat this turn's final as delivered. True: the stream had
already delivered it, the reconcile edit landed, the send succeeded, or there was nothing
textual to send. False: the send was REFUSED (flood control, dead transport) â€” the caller
must leave the normal completion send as the fallback, or the user gets nothing. A connector
DECLINE returns True: that destination is not approved and must not be re-sent.)Ú+_strip_response_attachments_for_direct_sendFÚ
message_idNÚ__no_edit__Ú_turn_split_deliveryT)r/   r  r¯   Úfinalizer½   zPQueued-lane final reconciled by editing message %s in place (no duplicate send).)Údeclined_sendz‚Queued-lane reconcile edit DECLINED by the connector's egress guard; not falling back to a send (the destination is not approved).z=Queued-lane reconcile edit failed (%s); falling back to send.r6   )rN   rÈ   r  )rÐ   )rš   r  r<   Úedit_messager/   r:   rÀ   Úgateway.relay.egressr  rì   r9   r;   Ú_send_queued_final_textrú   r   )r|   ru   rÈ   r“   r”   rý   rþ   rÿ   Ústream_consumerrY   r   r  Útext_contentÚ_reconciledÚ
_sc_msg_idÚ	_edit_resr  Ú_qeÚ_sents   &&&&&&&&&&&        r"   Ú_deliver_queued_first_responseÚ8GatewayNotificationsMixin._deliver_queued_first_response  sz  é € õ$ 	Lß%ÙFÀxÓYˆLßð $�Ü$ _°lÀDÓI�
çØ" mÔ3Ü# OÐ5KÈU×SÒSðkØ*1×*>Ñ*>Ø$*§N¡N¸zÐjnð +?ó +÷ %˜	ô # 9¨i¸×?Ò?Ø*.˜KÜ"ŸK™KØ rØ *õõ Ká,¨Y×7Ò7Ü &§¡ð%Sô!"ñ
 (,ð  8÷ #Ø"&×">Ñ">Ø¨ÐAQØ*ó#,÷ ,�Eô # 5¨)°U×;Ò;ñ  %÷ ÙØ×/Ñ/Ø”l¨°6ÔWÐY`Ø$ð 0ó 
÷ 	
ð 	
ñ ñS%øô, %ô kÜŸ™Ð%dÐfi×jÑjûðkúñ,ñ	
ùs~   ‚AE2Á!E  Á4D>Á5/E  Â$E2Â%E  Â9E  Ã
E2ÃE2Ã0E.Ã1 E2Ä%E2Ä7E0Ä8E2Ä>E  Å E+ÅE&Å!E2Å&E+Å+E2Å0E2c               ó0   € 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*   rY   r   r    )r!   s   "r"   r#   r°   _  s>   € ÷ ñ Ø,ðØ<?ðØKcðà'ðà6Cðð *ñr$   c           	   ƒ  ó˜  "  € V'       dK   \        V\        4      '       d5   VP                  \        RW'R7      Wc\	        V4      VR7      G Rj  x€L
 w  r‰M%VP                  VP                  W4R7      G Rj  x€L
 p\        VRR4      '       g8   \        P                  R\        VR	R
4      \        VRR4      ;'       g    R4       V#  Lx LR5i)a¦  Send a queued-lane final through the same ledger bracket as the normal final
(``send_final_ledgered``). This lane used to call ``adapter.send`` bare and discard the
result, so a final refused here (flood control, a transport that had just died) left no
ledger row and was gone for good. The ledger identity is the raw inbound message id;
``event_message_id`` is only the reply anchor, which is None wherever replies are not used
(Telegram forum topics, Slack reaction handoffs) and so cannot identify the turn; with no
inbound id the ledger falls back to the event's own (empty) message id. Adapters without
the base contract and sends without a session key keep the plain send.r6   )rN   rÈ   Úledger_message_id)Úreply_toNr    r½   Fz'Queued-lane final send to %s failed: %sr/   rº   Úerrorz	no result)
rÁ   r   Úsend_final_ledgeredr   r   r¡   r/   r<   r:   rì   )
r|   r“   rÈ   r  r”   rý   rY   r   rË   Ú_s
   &&&&&&&&  r"   r
  Ú1GatewayNotificationsMixin._send_queued_final_text_  s»   é € ÷ œ: gÔ/B×CÒCØ%×9Ñ9Ü "¨VÔZØÔ+@ÀÓ+JÐUeð :ó g÷ g‰IˆF�Að #Ÿ<™<¨¯©¸˜<ÓX×XˆFÜ�v˜y¨%×0Ò0Ü�N‰NØ9¼7À6È9ÐVYÓ;ZÜ˜ ¨Ó.×=Ð=°+ô?ð ˆñgñ Yùs+   ‚AC
ÁCÁ'C
Á5CÁ6AC
Â=
C
ÃC
c               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r°   x  s   € ÷ Xñ X°Tñ Xr$   c                ó  € \        V RR4      pV'       d   VP                  4       '       g   R#  \        P                  ! V P	                  4       4      V n        R#   \         d    \        P                  R4        R# i ; i)z;Ensure a background task is watching for update completion.Ú_update_notification_taskNz;Skipping update notification watcher: no running event loop)	r<   ÚdoneÚasyncioÚcreate_taskÚ_watch_update_progressr  ÚRuntimeErrorr:   r;   )r|   Úexisting_tasks   & r"   Ú#_schedule_update_notification_watchÚ=GatewayNotificationsMixin._schedule_update_notification_watchx  se   € ä Ð&AÀ4ÓHˆß ×!3Ñ!3×!5Ò!5Ùð	XÜ-4×-@Ò-@À×A\ÑA\ÓA^Ó-_ˆDÖ*øÜô 	XÜ�L‰LÐV×Wð	Xús   ¯)A Á A>Á=A>c               ó   € V ^8„  d   QhRR/# )r   r   rp   r    )r!   s   "r"   r#   r°   ƒ  s   € ÷ 
ñ 
ÐDñ 
r$   c           	     	ó�   € ^ RI Hp V P                  VR,          VR,          VR,          VR,          VR,          VR,          R7      # )	r–   )Ú_hermes_homez.update_pending.jsonz.update_pending.claimed.jsonz.update_output.txtz.update_exit_codez.update_prompt.jsonz.update_response)rq   rr   rC   rs   rt   ru   )rš   r)  r�   )Úclsr)  s   & r"   Ú_update_pathsÚ'GatewayNotificationsMixin._update_paths‚  sQ   € å,Ø×ÑØ Ð#9Õ9Ø Ð#AÕAÈ,ÐYmÕJmØ"Ð%8Õ8ØÐ"7Õ7À,ÐQcÕBcð	  ó 
ð 	
r$   c               ó    € V ^8„  d   QhRRRR/# )r   ÚdatarW   r   r*   r    )r!   s   "r"   r#   r°   �  s   € ÷ ñ ˜dð  }ñ r$   c                óf  € \        V P                  R4      ;'       g    R4      P                  4       pV'       d   V# ^ RIHp \        V P                  R4      ;'       g    R4      P                  R4      p\        V4      ^8¼  d,   V^ ,          R8X  d   V^,          R9  d   V! V^,          4      # R# )	zÔOwning profile of a persisted restart/update marker: explicit ``profile``, else the
``agent:<profile>:`` lane of its ``session_key`` (markers written before ``profile`` was
persisted); ``None`` = default profile.r)   r6   )Ú"profile_from_session_key_namespacerY   r.   ÚagentN)Úmainr6   )r   r]   rf   Úgateway.sessionr0  ÚsplitrG   )r.  r)   r0  Úpartss   &   r"   Ú_marker_profileÚ)GatewayNotificationsMixin._marker_profileŒ  sŒ   € ô
 �d—h‘h˜yÓ)×/Ð/¨RÓ0×6Ñ6Ó8ˆßØˆNÝFÜ�D—H‘H˜]Ó+×1Ð1¨rÓ2×8Ñ8¸Ó=ˆÜˆu‹:˜Œ?˜u Q�x¨7Ô2°u¸QµxÀ|Ô7SÙ5°e¸AµhÓ?Ð?Ùr$   c               ó    € V ^8„  d   QhRRRR/# )r   r.  rW   r   zOptional[float]r    )r!   s   "r"   r#   r°   ›  s   € ÷ /ñ / $ð /¨?ñ /r$   c                ó†  € \        V P                  R4      ;'       g    R4      P                  4       pV'       g   R#  \        P                  ! V4      pTP                  '       d!   \        P                  ! TP                  4      M\        P                  ! 4       pY2,
          P                  4       #   \
         d     R# i ; i)uþ   Age of a persisted update marker, from the ``timestamp`` stamped by its writer.

``None`` when the marker carries no parseable stamp â€” the field is absent on markers
written before it existed, and callers keep the old retry behavior rather than guess.
Ú	timestampr6   N)	r   r]   rf   r   ÚfromisoformatÚ
ValueErrorÚtzinfoÚnowÚtotal_seconds)r.  ÚrawÚstampedr>  s   &   r"   Ú_marker_age_secondsÚ-GatewayNotificationsMixin._marker_age_secondsš  sŒ   € ô �$—(‘(˜;Ó'×-Ð-¨2Ó.×4Ñ4Ó6ˆßÙð	Ü×,Ò,¨SÓ1ˆGð /6¯n¯n¨nŒh�lŠl˜7Ÿ>™>Ô*Ä(Ç,Â,Ã.ˆØ•×,Ñ,Ó.Ð.øô	 ô 	Úð	ús   ¾B1 Â1C Â?C c               ó    € V ^8„  d   QhRRRR/# )r   Úpathsr�   r   zOptional[_UpdateTarget]r    )r!   s   "r"   r#   r°   ¬  s   € ÷ ñ ¨Lð Ð=Tñ r$   c           
     ó²  € VP                   VP                  3 EF$  pVP                  4       '       g   K  \        \        4      ;_uu_ 4        \
        P                  ! VP                  RR7      4      pVP                  R4      pVP                  R4      pVP                  R4      pV'       d	   V'       g    RRR4       K¨  \        V4      pV P                  WpP                  V4      4      pV'       g    RRR4        R# V P                  WuW84      p	T P                  Y…T;'       g    V RV 2W—4      uuRRR4       u # 	  R#   + '       g   i     EK=  ; i)zQResolve adapter/chat/session for update watcher messages from the pending marker.ú	utf-8-sig©Úencodingr=   r/   rY   Nr.   )rr   rq   r{   r   r9   ÚjsonÚloadsÚ	read_textr]   r   Ú_authorization_adapterr6  Ú_pending_marker_metadatar£   )
r|   rE  Úpathrq   Úplatform_strr/   rY   r=   r“   r”   s
   &&        r"   Ú_resolve_update_targetÚ0GatewayNotificationsMixin._resolve_update_target¬  s  € à—]‘] E§M¡MÔ2ˆDØ—;‘;—=’=ÙÜœ)×$Õ$ÜŸ*š* T§^¡^¸[ ^Ó%IÓJ�Ø&Ÿ{™{¨:Ó6�Ø!Ÿ+™+ iÓ0�Ø%Ÿk™k¨-Ó8�ß$¯Ø÷ %Ñ$ô $ LÓ1�ð ×5Ñ5°h×@TÑ@TÐU\Ó@]Ó^�ßØ÷ %Ò$ð  ×8Ñ8¸ÈGÓ]�à×)Ñ)Ø k×&PÐ&P¸°~ÀQÀwÀiÐ5PÐRZó÷ %Ô$ñ 3ñ* ÷% %×$Ñ$ús   ÁA)EÂ6EÃ4EÄ 3EÅEc               ó   € V ^8„  d   QhRR/# )r   r.  rW   r    )r!   s   "r"   r#   r°   Å  s   € ÷ 
ñ 
Àñ 
r$   c           	     óˆ   € V P                  WVP                  R4      VP                  R4      VP                  R4      VR7      # )z\Thread metadata for a persisted update/restart marker (thread_id/chat_type/message_id keys).r0   re   r  )re   Úreply_to_message_idr“   )Ú_thread_metadata_for_targetr]   )r|   r=   r/   r.  r“   s   &&&&&r"   rN  Ú2GatewayNotificationsMixin._pending_marker_metadataÅ  sA   € à×/Ñ/Ø˜tŸx™x¨Ó4ÀÇÁÈÓ@UØ $§¡¨Ó 6Àð 0ó 
ð 	
r$   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rE  r�   ÚdeadlineÚfloatÚpoll_intervalr   r�   r    )r!   s   "r"   r#   r°   Ì  s+   € ÷ 3ñ 3¸ð 3ÐQVð 3Ðglð 3Ðquñ 3r$   c              ƒ  ób  "  € \         P                  R4       \        P                  ! 4       pVP	                  4       '       dv   VP                  4       V8  da   VP                  P                  4       '       d!   V P                  4       G Rj  x€L
 '       d   R# \        P                  ! V4      G Rj  x€L
  K‹  VP	                  4       '       dZ   VP                  P                  4       '       g8   VP                  P                  RRR7       V P                  4       G Rj  x€L
  R# R# R#  L� Ly L5i)zSFallback when no adapter/chat can be resolved: wait for the exit code, then notify.zOUpdate watcher: cannot resolve adapter/chat_id, falling back to completion-onlyNÚ124úutf-8rH  )r:   rì   r   Úget_running_loopr}   Útimers   r{   Ú_send_update_notificationÚsleepÚ
write_text)r|   rE  rY  r[  Úloops   &&&& r"   Ú_watch_update_completion_onlyÚ7GatewayNotificationsMixin._watch_update_completion_onlyÌ  sÖ   é € ä�‰ÐhÔiä×'Ò'Ó)ˆØ×Ñ×!Ò! d§i¡i£k°HÔ&<Ø�‰×%Ñ%×'Ò'°$×2PÑ2PÓ2R×,RÖ,RÙÜ—-’- Ó.×.Ò.Ø×Ñ×Ò u§¡×'=Ñ'=×'?Ò'?Ø�O‰O×&Ñ& u°wÐ&Ô?Ø×0Ñ0Ó2×2Ò2ñ (@Ññ -Sá.ñ 3ùsT   ‚A D/Á4D/Á8D/ÂD)Â	D/ÂD/Â1D+Â2D/ÃD/Ã.0D/ÄD-ÄD/Ä+D/Ä-D/c               ó    € V ^8„  d   QhRRRR/# )r   rE  r�   r   rE   r    )r!   s   "r"   r#   r°   Ú  s   € ÷ Sñ S ð S°#ñ Sr$   c                	ó|   € \        V P                  P                  R R7      P                  4       ;'       g    R4      # )rG  rH  Ú1)rE   rs   rL  rf   )rE  s   &r"   Ú_update_exit_codeÚ+GatewayNotificationsMixin._update_exit_codeÙ  s0   € ä�5—?‘?×,Ñ,°kÐ,ÓB×HÑHÓJ×QÐQÈcÓRÐRr$   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rO  r   ÚoffsetrE   r   ztuple[str, int]r    )r!   s   "r"   r#   r°   Þ  s&   € ÷ Jñ J¨ð J°cð J¸oñ Jr$   c                óÈ   €  V P                  4       p\        T4      T8:  d   R\        T4      3# Y!R P                  RRR7      \        T4      3#   \         d    RT3u # i ; i)z?Read update output defensively; logs may contain invalid UTF-8.r6   Nr^  Úreplace©Úerrors)Ú
read_bytesÚOSErrorrG   Údecode)rO  rm  r.  s   && r"   Ú_read_update_output_sinceÚ3GatewayNotificationsMixin._read_update_output_sinceÝ  sm   € ð	Ø—?‘?Ó$ˆDô ˆt‹9˜ÔØ”s˜4“y�=Ð Ø�Gˆ}×#Ñ# G°IÐ#Ó>ÄÀDÃ	ÐIÐIøô	 ô 	Ø�v�:Òð	ús   ‚A ÁA!Á A!c               ó$   € V ^8„  d   QhRRRRRR/# )r   Útargetr£   rN   r   r   r�   r    )r!   s   "r"   r#   r°   è  s&   € ÷ 	Iñ 	I°ð 	IÀSð 	IÈTñ 	Ir$   c           
   ƒ  ód  "  € ^ RI Hp V! V4      P                  4       pV'       g   R# Rp\        ^ \	        V4      V4       FS  p\        \        P                  R4      ;_uu_ 4        VP                  RWFWe,             R24      G Rj  x€L
  RRR4       KU  	  R#  L  + '       g   i     Kl  ; i5i)zVSend buffered update output as fenced chunks that fit message limits (Telegram: 4096).©Ú
strip_ansiNé¬  zUpdate stream send failed: %sz```
ú
```)	Útools.ansi_stripr{  rf   ÚrangerG   r   rÅ   rÆ   r¡   )r|   rx  rN   r{  ÚcleanÚ	max_chunkÚis   &&&    r"   Ú_send_update_outputÚ-GatewayNotificationsMixin._send_update_outputè  sŠ   é € å/Ù˜4Ó ×&Ñ&Ó(ˆßÙØˆ	Ü�qœ#˜e›* iÖ0ˆAÜ ¤§¡Ð0O×PÕPØ—k‘k E¨%°!µ-Ð*@Ð)AÀÐ"GÓH×HÐH÷ QÑPó 1áH÷ Q×PÐPüs0   ‚A$B0Á&!BÂB
ÂBÂB0ÂBÂB-Â'	B0c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rx  r£   Úprompt_textr   Údefaultr   r�   r    )r!   s   "r"   r#   r°   ó  s0   € ÷ _ñ _°=ð _Èsð _Ð]`ð _Ðeiñ _r$   c           
   ƒ  ó¦  "  € RpVP                   p\        \        V4      RR4      em   \        \        P
                  R4      ;_uu_ 4        VP                  VP                  W#VP                  VP                  4       R7      G Rj  x€L
  RpRRR4       V'       gJ   V'       d   \        RVR7      MR	p\        VR
R4      pVP                  \        RW&VR7      4      G Rj  x€L
  RV P                  VP                  4      P                  n        \        P!                  RVP                  VR,          4       R#  L³  + '       g   i     L·; i Lm5i)zWForward an update prompt: platform-native buttons first (Discord, Telegram), else text.FÚsend_update_promptNz%Button-based update prompt failed: %s)r/   rt   r‡  rY   r”   Tzgateway.update.prompt_default)r‡  r6   Útyped_command_prefixÚ/zgateway.update.prompt)rt   Údefault_hintÚprefixz!Forwarded update prompt to %s: %s:NéP   N)r“   r<   Útyper   rÅ   rÆ   r‰  r/   rY   r›   r   r¡   Ú_session_stateÚ
persistentÚupdate_prompt_pendingr:   rÀ   )r|   rx  r†  r‡  Úsent_buttonsr“   rŒ  Ú_ps   &&&&    r"   Ú_forward_update_promptÚ0GatewayNotificationsMixin._forward_update_promptó  s  é € àˆØ—.‘.ˆÜ”4˜“=Ð"6¸Ó=ÒIÜ ¤§¡Ð0W×XÕXØ×0Ñ0Ø"ŸN™N°;Ø &× 2Ñ 2¸V×=QÑ=QÓ=Sð 1ó ÷ ð ð  $�÷ Y÷ ßRYœ1Ð<ÀgÕNÐ_aˆLÜ˜Ð"8¸#Ó>ˆBØ—+‘+œaÐ 7ÀÐoqÔrÓs×sÐsàSWˆ×Ñ˜F×.Ñ.Ó/×:Ñ:ÔPÜ�‰Ð7¸×9KÑ9KÈ[ÐY\ÕM]Ö^ñ÷ Y×Xúñ tùsI   ‚A	EÁ;D<ÂD:ÂD<ÂEÂEÂ%<EÃ!EÃ"AEÄ:D<Ä<E	Å	Ec               ó$   € V ^8„  d   QhRRRRRR/# )r   rE  r�   rY   r*   r   r�   r    )r!   s   "r"   r#   r°     s"   € ÷ ;ñ ;¨<ð ;Àmð ;ÐX\ñ ;r$   c                	óv   € VP                  4        V P                  V4      pVe   RVP                  n        R # R # )NF)r‡   Ú_peek_session_stater‘  r’  )r|   rE  rY   Ústates   &&& r"   Ú_clear_update_markersÚ/GatewayNotificationsMixin._clear_update_markers  s7   € Ø×ÑÔØ×(Ñ(¨Ó5ˆØÒØ5:ˆE×ÑÖ2ñ r$   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r[  rZ  Ústream_intervalÚtimeoutr   r�   r    )r!   s   "r"   r#   r°     s2   € ÷ E;ñ E;Ø"ðE;Ø;@ðE;ØQVðE;à	ñE;r$   c              ƒ  ó<  a aaaaaa"  € S P                  4       o\        P                  ! 4       oSP                  4       V,           pS P	                  S4      oSf   S P                  SWA4      G Rj  x€L
  R# SP                  p^ oSP                  4       oRoR VVVV V3R llpR VVVV 3R llpSP                  4       V8  Ed   SP                  P                  4       '       d°   V! 4        V! 4       G Rj  x€L
  \        \        P                  R4      ;_uu_ 4        S P                  S4      pSP                  V^ 8X  d   \        R4      M	\        4       4      G Rj  x€L
  \         P#                  R	W…4       RRR4       S P%                  SV4       R# V! 4        SP'                  4       '       d,   SP                  4       S,
          V8¼  d   V! 4       G Rj  x€L
  V'       d   S P)                  V4      MRp	SP*                  P                  4       '       d«   V'       d£   \-        \-        V	R
R4      RR4      '       g…    \.        P0                  ! SP*                  P3                  RR7      4      p
V
P5                  RR4      pV'       d:   V! 4       G Rj  x€L
  S P7                  SWºP5                  RR4      4      G Rj  x€L
  \        P>                  ! V4      G Rj  x€L
  EK3  SP                  P                  4       '       g™   \         PA                  RV4       SP                  PC                  RRR7       V! 4       G Rj  x€L
  \E        \F        4      ;_uu_ 4        SP                  \        R4      4      G Rj  x€L
  RRR4       S P%                  SV4       R# R#  EL- EL© ELE  + '       g   i     EL6; i ELâ EL* EL  \.        P8                  \:        3 d"   p\         P=                  RT4        Rp?EL8Rp?ii ; i EL' LÄ LŒ  + '       g   i     L’; i5i)a  Watch ``hermes update --gateway``, streaming output + forwarding prompts.

Polls ``.update_output.txt`` for new content and sends chunks to the user periodically;
detects ``.update_prompt.json`` (written when the update process needs input) and forwards it.
Nr6   c               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   ÚFGatewayNotificationsMixin._watch_update_progress.<locals>.__annotate__   s   € ÷ 	=ñ 	= Tñ 	=r$   c               “  ó¢   <"  € SR up oV P                  4       '       d-   SP                  4       oSP                  SV 4      G Rj  x€L
  R# R#  L5i©r6   N)rf   r`  rƒ  )rN   ÚbufferÚlast_stream_timerd  r|   rx  s    €€€€€r"   Ú_flush_bufferÚGGatewayNotificationsMixin._watch_update_progress.<locals>._flush_buffer   sF   øé € à! 2ˆLˆD�&Ø�z‰z�|Š|Ø#'§9¡9£;Ð Ø×.Ñ.¨v°tÓ<×<Ò<ñ á<ùs   ƒAAÁAÁ	Ac               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r¢  '  s   € ÷ 	$ñ 	$ $ñ 	$r$   c                 ó  <€ SP                   P                  4       '       dK   \        \        4      ;_uu_ 4        SP	                  SP                   S4      w  p oSV ,          oR R R 4       R # R #   + '       g   i     R # ; ir\   )rC   r{   r   rs  ru  )Úchunkr¥  Ú
bytes_sentrE  r|   s    €€€€r"   Ú_read_new_outputÚJGatewayNotificationsMixin._watch_update_progress.<locals>._read_new_output'  s]   ø€ à�|‰|×"Ñ"×$Ò$Üœg×&Õ&Ø(,×(FÑ(FÀuÇ|Á|ÐU_Ó(`Ñ%�E˜:Ø˜e•O�F÷ 'Ñ&ñ %ß&×&Ð&ús   ¹)A.Á.A?	z$Update final notification failed: %szgateway.update.finishedz&Update finished (exit=%s), notified %sr‘  r’  FrG  rH  rt   r‡  z Failed to read update prompt: %sz$Update watcher timed out after %.0fsr]  r^  zgateway.update.timed_out)$r+  r   r_  r`  rQ  re  rY   rs   r{   r   rÅ   rå   rj  r¡   r   r&   r:   rÀ   r›  rf   r™  rt   r<   rJ  rK  rL  r]   r•  ÚJSONDecodeErrorrs  r;   rb  rì   rc  r   r9   )r|   r[  rž  rŸ  rY  rY   r§  r­  rs   Ú_pending_stateÚprompt_datar†  rù   r¥  r¬  r¦  rd  rE  rx  s   f&&&         @@@@@@r"   r"  Ú0GatewayNotificationsMixin._watch_update_progress  s$  þé € ð ×"Ñ"Ó$ˆÜ×'Ò'Ó)ˆØ—9‘9“; Õ(ˆØ×,Ñ,¨UÓ3ˆØŠ>Ø×4Ñ4°U¸HÓT×TÐTÙØ×(Ñ(ˆØˆ
ØŸ9™9›;ÐØˆ÷	=ô 	=÷	$ó 	$ð �i‰i‹k˜HÕ$Ø�‰×%Ñ%×'Ò'Ù Ô"Ù#“o×%Ð%Ü$¤W§_¡_Ð6\×]Õ]Ø $× 6Ñ 6°uÓ =�IØ Ÿ+™+Ø8AÀQ¼œÐ3Ô4ÔLaÓLcó÷ ð ô —K‘KÐ HÈ)Ôa÷ ^ð ×*Ñ*¨5°+Ô>ÙÙÔØ�|‰|�~Š~ 4§9¡9£;Ð1AÕ#AÀoÔ"UÙ#“o×%Ð%çFQ˜T×5Ñ5°kÔBÐW[ˆNØ�|‰|×"Ñ"×$Ò$¯¼WÜ˜¨°dÓ;Ð=TÐV[÷>ò >ðHÜ"&§*¢*¨U¯\©\×-CÑ-CÈ[Ð-CÓ-YÓ"Z�KØ"-§/¡/°(¸BÓ"?�Kß"Ù+›o×-Ð-Ø"×9Ñ9¸&À+ÏÉÐ_hÐjlÓOmÓn×nÐnô —-’- Ó.×.Ó.Ø�‰×%Ñ%×'Ò'Ü�N‰NÐAÀ7ÔKØ�O‰O×&Ñ& u°wÐ&Ô?Ù“/×!Ð!Üœ)×$Õ$Ø—k‘k¤!Ð$>Ó"?Ó@×@Ð@÷ %à×&Ñ& u¨kÖ:ñ (òe Uò0 &ò÷ ^×]Ð]úò &ò .ÚnøÜ×,Ñ,¬gÐ6ô HÜ—L‘LÐ!CÀQ×GÒGûðHúâ.ñ "á@÷ %×$üs  ‰A'PÁ0NÁ1A4PÃ&PÃ7N Ã8&PÄA N&ÅN#ÅN&Å98PÆ2&PÇN:ÇPÇ%2PÈPÈ PÈ?A	O Ê	
O ÊN=Ê)O Ê=O Ê>O ËPËPË&PÌ=PÍ PÍPÍP	Í:PÍ;P	Í?PÎ PÎ#N&Î&N7	Î1
PÎ=O Ï O ÏO?ÏO:Ï4PÏ:O?Ï?PÐPÐP	Ð	P	ÐPc               ó   € V ^8„  d   QhRR/# rw   r    )r!   s   "r"   r#   r°   S  s   € ÷ Jñ J°ñ Jr$   c           	   ƒ  ó°
  aaa"  € ^ RI Hp V P                  4       oSP                  4       '       g   R# RoSP                  oR VVV3R llp SP
                  P                  4       '       d(    SP
                  P                  SP                  4       MjSP                  P                  4       '       gK    S'       d@   SSP                  SP                  SP                  3 F  pVP                  RR7       K  	  R# R# \        P                  ! SP                  P                  RR7      4      pVP                  R	4      pVP                  R
4      pSP                  P                  4       '       gO   V! R4      S'       d?   SSP                  SP                  SP                  3 F  pVP                  RR7       K  	  # # V P!                  S4      pSP                  P                  4       '       d,   SP                  P#                  4       P%                  RRR7      MRp\'        V4      p	V P)                  W�P+                  V4      4      p
V'       Ed   V
'       gú   V P-                  V4      pVe–   V\.        8”  d‹   \0        P3                  RWVVR,          V4       V P5                  SVP                  R4      4        S'       d@   SSP                  SP                  SP                  3 F  pVP                  RR7       K  	  R# R# V! RV4      S'       d?   SSP                  SP                  SP                  3 F  pVP                  RR7       K  	  # # V'       d¿   T P7                  W–WJ4      p^ RIHp V! V4      P=                  4       pV^ 8X  d'   \?        R4      pV'       d   V R\A        VR4       R2pM*\C        4       pV'       d   \?        RV\A        VR4      R7      pV
PE                  WnV! WÉR7      R7      G Rj  x€L
  \0        PG                  RWVV4       S'       d>   SSP                  SP                  SP                  3 F  pTP                  RR7       K  	  R#   \         do    SP                  P                  4       '       gK    S'       d@   SSP                  SP                  SP                  3 F  pTP                  RR7       K  	  R# R#  ELØi ; i LÞ  \H         d!   p\0        P3                  R T4        Rp?LëRp?ii ; i  S'       d?   SSP                  SP                  SP                  3 F  pTP                  RR7       K  	  i i ; i5i)!zˆIf an update finished, notify the user.

False while the update is still running (caller may retry); True after a definitive send/skip.
r—   FTc               ó    € V ^8„  d   QhRRRR/# )r   Úreasonr   r   rx   r    )r!   s   "r"   r#   ÚIGatewayNotificationsMixin._send_update_notification.<locals>.__annotate___  s   € ÷ 	ñ 	˜3ð 	¨$ñ 	r$   c                óž   <€ \         P                  ! V .VO5!   R oSP                  oSP                  P	                  SP                  4       R # ©F)r:   rÀ   rq   rr   ro  )r¶  ÚargsÚactive_pending_pathÚcleanuprE  s   &*€€€r"   Ú_deferÚCGatewayNotificationsMixin._send_update_notification.<locals>._defer_  s<   ø€ ä�KŠK˜Ð& Ô&ØˆGØ"'§-¡-ÐØ�M‰M×!Ñ! %§-¡-Ô0Ùr$   rƒ   rG  rH  r=   r/   z2Update notification deferred: update still runningr^  ro  rp  r6   NzRPost-update notification for %s:%s dropped after %.1fh: %s adapter never connectedr'   rY   z:Update notification deferred: %s adapter not connected yetrz  zgateway.update.finished_successz

```
r|  r}  zgateway.update.last_linesé   )ÚmsgÚtailr™   r    z0Sent post-update notification to %s:%s (exit=%s)z#Post-update notification failed: %s)%rš   r˜   r+  r}   rr   rq   r{   ro  ÚFileNotFoundErrorrC   rs   r…   rJ  rK  rL  r]   rj  rr  rt  r   rM  r6  rB  Ú'_UPDATE_NOTIFY_MAX_ADAPTER_WAIT_SECONDSr:   rì   r›  rN  r~  r{  rf   r   rH   r&   r¡   rÀ   r9   )r|   r˜   r½  r†   rq   rP  r/   rs   rC   r=   r“   Úager”   r{  rÀ  rù   r»  r¼  rE  s   &               @@@r"   ra  Ú3GatewayNotificationsMixin._send_update_notificationS  s`  úé € õ
 	=Ø×"Ñ"Ó$ˆØ× Ñ ×"Ò"ÙØˆØ#Ÿm™mÐ÷	ò 	ð5	.Ø�}‰}×#Ñ#×%Ò%ð$Ø—M‘M×)Ñ)¨%¯-©-Õ8ð —]‘]×)Ñ)×+Ò+Ø÷V Ø-¨u¯}©}¸e¿l¹lÈEÏOÉOÓ\�AØ—H‘H¨�HÖ-ó ]ñ ôU —j’j §¡×!8Ñ!8À+Ð!8Ó!NÓOˆGØ"Ÿ;™; zÓ2ˆLØ—k‘k )Ó,ˆGØ—?‘?×)Ñ)×+Ò+ÙÐRÓS÷L Ø-¨u¯}©}¸e¿l¹lÈEÏOÉOÓ\�AØ—H‘H¨�HÖ-ò ]ð ðK ×.Ñ.¨uÓ5ˆIØTY×T`ÑT`×TgÑTg×TiÒTi�U—\‘\×,Ñ,Ó.×5Ñ5°gÀiÐ5ÔPÐoqˆFÜ Ó-ˆHØ×1Ñ1°(×<PÑ<PÐQXÓ<YÓZˆGßˆwŸwØ×.Ñ.¨wÓ7�Ø’? sÔ-TÔ'Tô —N‘Nð$Ø%1¸CÀ&½LÈ,ôXð ×.Ñ.¨u°g·k±kÀ-Ó6PÔQØ÷* Ø-¨u¯}©}¸e¿l¹lÈEÏOÉOÓ\�AØ—H‘H¨�HÖ-ó ]ñ ñ% ÐZÐ\hÓi÷$ Ø-¨u¯}©}¸e¿l¹lÈEÏOÉOÓ\�AØ—H‘H¨�HÖ-ò ]ð ÷# Ø×8Ñ8¸ÈGÓ]�Ý7Ù# FÓ+×1Ñ1Ó3�Ø ”>ÜÐ=Ó>�CßØ!$  YÔ/BÀ6È4Ó/PÐ.QÐQVÐW˜øä/Ó1�CßÜÐ ;ÀÔK^Ð_eÐgjÓKkÔl˜Ø—l‘l 7Ñ:VÐW_Ô:s�lÓt×tÐtÜ—‘ÐNÐP\ÐgpÔq÷ Ø-¨u¯}©}¸e¿l¹lÈEÏOÉOÓ\�AØ—H‘H¨�HÖ-ñ ]áøôe )ô $Ø Ÿ=™=×/Ñ/×1Ò1Ø#÷Z Ø-¨u¯}©}¸e¿l¹lÈEÏOÉOÓ\�AØ—H‘H¨�HÖ-ó ]ñ ò] 2ð$úñT uøäô 	EÜ�N‰NÐ@À!×DÑDûð	Eû÷ Ø-¨u¯}©}¸e¿l¹lÈEÏOÉOÓ\�AØ—H‘H¨�HÖ-ò ]ð üsÑ   …AUÁ S Á/%Q Â S Â6A	UÃ?A1S Å1S Å8AUÆ?0S Ç0A(S ÉA S Ê:A	UÌS ÌAUÍS ÍB"S Ï<SÏ=S ÐAUÑ*SÒ
S ÒUÒAUÓS ÓSÓS ÓTÓ(TÓ>T ÔTÔT ÔAUÕUc               ó   € V ^8„  d   QhRR/# )r   r   z(Optional[tuple[str, str, Optional[str]]]r    )r!   s   "r"   r#   r°   Ÿ  s   € ÷ 30ñ 30Ð2Zñ 30r$   c           
   ƒ  óN  "  € ^ RI Hp ^ RIHpHp VR,          pVP                  4       '       g   R#  \        P                  ! VP                  RR7      4      pVP                  R4      pVP                  R4      pVP                  R	4      pV'       d	   V'       g    VP                  R
R7       R# \        V4      p	V! W�P                  V P                  V P                  V4      4      4      p
V
f,   \        P!                  RV4        VP                  R
R7       R# V P                  P"                  P                  V	4      pVe>   VP$                  '       g,   \        P'                  RV4        VP                  R
R7       R# V P)                  W—WZP*                  4      pVP                  R4      R
J dK   \-        T;'       g    / 4      pR F/  pVP                  V4      '       g   K  \/        W],          4      WÍ&   K1  	  V
P1                  V	\/        V4      \3        R4      V! WÉR7      R7      G Rj  x€L
 p\5        V4      '       d6   \        P7                  RWg\9        V4      4        VP                  R
R7       R# \        P'                  RWg4       \/        V4      \/        V4      V'       d   \/        V4      MR3VP                  R
R7       #  Lœ  \:         d4   p\        P7                  RT4        Rp?TP                  R
R7       R# Rp?ii ; i  TP                  R
R7       i ; i5i)zANotify the chat that initiated /restart that the gateway is back.r4   )r)  r˜   z.restart_notify.jsonNrG  rH  r=   r/   r0   Trƒ   z6Restart notification skipped: no live transport for %szJRestart notification suppressed: %s has gateway_restart_notification=falseÚdelivered_via_upstream_relayzgateway.startup.restartedr™   r    z3Restart notification to %s:%s was not delivered: %sz"Sent restart notification to %s:%szRestart notification failed: %s)r¹   Úscope_id)r8   r5   rš   r)  r˜   r{   rJ  rK  rL  r]   r…   r   r>   Ú_adapters_for_profiler6  r:   r;   Ú	platformsÚgateway_restart_notificationrÀ   rN  r“   rW   r   r¡   r   r   rì   r   r9   )r|   r5   r)  r˜   Únotify_pathr.  rP  r/   r0   r=   Ú	transportÚplatform_cfgr”   r`   rË   rù   s   &               r"   Ú_send_restart_notificationÚ4GatewayNotificationsMixin._send_restart_notificationŸ  s¬  é € å?ßJØ"Ð%;Õ;ˆØ×!Ñ!×#Ò#Ùð,	0Ü—:’:˜k×3Ñ3¸[Ð3ÓIÓJˆDØŸ8™8 JÓ/ˆLØ—h‘h˜yÓ)ˆGØŸ™ Ó-ˆIß§wØðL ×Ñ¨$ÐÖ/ôK   Ó-ˆHñ 3ØŸ+™+ t×'AÑ'AÀ$×BVÑBVÐW[ÓB\Ó']ó_ˆIàÒ Ü—‘ÐUÐWcÔdØð< ×Ñ¨$ÐÖ/ð;  Ÿ;™;×0Ñ0×4Ñ4°XÓ>ˆLØÒ'°×0Y×0YÐ0YÜ—‘Ø`Ðbnôð ð0 ×Ñ¨$ÐÖ/ð/ ×4Ñ4°XÈ×N_ÑN_Ó`ˆHØ�x‰xÐ6Ó7¸4Ó?Ü § ¨BÓ/�Û4�EØ—x‘x —”Ü*-¨d­kÓ*:˜›ñ 5ð %Ÿ>™>Øœ#˜g›,¬Ð*EÓ(FÙ5°hÔRð *ó ÷ ˆFô ˜F×#Ò#Ü—‘ØIÈ<ÔbmÐntÓbuôð ð ×Ñ¨$ÐÖ/ô �K‰KÐ<¸lÔTÜ�|Ó$¤c¨'£lÇi´C¸	´NÐUYÐYð
 ×Ñ¨$ÐÕ/ñ#øô ô 	Ü�N‰NÐ<¸aÔ@Ûà×Ñ¨$ÐÖ/ûð		ûð ×Ñ¨$ÐÕ/üs—   ‚0L%³A(K ÂL%Â1AK ÄL%Ä:K ÅK Å.L%Æ>K Ç K Ç&AK È.KÈ/5K É%L%É9?K Ê8L%ËK ËLËLË.L Ë2L%ÌLÌL ÌL"Ì"L%c              #  ó  "  € V P                   P                  P                  4        FY  w  rVP                  pV'       d   VP                  '       g   K-  \        WP                   V P                  4      pVf   KS  WW43x € K[  	  R# 5i)zaYield ``(platform, platform_cfg, home, transport)`` for every home channel with a live transport.N)r>   rË  ÚitemsÚhome_channelr/   rA   r?   )r|   r=   rÏ  ÚhomerÎ  s   &    r"   Ú_home_channel_transportsÚ2GatewayNotificationsMixin._home_channel_transportsÔ  sg   é € à&*§k¡k×&;Ñ&;×&AÑ&AÖ&CÑ"ˆHØ×,Ñ,ˆDß˜tŸ|Ÿ|˜|ÙÜ0°¿;¹;ÈÏÉÓVˆIØÒ ÙØ¨$Ð9Ô9ó 'Dùs   ‚ABÁ4Bc              #  ó"  "  € V P                   P                  P                  4        F  w  rRW3x € K  	  \        V RR4      ;'       g    / P                  4        F.  w  r4VP                  P                  4        F  w  rW1V3x € K  	  K0  	  R# 5i)aš  ``(profile, platform, platform_cfg)`` for every SERVED profile's configured home channel.

``self.config`` is the launch profile's alone, but one host process multiplexes every
profile, so a host-wide notice built from it silently skips the others' channels. The
secondary configs are the ones ``_load_secondary_profile_config`` already cached at
adapter start; ``profile`` is ``None`` for the launch profile.
NÚ_profile_configs)r>   rË  rÓ  r<   )r|   r=   rÏ  r)   Úprofile_cfgs   &    r"   Ú_served_home_channel_configsÚ6GatewayNotificationsMixin._served_home_channel_configsß  s…   é € ð '+§k¡k×&;Ñ&;×&AÑ&AÖ&CÑ"ˆHØ˜Ð.Ô.ñ 'Dä%,¨TÐ3EÀtÓ%L×%RÐ%RÐPR×$YÑ$YÖ$[Ñ ˆGØ*5×*?Ñ*?×*EÑ*EÖ*GÑ&�Ø¨Ð5Ô5ó +Hó %\ùs   ‚ABÁ
ABc           	   #  óÖ  "  € V P                  4        F  w  rr4RWW43x € K  	  \        V RR4      ;'       g    / P                  4        Fš  w  rV\        V RR4      ;'       g    / P                  V4      ;'       g    / pVP                  P                  4        FG  w  rVP
                  pV'       d   VP                  '       g   K-  \        WWuR7      pVf   K@  WQW#V3x € KI  	  Kœ  	  R# 5i)u«   ``(profile, platform, platform_cfg, home, transport)`` for every served profile's home
channel with a live transport â€” the launch profile's (``profile`` ``None``) first.NrÙ  Ú_profile_adapters©r)   )rÖ  r<   rÓ  r]   rË  rÔ  r/   rA   )r|   r=   rÏ  rÕ  rÎ  r)   rÚ  r?   s   &       r"   Ú_served_home_channel_transportsÚ9GatewayNotificationsMixin._served_home_channel_transportsí  sÚ   é € ð 8<×7TÑ7TÖ7VÑ3ˆH DØ˜°Ð?Ô?ñ 8Wä%,¨TÐ3EÀtÓ%L×%RÐ%RÐPR×$YÑ$YÖ$[Ñ ˆGÜ Ð&9¸4Ó@×FÐFÀB×KÑKÈGÓT×ZÐZÐXZˆHØ*5×*?Ñ*?×*EÑ*EÖ*GÑ&�Ø#×0Ñ0�ß 4§<§< <ÙÜ4°XÈHÔf�	ØÒ$ÙØ¨¸YÐFÔFó +Hó %\ùs   ‚5C)¸AC)Á;AC)Ã&C)c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úmessager   Úfailure_fmtr   rx   r    )r!   s   "r"   r#   r°   ý  s$   € ÷ ñ ÐSVð Ðehð Ðmqñ r$   c              ƒ  ó|  "  € ^ RI Hp  V P                  WP                  VP                  VP
                  R7      pVP                  '       dX   \        T;'       g    / 4      pVP                  '       d   VP                  VR&   VP                  '       d   VP                  VR&   V! WqR7      pVf   VP                  '       d1   VP                  V\        VP                  4      WHR7      G Rj  x€L
 p	M7VP
                  P                  \        VP                  4      V4      G Rj  x€L
 p	\        V	4      '       d7   \        P                  WQP                  VP                  \!        V	4      4       R# R	#  L… LO  \"         d7   p
\        P                  YQP                  TP                  T
4        Rp
?
R# Rp
?
ii ; i5i)
z\Best-effort send to one home channel; True on success, failures logged with ``failure_fmt``.r—   )r“   r¹   rÉ  r™   Nr    FT)rš   r˜   rV  r/   r0   r“   Úis_relayrW   r¹   rÉ  r¡   r   r   r:   rì   r7   r   r9   )r|   r=   rÕ  rÎ  rã  rä  r˜   r”   r›   rË   r@   s   &&&&&&     r"   Ú_send_home_channel_messageÚ4GatewayNotificationsMixin._send_home_channel_messageý  sC  é € å<ð	Ø×7Ñ7¸Ç,Á,ÐPT×P^ÑP^Ðhq×hyÑhyÐ7ÓzˆHØ×!×!Ð!Ü § ¨BÓ/�Ø—<—<�<Ø*.¯,©,�H˜YÑ'Ø—=—=�=Ø+/¯=©=�H˜ZÑ(Ù8¸ÔUˆMØÒ(¨I×,>×,>Ð,>Ø(Ÿ~™~¨h¼¸D¿L¹LÓ8IÈ7˜~Ók×k‘à(×0Ñ0×5Ñ5´c¸$¿,¹,Ó6GÈÓQ×Q�Ü˜F×#Ò#Ü—‘˜{¯N©N¸D¿L¹LÌ+ÐV\ÓJ]Ô^ÙÙñ láQøô
 ô 	Ü�N‰N˜;¯©¸¿¹ÀcÔJÝûð	üsl   ‚F<ŠAE8 ÁE8 Á5 E8 Â-E8 Ã*E8 Ã.E4Ã/7E8 Ä&E6Ä'A	E8 Å0F<Å4E8 Å6E8 Å8F9Æ+F4Æ.F<Æ4F9Æ9F<zOptional[asyncio.Lock]Ú_planned_restart_notice_lockc               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r°     s   € ÷ %^ñ %^ÀDñ %^r$   c              ƒ  óÎ  "  € ^ RI Hp ^ RIHp V P                  f   \
        P                  ! 4       V n        V P                  ;_uu_4       GRj  x€L
  V! 4       pVP                  4       '       g    RRR4      GRj  x€L
  R#  \        P                  ! VP                  RR7      4      pVP                  R. 4       Uu0 uF  p\        V4      kK  	  ppV P                  4        UUU	u0 uF‹  w  rxp	V	P                  '       g   K  V	P                  P                  '       g   K8  V	P                   '       g   KL  \#        WxP$                  V	P                  P                  V	P                  P&                  4      kK�  	  p
ppp	Y`P)                  VR7      G Rj  x€L
 ,          pW¦8:  d&   VP+                  RR	7        RRR4      GRj  x€L
  R# V Uu. uF  p\-        V4      NK  	  upVR&   V! W4RR
7       RRR4      GRj  x€L
  R#  EL´ EL‰u upi u up	ppi  L� LTu upi   \.         d    \0        P3                  RRR7        LQi ; i LI  + GRj  x€L 
 '       g   i     R# ; i5i)a3  Send the planned-restart online notice to every home channel still owed one; clear
``.restart_pending.json`` only once all of them were reached.

Runs from the boot pass and again from ``_install_reconnected_adapter``, so a home whose
platform was down at boot gets its notice when the platform comes back (#112109). Delivered
targets are recorded in the marker so neither a later replay nor the next process (if this
one restarts first) notifies a home twice. The lock serializes a boot pass that outlived the
restore gate against a concurrent reconnect replay.
)Ú"_planned_restart_notification_path)Úatomic_json_writeNrG  rH  Údelivered_targets)Úskip_targetsTrƒ   )Úindentz,Planned-restart notification remains pendingr»   )rš   rì  Úutilsrí  ré  r   ÚLockr{   rJ  rK  rL  r]   r,   rÛ  rÔ  r/   rÌ  r1   r7   r0   Ú(_send_home_channel_startup_notificationsr…   Úlistr9   r:   rì   )r|   rì  rí  rO  r.  rx  Ú	deliveredr)   r=   ÚcfgÚoweds   &          r"   Ú,_replay_pending_planned_restart_notificationÚFGatewayNotificationsMixin._replay_pending_planned_restart_notification  só  é € õ 	CÝ+à×,Ñ,Ò4Ü07·²³ˆDÔ-Ø×4×4×4Ó4Ù5Ó7ˆDØ—;‘;—=’=Ø÷ 5×4Ñ4ð^Ü—z’z $§.¡.¸+ .Ó"FÓG�Ø9=¿¹ÐBUÐWYÔ9ZÓ[Ñ9Z¨vœU 6ž]Ñ9Z�	Ð[ð 37×2SÑ2SÔ2Uõñ 3VÑ.˜¨3Ø×'Õ'ôgð -0×,<Ñ,<×,DÕ,Dôgð JM×IiÕIiôgÔ-Ø§¡°×1AÑ1A×1IÑ1IÈ3×K[ÑK[×KeÑKeögá2Uð ò ð ×#PÑ#PÐ^gÐ#PÓ#h×hÕh�	ØÔ$Ø—K‘K¨4�KÔ0Ø÷% 5×4Ñ4ñ& IRÓ,RÉ	¸f¬T°&®\É	Ñ,R�Ð(Ñ)Ù! $°TÕ:÷) 5×4×4ùò \ùôñ iñ 5ùò& -Søäô ^Ü—‘ÐMÐX\�Ö]ð^ú÷+ 5×4×4Ó4üsñ   ‚AI%ÁHÁI%ÁIÁ2I%Á=HÁ>I%Â:HÂ?H	ÃHÃ)HÄHÄ#HÄ7AHÅ:HÆH
Æ"HÆ7I%ÇHÇI%Ç	HÇHÇ!HÇ1I%Ç<IÇ=I%ÈI%È	HÈI%ÈHÈ"IÉ IÉIÉIÉI%ÉI"	ÉIÉ
I"	ÉI"	É	I%rï  c               ó    € V ^8„  d   QhRRRR/# )r   rï  z-Optional[set[tuple[str, str, Optional[str]]]]r   z#set[tuple[str, str, Optional[str]]]r    )r!   s   "r"   r#   r°   >  s   € ÷ )ñ )ØLð)à	,ñ)r$   c             ƒ  ó   "  € \        4       pT;'       g    \        4       p\        R4      p\        V P                  4       4      pV UUUU	U
u0 uFf  w  rgr‰p
\	        WgP
                  V	P                  V	P                  4      V9   g   K9  \        VP
                  V	P                  V	P                  VR7      kKh  	  pp	pppp
V EF+  w  rgrÉpVP                  '       g#   \        P                  RVP
                  4       K<  \	        WgP
                  V	P                  V	P                  4      pWã9   g   Wâ9   d   Ku  \        VP
                  V	P                  V	P                  VR7      pWû9   d   VP                  V4       K»  V P                  WyWÔR4      G Rj  x€L
 '       g   KÞ  VP                  V4       VP                  V4       \        P                  RVP
                  V	P                  4       EK.  	  V# u up
p	pppi  Li5i)uÜ  Notify EVERY served profile's configured home channels that the gateway is back online.

Best-effort, once per home CHAT â€” several served profiles can share one chat (a single
Telegram group for the whole host), and one host process restarting once owes that chat
one notice. Accounting stays per profile so the marker's owed set still discharges.
``skip_targets`` lets startup avoid duplicate messages when a more specific restart
notification is queued for the same chat.
zgateway.startup.onlinerß  zWHome-channel startup notification suppressed: %s has gateway_restart_notification=falsez6Home-channel startup notification failed for %s:%s: %sNz/Sent home-channel startup notification to %s:%s)Úsetr   rô  rà  r1   r7   r/   r0   r   rÌ  r:   rÀ   Úaddrç  )r|   rï  rõ  Úskippedrã  Útargetsr)   r=   Ú_cfgrÕ  Ú
_transportÚnotified_chatsrÏ  rÎ  rx  Úchats   &$              r"   ró  ÚBGatewayNotificationsMixin._send_home_channel_startup_notifications>  s¬  é € ô :=»ˆ	Ø×'Ð'¤#£%ˆÜÐ,Ó-ˆÜ�t×;Ñ;Ó=Ó>ˆñ >E÷
á=DÑ9� 4¨zÜ(¨·.±.À$Ç,Á,ÐPT×P^ÑP^Ó_ÐcjÑjô `Ô  §¡°·±¸t¿~¹~ÐW^×_Ù=Dð 	ô 
ô
 AHÑ<ˆG˜|°9Ø×<×<Ð<Ü—‘ØmØ—N‘Nôñ Ü.¨w¿¹ÈÏÉÐVZ×VdÑVdÓeˆFØÔ  FÔ$7ÙÜ'¨¯©¸¿¹ÀdÇnÁnÐ^eÔfˆDØÔ%Ø—‘˜fÔ%ÙØ×4Ñ4Ø 	Ð4ló÷ ÷ ð ð ×"Ñ" 4Ô(Ø—‘˜fÔ%Ü—‘ÐMÈxÏ~É~Ð_c×_kÑ_k×lñ' AHð( Ðùö3
ñ&ùs,   ‚AG>Á6G3Â1G3Â9CG>ÆG<ÆG>ÆAG>c               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r°   i  s   € ÷ 5#ñ 5#¸dñ 5#r$   c              ƒ  óè  a aaaa"  € \        S RR4      pV'       g   R# \        S RR4      e<   S P                  4        S P                  pV'       g   \        P	                  R4       R# ^ RIHpHp ^ RIH	pH
p V! V4      pV! 4       pVR8X  d%   V! 4       pV! 4       R,          p	\        R	WxV	R
7      oMiVR8X  d   \        RVR7      oMT^ RIHp
 V
! V4      pVP                  pVP                  \         9  d   \        RWÇR7      p\        RVP"                  VR7      o\        P%                  RV4       ^ RIHp S P+                  4        F"  w  opooV! VVVV V3R lSR7      G Rj  x€L
  K$  	  R#  L
5i)u  Broadcast a state.db failure warning to all home channels.

When SessionDB init fails at gateway startup, messages may flow but nothing is persisted
â€” /resume, /history, and session_search all silently break. Best-effort: failures are
logged, not raised.

See #88235.
Ú_session_db_init_errorNÚ_session_db_handle_cachezMstate.db recovered before the home-channel warning went out; not broadcasting)Úget_default_hermes_rootÚprofile_cli_selector)Ú_default_db_pathÚclassify_persistence_errorÚcorruptÚbackupszgateway.startup.db_corrupt)Úprofile_argÚdb_pathÚbackups_dirÚ	fts_indexzgateway.startup.db_fts_corrupt)r  )Údescribe_storage_failurezgateway.startup.db_then_restart)Úactionr  zgateway.startup.db_unavailable)Úcauser  z:Broadcasting state.db failure warning to home channels: %s©Úpresent_notificationc                 ó.   <€ SP                  SS SSR 4      # )z2state.db warning notification failed for %s:%s: %s)rç  )rÕ  rã  r=   r|   rÎ  s   €€€€€r"   Ú<lambda>ÚRGatewayNotificationsMixin._send_session_db_warning_notifications.<locals>.<lambda>œ  s   ø€ ˜×7Ñ7Ø˜d I¨wÐ8lônr$   r™   )r<   Ú!_open_session_db_for_active_scoper  r:   rÀ   Úhermes_constantsr	  r
  Úhermes_stater  r  r   Úhermes_state_user_copyr  r  r  Ú_SELF_CLEARING_STORAGE_CAUSESÚglossrì   Úgateway.warning_notificationsr  rÖ  )r|   r  r	  r
  r  r  r  r  r  r  r  Úfailurer  r  Ú_platform_cfgrÕ  rã  r=   rÎ  s   f              @@@@r"   Ú&_send_session_db_warning_notificationsÚ@GatewayNotificationsMixin._send_session_db_warning_notificationsi  sS  üé € ô ˜Ð6¸Ó=ˆßÙô
 �4Ð3°TÓ:ÒFØ×2Ñ2Ô4Ø×/Ñ/ˆEßÜ—‘ÐkÔlÙßRßMÙ*¨5Ó1ˆñ +Ó,ˆØ�IÔÙ&Ó(ˆGÙ1Ó3°iÕ?ˆKÜÐ4À+ÐlwÔx‰GØ�kÔ!ô Ð8ÀkÔR‰GåGÙ.¨uÓ5ˆGð
 —^‘^ˆFØ�}‰}Ô$AÔAÜÐ<ÀVÔe�ÜÐ8ÀÇÁÐV\Ô]ˆGÜ�‰ÐSÐUZÔ[ÝFØ8<×8UÑ8UÖ8WÑ4ˆH�m T¨9Ù&÷nð nà!ô#÷ #ò #ó 9Xñ#ùs   ‡A
E2ÁDE2Å%E0Å&E2c               ó   € V ^8„  d   QhRR/# ©r   rV   rW   r    )r!   s   "r"   r#   r°      s   € ÷ @
ñ @
¨tñ @
r$   c                ó°  a€ ^ RI Hp \        SP                  R4      ;'       g    R4      P	                  4       p/ pV'       d–    V P
                  P                  4        V P
                  P                  P                  V4      pV'       d%   \        VRR4      '       d   V P                  V4      # T P                  T4      pTe   T# T! T4      ;'       g    / pVP                  R4      p\        SP                  R4      ;'       g    VP                  R4      ;'       g    R4      P	                  4       P                  4       p	\        SP                  R	4      ;'       g    VP                  R	4      ;'       g    R4      P	                  4       P                  4       p
\        SP                  R
4      ;'       g    VP                  R
4      ;'       g    R4      P	                  4       pV	'       d   V
'       d	   V'       g>   \        S4      '       d   R# \        P!                  RW9W«SP                  RR4      4       R#  \#        V	4      pVP$                  \&        9  d5    ^ RIHp VP-                  VP$                  4      '       g   \/        V	4      hM R V3R llpV! R4      pVf   V
R9  d   \        P!                  RW›V
4       \1        WËW®! R4      V! R4      V! R4      WøR7      #   \         d"   p\        P                  RY64        Rp?EL^Rp?ii ; i  \         d    \/        T	4      hi ; i  \         d    \        P!                  RT	4        R# i ; i)z©Resolve the canonical source for a synthetic background-process event.

Prefer the persisted session-store origin; the active foreground event causes cross-topic bleed.
©Ú_parse_session_keyrY   r6   ÚoriginNz>Synthetic process-event session-store lookup failed for %s: %sr)   r=   re   r/   zcSynthetic event source unresolvable: session_key=%r platform=%r chat_type=%r chat_id=%r evt_type=%sr�  rº   )Úplatform_registryz9Synthetic process event has invalid platform metadata: %rc               ó    € V ^8„  d   QhRRRR/# )r   r`   r   r   r*   r    )r!   s   "r"   r#   ÚKGatewayNotificationsMixin._build_process_event_source.<locals>.__annotate__Ñ  s   € ÷ 	=ñ 	=˜ð 	= ñ 	=r$   c                ó|   <€ \        SP                  V 4      ;'       g    R 4      P                  4       ;'       g    R# r¤  )r   r]   rf   )r`   rV   s   &€r"   Ú_optÚCGatewayNotificationsMixin._build_process_event_source.<locals>._optÑ  s/   ø€ Ü�s—w‘w˜u“~×+Ð+¨Ó,×2Ñ2Ó4×<Ð<¸Ð<r$   rÉ  z§Synthetic event source for %s chat=%s (%s) reconstructed without scope_id; scoped relay egress may be declined by the connector's tenant guard (user_id fallback only).r0   r¹   Ú	user_name)r=   r/   re   r0   r¹   r2  rÉ  r)   )ÚdmÚthread)rš   r*  r   r]   rf   Úsession_storeÚ_ensure_loadedÚ_entriesr<   Ú_restored_sourcer9   r:   r;   Ú_get_cached_session_sourcerg   rj   rì   r   r7   r   Úgateway.platform_registryr,  Úis_registeredr<  r   )r|   rV   r*  rY   ÚderivedÚentryr@   Úcached_sourcer)   Úplatform_namere   r/   r=   r,  r0  rÉ  s   &f              r"   Ú_build_process_event_sourceÚ5GatewayNotificationsMixin._build_process_event_source   s×  ø€ õ
 	3Ü˜#Ÿ'™' -Ó0×6Ð6°BÓ7×=Ñ=Ó?ˆØˆßðqØ×"Ñ"×1Ñ1Ô3Ø×*Ñ*×3Ñ3×7Ñ7¸ÓD�ßœW U¨H°d×;Ò;Ø×0Ñ0°Ó7Ð7ð !×;Ñ;¸KÓHˆMØÒ(Ø$Ð$Ù(¨Ó5×;Ð;¸ˆGØ—+‘+˜iÓ(ˆÜ˜CŸG™G JÓ/×PÐP°7·;±;¸zÓ3J×PÐPÈbÓQ×WÑWÓY×_Ñ_ÓaˆÜ˜Ÿ™ Ó,×NÐN°·±¸KÓ0H×NÐNÈBÓO×UÑUÓW×]Ñ]Ó_ˆ	Ü�c—g‘g˜iÓ(×HÐH¨G¯K©K¸	Ó,B×HÐHÀbÓI×OÑOÓQˆß§I·Wô -¨S×1Ò1ÙÜ�N‰NðQà¨IÀÇÁÈÐPSÓ@Tôñ
 ð	Ü Ó.ˆHà�~‰~Ô%=Ô=ð4ÝKØ,×:Ñ:¸8¿>¹>×JÒJÜ(¨Ó7Ð7ð Kð >÷	=ð 	=ñ ˜
Ó#ˆØÒ 	Ð1AÔ Aô �N‰NðHàIVÐajôô
 Ø¸)ÈtÐT_ÓO`Ù˜“O©t°KÓ/@È8ô
ð 	
øô_ ô qÜ—‘Ð]Ð_j×pÒpûðqûô: !ô 4Ü$ ]Ó3Ð3ð4ûäô 	Ü�N‰NÐVÐXeÔfÚð	úsI   ÁAK' Â#K' È= L0 É&L ÊL Ë'LË2LÌLÌL-Ì-L0 Ì0!MÍMc               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r°   â  s   € ÷ *ñ *ÀDñ *r$   c           	   ƒ  óŽ  "  € ^ RI HpHp V! V4      pV FÚ  pV P                  V4      ;_uu_4       GRj  x€L
  ^ RIHp V! V4      '       g    RRR4      GRj  x€L
  KL  V P                  4       R8X  d    RRR4      GRj  x€L
  Kt  V! V4      pV'       g    RRR4      GRj  x€L
  K—   V P                  Wu4      G Rj  x€L
 pRRR4      GRj  x€L
  XRJ g   KÉ  VP                  V4       KÜ  	  R#  L¿ Lœ Lv LU L;  \         d    \        P                  R4       Rp L]i ; i LU  + GRj  x€L 
 '       g   i     Ll; i5i)u²  Consume queued watch events and inject them when notifications are enabled.

The queue is ALWAYS drained (so watch events don't rot or requeue-spin) but injection is
skipped when the OWNING profile's ``display.background_process_notifications`` is ``off``
â€” one shared queue carries every served profile's events, so the gate is evaluated per
event inside its profile scope, never once for the ambient (launch) profile.

See #9290.
)Ú_drain_gateway_watch_eventsÚ$_format_gateway_process_notificationN©Úshould_surface_notificationÚoffz"Watch notification injection errorF)rš   rD  rE  Ú_completion_event_scopeÚ$tools.process_registry_notificationsrG  Ú#_load_background_notifications_modeÚ_inject_watch_notificationr9   r:   Ú	exceptionÚput)	r|   Úcompletion_queuerD  rE  Úwatch_eventsrV   rG  Ú
synth_textrõ  s	   &&       r"   Ú_drain_watch_notificationsÚ4GatewayNotificationsMixin._drain_watch_notificationsâ  s  é € ÷ 	bÙ2Ð3CÓDˆÛˆCØ×3Ñ3°C×8×8Õ8Ý\Ù2°3×7Ò7Ø÷ 9×8Ñ8ð ×;Ñ;Ó=ÀÔFØ÷ 9×8Ñ8ñ BÀ#ÓF�
ß!Ø÷ 9×8Ñ8ð&Ø&*×&EÑ&EÀjÓ&V× V�I÷ 9×8ð ˜EÕ!Ø ×$Ñ$ SÖ)ó!  ß8ñ !WøÜ ô &Ü×$Ñ$Ð%IÔJØ %’Ið&ú÷ 9×8×8Ò8üsÚ   ‚3EµC5
¶E¹D)ÁEÁC7ÁEÁ!D)Á7EÂC9ÂEÂ	D)ÂD)ÂEÂ%C;Â&EÂ-C?ÃC=
ÃC?ÃEÃD'ÃEÃEÃ7EÃ9EÃ;EÃ=C?Ã?"D$	Ä!D)Ä#D$	Ä$D)Ä'EÄ)EÄ/D2Ä0
EÄ;EÄ=Ec               ó   € V ^8„  d   QhRR/# ©r   r?  r   r    )r!   s   "r"   r#   r°      s   € ÷ ñ ¸ñ r$   c                óv   € V P                   P                  4        F  w  r#VP                  V8X  g   K  Vu # 	  R# )zYLiteral ``p.value == platform_name`` scan over connected adapters (native adapters only).N)r?   rÓ  r7   )r|   r?  r†   Úas   &&  r"   Ú_adapter_by_platform_valueÚ4GatewayNotificationsMixin._adapter_by_platform_value   s1   € à—M‘M×'Ñ'Ö)‰DˆAØ�w‰w˜-Ö'Ø’ñ *ñ r$   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rQ  r   Úraw_sidrV   rW   r   rx   r    )r!   s   "r"   r#   r°     s*   € ÷ %ñ %¸sð %ÈSð %ÐW[ð %Ð`dñ %r$   c              ƒ  óB  aaaaaaaa"  € ^ RI HoHo \        P                  ! 4       pSP                  R4      R8X  d   RpRpVVVVV3R lpM‚RpRp^ R	IHo  \        P                  ! V P                  SS4      G R
j  x€L
 oS'       d:   ^ RIHp
 \!        \"        P$                  SSR7      pT
! T P'                  T4      4      pTTTTTTT3R lp \        P)                  VS4       T;_uu_4       GR
j  x€L
  V! 4       G R
j  x€L
  R
R
R
4      GR
j  x€L
  R#  Lœ  \         d#   p	\        P                  TST	4        R
p	?	R# R
p	?	ii ; i LW LJ L<  + GR
j  x€L 
 '       g   i     R# ; i  \*         d#   p	\        P                  TST	4        R
p	?	R# R
p	?	ii ; i5i)uN  Deliver to a non-push (api_server) session by raw session id.

Async-delegation completions are persisted as a durable delivery row â€” after the parent
turn's event.complete the CLIENT owns the next turn on this stateless surface, so never
self-post them as a new role=user prompt. Other watch events wake the session via self-post.
)Údeliver_wakeÚpersist_delegation_deliveryr�  Úasync_delegationu`   Async delegation completion â€” persisting delivery row for api_server session %s (no wake turn)z;Async delegation delivery persist failed for session %s: %sc                 ó   <€ S! S SSSR 7      # ))rN   Ú
session_idrV   r    )r“   rV   r^  r[  rQ  s   €€€€€r"   r  ÚAGatewayNotificationsMixin._self_post_api_server.<locals>.<lambda>  s   ø€ Ñ9¸'È
Ð_fÐloÕpr$   uI   Watch pattern notification â€” waking api_server session %s via self-postz;Watch notification self-post wake failed for session %s: %s©Údiagnostic_process_eventNF©Ú_async_profile_runtime_scope©r=   r/   r)   c            	     óZ   <€ S! S \        S4      SSS! S4      '       d   R R7      # RR7      # )Ú
diagnosticrË   )rN   ra  r)   Únotification_category)rT   )r“   r]  rd  rV   r[  ÚservedrQ  s   €€€€€€€r"   r  rb  #  s6   ø€ ™l¨7Ô9TÐU_Ó9`Ðmtð  EÙ6NÈs×6SÒ6S lõcØYaõcr$   T)Úgateway.waker]  r^  Ú
contextlibÚnullcontextr]   Úagent.notification_presentationrd  r   Ú	to_threadÚ_served_api_server_wake_profileÚLookupErrorr:   rì   rš   rf  r   r   Ú
API_SERVERÚ _resolve_profile_home_for_sourcerÀ   r9   )r|   r“   rQ  r[  rV   ÚscoperÀ   ÚfailÚdeliverrù   rf  rÈ   r]  rd  r^  rk  s   &ffff       @@@@r"   Ú_self_post_api_serverÚ/GatewayNotificationsMixin._self_post_api_server  s@  ÿé € ÷ 	KÜ×&Ò&Ó(ˆØ�7‰7�6‹?Ð0Ô0ØuˆDØPˆDßpÐp‰Gà^ˆDØPˆDÝPðÜ&×0Ò0°×1UÑ1UÐWZÐ\cÓd×d�÷ õ EÜ&´×0CÑ0CÈWÐ^dÔe�Ù4°T×5ZÑ5ZÐ[aÓ5bÓc�÷cò cˆGð	Ü�K‰K˜˜gÔ&ß—u’uÙ“i—�÷ —uáñ! eøÜô Ü—‘˜t W¨aÔ0Ýûðúñ Ù÷ —u—u‘uáûÜô 	Ü�N‰N˜4 ¨!Ô,Ýûð	üsß   ŠAFÁ%D Á=DÁ>D ÂFÂ
AFÃ$E/ Ã4EÃ5E/ Ã8EÄEÄEÄE/ ÄEÄE/ ÄFÄD ÄE	Ä'EÄ>FÅE	Å	FÅE/ ÅEÅE/ ÅE,	ÅEÅ
E,	Å$E,	Å&E/ Å*FÅ,E/ Å/FÅ:FÆFÆFÆFc               ó$   € V ^8„  d   QhRRRRRR/# )r   rV   rW   r[  r   r   r*   r    )r!   s   "r"   r#   r°   .  s&   € ÷ iñ i°4ð iÀ#ð iÈ-ñ ir$   c                óÐ  a aaa€ \        S P                  RR4      '       g   R# ^ RIHp ^ RIHo \        S RR4      ;'       g    Ro\        \        S P                  V4      RR4      ;'       g    R	4      P                  4       pV'       d4   VS8w  d-   S! S P                  VS4      '       d   V# \        R
V: R24      h\        VVV V3R lV! S P                  4       4       R4      # )uU  The served (non-primary) profile whose own session store holds *raw_sid*, else ``None``
(the default profile's HTTP self-post). Blocking: reads served ``state.db`` files.

A served profile's ``api_server`` turn binds the RAW session id as its session key, so its
completion event names no profile: the only ownership proof is the served profile's own
store, exactly the rung the Kanban notifier applies. An event whose source DOES name a
served profile (structured key / persisted origin) must be owned by that profile or it
raises ``LookupError`` â€” never a wake in the default profile's store.
Úmultiplex_profilesFN)Ú_multiplex_profile_homes)Úsession_owned_by_profileÚ_primary_profile_namer‡  r)   r6   z!session is not in served profile z's own storec              3  óv   <"  € T F.  w  rVS8w  g   K  S! SP                   VS4      '       g   K*  Vx € K0  	  R # 5ir\   )r>   )r_   rí   Ú_homeÚprimaryr[  r|   r~  s   &  €€€€r"   ra   ÚLGatewayNotificationsMixin._served_api_server_wake_profile.<locals>.<genexpr>B  s;   øé € ð bÑ-R™k˜dØ ™ô Ù,DÀTÇ[Á[ÐRVÐX_×,`÷ ’TÓ-Rùs   ƒ9“9¯
9)r<   r>   rš   r}  rl  r~  r   r@  rf   rr  Únext)r|   rV   r[  r}  Úhintedr‚  r~  s   f&f  @@r"   rq  Ú9GatewayNotificationsMixin._served_api_server_wake_profile.  sÊ   û€ ô �t—{‘{Ð$8¸%×@Ò@ÙÝ8Ý9Ü˜$Ð 7¸Ó>×KÐKÀ)ˆÜ”W˜T×=Ñ=¸cÓBÀIÈtÓT×ZÐZÐXZÓ[×aÑaÓcˆß�f Ô'Ù'¨¯©°V¸W×EÒEØ�ÜÐ AÀ&ÁÈ<ÐXÓYÐYÜ÷ bÑ-EÀdÇkÁkÔ-Ró bØcgóið 	ir$   c               ó   € V ^8„  d   QhRR/# rU  r    )r!   s   "r"   r#   r°   E  s   € ÷ Xñ X¸ñ Xr$   c                óÊ  a€ ^ RI Hp VeY   V P                  V4      pVe
   V^ ,          # \        VRR4      RJ d*   V P                  P                  \        P                  4      # V P                  \        VRR4      4      p V! \        S4      V P                  V4      pVe   VP                  # \        V3R lVP                  4        4       R4      #   \         d    Rp LCi ; i)a  Adapter for a synthetic-event platform: alias-aware transport resolver first (one
Platform.RELAY adapter fronts N logical platforms; native wins), literal ``p.value`` scan as
fallback for minimal runner stubs / exotic platform strings when the resolver can't run.r4   NrÈ  FTr)   c              3  óR   <"  € T F  w  rVP                   S8X  g   K  Vx € K  	  R # 5ir\   )r7   )r_   r†   rW  r?  s   &  €r"   ra   ÚGGatewayNotificationsMixin._resolve_injection_adapter.<locals>.<genexpr>Y  s"   øé € ÐPÑ#3™4˜1°q·w±wÀ-Ñ7O—Q’QÓ#3ùs   ƒ'�
')r8   r5   Ú_transport_ownerr<   r?   r]   r   ÚRELAYrÊ  r>   r9   r“   r„  rÓ  )r|   r?  rÈ   r5   Úownerr?   r  s   &f&    r"   Ú_resolve_injection_adapterÚ4GatewayNotificationsMixin._resolve_injection_adapterE  sÖ   ø€ õ 	@ØÒØ×)Ñ)¨&Ó1ˆEØÒ Ø˜Q•x�Ü�vÐ=¸uÓEÈÓMØ—}‘}×(Ñ(¬¯©Ó8Ð8ð ×-Ñ-¬g°f¸iÈÓ.NÓOˆð	Ù3´H¸]Ó4KÈTÏ[É[ÐZbÓcˆJð Ò!Ø×%Ñ%Ð%ÜÔP 8§>¡>Ô#3ÓPÐRVÓWÐWøô	 ô 	ØŠJð	ús   ÂC ÃC"Ã!C"Úraise_not_acceptedc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   rQ  r   rV   rW   r�  rx   r   r©   r    )r!   s   "r"   r#   r°   [  s2   € ÷ ^ñ ^Øð^Ø$(ð^ØAEð^à	ñ^r$   c             ƒ  ó	  "  € ^ RI HpHpHp \        P
                  ! V P                  V4      G Rj  x€L
 pV'       g©   \        V4      pV'       dn   V P                  P                  \        P                  4      p	V	e)   V! V	4      '       g   V P                  W‘W‚4      G Rj  x€L
 # \        P                  RV4       R# \        P                  RVP                  RR4      4       R# \!        VP"                  R4      '       d   VP"                  P$                  M\'        VP"                  4      p
V P)                  W§4      p	V	'       g\   V
\        P                  P$                  8X  d=   \+        VR	R4      '       d*   V P                  P                  \        P                  4      p	V	'       g   R# V! V	4      '       gt   \'        VP                  R
4      ;'       g    R4      P-                  4       ;'       g     \'        VP.                  ;'       g    R4      pV P                  W‘W‚4      G Rj  x€L
 #  RR/p\1        V4      p\'        VP                  R4      ;'       g    R4      P-                  4       p^ RIHp V! V4      '       d   RVR&   VP7                  R4      '       d   WËR&   \'        VP                  R4      ;'       g    R4      P-                  4       pV'       d   WëR&   \'        VP                  R4      ;'       g    R4      P-                  4       pV'       d   WûR&   VP                  R4      ;p'       d   \9        V4      VR&   \'        VP                  R4      ;'       g    R4      P-                  4       ;'       g    RpV'       d   VVR&   \+        VRR4      '       d   ^ RIHp V! VRR7      p\?        V\@        PB                  VRVR7      p\        PE                  R W§P.                  VPF                  4       \+        V	R!R4      p\I        V4      '       d	   V! V4       V! V	V4      G Rj  x€L
  R#  EL EL• EL L  T d    T'       d   h  R# \J         d"   p\        PM                  R"T4        Rp?R# Rp?ii ; i5i)#aH  Inject a watch/completion notification as a synthetic message event.

Routing comes from the queued event, never the active foreground message. Returns
``True`` on adapter acceptance, ``False`` on retryable adapter failure, ``None`` with no
gateway route. Not transactional: a crash after acceptance can replay (at-least-once).
)ÚWakeNotAcceptedÚadapter_supports_pushÚadmit_internal_eventNz[Deferring watch notification for raw session %s: no api_server adapter to self-post throughFzCDropping watch notification with no routing metadata for process %sra  Úunknownr7   r)   rc   r6   Únotification_originÚprocess_registry_syntheticrY   rc  ri  rj  rZ   Úgateway_session_keyÚparent_session_idÚgateway_session_idr¬   Úgateway_proven_session_idÚcompletion_idsÚgateway_completion_idsr  Úoriginal_trigger_message_id)Úreplace_source)r  T)rN   Úmessage_typerÈ   Úinternalr”   uA   Watch pattern notification â€” injecting for %s chat=%s thread=%sÚprime_routing_cachez&Watch notification injection error: %s)'rl  r“  r”  r•  r   rp  r@  rj   r?   r]   r   rs  rx  r:   r;   rì   rÃ   r=   r7   r   rŽ  r<   rf   r/   rT   ro  rd  rh   rô  Úgateway.session_identityr   r   r   ÚTEXTrÀ   r0   Úcallabler9   r  )r|   rQ  rV   r�  r“  r”  r•  rÈ   r[  r“   r?  r”   rY   rd  rš  r¬   r�  Útrigger_message_idr   Úsynth_eventÚ_primerù   s   &&&$                  r"   rL  Ú4GatewayNotificationsMixin._inject_watch_notification[  s±  é € ÷ 	^Ñ]Ü×(Ò(¨×)IÑ)IÈ3ÓO×Oˆßä3°CÓ8ˆGßØŸ-™-×+Ñ+¬H×,?Ñ,?Ó@�ØÒ&Ñ/DÀW×/MÒ/MØ!%×!;Ñ!;¸GÐQXÓ!^×^Ð^Ü—‘ØqØôñ Ü�N‰NØUØ—‘˜ iÓ0ôñ Ü18¸¿¹È'×1RÒ1R˜Ÿ™×-Ò-ÔX[Ð\b×\kÑ\kÓXlˆØ×1Ñ1°-ÓHˆß˜=¬H×,?Ñ,?×,EÑ,EÔEÌ'ÐRXÐZcÐei×JjÒJjð —m‘m×'Ñ'¬×(;Ñ(;Ó<ˆGßÙÙ$ W×-Ò-ô ˜#Ÿ'™'Ð"5Ó6×<Ð<¸"Ó=×CÑCÓE×bÐbÌÈVÏ^É^×MaÐMaÐ_aÓIbˆGØ×3Ñ3°GÈÓV×VÐVð5	Ø(=Ð?[Ð'\ˆHÜ4°ZÓ@ˆJÜ˜cŸg™g mÓ4×:Ð:¸Ó;×AÑAÓCˆKÝPÙ'¨×,Ò,Ø4@�Ð0Ñ1Ø×%Ñ% h×/Ò/Ø2=Ð.Ñ/Ü # C§G¡GÐ,?Ó$@×$FÐ$FÀBÓ G× MÑ MÓ OÐß Ø1BÐ-Ñ.Ü # C§G¡GÐ,?Ó$@×$FÐ$FÀBÓ G× MÑ MÓ OÐß Ø8IÐ4Ñ5Ø!$§¡Ð)9Ó!:Ð:ˆ~Ö:Ü59¸.Ó5I�Ð1Ñ2ô "% S§W¡W¨\Ó%:×%@Ð%@¸bÓ!A×!GÑ!GÓ!I×!QÐ!QÈTÐß!Ø:L�Ð6Ñ7Ü�v˜|¨T×2Ò2ÝCÙ'¨¸4Ô@�Ü&Ø¬k×.>Ñ.>ÀvÐX\Ø!ôˆKô �K‰KØSØŸ~™~¨v×/?Ñ/?ôô ˜WÐ&;¸TÓBˆFÜ˜×ÒÙ�{Ô#Ù& w°Ó<×<Ð<ÙòY Pò _ò. WñZ =øàô 	ç!ØÚÜô 	Ü�L‰LÐAÀ1ÔEÝûð	üsõ   ‚/Q?±P3²Q?¾AQ?ÂQ?Â!P6Â"DQ?Æ)Q?Æ9Q?ÇQ?Ç2Q?ÈQ?È'P9È(Q?È-+P> É(P> ÊP> Ê P> Ê?P> Ë P> Ë=P> ÌP> Ì7*P> Í"P> Í>
P> Î	B#P> Ð,P<Ð-P> Ð1Q?Ð6Q?Ð9Q?Ð<P> Ð>Q<ÑQ<ÑQ?ÑQ<ÑQ<ÑQ7Ñ1Q?Ñ7Q<Ñ<Q?c               ó    € V ^8„  d   QhRRRR/# )r   rV   rW   r   z!Optional[tuple[str, str, object]]r    )r!   s   "r"   r#   r°   ¼  s   € ÷ ñ ¨4ð Ð4Uñ r$   c                ó  € \        V P                  R4      ;'       g    R4      pVR8X  dŽ   \        V P                  R4      ;'       g    R4      pV'       g   R# V P                  R4      '       dE   V P                  R4      ;'       g    / .^ ,          ;'       g    / P                  RR4      pWR	V 23# WR3# VR
8X  dF   \        V P                  R4      ;'       g    R4      pV P                  R4      pV'       d	   Ve   WV3# R# )a?  Return a producer-stable identity when one is available.

Delegation UUIDs identify one producer completion. Process session IDs include the
persisted spawn epoch so a reused ID is a distinct incarnation; legacy events without
``started_at`` are delivered undeduplicated rather than risk suppressing a real completion.
r�  r6   r_  r¦   NÚtask_failure_noticeÚresultsÚ
task_indexztask_failure:Ú
completionra  Ú
started_at©r   r]   )rV   Úevt_typeÚproducer_idÚtask_idxr±  s   &    r"   Ú_completion_delivery_identityÚ7GatewayNotificationsMixin._completion_delivery_identity»  sñ   € ô �s—w‘w˜v“×,Ð,¨"Ó-ˆØÐ)Ô)Ü˜cŸg™g oÓ6×<Ð<¸"Ó=ˆKßÙØ�w‰wÐ,×-Ò-ð !ŸW™W YÓ/×7Ð7°B°4¸Õ;×AÐA¸r×FÑFÀ|ÐUWÓX�Ø °¸x¸jÐ/IÐJÐJØ¨2Ð.Ð.Ø�|Ô#Ü˜cŸg™g lÓ3×9Ð9°rÓ:ˆKØŸ™ Ó.ˆJß˜zÒ5Ø ¨zÐ:Ð:Ùr$   c               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r°   Õ  s   € ÷ Fñ FÀñ Fr$   c                óð   € V F-  pV P                   P                  V4       RV P                  V&   K/  	  \        V P                  4      V P                  8”  d   V P                  P                  RR7       KB  R# )zeMove identities inflight -> delivered and trim retention. Caller holds ``_completion_delivery_lock``.NF)Úlast)Ú_completion_deliveries_inflightÚdiscardÚ _completion_deliveries_deliveredrG   Ú_completion_delivery_retentionÚpopitem)r|   Ú
identitiesÚidentitys   && r"   Ú"_mark_completions_delivered_lockedÚ<GatewayNotificationsMixin._mark_completions_delivered_lockedÕ  sh   € ã"ˆHØ×0Ñ0×8Ñ8¸ÔBØ>BˆD×1Ñ1°(Ó;ñ #ô �$×7Ñ7Ó8¸4×;^Ñ;^Ô^Ø×1Ñ1×9Ñ9¸uÐ9ÖEñ _r$   Úclaimc               ó    € V ^8„  d   QhRRRR/# )r   rÄ  rx   r   r    )r!   s   "r"   r#   r°   Ý  s   € ÷ ñ ¸Dð ÈTñ r$   c               ó
  € V P                   ;_uu_ 4        WP                  9   ;'       g    WP                  9   pV'       d$   V'       g   V P                  P                  V4       VuuRRR4       #   + '       g   i     R# ; i)z£True when ``identity`` is inflight or already delivered this gateway lifecycle.

With ``claim`` an unseen identity is atomically marked inflight (same lock hold).
N)Ú_completion_delivery_lockr»  r½  rý  )r|   rÁ  rÄ  Úseens   &&$ r"   Ú_completion_identity_seenÚ3GatewayNotificationsMixin._completion_identity_seenÝ  sf   € ð
 ×+×+Ó+à×@Ñ@Ñ@÷ Eð EØ×DÑDÑDð ÷ ŸTØ×4Ñ4×8Ñ8¸ÔBØ÷ ,×+×+Ó+ús   •,A1ÁA1Á
A1Á1B	c               ó$   € V ^8„  d   QhRRRRRR/# )r   rš  r   rY   r   r    )r!   s   "r"   r#   r°   ë  s(   € ÷ Zñ ZÀ3ð ZÐUXð ZÐbeñ Zr$   c              ƒ  óN   "  € V P                  W4      G Rj  x€L
 ^ ,          #  L5i)us  Classify an async-completion target before adapter acceptance: ``"deliver"`` (spawning
session live or compression-rotated with a live continuation; the resolver still retargets),
``"terminal"`` (parent gone for good â€” unknown / user boundary like /new; drop the durable row
rather than falsely ack), ``"retry"`` (DB unavailable / rotation mid-flight; defer the claim).N)Ú_classify_completion_owner)r|   rš  rY   s   &&&r"   Ú_classify_completion_targetÚ5GatewayNotificationsMixin._classify_completion_targetë  s%   é € ð
 ×5Ñ5Ð6GÓU×UÐWXÕYÐYÑUùs   ‚%—#˜%c               ó$   € V ^8„  d   QhRRRRRR/# )r   rš  r   rY   r   ztuple[str, str, str]r    )r!   s   "r"   r#   r°   ò  s(   € ÷ !Rñ !RÀ#ð !RÐTWð !RÐauñ !Rr$   c              ƒ  óî  "  € ^ RI Hp \        V RR4      pVf   R# RpV'       d_    \        \        V 4      P
                  p\        P                  ! VP                  4      G Rj  x€L
  VP                  P                  V4      pT P                  Y'       d   VP                  MR4      G Rj  x€L
 w  rqpTp	VR8X  dn   Vej   VP                  R	4      '       dS   \!        VP                  R
4      ;'       g    R4      p
V
R8w  d   W£9   d   RMRpMV P#                  WEV4      G Rj  x€L
 w  ryVR8w  d   VRR3# YqT	;'       g    T3#  Lß  \         d    \        P                  RTRR7       Ru # i ; i LÄ LO5i)zí``_classify_completion_target``'s verdict and, on ``"deliver"``, the owning session it proved
(a delegate child's pin resolved through ``model_config._delegate_from``) and the session delivery
reaches (the owner, or its compression tip).)Ú_USER_BOUNDARY_END_REASONSÚ_session_dbNr6   z%Completion route lookup failed for %sTr»   rw  Úended_atÚ
end_reasonÚcompressionÚterminal)Úretryr6   r6   )rš   rÒ  r<   r	   r   r5  r   rp  r6  r7  r]   r9   r:   r;   Ú_lookup_completion_ownerra  r   Ú#_resolve_compression_lineage_target)r|   rš  rY   rÒ  Ú
session_dbr=  r5  ÚverdictÚparentÚtarget_session_idrÕ  s   &&&        r"   rÍ  Ú4GatewayNotificationsMixin._classify_completion_ownerò  st  é € õ 	;Ü˜T =°$Ó7ˆ
ØÒØ"Ð"Øˆßð'Ü.2´3¸«o×.KÑ.K�Ü×'Ò'¨×(DÑ(DÓE×EÐEØ%×.Ñ.×2Ñ2°;Ó?�ð 48×3PÑ3PØ¶5˜u×/Ò/¸bó4
÷ .
Ñ*ˆ Fð .ÐØ�iÔ FÒ$6¸6¿:¹:Àj×;QÒ;QÜ˜VŸZ™Z¨Ó5×;Ð;¸Ó<ˆJØ˜]Ô*ð )3Ô(P™*ÐV_‘à37×3[Ñ3[ØÐ'8ó4÷ .Ñ*�ð �iÔØ˜B �?Ð"ØÐ+<×+QÐ+QÐ@QÐQÐQñ+ Føäô 'Ü—‘ÐDÀkÐ\`�ÔaØ&Ò&ð'úñ.
ñ.ùsj   ‚#E5§=E Á$EÁ%E Â(E5Â,E1Â-*E5ÃE5Ã5.E5Ä#E3Ä$E5Å E5ÅE Å%E.Å+E5Å-E.Å.E5Å3E5c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úkindr   r¦   r§   r   r�   r    )r!   s   "r"   r#   r°     s.   € ÷ jñ j Cð j¸ð jÀsð jÈtñ jr$   c                óò   € \         V ,          w  r4 ^ RIHp \        WS4      ! W4       R#   \         dB    \
        P                  T R8X  d   \        P                  M\        P                  TRR7        R# i ; i)z?Best-effort ``drop``/``release`` of a durable completion claim.NrL   Tr»   )
Ú_DURABLE_CLAIM_OPSÚtools.async_delegationr_  r<   r9   r:   ÚlogrÅ   rå   rÆ   )rá  r¦   r§   Úfn_nameÚfail_msgÚ_ads   &&&   r"   Ú_settle_durable_claimÚ/GatewayNotificationsMixin._settle_durable_claim  s]   € ô /¨tÕ4Ñˆð	jÝ0Ü�CÔ! -Ö:øÜô 	jÜ�J‰J¨$°*Ô*<”w—’Ä'Ç-Á-ÐQYÐdhˆJ×ið	jús   ‘* ªAA6Á5A6c               ó    € V ^8„  d   QhRRRR/# )r   rV   rW   r   rx   r    )r!   s   "r"   r#   r°     s   € ÷ ñ °Dð ¸Tñ r$   c              ƒ  óà  "  € ^ RI Hp \        VP                  R4      ;'       g    R4      P	                  4       pV'       dI   T P                  T\        VP                  R4      ;'       g    R4      4      G Rj  x€L
 pVR8w  d   VR8H  # \        P                  ! V P                  V4      G Rj  x€L
 pVeZ   \        VP                  R4      '       d   VP                  P                  M\        VP                  4      pV P                  We4      pMR\        V4      pV'       d*   V P                  P                  \        P                   4      MRpVe   V! V4      '       d   R	# Vf   R	# V! V4      '       gE   \#        VR
R4      p	 \%        V	4      '       d!   \        P                  ! V	4      G Rj  x€L
 f   R	#  R# R#  ELC EL L  \&         d    \(        P+                  RRR7        R	# i ; i5i)zHUnavailable owners/transports must not spend a durable delivery attempt.)r”  rš  r6   rY   Nrw  r×  r7   FÚ_ensure_session_dbz(Async-completion delivery DB unavailableTr»   )rl  r”  r   r]   rf   rÎ  r   rp  r@  rÃ   r=   r7   rŽ  rj   r?   r   rs  r<   r¦  r9   r:   r;   )
r|   rV   r”  rš  rÜ  rÈ   r=   r“   r[  Úensures
   &&        r"   Ú_completion_delivery_readyÚ4GatewayNotificationsMixin._completion_delivery_ready  s™  é € å6ä §¡Ð(;Ó <× BÐ BÀÓC×IÑIÓKÐßØ ×<Ñ<Ð=NÔPSÐTW×T[ÑT[Ð\iÓTj×TpÐTpÐnpÓPqÓr×rˆGØ˜)Ô#à *Ñ,Ð,Ü×(Ò(¨×)IÑ)IÈ3ÓO×OˆØÒÜ07¸¿¹È×0QÒ0Q�v—‘×,Ò,ÔWZÐ[a×[jÑ[jÓWkˆHØ×5Ñ5°hÓG‰Gä3°CÓ8ˆGß@G�d—m‘m×'Ñ'¬×(;Ñ(;Ô<ÈTˆGØÒ"Ñ'<¸W×'EÒ'EÙØŠ?ÙÙ$ W×-Ò-Ü˜WÐ&:¸DÓAˆFðÜ ×'Ò'´×1BÒ1BÀ6Ó1J×+JÒ+RÙ ð ,Só
 ò/ sò Pñ ,Køäô Ü—‘ÐGÐRV�ÔWÚðüss   ‚A G.Á(G.Á,G.Á:F=Á;4G.Â/G Â0B0G.Å!G.Å7G.Æ*G Æ/GÆ0G Æ6G.Ç G.ÇG Ç"G+Ç'G.Ç*G+Ç+G.c               ó    € V ^8„  d   QhRRRR/# )r   rV   rW   r   r­   r    )r!   s   "r"   r#   r°   >  s   € ÷ <ñ <¸ð <ÐAQñ <r$   c              ƒ  ó–  "  € V P                  4       pVP                  R4      pVR8X  d1   V P                  V4      G Rj  x€L
 '       g   RRuVn        Vn        V# VR8X  d¿   VP                  R4      '       g¨   \        VP                  R4      ;'       g    R4      Vn        VP                  '       dl    ^ RIHp R	\        V 4       R
\        R4      P                  4       P                   2Vn        V! VP                  VP                  4      '       g
   RVn        V# M
M	VR8w  d   V# \        VP                  R4      ;'       g    R4      P#                  4       pV'       g   V# T P%                  T\        VP                  R4      ;'       g    R4      4      G Rj  x€L
 w  qrn        Vn        VR8X  d¦   VR8X  df   \        P!                  RVP                  ;'       g    RV4       VP                  '       d(   V P+                  RVP                  VP                  4       M0\        P!                  RVP                  R4      ;'       g    RV4       RVn        V# VR8X  d   RRRuVn        Vn        Vn        V#  EL:  \         d=   p\        P!                  RTP                  T4       RRuTn        Tn        Tu Rp?# Rp?ii ; i EL*5i)a3  Claim the durable row (async delegations) and verify the target before adapter acceptance.

Adapter acceptance is not proof of delivery: the inner resolver can still fail closed inside
the pipeline after acceptance, falsely acking the durable row. Verifying first gives drops an
honest durable disposition.
r�  r_  NFr­  r¦   r6   )Úclaim_completion_deliveryzgateway:r.   Úuuidz/Could not claim durable async completion %s: %sr°  rš  rY   r×  z�Async delegation %s targets permanently-gone session %s; terminally dropping delivery (result remains in the delegation records).z<legacy>rI   z®Background process %s completion targets permanently-gone session %s (user boundary such as /new); dropping notification (output remains available via process(action='log')).ra  z	<unknown>rØ  T)r­   r]   rï  r¨   rª   r   r¦   rä  ró  ÚidÚ
__import__Úuuid4Úhexr§   r9   r:   rì   rf   rÍ  r«   r¬   ré  rK   )r|   rV   rÄ  r³  ró  r@   rš  rÜ  s   &&      r"   Ú_preflight_completion_deliveryÚ8GatewayNotificationsMixin._preflight_completion_delivery>  s�  é € ð ×%Ñ%Ó'ˆØ—7‘7˜6“?ˆØÐ)Ô)¸×8WÑ8WÐX[Ó8\×2\Ö2\Ø05°uÐ-ˆEŒM˜5Ô-ØˆLð Ð)Ô)°#·'±'Ð:O×2PÒ2PÜ"% c§g¡g¨oÓ&>×&DÐ&DÀ"Ó"EˆEÔØ×"×"Ð"ð	!ÝPØ'/´°4³¨z¸¼:ÀfÓ;M×;SÑ;SÓ;U×;YÑ;YÐ:ZÐ%[�E”NÙ4°U×5HÑ5HÈ%Ï.É.×YÒYØ(-˜œØ$˜ð Zð	 #ð ˜Ô%ØˆLô   §¡Ð(;Ó <× BÐ BÀÓC×IÑIÓKÐß ØˆLð
 JN×IhÑIhØœs 3§7¡7¨=Ó#9×#?Ð#?¸RÓ@óJB÷ DBÑ@ˆÔ'¨Ô)@à�jÔ ØÐ-Ô-Ü—‘ð_à×'Ñ'×5Ð5¨:Ð7Hôð
 —>—>�>Ø×.Ñ.¨v°u×7JÑ7JÈEÏNÉNÔ[øä—‘ðið —G‘G˜LÓ)×8Ð8¨[Ð:Kô	ð "ˆEŒMð ˆð ˜Ôà=BÀEÈ4Ð:ˆEŒM˜5Ô-¨u¬{Øˆòg 3]øô !ô !Ü—N‘NÐ#TÐV[×ViÑViÐknÔoØ8=¸uÐ5�E”M 5Ô#5Ø •Lûð!úòDBùs…   ‚=K	¿I9Á 	K	Á
.K	Á9K	ÂK	Â5A(I< Ä(K	ÅK	Å#*K	ÆK	ÆKÆAK	ÇK	Ç9AK	É	1K	É<KÊ1J>Ê8KÊ9K	Ê>KËK	c               ó   € V ^8„  d   QhRR/# r'  r    )r!   s   "r"   r#   r°   |  s   € ÷ :ñ :¨4ñ :r$   c                óŽ  € ^ RI Hp ^ RIHp V P	                  V4      pVe   \        VRR4      '       gP   \        V4      pV'       d0   \        \        V RR4      RR4      '       d   V P                  W4      # ^ RIH	p V! 4       # V P                  V4      pV! 4       \        V4      8X  d   \        P                  ! 4       # V! V4      # )	uv  Profile runtime scope of the session a completion event targets (a no-op context when the
event is the default profile's or the scope is already installed).

The pre-flight (``_classify_completion_target`` â†’ ``_session_db``) and every durable-ledger op
(``tools.async_delegation`` â†’ ``get_hermes_home()/state.db``) resolve from the ambient scope.
The supervised ``_async_delegation_watcher`` and startup-recovered process watchers run under
the ROOT scope, so a secondary profile's completion was looked up in the DEFAULT profile's
state.db â€” classified ``terminal`` and dropped, its ledger row stranded ``pending`` forever.re  )Úget_hermes_home_overrideNr)   r>   r|  F©Ú)async_launch_profile_scope_if_multiplexed)rš   rf  r  rý  r@  r<   rj   Ú_served_api_server_event_scopeÚ!tui_gateway.launch_profile_policyrÿ  rt  r   rm  rn  )r|   rV   rf  rý  rÈ   r[  rÿ  Úprofile_homes   &&      r"   rI  Ú1GatewayNotificationsMixin._completion_event_scope|  s­   € õ 	=Ý=Ø×1Ñ1°#Ó6ˆØŠ>¤¨°¸D×!AÒ!AÜ3°CÓ8ˆGßœ7¤7¨4°¸4Ó#@ÐBVÐX]×^Ò^Ø×:Ñ:¸3ÓHÐHõ dÙ<Ó>Ð>Ø×<Ñ<¸VÓDˆÙ#Ó%¬¨\Ó):Ô:Ü×)Ò)Ó+Ð+Ù+¨LÓ9Ð9r$   c               ó    € V ^8„  d   QhRRRR/# )r   rV   rW   r[  r   r    )r!   s   "r"   r#   r°   —  s   € ÷ ñ ¸ð Àsñ r$   c               ó’  "  € ^ RI Hp ^ RIHp \        P
                  ! V P                  W4      G Rj  x€L
 pV'       d4   \        \        P                  W%R7      pV! V P                  V4      4      pMV! 4       pT;_uu_4       GRj  x€L
  R5x € RRR4      GRj  x€L
  R#  Lp L L
  + GRj  x€L 
 '       g   i     R# ; i5i)zžScope of the served profile whose own store holds a raw api_server session (its events name no
profile), else the launch profile's, as for any unrouted event.re  rþ  Nrg  )rš   rf  r  rÿ  r   rp  rq  r   r   rs  rt  )r|   rV   r[  rf  rÿ  rk  rÈ   ru  s   &&&     r"   r   Ú8GatewayNotificationsMixin._served_api_server_event_scope–  s   é € õ 	=Ý_Ü×(Ò(¨×)MÑ)MÈsÓ\×\ˆßÜ"¬H×,?Ñ,?ÈÔaˆFÙ0°×1VÑ1VÐW]Ó1^Ó_‰Eá=Ó?ˆEß—5’5Ü÷ —5‘5ñ ]÷ —5—5•5üsd   ‚1C³B$´CÁ ACÂB&Â	CÂB*ÂCÂB(ÂCÂ&CÂ(CÂ*C	Â0B3Â1
C	Â<C	Â>	CÚsibling_claimsc               ó$   € V ^8„  d   QhRRRRRR/# ©r   rQ  r   rV   rW   r   r©   r    )r!   s   "r"   r#   r°   ¥  s)   € ÷ 
@ñ 
@Øð
@Ø$(ð
@à	ñ
@r$   c             ƒ  óî   "  € V P                  V4      ;_uu_4       GRj  x€L
  V P                  WVR7      G Rj  x€L
 uuRRR4      GRj  x€L
  #  L1 L L	  + GRj  x€L 
 '       g   i     R# ; i5i)zðAcknowledge one admitted batch, refund refusals, or release failed deliveries.

True means adapter admission, not model execution; None means deduplicated or
terminal. False remains retryable. Claims are settled together for every sibling.
N©r  )rI  Ú'_deliver_completion_notification_scoped)r|   rQ  rV   r  s   &&&$r"   Ú _deliver_completion_notificationÚ:GatewayNotificationsMixin._deliver_completion_notification¥  sZ   é € ð ×/Ñ/°×4×4Õ4Ø×EÑEØ°ð Fó @÷ @÷ 5×4Ô4ñ@÷ 5×4×4Ó4üsY   ‚A5 A¡A5¤A»A¼A¿A5ÁAÁA5ÁAÁA5ÁA2	ÁA!Á
A2	Á*A2	Á,	A5c               ó$   € V ^8„  d   QhRRRRRR/# r	  r    )r!   s   "r"   r#   r°   ±  s)   € ÷ 0kñ 0kØð0kØ$(ð0kà	ñ0kr$   c          
   ƒ  	ó^  "  € ^ RI Hp ^ RIHp V! V4      '       g   R# V P	                  V4      pV P                  4       pR;p;rš V P                  V4      G Rj  x€L
 pVP                  '       Eg   VP                  V	'       dA   V'       g9   V P                  ;_uu_ 4        V P                  P                  V4       RRR4       V'       d   RMV
'       g   VP                  '       d   RMRpVP                  '       d'   V P                  W·P                  VP                  4       V F(  w  rÍV'       g   K  V P                  W¼R,          V4       K*  	  V'       d0   V'       d'   T P!                  V UUu. uF  w  rïVNK	  	  upp4       # # # VEe/   V P#                  VR	R
7      '       Ed    V	'       dA   V'       g9   V P                  ;_uu_ 4        V P                  P                  V4       RRR4       V'       d   RMV
'       g   VP                  '       d   RMRpVP                  '       d'   V P                  W·P                  VP                  4       V F(  w  rÍV'       g   K  V P                  W¼R,          V4       K*  	  V'       d2   V'       d(   T P!                  V UUu. uF  w  rïVNK	  	  upp4       R# R# R# R	p	VP$                  '       d   / VCRVP$                  RVP&                  /CpVP                  '       d   VP                  .M. pTV UUu. uF  w  rÍV'       g   K  VR,          NK  	  upp,          p/ VCRV/CpV P)                  WR	R7      G Rj  x€L
 pVR	JEd   TV	'       dA   V'       g9   V P                  ;_uu_ 4        V P                  P                  V4       RRR4       V'       d   RMV
'       g   VP                  '       d   RMRpVP                  '       d'   V P                  W·P                  VP                  4       V F(  w  rÍV'       g   K  V P                  W¼R,          V4       K*  	  V'       d0   V'       d'   T P!                  V UUu. uF  w  rïVNK	  	  upp4       # # # R	pVe0   V P                  ;_uu_ 4        V P+                  V34       RRR4        V	'       dA   V'       g9   V P                  ;_uu_ 4        V P                  P                  V4       RRR4       V'       d   RMV
'       g   VP                  '       d   RMRpVP                  '       d'   V P                  W·P                  VP                  4       V F(  w  rÍV'       g   K  V P                  W¼R,          V4       K*  	  V'       d2   V'       d(   T P!                  V UUu. uF  w  rïVNK	  	  upp4       R	# R	# R	#  ELc  + '       g   i     EL; iu uppi   + '       g   i     ELø; iu uppi u uppi  ELŸ  + '       g   i     EL^; iu uppi   + '       g   i     EL}; i  + '       g   i     ELH; iu uppi   T Ed1    R	p
 T	'       dU   T'       gM   T P                  ;_uu_ 4        T P                  P                  T4       RRR4       M  + '       g   i     M; iT'       d   RMT
'       g   TP                  '       d   RMRpTP                  '       d'   T P                  Y·P                  TP                  4       T F(  w  rÍT'       g   K  T P                  Y¼R,          T4       K*  	  T'       d9   T'       d/   T P!                  T UUu. uF  w  rïTNK	  	  Mu uppi upp4       R# R# R# i ; i  T	'       dU   T'       gM   T P                  ;_uu_ 4        T P                  P                  T4       RRR4       M  + '       g   i     M; iT'       d   RMT
'       g   TP                  '       d   RMRpTP                  '       d'   T P                  Y·P                  TP                  4       T F(  w  rÍT'       g   K  T P                  Y¼R,          T4       K*  	  T'       d7   T'       d.   T P!                  T UUu. uF  w  rïTNK	  	  Mu uppi upp4       i i i ; i5i)r–   )r“  rF  NFrL   rK   rJ   r¦   T)rÄ  rš  r¬   r�  )r�  )rl  r“  rJ  rG  r¶  r­   rù  r¨   rª   rÇ  r»  r¼  rK   r§   ré  r¦   Ú%_record_coalesced_completion_siblingsrÉ  r«   r¬   rL  rÂ  )r|   rQ  rV   r  r“  rG  rÁ  rÄ  ÚacceptedÚidentity_claimedÚrefusedÚ	operationÚsiblingr§   rÏ   Ú	_claim_idr�  Úinjection_results   &&&$              r"   r  ÚAGatewayNotificationsMixin._deliver_completion_notification_scoped±  s‚  é € õ 	1ÝTÙ*¨3×/Ò/ÙØ×5Ñ5°cÓ:ˆØ×%Ñ%Ó'ˆØ05Ð5ˆÐ5Ð#ð&	kØ×=Ñ=¸cÓB×BˆEØ—=—=‘=Ø×)Ñ)÷2  ¯Ø×3×3Ó3Ø×8Ñ8×@Ñ@ÀÔJ÷ 4ç&.™
¿wÈ%Ï+Ï+È+±GÐ[dˆIØ�~�~ˆ~Ø×*Ñ*¨9×6IÑ6IÈ5Ï>É>ÔZÛ%3Ñ!�ß‘8Ø×.Ñ.¨yÀ/Õ:RÐT\Ö]ñ &4÷ ŸNØ×:Ñ:ÑZhÔ;iÑZhÑFVÀe»EÑZhÒ;iÕjð +ˆxðC Ó#Ø×1Ñ1°(À$Ð1×GÓGØ÷,  ¯Ø×3×3Ó3Ø×8Ñ8×@Ñ@ÀÔJ÷ 4ç&.™
¿wÈ%Ï+Ï+È+±GÐ[dˆIØ�~�~ˆ~Ø×*Ñ*¨9×6IÑ6IÈ5Ï>É>ÔZÛ%3Ñ!�ß‘8Ø×.Ñ.¨yÀ/Õ:RÐT\Ö]ñ &4÷ ŸNØ×:Ñ:ÑZhÔ;iÑZhÑFVÀe»EÑZhÒ;iÖjñ +‰xð= $(Ð Ø×%×%Ð%ðE˜ð EÐ1°5×3IÑ3IØ*¨E×,CÑ,CñE�ð 7<·n·n°n˜e×1Ñ1Ñ2È"ˆNØÑQ_ÔlÑQ_Ñ<M¸GÔckÔ7˜w ×7Ð7ÑQ_ÒlÕlˆNØ;�SÐ;Ð*¨NÑ;ˆCØ%)×%DÑ%DÀZÐimÐ%DÓ%n×nÐØ tÔ+Ø'÷  ¯Ø×3×3Ó3Ø×8Ñ8×@Ñ@ÀÔJ÷ 4ç&.™
¿wÈ%Ï+Ï+È+±GÐ[dˆIØ�~�~ˆ~Ø×*Ñ*¨9×6IÑ6IÈ5Ï>É>ÔZÛ%3Ñ!�ß‘8Ø×.Ñ.¨yÀ/Õ:RÐT\Ö]ñ &4÷ ŸNØ×:Ñ:ÑZhÔ;iÑZhÑFVÀe»EÑZhÒ;iÕjð +ˆxð% ˆHØÒ#Ø×3×3Ó3Ø×;Ñ;¸X¸KÔH÷ 4à÷
  ¯Ø×3×3Ó3Ø×8Ñ8×@Ñ@ÀÔJ÷ 4ç&.™
¿wÈ%Ï+Ï+È+±GÐ[dˆIØ�~�~ˆ~Ø×*Ñ*¨9×6IÑ6IÈ5Ï>É>ÔZÛ%3Ñ!�ß‘8Ø×.Ñ.¨yÀ/Õ:RÐT\Ö]ñ &4÷ ŸNØ×:Ñ:ÑZhÔ;iÑZhÑFVÀe»EÑZhÒ;iÖjñ +‰xòI C÷8 4×3Ð3üó <j÷ 4×3Ð3üó <jùó1 mân÷ 4×3Ð3üó <j÷# 4×3Ð3ú÷ 4×3Ð3üó <jøð õ 	ØˆGØç¯Ø×3×3Ó3Ø×8Ñ8×@Ñ@ÀÔJ÷ 4×3×3Ð3úç&.™
¿wÈ%Ï+Ï+È+±GÐ[dˆIØ�~�~ˆ~Ø×*Ñ*¨9×6IÑ6IÈ5Ï>É>ÔZÛ%3Ñ!�ß‘8Ø×.Ñ.¨yÀ/Õ:RÐT\Ö]ñ &4÷ ŸNØ×:Ñ:ÑZhÔ;iÑZhÑFVÀe»EÒZhùÖ;iÖjñ +‰xð	û÷  ¯Ø×3×3Ó3Ø×8Ñ8×@Ñ@ÀÔJ÷ 4×3×3Ð3úç&.™
¿wÈ%Ï+Ï+È+±GÐ[dˆIØ�~�~ˆ~Ø×*Ñ*¨9×6IÑ6IÈ5Ï>É>ÔZÛ%3Ñ!�ß‘8Ø×.Ñ.¨yÀ/Õ:RÐT\Ö]ñ &4÷ ŸNØ×:Ñ:ÑZhÔ;iÑZhÑFVÀe»EÒZhùÖ;iÕjð +ˆxüs¸  ‚Ab-ÁY ÁV=ÁY Á2Y Á=b-Âb-Â!W Â=b-Ã	b-Ãb-Ã)b-Ã?2b-Ä6$b-Åb-Å#b-Å3WÆ b-ÆY Æ+b-Æ;b-ÇWÇ+b-Ç;	b-Èb-Èb-È-2b-É$$b-Ê	b-Êb-Ê!W.
Ê.b-Ê<Y Ë/Y Ì Y ÌW4Ì&W4Ì3(Y ÍW:ÍY Í(b-Í8b-ÎW=Î(b-Î8	b-Ïb-Ïb-Ï*2b-Ð!$b-Ñb-Ñb-ÑXÑ+b-Ñ6Y ÒXÒ#Y Ò,b-Ò<b-ÓX+Ó,b-Ó<	b-Ôb-Ôb-Ô.2b-Õ%$b-Ö
b-Öb-Ö"X?
Ö/b-Ö=Y × W×b-×W+	×%b-×4Y ×=XØb-ØX(	Ø"	Y Ø+X<	Ø6b-Ù
]=Ù^  Ùb-Ù b-Ù4ZÚ	b-ÚZ)	Ú$b-Ú4	b-Ú>b-Ûb-Û&2b-Ü$b-Ýb-Ý
b-Ý](
Ý'b-Ý<]=Ý=^  Þ b*Þb*Þ%_
	ß	b*ß
_ßb*ß%	b*ß/b*àb*à2b*á$b*á3b*á;b*âbâb*â*b-c               ó$   € V ^8„  d   QhRRRRRR/# )r   rV   rW   Úfieldsútuple[str, ...]r   r    )r!   s   "r"   r#   r°   ä  s&   € ÷ Dñ D˜dð D¨Oð DÀñ Dr$   c                	óh   a € \         ;QJ d    . V 3R  lV 4       F  NK  	  5# ! V 3R  lV 4       4      # )c              3  ól   <"  € T F)  p\        SP                  V4      ;'       g    R 4      x € K+  	  R# 5ir¤  r²  r^   s   & €r"   ra   Ú=GatewayNotificationsMixin._event_route_key.<locals>.<genexpr>å  s)   øé € ÐC¹F°5”S˜Ÿ™ ›×-Ð-¨2×.Ð.»Fùs   ƒ!4¥4)r,   )rV   r  s   f&r"   Ú_event_route_keyÚ*GatewayNotificationsMixin._event_route_keyã  s%   ø€ çŒuÔC¹FÓC�uÐCˆuÔC¹FÓCÓCÐCr$   c               ó    € V ^8„  d   QhRRRR/# )r   Úentriesz&list[tuple[str, dict, asyncio.Future]]r   r   r    )r!   s   "r"   r#   r°   è  s   € ÷  ñ  Ð7]ð  Ðbeñ  r$   c           	     óÊ  € ^ RI Hp R\        V 4       R2R.pV R,          pV Fä  w  rEp\        VP	                  R4      ;'       g    R4      pVP	                  R4      p\        VP	                  R	4      ;'       g    R
4      p	T! \        VP	                  R4      ;'       g    R4      4      P                  4       p
\        V
4      R8”  d	   RV
RR  2p
VP                  RV RV RV	 24       V
'       g   KÓ  VP                  V
4       Kæ  	  \        V 4      \        V4      ,
          pV'       d   VP                  RV R24       VP                  R4       RP                  V4      # )zDBuild one bounded synthetic event from several redacted completions.©Ú#_redact_gateway_user_facing_secretsú[IMPORTANT: z1 background processes completed for this session.zcTreat these results as one completion batch and send at most one consolidated user-facing response.:Né
   Nra  r–  rs   Úcompletion_reasonÚexitedrC   r6   r¿  u   [â€¦ truncated â€¦]
Nz
- z: exit_code=z	, reason=u   
- â€¦ and zV more completion(s); inspect them with the process tool if they affect the conclusion.zHIf a result does not change the current conclusion, absorb it silently.]Ú
iàüÿÿ)rš   r&  rG   r   r]   rf   ÚappendÚjoin)r#  r&  ÚlinesÚshownÚ_textrV   Ú_futurera  rs   r¶  rC   Úomitteds   &           r"   Ú%_format_coalesced_process_completionsÚ?GatewayNotificationsMixin._format_coalesced_process_completionsç  sR  € õ 	Dàœ3˜w›<˜.Ð(YÐZð1ð
ˆð
 ˜•ˆÛ#(ÑˆE˜Ü˜SŸW™W \Ó2×?Ð?°iÓ@ˆJØŸ™ Ó,ˆIÜ˜Ÿ™Ð!4Ó5×AÐA¸ÓBˆFñ 9¼¸S¿W¹WÀXÓ=N×=TÐ=TÐRTÓ9UÓV×\Ñ\Ó^ˆFÜ�6‹{˜SÔ Ø0°¸¸°°Ð@�Ø�L‰L˜4 
˜|¨<¸	°{À)ÈFÈ8ÐTÔUß‰vØ—‘˜VÖ$ñ $)ô �g“,¤ U£Õ+ˆßØ�L‰LØ˜w˜ið (Bð Bôð 	�‰Ð_Ô`Ø�y‰y˜ÓÐr$   c               ó    € V ^8„  d   QhRRRR/# )r   Úeventsú
list[dict]r   r�   r    )r!   s   "r"   r#   r°     s   € ÷ @ñ @¸Jð @È4ñ @r$   c                óè   € \        V P                  V4       Uu. uF
  q"f   K  VNK  	  ppV P                  ;_uu_ 4        V P                  V4       RRR4       R# u upi   + '       g   i     R# ; i)zCExtend a successful primary delivery claim to its batched siblings.N)Úmapr¶  rÇ  rÂ  )r|   r6  r‚  rÀ  s   &&  r"   r  Ú?GatewayNotificationsMixin._record_coalesced_completion_siblings  sY   € ä!$ T×%GÑ%GÈÔ!PÓbÑ!P˜A—a�aÑ!Pˆ
ÐbØ×+×+Ó+Ø×3Ñ3°JÔ?÷ ,Ñ+ùò cß+×+Ð+ús   ™A£A¿A Á A1	c               ó    € V ^8„  d   QhRRRR/# )r   Úkeyr  r   r�   r    )r!   s   "r"   r#   r°     s   € ÷ %Iñ %I¸ð %IÈTñ %Ir$   c           
   ƒ  óF  "  € \         P                  ! 4       p. pRp \         P                  ! V P                  4      G Rj  x€L
  V P                  P                  V. 4      pV P                  P                  V4      VJ d   V P                  P                  VR4       V'       gR    V P                  W44       V P                  P                  V4      VJ d   V P                  P                  VR4       R# R# \        V4      ^8X  d   V^ ,          ^ ,          MV P                  V4      pRpV F%  w  rgpV P                  WW4      G Rj  x€L
 pVf   K%   M	  VRJ d8   \        V4      ^8”  d(   T P                  V UU	Uu. uF  w  riq‰NK	  	  upp	p4       T P                  Y44       T P                  P                  T4      TJ d   T P                  P                  TR4       R# R#  EL  Lžu upp	pi   \         P                   d)    RpT'       g   T P                  P                  T. 4      ph \         d    \        P!                  R4       Rp L»i ; i  T P                  Y44       T P                  P                  T4      TJ d   T P                  P                  TR4       i i ; i5i)zBDeliver one short-window completion batch and resolve its waiters.FNTz,Coalesced process completion delivery failed)r   Úcurrent_taskrb  Ú%_completion_notification_batch_windowÚ _completion_notification_batchesÚpopÚ$_completion_notification_batch_tasksr]   Ú_settle_batch_waitersrG   r3  r  r  ÚCancelledErrorr9   r:   rM  )
r|   r<  r>  r#  rõ  rQ  r0  Úcandidate_evtr1  rV   s
   &&        r"   Ú_flush_process_completion_batchÚ9GatewayNotificationsMixin._flush_process_completion_batch  sR  é € ä×+Ò+Ó-ˆØ:<ˆØ$)ˆ	ð 	IÜ—-’- × JÑ JÓK×KÐKØ×;Ñ;×?Ñ?ÀÀRÓHˆGà×8Ñ8×<Ñ<¸SÓAÀ\ÓQØ×9Ñ9×=Ñ=¸cÀ4ÔHßØð, ×&Ñ& wÔ:à×8Ñ8×<Ñ<¸SÓAÀ\ÓQØ×9Ñ9×=Ñ=¸cÀ4ÖHñ Rô/ +.¨g«,¸!Ô*;˜ � AžÀ×AkÑAkÐlsÓAtˆJð ˆIÛ18Ñ-� gØ"&×"GÑ"GÈ
Ó"b×b�	ØÔ(Ùñ 29ð ˜DÓ ¤S¨£\°AÔ%5Ø×:Ñ:Ñ[bÕ;cÑ[bÑDWÀEÐPWºCÑ[bÓ;cÔdð ×&Ñ& wÔ:à×8Ñ8×<Ñ<¸SÓAÀ\ÓQØ×9Ñ9×=Ñ=¸cÀ4ÖHñ Rò= Lñ cùô <døÜ×%Ñ%ô 	àˆIßØ×?Ñ?×CÑCÀCÈÓL�ØÜô 	Ü×ÑÐKÔLØŠIð	ûð
 ×&Ñ& wÔ:à×8Ñ8×<Ñ<¸SÓAÀ\ÓQØ×9Ñ9×=Ñ=¸cÀ4ÕHð Rüs�   ‚J!�#G, Á G ÁA"G, Â%AJ!Ã5AG, ÅG#ÅG, Å+G, Å:G%Æ	G, ÆAJ!Ç G, Ç#G, Ç%G, Ç,IÈ%IÈ1IÉ	I ÉIÉI ÉAJÊJ!c               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r°   4  s   € ÷ *ñ *°$ñ *r$   c                	óp   € V  F/  w  r#pVP                  4       '       d   K  VP                  V4       K1  	  R # r\   )r  Ú
set_result)r#  rË   r0  Ú_evtÚfutures   &&   r"   rC  Ú/GatewayNotificationsMixin._settle_batch_waiters3  s*   € ã#*ÑˆE˜Ø—;‘;—=”=Ø×!Ñ! &Ö)ó $+r$   c               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r°   9  s   € ÷ Sñ S¸dñ Sr$   c              ƒ  ó(  "  € RV n         \        V R\        4       4       Uu0 uF  pVP                  4       '       d   K  VkK  	  ppV F  pVP	                  4        K  	  V'       d   \
        P                  ! VRR/ G Rj  x€L
  \        V R/ 4      pVP                  4        F  pV P                  VR4       K  	  VP                  4        \        V R/ 4      P                  4        \        V R\        4       4      P                  4        R# u upi  L�5i)z:Settle pending completion batches before adapter teardown.TÚ*_completion_notification_batch_flush_tasksÚreturn_exceptionsNr@  FrB  )
Ú)_completion_notification_batches_stoppingr<   rü  r  Úcancelr   ÚgatherÚvaluesrC  Úclear)r|   ÚtaskÚtasksÚbatchesr#  s   &    r"   Ú&_cancel_process_completion_batch_tasksÚ@GatewayNotificationsMixin._cancel_process_completion_batch_tasks9  sé   é € à9=ˆÔ6ô   Ð&RÔTWÓTYÔZó
áZ�Ø—9‘9—;÷ ˆDÙZð 	ð 
ó
 ˆDØ�K‰KŽMñ çÜ—.’. %Ð@¸4Ñ@×@Ð@ä˜$Ð BÀBÓGˆØ—~‘~Ö'ˆGØ×&Ñ& w°Ö6ñ (à�‰ŒÜ�Ð<¸bÓA×GÑGÔIÜ�ÐBÄCÃEÓJ×PÑPÖRùò
ñ Aùs(   ‚D¡D¾DÁ"DÁ'DÂ DÂBDc               ó$   € V ^8„  d   QhRRRRRR/# r	  r    )r!   s   "r"   r#   r°   M  s#   € ÷  ñ  Èð  ÐSWð  Ð\jñ  r$   c              ƒ  ó´  "  € V P                  V4      ;_uu_4       GRj  x€L
  ^ RIHp V! V4      '       g    RRR4      GRj  x€L
  R# RRR4      GRj  x€L
  R\        3R\        3R\        3RR 3RR	 3R
\        33 F)  w  rE\        W4      '       d   K  \        WV! 4       4       K+  	  V P                  '       d   R# V P                  V. V P                  ORNRN54      p\        P                  ! 4       P                  4       pV P                  P                  V. 4      P                  WV34       W`P                   9  da   \        P"                  ! V P%                  V4      4      pW€P                   V&   V P'                  V4       V P)                  V P*                  V4       VG Rj  x€L
 #  EL� ELn EL_  + GRj  x€L 
 '       g   i     ELw; i L*5i)zIFan in policy-admitted process completions with compatible pinned owners.NrF  r@  rB  rP  r?  c                 ó   € R # )gš™™™™™¹?r    r    r$   r"   r  ÚTGatewayNotificationsMixin._enqueue_process_completion_notification.<locals>.<lambda>Y  s   € ¹cr$   rR  c                 ó   € R # r¹  r    r    r$   r"   r  r_  Z  s   € Á%r$   Ú_background_tasksFrš  rc   )rI  rJ  rG  rW   rü  rÃ   ÚsetattrrR  r   Ú_COMPLETION_BATCH_KEY_FIELDSr   r_  Úcreate_futurer@  Ú
setdefaultr,  rB  r!  rF  Ú_retain_background_taskÚ_track_task_inrP  )	r|   rQ  rV   rG  Úattrr‡  r<  rL  rW  s	   &&&      r"   Ú(_enqueue_process_completion_notificationÚBGatewayNotificationsMixin._enqueue_process_completion_notificationM  s‘  é € ð ×/Ñ/°×4×4Õ4ÝXÙ.¨s×3Ò3Ø÷ 5×4×4×4Ñ4ð 0´Ð6Ð9_ÔaeÐ8fØ9¼3Ð?Ø4±kÐBØ8¹-ÐHÐK^Ô`cÐJdó	
‰MˆDô ˜4×&Ô&Ü˜¡G£IÖ.ñ
ð ×9×9Ð9Ùð ×#Ñ#ØÐ_�4×4Ñ4Ð_Ð6IÐ_ÐK^Ñ_ó
ˆô ×)Ò)Ó+×9Ñ9Ó;ˆØ×-Ñ-×8Ñ8¸¸bÓA×HÑHÈ*Ð[aÐIbÔcØ×?Ñ?Ô?Ü×&Ò& t×'KÑ'KÈCÓ'PÓQˆDØ=A×5Ñ5°cÑ:à×(Ñ(¨Ô.Ø×Ñ × OÑ OÐQUÔVØ�|Ð÷9 5×4×4×4Ò4úñ8 ùst   ‚G F0¡G¤F9ºGÁF3ÁGÁF6Á=GÂ&GÃC*GÆ+GÆ,GÆ3GÆ6GÆ9G	Æ?GÇ 
G	ÇG	Ç
Gc               ó    € V ^8„  d   QhRRRR/# )r   rV   rW   r   r�   r    )r!   s   "r"   r#   r°   o  s   € ÷ 3ñ 3°Dð 3¸Tñ 3r$   c                ód  € ^ RI Hp VP                  R4      '       d   R# T! VP                  RR4      ;'       g    R4      pV'       g   R# VP                  RR4      VR&   VP                  RR4      VR&   VP                  RR4      VR&   VP                  R4      '       d   VR,          VR&   R# R# )	zûFill platform/chat_id/thread_id/chat_type on an async-delegation event.

Such events only carry ``session_key`` (the daemon worker lacks per-message routing
metadata). Best-effort: a CLI-origin event (empty session_key) is left as-is and won't route.
r)  r=   NrY   r6   re   r/   r0   )rš   r*  r]   )r|   rV   r*  Úparseds   &&  r"   Ú _enrich_async_delegation_routingÚ:GatewayNotificationsMixin._enrich_async_delegation_routingo  sœ   € õ 	3Ø�7‰7�:×ÒÙÙ# C§G¡G¨M¸2Ó$>×$DÐ$DÀ"ÓEˆßÙØ Ÿ*™* Z°Ó4ˆˆJ‰Ø!Ÿ:™: k°2Ó6ˆˆKÑØŸ™ I¨rÓ2ˆˆI‰Ø�:‰:�k×"Ò"Ø% kÕ2ˆC�Óñ #r$   c               ó    € V ^8„  d   QhRRRR/# ©r   Úgroupr7  r   r©   r    )r!   s   "r"   r#   r°   �  s   € ÷ Lñ L¸:ð LÈ.ñ Lr$   c              ƒ  óø   "  € V P                  V^ ,          4      ;_uu_4       GRj  x€L
  V P                  V4      G Rj  x€L
 uuRRR4      GRj  x€L
  #  L/ L L	  + GRj  x€L 
 '       g   i     R# ; i5i)a`  Deliver a same-session batch of async completions as ONE turn: the primary carries the
consolidated text of every sibling THIS runner claimed (siblings owned elsewhere are excluded;
their claims are acked only after adapter acceptance). True after acceptance, False to requeue
the group, None when nothing is deliverable here (retry siblings requeued).N)rI  Ú&_deliver_async_delegation_group_scoped)r|   rr  s   &&r"   Ú_deliver_async_delegation_groupÚ9GatewayNotificationsMixin._deliver_async_delegation_group�  sL   é € ð ×/Ñ/°°aµ×9×9Õ9Ø×DÑDÀUÓK×K÷ :×9Ô9ÙK÷ :×9×9Ó9üs\   ‚%A:§A¨A:«AÁ AÁAÁA:ÁAÁA:ÁAÁA:ÁA7	Á#A&Á$
A7	Á/A7	Á1	A:c               ó    € V ^8„  d   QhRRRR/# rq  r    )r!   s   "r"   r#   r°   Š  s   € ÷ >ñ >À*ð >ÐQ_ñ >r$   c           	   ƒ  	ó¼  "  € ^ RI Hp ^ RIHp V'       do   V^ ,          P	                  R4      '       dQ   . pV F=  pV! V4      pV'       g   K  TP                  V P                  We4      G Rj  x€L
 4       K?  	  RV9   d   R# R# . pV FÝ  pV! V4      pV'       g   K  \        VP	                  R4      ;'       g    R4      p	V	'       d]   T P                  T	\        VP	                  R	4      ;'       g    R4      4      G Rj  x€L
 R
8X  d   V P                  W…4      G Rj  x€L
  K�  V P                  V4      p
V
e   V P                  V
4      '       d   KË  VP                  WX34       Kß  	  V'       g   R# \        V4      ^8X  d%   V^ ,          w  rXV P                  W…4      G Rj  x€L
 # V F'  w  r[V P                  V4      G Rj  x€L
 '       d   K&   R# 	  ^ RIHp V^ ,          w  rÞV.p. pVR,           FD  w  rXV! VR\        V 4       24      pVf   K   VP                  VV34       VP                  V4       KF  	  V'       g   V P                  Wí4      G Rj  x€L
 # R\        V4       R2pRP!                  V.VO4      pV P                  VVVR7      G Rj  x€L
 pVf(   V F!  w  ppVP"                  P%                  V4       K#  	  V#  EL\ ELË EL° EL/ EL L LB5i)r–   )rE  ©Úprocess_registryrc   NFTrš  r6   rY   r×  )Úclaim_event_deliveryrm   zgateway-batch:r'  zé background subagent delegations completed for this session. Treat these results as one completion batch and send at most one consolidated user-facing response. If a result does not change the current conclusion, absorb it silently.]rP   r  )rš   rE  Útools.process_registryrz  r]   r,  r  r   rÎ  r¶  rÉ  rG   rï  rä  r{  rõ  r-  rO  rN  )r|   rr  rE  Ú_prÚoutcomesrV   rN   ÚdeliverablerQ  rÝ  rÁ  r0  r{  Úprimary_evtÚprimary_textÚblocksÚsiblingsr§   ÚheaderÚconsolidatedrõ  r  s   &&                    r"   rt  Ú@GatewayNotificationsMixin._deliver_async_delegation_group_scopedŠ  s¼  é € ÝDÝB÷ �U˜1•X—\‘\Ð"5×6Ò6ØˆHÛ�Ù;¸CÓ@�ß‘4Ø—O‘O¨$×*OÑ*OÐPTÓ*Z×$ZÖ[ñ ð " XÔ-�5Ð7°4Ð7Ø.0ˆÛˆCÙ=¸cÓBˆJßÙÜ˜Ÿ™Ð!4Ó5×;Ð;¸Ó<ˆFß × @Ñ @ÀÌÈSÏWÉWÐUbÓMc×MiÐMiÐgiÓIjÓ k×kÐoyÔyØ×;Ñ;¸JÓL×LÐLÙØ×9Ñ9¸#Ó>ˆHØÒ#¨×(FÑ(FÀx×(PÒ(PÙØ×Ñ Ð0Ö1ñ ÷ ÙÜˆ{Ó˜qÔ Ø)¨!�n‰OˆCØ×>Ñ>¸zÓO×OÐOó &‰JˆCØ×8Ñ8¸Ó=×=×=Ð=Úñ &õ 	@Ø$/°¥NÑ!ˆØ�ˆØ+-ˆØ*¨2Ÿ˜‰OˆCÙ+¨C°>Ä"ÀTÃ(ÀÐ1LÓMˆHØÒáØ�O‰O˜S (˜OÔ,Ø�M‰M˜*Ö%ñ  /÷ Ø×>Ñ>¸|ÓY×YÐYàœ3˜v›;˜-ð (að að 	ð —{‘{ FÐ#4¨VÐ#4Ó5ˆØ×?Ñ?Ø˜+°hð @ó 
÷ 
ˆ	ð Òã"*‘��YØ×$Ñ$×(Ñ(¨Ö-ñ #+àÐòi %[ò lÚLò Pò >ñ Zñ
ùs´   ‚2KµKÁKÁ-K	
Á.AKÂ;KÃ
(KÃ3KÄKÄKÄKÄ 1KÅKÅ21KÆ#KÆ$KÇKÇKÇA3KÉKÉKÉ>KÊKÊ2KËKËKËKËKËKËKc               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r°   Ê  s   € ÷ 0ñ 0Àdñ 0r$   c                óR   aa€ ^ RI Ho ^ RIHo V P	                  VVV3R lR4       R# )zóRe-queue undelivered async completions from every SECONDARY profile's ledger. The process
registry's ``restore_completions()`` covers only the launch profile's ``state.db``; a
secondary's rows would otherwise never be replayed after a restart.)Úrestore_undelivered_completionsry  c                 ó(   <€ S! S P                   4      # r\   ©rO  )r}  r‰  s   €€r"   r  ÚQGatewayNotificationsMixin._restore_secondary_completion_ledgers.<locals>.<lambda>Ð  s   ø€ Ñ;ZÐ[^×[oÑ[oÔ;pr$   ÚRestoredN)rä  r‰  r|  rz  Ú_each_secondary_ledger)r|   Úprofile_homesr}  r‰  s   &&@@r"   Ú%_restore_secondary_completion_ledgersÚ?GatewayNotificationsMixin._restore_secondary_completion_ledgersÊ  s"   ù€ õ 	KÝBØ×#Ñ# MÕ3pØ$.ö	0r$   c               ó   € V ^8„  d   QhRR/# r€   r    )r!   s   "r"   r#   r°   Ó  s   € ÷ ;ñ ;°Dñ ;r$   c                ób  aa€ ^ RI Ho ^ RIHo VV3R lp\	        \
        P                  R4      ;_uu_ 4        V! 4       ;p'       d   \        P                  RV4       RRR4       T P                  \        V RR4      ;'       g    / P                  4       VR4       R#   + '       g   i     LH; i)	zëOffer completions whose owner process died while this gateway runs (#97202): the launch
ledger in the launch scope, each served secondary under its own. Startup replay only covers
owners that were already gone when the gateway started.)Úsweep_orphaned_completionsry  c                 ó(   <€ S! S P                   4      # r\   r‹  )r}  r”  s   €€r"   r  ÚNGatewayNotificationsMixin._sweep_orphaned_completion_ledgers.<locals>.<lambda>Ù  s   ø€ Ñ2°3×3GÑ3GÔHr$   z*Orphaned async completion sweep failed: %sz*Re-offered %d orphaned async completion(s)NÚ_served_profile_homeszRe-offered orphaned)rä  r”  r|  rz  r   rÅ   rÆ   r:   rÀ   rŽ  r<   rÓ  )r|   ÚsweepÚcountr}  r”  s   &  @@r"   Ú"_sweep_orphaned_completion_ledgersÚ<GatewayNotificationsMixin._sweep_orphaned_completion_ledgersÓ  sƒ   ù€ õ 	FÝBÝHˆÜœWŸ]™]Ð,X×YÕYÙ›ÐˆuÖÜ—‘ÐHÈ%ÔP÷ Zð 	×#Ñ#¤W¨TÐ3JÈDÓ%Q×%WÐ%WÐUW×$^Ñ$^Ó$`ÐbgØ$9ö	;÷ Z×Yús   ¸&BÂB.	c               ó    € V ^8„  d   QhRRRR/# )r   Úverbr   r   r�   r    )r!   s   "r"   r#   r°   à  s   € ÷ oñ o¸cð oÀdñ or$   c                ód  € ^ RI Hp \        V RR4      pV FY  w  rgWe8X  d   K   V! \        V4      / 4      ;_uu_ 4        V! 4       pRRR4       X'       g   KB  \
        P                  RY8T4       K[  	  R#   + '       g   i     L7; i  \         d    \
        P                  RTRR7        K˜  i ; i)zZRun ``fn`` (returns a completion count) once per SECONDARY profile, bound to that profile.)Ú_profile_runtime_scoper  Nz1Could not replay async completions for profile %rTr»   z4%s %d undelivered async completion(s) for profile %r)rš   rŸ  r<   r   r9   r:   rì   rÀ   )	r|   r�  Úfnr�  rŸ  r‚  Úprofile_namer  r™  s	   &&&&     r"   rŽ  Ú0GatewayNotificationsMixin._each_secondary_ledgerà  s˜   € å6Ü˜$Ð 7¸Ó>ˆÛ*7Ñ&ˆLØÔ&ÙðÙ+¬D°Ó,>À×CÕCÙ›D�E÷ D÷
 ‰uÜ—‘ÐRÐTXÐamÖnó +8÷ D×Cûäô Ü—‘ÐRÐT`Ðko�ÔpÚðús.   ¤B¾A5ÁBÁ5BÂ BÂBÂ#B/Â.B/c               ó    € V ^8„  d   QhRRRR/# )r   ÚintervalrZ  r   r�   r    )r!   s   "r"   r#   r°   ð  s   € ÷ 0*ñ 0*¸ð 0*Èñ 0*r$   c           	   ƒ  ó¼  "  € \         P                  ! ^4      G Rj  x€L
  ^ RIHp ^ RIHp RpV P                  '       Ed   \        \        P                  R4      ;_uu_ 4        Ve"   \        P                  ! 4       V,
          V8¼  d>   \        P                  ! 4       p\         P                  ! V P                  4      G Rj  x€L
  V P                  VP                  4      G Rj  x€L
  . p. pVP                  P!                  4       '       gG    VP                  P#                  4       pTP'                  R4      R8X  d   TMTP)                  T4       Kf  V F  pVP                  P+                  V4       K   	  / pV FN  pV P-                  V4       VP/                  V P1                  WpP2                  4      . 4      P)                  V4       KP  	  VP5                  4        FI  p	 V P7                  V	4      G Rj  x€L
 p
V
RJ d'   V	 F  pVP                  P+                  V4       K   	  KI  KK  	  RRR4       \         P                  ! V4      G Rj  x€L
  EK%  R#  EL: EL— ELw  \$         d     EK  i ; i L{  \$         dF   pT	 F  pTP                  P+                  T4       K   	  \8        P;                  RT4        Rp?Ká  Rp?ii ; i  + '       g   i     L¤; i L�5i)	zàDrain async completions and pattern notifications even while sessions are idle.

Background subagents and process pattern events have no per-process notification
consumer; both must progress without a later foreground turn.
N)ÚORPHAN_SWEEP_INTERVAL_Sry  z"Async delegation watcher error: %sr�  r_  Fz$Async delegation injection error: %s)r   rb  rä  r¦  r|  rz  Ú_runningr   rÅ   rÆ   r`  Ú	monotonicrp  rš  rR  rO  ÚemptyÚ
get_nowaitr9   r]   r,  rN  rn  re  r   Ú_ASYNC_GROUP_KEY_FIELDSrU  ru  r:   r  )r|   r¤  r¦  r}  Úlast_orphan_sweepÚrequeueÚasync_eventsrV   Úgroupsrr  rõ  rù   s   &&          r"   Ú_async_delegation_watcherÚ3GatewayNotificationsMixin._async_delegation_watcherð  sW  é € ô �mŠm˜AÓ×ÐÝBÝBØ ÐØ�m�m‰mÜ ¤§¡Ð0T×UÕUà$Ò,´·²Ó0@ÐCTÕ0TÐXoÔ0oÜ(,¯ªÓ(8Ð%Ü!×+Ò+¨D×,SÑ,SÓT×TÐTà×5Ñ5°c×6JÑ6JÓK×KÐKà�Ø!�Ø×.Ñ.×4Ñ4×6Ò6ðØ!×2Ñ2×=Ñ=Ó?˜ð &)§W¡W¨V£_Ð8JÔ%J‘\ÐPW×_Ñ_Ð`cÖdÛ"�CØ×(Ñ(×,Ñ,¨SÖ1ñ #ð =?�Û'�CØ×9Ñ9¸#Ô>Ø×%Ñ% d×&;Ñ&;¸C×A]ÑA]Ó&^Ð`bÓc×jÑjÐknÖoñ (ð $Ÿ]™]ž_�EðPØ*.×*NÑ*NÈuÓ*U×$U˜	Ø$¨Ó-Û', Ø #× 4Ñ 4× 8Ñ 8¸Ö =ó (-ñ .ñ -÷7 VôJ —-’- Ó)×)Ó)ñM ò	 	ò UâKøô %ô Ûðúñ  %Vøô %ô PÛ#(˜CØ×0Ñ0×4Ñ4°SÖ9ñ $)äŸ™Ð%KÈQ×OÒOûðPú÷C V×UúñJ *ùs¿   ‚KœI�$KÁ"KÁ$AKÃIÃ"KÃ%IÃ&'KÄIÄ)B8KÇ"I4Ç6I2
Ç7.I4È%KÈ+!KÉKÉ
KÉKÉKÉI/É*KÉ.I/É/KÉ2I4É4K	É?:J?	Ê9KÊ?K	ËKËK	Ë	Kc               ó    € V ^8„  d   QhRRRR/# )r   rD   rE   r   r   r    )r!   s   "r"   r#   r°   #  s   € ÷ ñ ¨cð °cñ r$   c           
     ó<  € ^ RI Hp ^ RIHp ^ RIHp V P                  '       d   V! V P                  V) R 4      MRpV'       dX   ^ RIHp \        V RR4      ;'       g    RpT! YWV P                  \        V RR4      ;'       g    RR	7      pV! WW4      pV! V4      pV# )
zZLast ``limit`` chars of process output through the secret redactors (unconditional floor).r%  rz  ©Útransform_process_outputNr6   ©Úredact_terminal_outputÚcommandÚtask_id©r¸  Ú
returncoder¹  )rš   r&  r~  r{  r|  rµ  Úoutput_bufferÚagent.redactr·  r<   rs   )ÚsessionrD   r&  r{  rµ  Ú
new_outputr·  Ú_commands   &&      r"   Ú_redacted_output_tailÚ/GatewayNotificationsMixin._redacted_output_tail"  s™   € õ 	DÝ/ÝCØCJ×CX×CXÐCX‘Z × 5Ñ 5°u°f°gÐ >Ô?Ð^`ˆ
ßÝ;Ü˜w¨	°2Ó6×<Ð<¸"ˆHÙ1°*Ð[b×[lÑ[lÜ:AÀ'È9ÐVXÓ:Y×:_Ð:_Ð]_ôaˆJá/°
ÓEˆJñ =¸ZÓHˆJØÐr$   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r?  r   ÚwatcherrW   r   rx   r    )r!   s   "r"   r#   r°   4  s'   € ÷ Qñ Q¸#ð QÈð QÐQUñ Qr$   c              ƒ  ó.  "  € \        VP                  R4      ;'       g    R4      P                  4       pV'       g   R# \        P                  ! V P
                  V4      G Rj  x€L
 pV P                  W4      pT\        VRR4      ;'       g    / 9   #  L/5i)z”Whether the session that launched *watcher*'s process is still inside a turn on its
adapter (``_active_sessions`` is the base adapter's busy guard).rY   r6   FNÚ_active_sessions)r   r]   rf   r   rp  r@  rŽ  r<   )r|   r?  rÄ  rY   rÈ   r“   s   &&&   r"   Ú_launching_turn_activeÚ0GatewayNotificationsMixin._launching_turn_active4  s   é € ô ˜'Ÿ+™+ mÓ4×:Ð:¸Ó;×AÑAÓCˆßÙÜ×(Ò(¨×)IÑ)IÈ7ÓS×SˆØ×1Ñ1°-ÓHˆØœw wÐ0BÀDÓI×OÐOÈRÑPÐPñ Tùs   ‚:B½&BÁ#BÁ$)BÂBc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r?  r   Úmessage_textrÄ  rW   r   r�   r    )r!   s   "r"   r#   r°   >  s+   € ÷ 	ñ 	¸ð 	Ð`cð 	Ðnrð 	Ðw{ñ 	r$   c              ƒ  	óœ  "  € ^ RI Hp \        P                  ! V P                  V4      G Rj  x€L
 pV P                  W4      pV'       dh   V'       d^   \        \        P                  R4      ;_uu_ 4        V'       d   RV/MRp	VP                  W$V! W‘R7      R7      G Rj  x€L
  RRR4       R# R# R#  L† L  + '       g   i     R# ; i5i)r–   r—   NzWatcher delivery error: %sr0   r™   r    )
rš   r˜   r   rp  r@  rŽ  r   rÅ   ÚERRORr¡   )
r|   r?  r/   r0   rÊ  rÄ  r˜   rÈ   r“   Ú	send_metas
   &&&&&&    r"   Ú_send_watcher_messageÚ/GatewayNotificationsMixin._send_watcher_message>  s¦   é € Ý<Ü×(Ò(¨×)IÑ)IÈ7ÓS×SˆØ×1Ñ1°-ÓHˆß—wÜ ¤§¡Ð0L×MÕMß8A˜[¨)Ñ4Àt�	Ø—l‘lØÑ4PÐQZÔ4sð #ó ÷ ð ÷ NÑMñ ‰7ñ Tñ
÷ N×MÐMüs?   ‚+C­B4®$CÁ"CÁ5,B8Â!B6Â"B8Â&CÂ6B8Â8C		Ã	Cc               ó$   € V ^8„  d   QhRRRRRR/# )r   rÄ  rW   ra  r   r   r    )r!   s   "r"   r#   r°   J  s"   € ÷ (
ñ (
°ð (
ÈCð (
ÐTXñ (
r$   c                óä  € ^ RI Hp ^ RIHp ^ RIHp ^ RIHp \        VRR4      ;'       g    RpVP                  '       d   V! VP                  4      MRpV'       d+   T! Y‡VP                  \        VRR4      ;'       g    RR7      MTpV! W‡4      pR	p	\        V4      V	8”  d=   W‰) R
 p
V
P                  R4      pVR8w  d   W«^,           R
 MT
p
R\        V
4       RV
 2pMTpRRRV/\         Uu/ uF  qÝV P                  VR4      bK  	  upCR\        VRR4      ;'       g    RR\        VRR4      ;'       g    RR\        V P                  R4      ;'       g    R4      P!                  4       ;'       g    R
R\        VRR
4      RV! V4      RVP                  R\        VRR4      R\        VRR4      RV! V4      RV P                  R4      ;'       g    \        VRR4      ;'       g    R/
C# u upi )zEBuild the synthetic ``completion`` event for an agent-notify watcher.r%  r¶  rz  r´  r¸  r6   r¹  rº  iÐ  Nr+  u'   [â€¦ output truncated â€” showing last z chars]
r�  r°  ra  Úowner_task_idr  r±  rs   r)  r*  Útermination_sourcerC   rš  éÿÿÿÿ)rš   r&  r½  r·  r~  r{  r|  rµ  r<   r¼  rs   rG   ÚfindÚ_WATCHER_ROUTE_FIELDSr]   r   rf   )rÄ  r¾  ra  r&  r·  r{  rµ  rÀ  Ú_rawÚ_LIMITÚ_tailÚ_nlÚ_outÚks   &&&           r"   Ú_build_process_completion_eventÚ9GatewayNotificationsMixin._build_process_completion_eventI  sý  € õ 	DÝ7Ý/ÝCÜ˜7 I¨rÓ2×8Ð8°bˆØ4;×4I×4IÐ4I‰z˜'×/Ñ/Ô0ÈrˆçZ^ñ (¨È7×K\ÑK\Ü07¸ÀÈBÓ0O×0UÐ0UÐSUõWØdhð 	á% dÓ5ˆàˆô ˆt‹9�vÔØ˜˜�NˆEØ—*‘*˜TÓ"ˆCØ'*¨b¤y�E �'˜(‘O°eˆEØ<¼SÀ»Z¸LÈ	ÐRWÐQXÐY‰DàˆDà�LØ˜*ð
õ /DÓDÑ.C¨�'—+‘+˜a Ó$Ò$Ñ.CÑDð
ð œW W¨o¸rÓB×HÐHÀbØ”w˜w¨	°2Ó6×<Ð<¸"Øœ#˜gŸk™k¨,Ó7×=Ð=¸2Ó>×DÑDÓF×NÐNÈ$Øœ' '¨<¸Ó>ØÑ:¸8ÓDØ˜×*Ñ*Ø¤¨Ð2EÀxÓ!PØ ¤'¨'Ð3GÈÓ"LØÑ9¸$Ó?àØ—‘Ð/Ó0×cÐc´G¸GÐEXÐZ\Ó4]×cÐcÐacñ
ð 	
ùò Es   Ã/G-c               ó$   € V ^8„  d   QhRRRRRR/# )r   ra  r   Únotify_moder   r    )r!   s   "r"   r#   r°   t  s(   € ÷ @ñ @¸ð @ÐSVð @Ð[^ñ @r$   c                óÞ  € ^ RI HpHp V P                  VR4      p\	        VRR4      p\        V\        \        34      '       d'   \        R\        P                  ! 4       V,
          4      MRpT! \	        VRR4      ;'       g    R4      p	VR8X  d   V! WVP                  VVR	7      # V! WVP                  RVR	7      p
VP                  4       '       d   \        R
W¦P                  4       R7      # T
# )u  Human-facing completion message. Every mode shares the one-line status header; the
raw-output modes (all/result/error) append the bounded output tail under it instead of the
old bracketed ``[Background process proc_â€¦ finished~ â€¦]`` debug wrapper (#54266).)Ú$_format_concise_process_notificationr&  iè  r±  Ng        r¸  r6   Úconcise)Úduration_secondszgateway.background.final_output©r„  rC   )rš   râ  r&  rÁ  r<   rÁ   rE   rZ  Úmaxr`  rs   rf   r   )r|   ra  r¾  rà  râ  r&  r¿  Ú_startedÚ_durr¸  r„  s   &&&&       r"   Ú_format_process_final_messageÚ7GatewayNotificationsMixin._format_process_final_messaget  sÙ   € ÷ 	jØ×/Ñ/°¸Ó>ˆ
Ü˜7 L°$Ó7ˆÜ3=¸hÌÌeÈ×3UÒ3UŒs�3œŸ	š	› hÕ.Ô/Ð[_ˆÙ5´g¸gÀyÐRTÓ6U×6[Ð6[ÐY[Ó\ˆØ˜)Ô#Ù7¸
ÈW×M^ÑM^Ð`jØIMôOð Oá5°jÈ7×K\ÑK\Ð^`ÐswÔxˆØak×aqÑaq×asÒasŒqÐ2¸6×JZÑJZÓJ\Ô]ÐÐyÐr$   c               ó   € V ^8„  d   QhRR/# r   r    )r!   s   "r"   r#   r°   ƒ  s   € ÷ Añ A¸#ñ Ar$   c           	     	ó"  € ^ RI HpHp V P                  VR4      pT! T! \	        VRR4      ;'       g    R4      4      p\        R4      V'       d   RV R2MR,           pVP                  4       '       d   \        RWdP                  4       R	7      # T# )
r–   )r&  Ú_shorten_command_for_displayiô  r¸  r6   z gateway.background.still_runningu    â€” `Ú`z gateway.background.recent_outputrå  )rš   r&  rí  rÁ  r<   r   rf   )r|   r¾  r&  rí  r¿  Ú	short_cmdr„  s   &&     r"   Ú_format_process_running_messageÚ9GatewayNotificationsMixin._format_process_running_messageƒ  s‘   € ßaØ×/Ñ/°¸Ó=ˆ
Ù0Ñ1TÔU\Ð]dÐfoÐqsÓUt×UzÐUzÐxzÓ1{Ó|ˆ	ÜÐ5Ó6×S\¸FÀ9À+ÈQÑ:OÐbdÕeˆØbl×brÑbr×btÒbtŒqÐ3¸F×K[ÑK[ÓK]Ô^ð  	Að  {Að  	Ar$   c               ó    € V ^8„  d   QhRRRR/# )r   rÄ  rW   r   rx   r    )r!   s   "r"   r#   r°   Š  s   € ÷ "ñ "¨4ð "°Dñ "r$   c                óÌ   € \        V RR4      p\        V RR4      '       d   Ve   VP                  4       '       g   R# ^ RIHp V! V P	                  V4      V\
        RR7      pVRJ# )a}  Start ``_run_process_watcher`` for a watcher registered mid-turn, from the agent's
tool thread. Waiting for the post-turn drain leaves a process that finishes while its
launching turn is still running with no watcher at all (#112033). False = the gateway
is not serving (startup, shutdown): the caller keeps the descriptor in
``pending_watchers`` for the startup / post-turn drain.Ú_gateway_loopNr§  F)Úsafe_schedule_threadsafez"Live process watcher arming failed)r:   Úlog_message)r<   Ú
is_runningÚagent.async_utilsrõ  Ú_run_process_watcherr:   )r|   rÄ  rd  rõ  rL  s   &&   r"   Úarm_process_watcherÚ-GatewayNotificationsMixin.arm_process_watcherŠ  sc   € ô �t˜_¨dÓ3ˆÜ�t˜Z¨×/Ò/°4²<ÀtÇÁ×GXÒGXÙÝ>Ù)Ø×%Ñ% gÓ.°¼VØ<ô
ˆð ˜TÐ!Ð!r$   c               ó    € V ^8„  d   QhRRRR/# )r   rÄ  rW   r   r�   r    )r!   s   "r"   r#   r°   š  s"   € ÷ __ñ __°$ð __¸4ñ __r$   c              ƒ  ó²  a aaaaa"  € ^ RI Hp ^ RIHpHp SR,          pSR,          pSP                  RR4      oSP                  RR4      oSP                  RR4      oSP                  R	R
4      pS P                  S4      ;_uu_4       GRj  x€L
  S P                  4       pRRR4      GRj  x€L
  \        P                  RWVXV4       VR8H  ;'       d    V'       * p	^ p
 \        P                  ! V4      G Rj  x€L
  VP                  V4      pVf   EM¦S P                  S4      ;_uu_4       GRj  x€L
  V! R\        VRR4      R\        VRR4      /4      pRRR4      GRj  x€L
  X'       g   VP                  '       d   EM6K¨  V	'       d   VP                  '       d   EMKÆ  \        VP                  4      pWÚ8„  pTp
VP                  '       Edš   V'       dÑ   VP!                  V4      '       gº   S P#                  SWµ4      pV! V4      pV'       g   EM¥S P%                  SS4      G Rj  x€L
 pS P'                  VV4      G Rj  x€L
 pVR
J d   EKt  V'       dO   VR9   g   VR8X  dA   VP(                  R9  d0   S P+                  W[R4      oS P-                  SSSSS4      G Rj  x€L
  EMVP!                  V4      '       d   \        P                  RV4       MâVR9   g   VR8X  d…   VP(                  R9  dt   S P+                  W[V4      o^ RIHp S P                  S4      ;_uu_4       GRj  x€L
  V! VVVV VV3R lSVP(                  R9  R7      G Rj  x€L
  RRR4      GRj  x€L
  MOV'       g   EK˜  VR8X  g   EK¢  V'       d   EK­  S P-                  SSSS P3                  V4      S4      G Rj  x€L
  EKÜ  \        P                  RV	'       d   RMRV4       R#  ELR EL5  + GRj  x€L 
 '       g   i     ELM; i EL ELÒ EL£  + GRj  x€L 
 '       g   i     EL»; i ELü ELå EL‰ EL LÜ LÎ  + GRj  x€L 
 '       g   i     Lå; i LŸ5i)a  Poll a background process and push updates until it exits. Mode
(``display.background_process_notifications``): concise (default one-liner; failures append
the output tail) / all (running updates + final raw) / result (final raw) / error (final raw
if exit != 0) / off.ry  )Úformat_process_notificationrG  ra  Úcheck_intervalr=   r6   r/   r0   Únotify_on_completeFNzCProcess watcher started: %s (every %ss, notify=%s, agent_notify=%s)rH  rÒ  r¹  rã  Úallr  ug   Process watcher: completion for %s already consumed via wait/log â€” skipping raw notification (#65379)r  c                 ó.   <€ SP                  SS SSS4      # r\   )rÎ  )r/   rÊ  r?  r|   r0   rÄ  s   €€€€€€r"   r  Ú@GatewayNotificationsMixin._run_process_watcher.<locals>.<lambda>ð  s   ø€  D×$>Ñ$>¸}ÈgÐW`ÐbnÐpwÔ$xr$   )r=   ri  zProcess watcher ended%s: %sz	 (silent)>   r  rË   rã  >   Nr–   )r|  rz  rJ  rþ  rG  r]   rI  rK  r:   r;   r   rb  r<   r*  rG   r¼  Úis_completion_consumedrÝ  rÇ  ri  rs   ré  rÎ  r!  r  rð  )r|   rÄ  rz  rþ  rG  ra  r¤  Úagent_notifyrà  ÚsilentÚlast_output_lenr¾  ÚsurfaceÚcurrent_output_lenÚhas_new_outputÚcompletion_evtrQ  Ú	turn_busyrõ  r  r/   rÊ  r?  r0   s   ff                  @@@@r"   rù  Ú.GatewayNotificationsMixin._run_process_watcherš  s¬  ýé € õ
 	<ßqØ˜\Õ*ˆ
ØÐ+Õ,ˆØŸ™ J°Ó3ˆØ—+‘+˜i¨Ó,ˆØ—K‘K ¨RÓ0ˆ	Ø—{‘{Ð#7¸Ó?ˆð ×/Ñ/°×8×8Õ8Ø×BÑBÓDˆK÷ 9×8ä�‰ÐZØ ¨K¸ô	Gà Ñ%×:Ð:¨lÔ*:ˆØˆØÜ—-’- Ó)×)Ð)Ø&×*Ñ*¨:Ó6ˆGØŠÙØ×3Ñ3°G×<×<Õ<Ù5Ø#¤W¨W°oÀrÓ%JØœw w°	¸2Ó>ð7ó �÷ =×<÷
 à—>—>�>ÙÙßà—>—>�>ÙÙÜ!$ W×%:Ñ%:Ó!;ÐØ/ÑAˆNØ0ˆOØ�~�~‰~÷  Ð(8×(OÑ(OÐPZ×([Ò([Ø%)×%IÑ%IÈ'ÐSZÓ%g�NÙ!<¸^Ó!L�Jß%Ùð '+×&AÑ&AÀ-ÐQXÓ&Y× Y�IØ&*×&SÑ&SÐT^Ð`nÓ&o× o�IØ  EÓ)ò !÷
 ! kÐ5QÔ&QØ# wÔ.°7×3DÑ3DÈIÔ3Uà'+×'IÑ'IÈ*Ð_hÓ'i˜Ø"×8Ñ8¸ÈÐQZÐ\hÐjqÓr×rÐrÙð $×:Ñ:¸:×FÒFÜ—L‘LðNØOYôð ØÐ">Ô>Ø 7Ô*¨w×/@Ñ/@È	Ô/Qà#'×#EÑ#EÀjÐ[fÓ#g�LÝRØ#×;Ñ;¸G×D×DÕDá2ßxÑxØ%2¸w×?PÑ?PÐXaÑ?aôc÷ cð c÷  E×Dð
 ß’ K°5×$8ÇÂð ×0Ñ0Ø! 7¨I°t×7[Ñ7[Ð\cÓ7dÐfmó÷ ó ô 	�‰Ð2Ç6±KÈrÐS]Ö^÷a 9×8×8×8úò *÷ =×<×<×<úò8 !ZÚ oò sò  Eñc÷  E×D×DÒDúñùs”  ˆBQÂO ÂQÂO&Â#QÂ.O#Â/'QÃ$QÃ;PÃ<8QÄ4PÄ5QÄ8#PÅQÅ&P	Å'QÅ3QÆQÆQÆ#9QÇQÇ49QÈ-P)È.QÉP,ÉQÉA	QÊ&P/Ê'QËA+QÌ/P2Ì0QÌ3%P9ÍP5ÍP9ÍQÍ(P7Í)
QÍ9QÎQÎ'QÎ5QÎ6QÏQÏ#QÏ&P 	Ï,O/Ï-
P 	Ï8P 	Ï:
QÐQÐ	QÐP&	ÐPÐ
P&	ÐP&	Ð 
QÐ,QÐ/QÐ2QÐ5P9Ð7QÐ9Q	Ð?QÑ 
Q	ÑQ	Ñ	Q)rR  ré  r  )rY   r=   re   r/   r0   r¹   )rY   rš  r­  r\   )NNFTNNN)ç       @g      @g      œ@)r6   r    )r  )Vr‰   rŠ   r‹   rŒ   r�   rc  r«  ÚdataclassesÚ	dataclassr�   r£   r­   rÌ   rú   r  r
  r%  Úclassmethodr+  Ústaticmethodr6  rB  rQ  rN  re  rj  ru  rƒ  r•  r›  r"  ra  rÐ  rÖ  rÛ  rà  rç  ré  rŽ   rø  ró  r$  r@  rR  rX  rx  rq  rŽ  rL  r¶  rÂ  rÉ  rÎ  rÍ  ré  rï  rù  rI  rm  Úasynccontextmanagerr   r  r  r   r3  r  rF  rC  rZ  ri  rn  ru  rt  r�  rš  rŽ  r°  rÁ  rÇ  rÎ  rÝ  ré  rð  rú  rù  r�   r    r$   r"   rl   rl   ~   s  ‡ Ùrð $oÐ Ú|Ð[wÐxzÕ[{Ñ|Ðà×Ñ÷*ð *ó ð*ð" ×Ñ÷^ð ^ó ð^ð  ×Ñ÷	ð 	ó ð	õ G÷D;b÷|I÷Võ2Xð ô
ó ð
ð ôó ðð ô/ó ð/õ"õ2
õ3ð ôSó ðSð ôJó ðJõ	Iõ_õ&;÷E;õNJõX30òj	:ò6òGõ ð0 <@Ð Ð"8Ó?õ%^ðN)ØOS÷)õV5#õn@
õD*õ<õ%õNi÷.Xð,^ØHM÷^ð@ ôó ðõ2FðÀ5÷ ÷Z÷!RðF ôjó ðjõõ><õ|:ð4 ×#Ñ#ôó $ðð
@Ø<>÷
@ð0kØ<>÷0kðd ôDó ðDð ô ó ð õ<@õ%IðN ô*ó ð*õ
Sõ( õD3õ$Lõ>õ@0õ;õo÷ 0*ðd ôó ðõ"Qõ	ð ô(
ó ð(
õT@õAõ"÷ __ñ __r$   rl   >   ú.3gpú.aviú.mkvú.movú.mp4ú.webm)rY   r=   re   r/   r0   r¹   r2  >   ú.gifú.jpgú.pngú.jpegú.webp>   Ú
turn_leaserÖ  Úcompression_closed)Údrop_completion_deliveryz'Could not drop durable completion claim)Úrelease_completion_deliveryz*Could not release durable completion claim)Údefer_completion_deliveryz+Could not defer unadmitted completion claim)Úcomplete_completion_deliveryz.Could not acknowledge durable completion claim):r�   Ú
__future__r   r   rm  r  rJ  rÅ   r`  r   r   Úpathlibr   Útypingr   r   r   r	   Ú
agent.i18nr   rÂ   r   r   ræ   r   r   Úgateway.platforms.eventr   r   r3  r   r   r   Úgateway.run_shutdownr   r   r   r   r   Ú#gateway.run_notifications_ownershipr   Ú	getLoggerr:   r&   rÃ  r1   rA   rH   rï   rÖ  rÛ   Ú	frozensetr  rã  rS   rT   rj   rl   r    r$   r"   Ú<module>r.     sí   ðñõ #ã Û Û Û Û Û Ý Ý Ý ß ,Ó ,å ß =ß Mß =ß EÑ Eß uÕ uÝ Qð 
×	Ò	˜=Ó	)€õ-ð +1Ð 'õbðÐUY÷ õ Gò
 @€àpÐ Ú8€ñ !*Ò*]Ó ^Ð ð ÐSØÐ\ØÐYØÐbð	Ð ðbð õ8õ Jô{_Ð Aö {_r$   