+
    jHà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HtHtHt ^ RI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( ^ RI)H*t* ]PV                  ! R4      t,R R lt-RR/R R llt.0 R&mt/R't00 R(mt1]2! 0 R)m4      t3^t4^<t5Rt6R R lt7RR*RR+RR,RR-/t8Rt9R R lt:R R lt;R  R! lt<R" R# lt= ! R$ R%](]*4      t>R# ).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)ÚPath)ÚAnyÚDictÚOptionalÚcast)Út)Újittered_backoff)Ú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)ÚGatewayUpdateNotificationsMixin)Ú!GatewayNotificationOwnershipMixinzgateway.runc               ó$   € V ^8„  d   QhRRRRRR/# )é   ÚprofileúOptional[str]Úplatform_valueÚstrÚreturnÚtuple© )Úformats   "Ú>/home/ubuntu/.hermes/hermes-agent/gateway/run_notifications.pyÚ__annotate__r%   !   s'   € ÷ bñ b }ð bÀcð bÐbgñ bó    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_keyr+   !   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%   ,   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.deliveryr/   Ú	ExceptionÚloggerÚdebugÚgetattr)ÚplatformÚconfigÚadaptersr   r/   Úexcs   &&&$  r$   Ú_safe_delivery_transportr;   ,   sY   € õ <ðÙ)¨(¸HÓEÐEøÜô Ü�‰Ø=ß$ˆwˆi�q‰M¨"¬g°hÀÈÓ.RÐTWô	Yõ ûð	ús   ˆ ‘Aœ0AÁAg      @c               ó    € V ^8„  d   QhRRRR/# )r   ÚstepÚintr    Úfloatr"   )r#   s   "r$   r%   r%   K   s   € ÷ Kñ K˜Cð K Eñ Kr&   c                ód   € \         P                  ! 4       \        V \        \        RR7      ,           # )zVWhen a refused queued notice is next offered: exponential from the drain base, capped.ç        ©Ú
base_delayÚ	max_delayÚjitter_ratio)ÚtimeÚ	monotonicr	   Ú!_WATCH_INJECTION_RETRY_BASE_DELAYÚ%_COMPLETION_INJECTION_RETRY_MAX_DELAY)r=   s   &r$   Ú_refusal_retry_atrJ   K   s,   € ä�>Š>ÓÔ.ØÔ:Ü7ÀcôKõ Kð Kr&   Ú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%   `   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)rP   s   &r$   Ú_mark_internal_notificationrV   `   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%   p   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_keyr0   r7   úagent:c              3  óF   <"  € T F  pSP                  V4      x € K  	  R # 5i©N)Úget©Ú.0ÚfieldrX   s   & €r$   Ú	<genexpr>Ú0_raw_process_event_session_id.<locals>.<genexpr>v   s   øé € Ð^Ñ8]¨u˜CŸG™G EŸN˜NÓ8]ùs   ƒ!TFÚorigin_session_id>   r0   Ú
api_server)r)   Ú	chat_typer*   )r   r_   ÚstripÚlowerÚ
startswithÚany)rX   r[   r7   s   f  r$   Ú_raw_process_event_session_idrl   p   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               ó    € V ^8„  d   QhRRRR/# )r   rX   rY   r    zdict[str, str]r"   )r#   s   "r$   r%   r%   {   s   € ÷ ñ  ð ¨ñ r&   c                óü   € ^ RI HpHpHp V P	                  RR4      pVR8X  d'   RTRV P	                  R4      ;'       g
    V! V .4      /# VR8X  d   RRRV! V 4      /# VR	8X  d   ^ R
IHp ^ RI Hp RVRV! V 4      /# / # )aH  The card of a local process notice: the async-result card the in-process TUI wrote for a
completion or async delegation (a gateway-side ``/review`` reports as one), and a liveness tick's
one-line receipt. The claim's ``message.start`` carries it, and an idle classic CLI only opens a
turn that has one. ``{}`` for a watch match.)ÚPROCESS_COMPLETE_DISPLAY_KINDÚasync_delegation_display_textÚprocess_completion_display_textÚtypeÚ
completionÚdisplay_kindÚdisplay_textÚ_display_textÚasync_delegationÚasync_delegation_completeÚ	heartbeat)Ú"INTERNAL_NOTIFICATION_DISPLAY_KIND)Úheartbeat_display_text)Ú$tools.process_registry_notificationsro   rp   rq   r_   Úgateway.response_filtersrz   r{   )rX   ro   rp   rq   Úevt_typerz   r{   s   &      r$   Ú_local_completion_cardr   {   s¥   € ÷
gñ gà�w‰w�v˜|Ó,€HØ�<ÔØÐ =Ø §¡¨Ó 8× bÐ bÑ<[Ð]`Ð\aÓ<bðdð 	dàÐ%Ô%ØÐ ;¸^ÑMjÐknÓMoÐpÐpØ�;Ôõ 	PÝOØÐ BÀNÑTjÐknÓToÐpÐpØ€Ir&   c               ó    € V ^8„  d   QhRRRR/# )r   rX   rY   r    zdict[str, Any]r"   )r#   s   "r$   r%   r%   ‘   s   € ÷ ñ  dð °~ñ r&   c                óØ  € RR/p\        V P                  R4      ;'       g    R4      P                  4       p^ RIHp V! V 4      '       d   RVR&   VP                  R4      '       d   W2R	&   \        V P                  R
4      ;'       g    R4      P                  4       pV'       d   WRR&   V P                  R4      '       d   V R,          VR&   VP                  \        P                  8X  d   VP                  \        V 4      4       \        V P                  R4      ;'       g    R4      P                  4       pV'       d   WbR&   V P                  R4      ;p'       d   \        V4      VR&   V# )zŽSynthetic-event metadata for a watch/completion notification: routing pins, proof ids,
automation identities, and the local async-result card.Únotification_originÚprocess_registry_syntheticr[   r0   ©Údiagnostic_process_eventÚ
diagnosticÚnotification_categoryr\   Úgateway_session_keyÚparent_session_idÚgateway_session_idÚ_automation_identitiesÚautomation_identitiesÚproven_session_idÚgateway_proven_session_idÚcompletion_idsÚgateway_completion_ids)r   r_   rh   Úagent.notification_presentationr…   rj   r7   r
   ÚLOCALÚupdater   Úlist)rX   ÚsourceÚmetadatar[   r…   r‰   r�   r�   s   &&      r$   Ú_watch_notification_metadatar—   ‘   s9  € ð !6Ð7SÐT€HÜ�c—g‘g˜mÓ,×2Ð2°Ó3×9Ñ9Ó;€KÝHÙ ×$Ò$Ø,8ˆÐ(Ñ)Ø×Ñ˜h×'Ò'Ø*5Ð&Ñ'Ü˜CŸG™GÐ$7Ó8×>Ð>¸BÓ?×EÑEÓGÐßØ):Ð%Ñ&Ø
‡w�wÐ'×(Ò(Ø,/Ð0HÕ,IˆÐ(Ñ)Ø‡�œ(Ÿ.™.Ô(ð 	�‰Ô.¨sÓ3Ô4Ü˜CŸG™GÐ$7Ó8×>Ð>¸BÓ?×EÑEÓGÐßØ0AÐ,Ñ-ØŸ™Ð!1Ó2Ð2€~Ö2Ü-1°.Ó-AˆÐ)Ñ*Ø€Or&   c                  óº  € ] tR t^¬t$ RtRyt. RzO]R,          O5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 tR tR tR R ltRtR]R&   R R ltRR/R R lltR R ltR R  ltR! R" l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
/R. R/ llt ]R0 R1 l4       t!R2 R3 lt"R4R
/R5 R6 llt#R}R7 R8 llt$R}R9 R: llt%]R; R< l4       t&R= R> lt'R? R@ lt(RA RB lt)]*PV                  RC RD l4       t,RER~/RF RG llt-RER~/RH RI llt.]RJ RK l4       t/]RL RM l4       t0RN RO lt1RP RQ lt2]RR RS l4       t3RT RU lt4RV RW lt5RX RY lt6RZ R[ lt7R\ R] lt8R^ R_ lt9R` Ra lt:Rb Rc lt;RRd Re llt<]Rf Rg l4       t=]Rh Ri l4       t>Rj Rk lt?Rl Rm lt@]Rn Ro l4       tARp Rq ltBRr Rs ltCRt Ru ltDRv Rw ltERxtFR# )€ÚGatewayNotificationsMixinzhProcess/completion/update notifications, media delivery and async-delegation delivery for GatewayRunner.ºé   NNc                  ó~   € ] 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.r0   r   Údelegation_idÚclaim_idTÚboolÚproceedNúOptional[bool]Úearly_resultÚowner_session_idr�   FrM   r"   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rž   Ú__annotations__rŸ   r¡   r£   r¤   r�   rM   Ú__static_attributes__r"   r&   r$   Ú_CompletionClaimr�   ³   sM   ‡ á=àˆ�sÓØˆ�#ÓØˆ�ÓØ'+ˆ�nÓ+Ø "Ð˜#Ó"Ø!#Ð˜3Ó#Øˆˆt×r&   r¬   c               ó    € V ^8„  d   QhRRRR/# )r   Úcontentr   r    ÚNoner"   )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_channelNr8   r)   r7   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_info©r–   ÚsuccessF)Úgateway.runr²   Ú_delivery_adapter_forr6   r
   ÚSLACKr4   ÚinfoÚ
isinstancerY   Úgateway.configrµ   r_   Úhasattrr¸   r7   Ú_thread_metadata_for_sourcer   ÚloggingÚDEBUGÚsend_private_noticer)   r¹   Úsend)Úselfr•   r®   r²   Úadapterr8   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   Úresponser   Ú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_voicer    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   Úsuffixri   Ú_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://r0   )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_imagesrY   rÆ   r•   Ú_reply_anchor_for_eventr)   Úsend_multiple_imagesr3   r4   ÚwarningÚnamer   rß   ri   r7   Ú
send_voiceÚ_VIDEO_EXTSÚ
send_videoÚsend_document)rË   rÓ   rÔ   rÌ   rÕ   Ú_quoter   rÙ   Úmedia_filesÚcleanedÚ_thread_metar)   rã   ÚpÚ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   rÓ   r   r•   r   r–   rÖ   Úevent_message_idr   Útext_already_deliveredr    Údeliver_mediar[   Ú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.r0   )rP   r•   r	  )rÕ   )r¿   r  r6   Úedit_messager)   r4   rÂ   Úgateway.relay.egressr  rñ   r3   r5   Ú_send_queued_final_textr   r   )rË   rÓ   r•   rÌ   r–   r  r  r  Ústream_consumerr[   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   r[   r  r"   )r#   s   "r$   r%   r°   j  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.r0   )rP   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)   r6   r4   rñ   )
rË   rÌ   r•   r  r–   r  r[   r  rÏ   Ú_s
   &&&&&&&&  r$   r  Ú1GatewayNotificationsMixin._send_queued_final_textj  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    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.r.   )Ú_hermes_homeÚ_non_conversational_metadataz.restart_notify.jsonNú	utf-8-sig©Úencodingr7   r)   r*   T©Ú
missing_okz6Restart notification skipped: no live transport for %szJRestart notification suppressed: %s has gateway_restart_notification=falseÚdelivered_via_upstream_relayzgateway.startup.restarted©r7   r½   z3Restart notification to %s:%s was not delivered: %sz"Sent restart notification to %s:%szRestart notification failed: %s)r¹   Úscope_id)r2   r/   r¿   r$  r%  ÚexistsÚjsonÚloadsÚ	read_textr_   Úunlinkr
   r8   Ú_adapters_for_profileÚ_marker_profiler4   r5   Ú	platformsÚgateway_restart_notificationrÂ   Ú_pending_marker_metadatarÌ   rY   r   rÊ   r   r   rñ   r   r3   )rË   r/   r$  r%  Únotify_pathÚdataÚplatform_strr)   r*   r7   Ú	transportÚplatform_cfgr–   rb   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)r8   r5  ÚitemsÚhome_channelr)   r;   r9   )rË   r7   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)r8   r5  r@  r6   )rË   r7   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.NrF  Ú_profile_adapters©r   )rC  r6   r@  r_   r5  rA  r)   r;   )rË   r7   r<  rB  r;  r   rG  r9   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    r    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%  Ú_thread_metadata_for_targetr)   r*   rÌ   Úis_relayrY   r¹   r-  rÊ   r   r   r4   rñ   r1   r   r3   )rË   r7   rB  r;  rP  rQ  r%  r–   Úsend_metadatarÏ   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¯   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_writeNr&  r'  Údelivered_targets)Úskip_targetsTr)  )Úindentz,Planned-restart notification remains pendingr»   )r¿   r]  Úutilsr^  rY  ÚasyncioÚLockr.  r/  r0  r1  r_   r!   rH  rA  r)   r6  r+   r1   r*   Ú(_send_home_channel_startup_notificationsr2  r”   r3   r4   rñ   )rË   r]  r^  Úpathr9  ÚtargetÚ	deliveredr   r7   Ú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.onlinerL  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”   rM  r+   r1   r)   r*   r   r6  r4   rÂ   ÚaddrW  )rË   r`  rh  ÚskippedrP  Útargetsr   r7   Ú_cfgrB  Ú
_transportÚnotified_chatsr<  r;  rg  Úchats   &$              r$   re  Ú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°   M  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)rW  )rB  rP  r7   rË   r;  s   €€€€€r$   Ú<lambda>ÚRGatewayNotificationsMixin._send_session_db_warning_notifications.<locals>.<lambda>€  s   ø€ ˜×7Ñ7Ø˜d I¨wÐ8lônr&   r,  )r6   Ú!_open_session_db_for_active_scoperz  r4   rÂ   Úhermes_constantsr|  r}  Úhermes_stater~  r  r   Úhermes_state_user_copyr†  r‡  rˆ  Ú_SELF_CLEARING_STORAGE_CAUSESÚglossrñ   Úgateway.warning_notificationsrŠ  rC  )rË   r  r|  r}  r~  r  rˆ  r‚  rƒ  r„  r†  Úfailurer‡  rŠ  Ú_platform_cfgrB  rP  r7   r;  s   f              @@@@r$   Ú&_send_session_db_warning_notificationsÚ@GatewayNotificationsMixin._send_session_db_warning_notificationsM  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   rX   rY   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_keyr[   r0   ÚoriginNz>Synthetic process-event session-store lookup failed for %s: %sr   r7   rg   r)   zcSynthetic event source unresolvable: session_key=%r platform=%r chat_type=%r chat_id=%r evt_type=%srr   rº   )Úplatform_registryz9Synthetic process event has invalid platform metadata: %rc               ó    € V ^8„  d   QhRRRR/# )r   rb   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# ©r0   N)r   r_   rh   )rb   rX   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).r*   r¹   Ú	user_name)r7   r)   rg   r*   r¹   r¦  r-  r   )ÚdmÚthread)r¿   r�  r   r_   rh   Úsession_storeÚ_ensure_loadedÚ_entriesr6   Ú_restored_sourcer3   r4   r5   Ú_get_cached_session_sourceri   rl   rñ   r
   r1   r   Úgateway.platform_registryrŸ  Úis_registeredÚ
ValueErrorr   )rË   rX   r�  r[   ÚderivedÚentryr:   Úcached_sourcer   Úplatform_namerg   r)   r7   rŸ  r¤  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   € ÷ 'Iñ 'IÀDñ 'Ir&   c           	   ƒ  óx  "  € ^ RI HpHp V! V4      pV EFL  pVP                  R4      pVe.   V\        P
                  ! 4       8”  d   VP                  V4       KF  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
  K�  V P                  4       R8X  d    RRR4      GRj  x€L
  K·  VP                  R4      R8X  d   ^ RIHp V! W4      G Rj  x€L
 p	M>V! V4      p
V
'       g    RRR4      GRj  x€L
  EK   V P                  W¥4      G Rj  x€L
 p	RRR4      GRj  x€L
  X	R
J g   EK;  V P#                  W4       EKO  	  R#  Lï LÌ L¦ Lz LZ L?  \         d    \        P!                  R	4       R
p	 Lai ; i LY  + GRj  x€L 
 '       g   i     Lp; 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_notificationÚ_watch_next_retry_atN©Úshould_surface_notificationÚoffrr   ry   )Údeliver_heartbeatz"Watch notification injection errorF)r¿   r¹  rº  r_   rF   rG   ÚputÚ_completion_event_scoper|   r½  Ú#_load_background_notifications_modeÚgateway.session_automationr¿  Ú_inject_watch_notificationr3   r4   Ú	exceptionÚ_requeue_refused_watch_event)rË   Úcompletion_queuer¹  rº  Úwatch_eventsrX   Únext_retry_atr½  r¿  rh  Ú
synth_texts   &&         r$   Ú_drain_watch_notificationsÚ4GatewayNotificationsMixin._drain_watch_notificationsÆ  sd  é € ÷ 	bÙ2Ð3CÓDˆÜˆCØŸG™GÐ$:Ó;ˆMØÒ(¨]¼T¿^º^Ó=MÔ-Mð !×$Ñ$ SÔ)ÙØ×3Ñ3°C×8×8Õ8Ý\Ù2°3×7Ò7Ø÷ 9×8Ñ8ð ×;Ñ;Ó=ÀÔFØ÷ 9×8Ñ8ð —7‘7˜6“? kÔ1ÝLÙ&7¸Ó&B× B‘Iá!EÀcÓ!J�Jß%Ø ÷ 9×8Ò8ð*Ø*.×*IÑ*IÈ*Ó*Z×$Z˜	÷ 9×8ð& ˜EÖ!Ø×1Ñ1Ð2B×Hó7  õ 9ñ !Cñ 9ñ %[øÜ$ô *Ü×(Ñ(Ð)MÔNØ$)š	ð*ú÷ 9×8×8Ò8üsð   ‚A6F:Á8E(
Á9F:Á<FÂF:ÂE*ÂF:Â$FÂ:F:ÃE,ÃF:Ã'FÃ3E.
Ã4FÄ	FÄ
F:ÄE0ÄF:ÄE4Ä2E2
Ä3E4Ä7F:ÅFÅF:ÅF:Å*F:Å,F:Å.FÅ0F:Å2E4Å4"F	ÆFÆF	ÆFÆF:ÆF7Æ$F'Æ%
F7Æ0F7Æ2F:c               ó    € V ^8„  d   QhRRRR/# ©r   rX   rY   r    r¯   r"   )r#   s   "r$   r%   r°   ð  s   € ÷ "ñ "¸Dð "ÀTñ "r&   c           
     ó4  € \        VP                  R4      ;'       g    ^ 4      ^,           pW!R&   VP                  RR4      '       d²   \        VP                  R4      ;'       g    ^ 4      ^,           pW1R&   V\        8¼  dx   \        P                  RVP                  R4      ;'       g    RVP                  R4      ;'       g    RVP                  R	4      ;'       g    RVP                  R
R4      V4       R# \        V4      VR&   V P                  V4       R# )a±  Retry a refused watch event on a bounded backoff, never on every 2 s tick (#140899).

Only a refusal proven permanent (``WakeNotAccepted.permanent``: the route has no session,
or the payload is invalid) counts toward the cap that drops it. A transient one (a restart's
after-turn wait, a parked profile, a full owner FIFO) or one whose owner may still appear (an
unowned or foreign-pinned notice) waits it out however long it lasts.
Ú_watch_retry_stepÚ_refusal_permanentFÚ_watch_injection_attemptszžWatch notification for %s chat=%s (type=%s session_id=%s) was refused %d times; dropping the queued event (output remains available via process(action='log'))r7   rº   r)   rr   Ú
session_idÚunknownNr»  )r>   r_   ÚpopÚ"_MAX_COMPLETION_INJECTION_ATTEMPTSr4   rñ   rJ   rÀ  )rÇ  rX   r=   Úrefusalss   &&  r$   rÆ  Ú6GatewayNotificationsMixin._requeue_refused_watch_eventï  sò   € ô �3—7‘7Ð.Ó/×4Ð4°1Ó5¸Õ9ˆØ#'ÐÑ Ø�7‰7Ð'¨×/Ò/Ü˜3Ÿ7™7Ð#>Ó?×DÐDÀ1ÓEÈÕIˆHØ/7Ð+Ñ,ØÔ=Ô=Ü—‘ð-ð —G‘G˜JÓ'×.Ð.¨3°·±¸	Ó0B×0IÐ0IÀcØ—G‘G˜F“O×*Ð* s¨C¯G©G°LÀ)Ó,LÈhôñ Ü&7¸Ó&=ˆÐ"Ñ#Ø×Ñ˜SÖ!r&   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)r9   r@  r1   )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   rÊ  r   Úraw_sidrX   rY   r    r    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_deliveryrr   rw   u`   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      # ))rP   rÓ  rX   r"   )rÌ   rX   rã  rà  rÊ  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: %sr„   NF©Ú_async_profile_runtime_scope©r7   r)   r   c            	     óZ   <€ S! S \        S4      SSS! S4      '       d   R R7      # RR7      # )r†   rÏ   )rP   rÓ  r   r‡   )rV   )rÌ   râ  r…   rX   rà  ÚservedrÊ  s   €€€€€€€r$   rŒ  rå  ,  s6   ø€ ™l¨7Ô9TÐU_Ó9`Ðmtð  EÙ6NÈs×6SÒ6S lõcØYaõcr&   T)Úgateway.wakerâ  rã  Ú
contextlibÚnullcontextr_   r‘   r…   rc  Ú	to_threadÚ_served_api_server_wake_profileÚLookupErrorr4   rñ   r¿   rç  r   r
   Ú
API_SERVERÚ _resolve_profile_home_for_sourcerÂ   r3   )rË   rÌ   rÊ  rà  rX   ÚscoperÂ   ÚfailÚdeliverrÿ   rç  r•   râ  r…   rã  rê  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   rX   rY   rà  r   r    r   r"   )r#   s   "r$   r%   r°   7  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_nameÚdefaultr   r0   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^   )r8   )ra   rò   Ú_homeÚprimaryrà  rË   rü  s   &  €€€€r$   rc   ÚLGatewayNotificationsMixin._served_api_server_wake_profile.<locals>.<genexpr>K  s;   øé € ð bÑ-R™k˜dØ ™ô Ù,DÀTÇ[Á[ÐRVÐX_×,`÷ ’TÓ-Rùs   ƒ9“9¯
9)r6   r8   r¿   rû  rë  rü  r   rµ  rh   rð  Únext)rË   rX   rà  rû  Úhintedr  rü  s   f&f  @@r$   rï  Ú9GatewayNotificationsMixin._served_api_server_wake_profile7  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/# rÚ  r"   )r#   s   "r$   r%   r°   N  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.r.   Nr+  FTr   c              3  óR   <"  € T F  w  rVP                   S8X  g   K  Vx € K  	  R # 5ir^   )r1   )ra   rû   rÜ  r´  s   &  €r$   rc   ÚGGatewayNotificationsMixin._resolve_injection_adapter.<locals>.<genexpr>b  s"   øé € ÐPÑ#3™4˜1°q·w±wÀ-Ñ7O—Q’QÓ#3ùs   ƒ'�
')r2   r/   Ú_transport_ownerr6   r9   r_   r
   ÚRELAYr3  r8   r3   rÌ   r  r@  )rË   r´  r•   r/   Úownerr9   rt  s   &f&    r$   Ú_resolve_injection_adapterÚ4GatewayNotificationsMixin._resolve_injection_adapterN  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   rÊ  r   rX   rY   r  r    r    r¢   r"   )r#   s   "r$   r%   r°   d  s2   € ÷ fñ fØðfØ$(ðfØAEðfà	ñf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
 #  \1        V4      p\3        W'4      p\'        VP                  R4      ;'       g    R4      P-                  4       ;'       g    RpV'       d   WËR&   \+        VRR4      '       d   ^ RIHp V! VRR7      p\9        V\:        P<                  VRVR7      p\        P?                  RW§P.                  VP@                  4       \+        V	RR4      p\C        V4      '       d	   V! V4       ^ RI"H#p V! V 4      pVe#   ^ RI$H%p ^ RI&H'p  V! V VWžV4      G Rj  x€L
  R# V! Wž4      G Rj  x€L
  R#  EL2 ELÅ ELB L!  T d$   pT! \'        T4      TPP                  R7      ThRp?ii ; i L>  T d²   p^ RI H)p T PU                  T\'        T4      T'       * R7      G Rj  x€L 
 pT;'       g    TPP                  T9   Tn+        T'       d   T'       g    Rp?R# T'       g   TPV                  TR&   \        P                  RY§P.                  T4       T'       d   h  Rp?R# Rp?i\X         d"   p\        P[                  RT4        Rp?R# Rp?ii ; i5i)a—  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 or a refused notice pinned to a permanently-gone session (``_watch_pin_gone``).
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 %srÓ  rÔ  r1   r   re   r0   r	  Úoriginal_trigger_message_id)Úreplace_source)r	  T)rP   Úmessage_typer•   Úinternalr–   uA   Watch pattern notification â€” injecting for %s chat=%s thread=%sÚprime_routing_cache)Úactive_authority)Úadmit_process_notice)ÚRuntimeStoreError)Úreason)ÚPERMANENT_REFUSAL_REASONS)ÚlogrÑ  z2Watch notification not admitted for %s chat=%s: %sz&Watch notification injection error: %s).rë  r  r  r  rc  rî  rµ  rl   r9   r_   r
   rñ  rö  r4   r5   rñ   rÅ   r7   r1   r   r  r6   rh   r)   rV   r—   Úgateway.session_identityr  r   r   ÚTEXTrÂ   r*   ÚcallableÚgateway.session_authoritiesr  rÃ  r  Úhermes_state_runtimer  r  r  Ú_watch_pin_goneÚ	permanentr3   r  )rË   rÊ  rX   r  r  r  r  r•   rà  rÌ   r´  r–   Útrigger_message_idr  Úsynth_eventÚ_primer  Ú	authorityr  r  r:   r  Úpin_gonerÿ   s   &&&$                    r$   rÄ  Ú4GatewayNotificationsMixin._inject_watch_notificationd  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ð<	Ü4°ZÓ@ˆJÜ3°CÓ@ˆHô "% 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Ü˜×ÒÙ�{Ô#ÝDÙ(¨Ó.ˆIØÒ$ÝKÝBðPÙ.¨t°YÀÐVYÓZ×ZÐZñ
 ñ +¨7Ó@×@Ð@ÙòQ Pò _ò. WñJ [øØ(ô PÙ)¬#¨c«(¸3¿:¹:ÔFÈCÐOûðPúñ Aøàô 	õ ?Ø!×1Ñ1°#´s¸3³xÐI[ÔE[Ð1Ó\×\Ð\ˆHØ$×OÐO¨¯
©
Ð6OÑ(OˆCŒMß× 2Ýß%Ø,/¯M©M�Ð(Ñ)Ü�N‰NÐOØ(¯.©.¸#ô?÷ "ØÝûÜô 	Ü�L‰LÐAÀ1ÔEÝûð	üs   ‚/R±M#²R¾ARÂRÂ!M&Â"DRÆ)RÆ9RÇRÇ2RÈRÈ'M)È(RÈ-AN É<
N ÊB4N Ì<M. Í
M,ÍM. ÍRÍN ÍNÍN Í!RÍ&RÍ)RÍ,M. Í.NÍ5NÎNÎN ÎQ?Î$+QÏOÏQÏQÏ;QÐRÐ	QÐ9QÑ
RÑQ?ÑQ?ÑQ:Ñ4RÑ:Q?Ñ?Rc               ó    € V ^8„  d   QhRRRR/# )r   rX   rY   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9   d=   V P                  R
4      '       d&   V\        V R,          4      \        V R
,          4      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.
rr   r0   rw   rž   NÚtask_failure_noticeÚresultsÚ
task_indexztask_failure:Úevent_idrÓ  rs   Ú
started_at>   ry   Úwatch_matchÚwatch_disabled©r   r_   )rX   r~   Úproducer_idÚtask_idxr3  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Ð.Ð.ð ÐEÔEÈ#Ï'É'ÐR\×J]ÒJ]Øœc # lÕ"3Ó4´c¸#¸j½/Ó6JÐKÐKØ�|Ô#Ü˜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_deliveredÚlenÚ_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   rH  r    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@  rp  )rË   rE  rH  Ú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   r[   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‰   r[   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   r[   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 P!                  WEW4      G Rj  x€L
 p
V
'       d   RT
r—MtV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#  EL  \         d    \        P                  RTRR7       Ru # i ; i Lë LÎ LR5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_dbNr0   z%Completion route lookup failed for %sTr»   rõ  Úended_atÚ
end_reasonÚcompressionÚterminal)Úretryr0   r0   )r¿   rV  r6   r   r   r©  rc  rî  rª  r«  r_   r3   r4   r5   Ú_lookup_completion_ownerrÓ  Ú_closed_local_targetr   Ú#_resolve_compression_lineage_target)rË   r‰   r[   rV  Ú
session_dbr²  r©  ÚverdictÚparentÚtarget_session_idÚ
closed_tiprY  s   &&&         r$   rQ  Ú4GatewayNotificationsMixin._classify_completion_owner  s›  é € õ 	;Ü˜T =°$Ó7ˆ
ØÒØ"Ð"Øˆßð'Ü.2´3¸«o×.KÑ.K�Ü×'Ò'¨×(DÑ(DÓE×EÐEØ%×.Ñ.×2Ñ2°;Ó?�ð 48×3PÑ3PØ¶5˜u×/Ò/¸bó4
÷ .
Ñ*ˆ Fð .Ðà×4Ñ4°ZÐHYÓb×bˆ
ßØ)2°JÑ&Ø˜	Ô! fÒ&8¸V¿Z¹ZÈ
×=SÒ=SÜ˜VŸZ™Z¨Ó5×;Ð;¸Ó<ˆJØ˜]Ô*ð )3Ô(P™*ÐV_‘à37×3[Ñ3[ØÐ'8ó4÷ .Ñ*�ð �iÔØ˜B �?Ð"ØÐ+<×+QÐ+QÐ@QÐQÐQò3 Føäô 'Ü—‘ÐDÀkÐ\`�ÔaØ&Ò&ð'úñ.
ñ
 cñ.ùs‚   ‚#F§=E- Á$E*Á%E- Â(FÂ,FÂ-FÃFÃFÃ%FÃ>FÄ.FÅ	FÅ
FÅ&FÅ*E- Å-%FÆFÆFÆFÆFÆF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.NrN   Tr»   )
Ú_DURABLE_CLAIM_OPSÚtools.async_delegationrw   r6   r3   r4   r  rÇ   rê   rÈ   )rg  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   rX   rY   r    r    r"   )r#   s   "r$   r%   r°   8  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‰   r0   r[   Nrõ  r[  r1   FÚ_ensure_session_dbz(Async-completion delivery DB unavailableTr»   )rë  r  r   r_   rh   rR  rc  rî  rµ  rÅ   r7   r1   r  rl   r9   r
   rñ  r6   r"  r3   r4   r5   )
rË   rX   r  r‰   ra  r•   r7   rÌ   rà  Úensures
   &&        r$   Ú_completion_delivery_readyÚ4GatewayNotificationsMixin._completion_delivery_ready8  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   rX   rY   r    r¬   r"   )r#   s   "r$   r%   r°   W  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.
rr   rw   NFr/  rž   r0   )Úclaim_completion_deliveryzgateway:r(   Úuuidz/Could not claim durable async completion %s: %srs   r‰   r[   r[  z�Async delegation %s targets permanently-gone session %s; terminally dropping delivery (result remains in the delegation records).z<legacy>rK   z®Background process %s completion targets permanently-gone session %s (user boundary such as /new); dropping notification (output remains available via process(action='log')).rÓ  z	<unknown>r\  T)r¬   r_   rt  r¡   r£   r   rž   rj  rx  ÚidÚ
__import__Úuuid4ÚhexrŸ   r3   r4   rñ   rh   rQ  r¤   r�   rn  rM   )rË   rX   rH  r~   rx  r:   r‰   ra  s   &&      r$   Ú_preflight_completion_deliveryÚ8GatewayNotificationsMixin._preflight_completion_deliveryW  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.ræ  )Úget_hermes_home_overrideNr   r8   rú  F©Ú)async_launch_profile_scope_if_multiplexed)r¿   rç  r�  r‚  rµ  r6   rl   Ú_served_api_server_event_scopeÚ!tui_gateway.launch_profile_policyr„  rò  r   rì  rí  )rË   rX   rç  r‚  r•   rà  r„  Úprofile_homes   &&      r$   rÁ  Ú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   rX   rY   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.ræ  rƒ  Nrè  )r¿   rç  r†  r„  rc  rî  rï  r   r
   rñ  rò  )rË   rX   rà  rç  r„  rê  r•   ró  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   rÊ  r   rX   rY   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Œ  )rÁ  Ú'_deliver_completion_notification_scoped)rË   rÊ  rX   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)   € ÷ 8kñ 8kØð8kØ$(ð8kà	ñ8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 R	R4      Ee&   ^ R
IHp V! W4      Ee   R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'       d2   V'       d(   T P!                  V UUu. uF  w  rïVNK	  	  upp4       R# R# R# 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 P1                  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L˜  + '       g   i     ELA; iu uppi   + '       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Lx; iu uppi   + '       g   i     EL—; i  + '       g   i     ELb; iu uppi   T EdG   pTP2                  '       * p
 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# Rp?i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¼  NFrN   rM   rL   rž   Úsession_authority©Úcompletion_admissionT)rH  r‰   r�   r�   )r  )rë  r  r|   r½  r9  r¬   r~  r¡   r£   rK  r>  r?  rM   rŸ   rn  rž   Ú%_record_coalesced_completion_siblingsr6   rÃ  r™  rM  r¤   r�   rÄ  rF  r&  )rË   rÊ  rX   rŒ  r  r½  rE  rH  ÚacceptedÚidentity_claimedÚrefusedÚ	operationÚsiblingrŸ   rÔ   Ú	_claim_idr™  r�   Úinjection_resultr:   s   &&&$                r$   r‘  ÚAGatewayNotificationsMixin._deliver_completion_notification_scopedÊ  s‡  é € õ 	1ÝTÙ*¨3×/Ò/ÙØ×5Ñ5°cÓ:ˆØ×%Ñ%Ó'ˆØ05Ð5ˆÐ5Ð#ð.	kØ×=Ñ=¸cÓB×BˆEØ—=—=‘=Ø×)Ñ)÷B  ¯Ø×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ôS �tÐ0°$Ó7ÓCÝKÙ'¨Ó2Ó>Ø#�HØ÷8  ¯Ø×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 Ó#Ø×1Ñ1°(À$Ð1×GÓGØ÷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 $(Ð Ø×%×%Ð%ð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òY C÷H 4×3Ð3üó <j÷ 4×3Ð3üó <j÷ 4×3Ð3üó <jùó7 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hÁ^ Á[2Á^ Á2^ Á=hÂhÂ![5Â=hÃ	hÃhÃ)hÃ?2hÄ6$hÅhÅ#hÅ3\	Æ hÆ#^ Æ/hÆ?hÇ\Ç/hÇ?	hÈ	hÈhÈ12hÉ($hÊhÊhÊ%\#
Ê2hË ^ Ë hË0hÌ\)Ì hÌ0	hÌ:hÍhÍ"2hÎ$hÎ>hÏhÏ\=
Ï#hÏ1^ Ð/^ Ð5^ Ñ
]Ñ]Ñ((^ Ò]	Ò^ ÒhÒ-hÓ]ÓhÓ-	hÓ7hÔ	hÔ2hÕ$hÕ;hÖhÖ] Ö hÖ+^ ×]&×^ ×!h×1hØ]:Ø!hØ1	hØ;hÙhÙ#2hÚ$hÚ?hÛhÛ^
Û$hÛ2^ Û5\Ü hÜ\ 	ÜhÜ)\:	Ü4hÝ^ Ý]ÝhÝ&]7	Ý1	^ Ý:^	ÞhÞc"ÞcÞ-c% Þ1hßhß_:ß1	hß:`
	àhà	hàhà1há2há>$hâ#hâ+hâ;c	
ãhãc"ã"c% ã%hã6hä
d/	ä&	hä/d?ä:hå
	håhå&hå<2hæ3$hçhç hç0g>ç=hèhc               ó$   € V ^8„  d   QhRRRRRR/# )r   rX   rY   Ú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£  r6  r`   s   & €r$   rc   Ú=GatewayNotificationsMixin._event_route_key.<locals>.<genexpr>  s)   øé € ÐC¹F°5”S˜Ÿ™ ›×-Ð-¨2×.Ð.»Fùs   ƒ!4¥4)r!   )rX   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é
   NrÓ  rÔ  Ú	exit_codeÚcompletion_reasonÚexitedÚoutputr0   i   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¯  rA  r   r_   rh   ÚappendÚjoin)r¬  r¯  ÚlinesÚshownÚ_textrX   Ú_futurerÓ  r²  r  rµ  Ú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)Úmapr9  rK  rF  )rË   rÁ  ÚirD  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   € ÷ 4Iñ 4I¸ð 4IÈTñ 4Ir&   c              ƒ  ón  "  € \         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 RR4      eˆ   ^ RI
HpHp V Uu. uF  qu! W^,          4      e   K  VNK  	  ppV'       gT   Rp V P                  W44       V P                  P                  V4      VJ d   V P                  P                  VR4       R# R# MTp\        V4      ^8X  d   V^ ,          ^ ,          MV P                  V4      p	^ RIHp
 T
! V UUUu. uF  w  r¼qÜNK	  	  uppp4      pRpV Fj  w  r¿p\#        WþR7      p\        V RR4      e+   \#        TV UUUu. uF  w  r¼pX! W4      NK  	  upppR7      pV P%                  WŸ4      G Rj  x€L
 pVf   Kj   M	  VRJ d8   \        V4      ^8”  d(   T P'                  V UUUu. uF  w  r¼qÜ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¡u upi u upppi u upppi  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.FNr—  )r™  Úproducer_identityT)rq   )rv   ©r‹   z,Coalesced process completion delivery failed)rc  Úcurrent_taskÚsleepÚ%_completion_notification_batch_windowÚ _completion_notification_batchesrÕ  Ú$_completion_notification_batch_tasksr_   Ú_settle_batch_waitersr6   rÃ  r™  rÊ  rA  r¾  r|   rq   rY   r’  rš  ÚCancelledErrorr3   r4   rÅ  )rË   rÈ  rÌ  r¬  rh  r™  rÊ  ÚitemÚentries_to_deliverrÊ  rq   r»  rX   r¼  ru   Úcandidate_evts   &&              r$   Ú_flush_process_completion_batchÚ9GatewayNotificationsMixin._flush_process_completion_batch-  sz  é € ä×+Ò+Ó-ˆØ:<ˆØ$)ˆ	ð/	IÜ—-’- × JÑ JÓK×KÐKØ×;Ñ;×?Ñ?ÀÀRÓHˆGà×8Ñ8×<Ñ<¸SÓAÀ\ÓQØ×9Ñ9×=Ñ=¸cÀ4ÔHßØðJ ×&Ñ& wÔ:à×8Ñ8×<Ñ<¸SÓAÀ\ÓQØ×9Ñ9×=Ñ=¸cÀ4ÖHñ RôM �tÐ0°$Ó7ÒCß^Ù7>Ó%n±w¨tÐBVÐW[ÐbcÕ]dÓBe§d d±wÐ"Ð%nß)Ø $�IØð> ×&Ñ& wÔ:à×8Ñ8×<Ñ<¸SÓAÀ\ÓQØ×9Ñ9×=Ñ=¸cÀ4ÖHñ RðG *ð &-Ð"Ü69Ð:LÓ6MÐQRÔ6RÐ,¨QÕ/°Ö2Ø#×IÑIÐJ\Ó]ð å\Ù:Ñ[mÕ;nÑ[mÑDWÀEÐPWºCÑ[mÓ;nÓoˆLð ˆIÛ1CÑ-� gÜ $ ]Ô O�Ü˜4Ð!4°dÓ;ÒGÜ$(¨ÙPbõPdÙPbÑ9L¸ÀWÑ)¨$Ö4ÑPbóPdô %e�Mà"&×"GÑ"GÈ
Ó"b×b�	ØÔ(Ùñ 2Dð ˜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ùò &oùô <oùôPdábùô <døÜ×%Ñ%ô 	àˆIßØ×?Ñ?×CÑCÀCÈÓL�ØÜô 	Ü×ÑÐKÔLØŠIð	ûð
 ×&Ñ& wÔ:à×8Ñ8×<Ñ<¸SÓAÀ\ÓQØ×9Ñ9×=Ñ=¸cÀ4ÕHð RüsÄ   ‚N5�#L  Á K!ÁA"L  Â%AN5Ã5L  ÄK$Ä'K$Ä-L  Ä:AN5Æ
AL  ÇK)Ç:L  ÈK0È'L  ÉK7ÉL  É+L  É;K9Ê	L  ÊAN5Ë!L  Ë$L  Ë9L  Ì M Ì%M ÍM ÍM# ÍM Í M# Í#AN2Î2N5c               ó   € V ^8„  d   QhRR/# r[  r"   )r#   s   "r$   r%   r°   d  s   € ÷ *ñ *°$ñ *r&   c                	óp   € V  F/  w  r#pVP                  4       '       d   K  VP                  V4       K1  	  R # r^   )ÚdoneÚ
set_result)r¬  rÏ   r»  Ú_evtÚfutures   &&   r$   rÑ  Ú/GatewayNotificationsMixin._settle_batch_waitersc  s*   € ã#*ÑˆE˜Ø—;‘;—=”=Ø×!Ñ! &Ö)ó $+r&   c               ó   € V ^8„  d   QhRR/# r[  r"   )r#   s   "r$   r%   r°   i  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Ï  FrÐ  )
Ú)_completion_notification_batches_stoppingr6   ro  rÚ  Úcancelrc  ÚgatherÚvaluesrÑ  Úclear)rË   ÚtaskÚtasksÚbatchesr¬  s   &    r$   Ú&_cancel_process_completion_batch_tasksÚ@GatewayNotificationsMixin._cancel_process_completion_batch_tasksi  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°   }  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.Nr¼  rÏ  rÐ  rá  rÎ  c                 ó   € R # )gš™™™™™¹?r"   r"   r&   r$   rŒ  ÚTGatewayNotificationsMixin._enqueue_process_completion_notification.<locals>.<lambda>‰  s   € ¹cr&   rã  c                 ó   € R # )Fr"   r"   r&   r$   rŒ  rð  Š  s   € Á%r&   Ú_background_tasksFr‰   re   )rÁ  r|   r½  rY   ro  rÅ   Úsetattrrã  r©  Ú_COMPLETION_BATCH_KEY_FIELDSrc  Úget_running_loopÚcreate_futurerÏ  Ú
setdefaultr·  rÐ  Úcreate_taskrÖ  Ú_retain_background_taskÚ_track_task_inrá  )	rË   rÊ  rX   r½  Úattrrþ  rÈ  rÝ  rè  s	   &&&      r$   Ú(_enqueue_process_completion_notificationÚBGatewayNotificationsMixin._enqueue_process_completion_notification}  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Î  r"   )r#   s   "r$   r%   r°   Ÿ  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œ  r7   Nr[   r0   rg   r)   r*   )r¿   r�  r_   )rË   rX   r�  Úparseds   &&  r$   Ú _enrich_async_delegation_routingÚ:GatewayNotificationsMixin._enrich_async_delegation_routingŸ  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   ÚgrouprÂ  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)rÁ  Ú&_deliver_async_delegation_group_scoped)rË   r  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/# r  r"   )r#   s   "r$   r%   r°   º  s   € ÷ Hñ HÀ*ð HÐQ_ñ H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RpV EF%  pV! V4      p	V	'       g   K  \        V RR4      e8   ^ RIH	p
 V
! W4      e(   V P                  W•4      G Rj  x€L
 RJ ;'       g    Tp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   EK  VP                  WY34       EK(  	  V'       g   V'       d   R# R# \        V4      ^8X  d%   V^ ,          w  rYV 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  ppV.p. pVR,           FD  w  rYV! 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                  VV4      G Rj  x€L
 # R\        V4       R2pRP'                  V.VO4      p\        V RR4      e5   ^ RIHp \+        TV.R V 4       O Uu. uF  pV! V V4      NK  	  upR7      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Lw ELZ LÅu upi  LJ5i)r–  )rº  ©Úprocess_registryre   NFTr—  r˜  r‰   r0   r[   r[  )Úclaim_event_deliveryrš   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.]rR   )rÊ  c              3  ó*   "  € T F	  w  rVx € K  	  R # 5ir^   r"   )ra   rÿ   r   s   &  r$   rc   ÚSGatewayNotificationsMixin._deliver_async_delegation_group_scoped.<locals>.<genexpr>ú  s   é € ÐKcÑZbÑRVÐRSÍAÓZbùs   ‚rË  r�  )r¿   rº  Útools.process_registryr  r_   r·  r’  r6   rÃ  r™  r   rR  r9  rM  rA  rt  rj  r  rz  r¸  rÊ  rY   rÇ  rÀ  )rË   r  rº  Ú_prÚoutcomesrX   rP   ÚdeliverableÚacknowledgedrÊ  r™  rb  rE  r»  r  Úprimary_evtÚprimary_textÚblocksÚsiblingsrŸ   ÚheaderÚconsolidatedrÊ  rÔ   rh  r   s   &&                        r$   r  Ú@GatewayNotificationsMixin._deliver_async_delegation_group_scopedº  sr  é € Ý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ßÙÜ�tÐ0°$Ó7ÒCÝKÙ'¨Ó2Ò>Ø)-×)NÑ)NÈzÓ)_×#_ÐcgÐ#g×#wÐ#wÐkw�LÙÜ˜Ÿ™Ð!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ñ! ÷" ß'�4Ð1¨TÐ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ˆÜ�4Ð,¨dÓ3Ò?ÝDÜ˜{Ø=HÐ<dÑKcÑZbÓKcÑ<dóDfÙ<d°5Ñ! $¨Ö.Ñ<dñDfô gˆKà×?Ñ?Ø˜+°hð @ó 
÷ 
ˆ	ð Òã"*‘��YØ×$Ñ$×(Ñ(¨Ö-ñ #+àÐò} %[ò $`ò lÚLò Pò >ñ ZùòDfñ
ùsß   ‚2M>µM>ÁM>Á-M#
Á.A&M>ÃM&ÃM>Ã"!M>ÄM>Ä(M>Ä<M>Å
M)ÅM>Å(M,Å)1M>Æ!M>Æ=M>Ç3M>Ç8M/Ç9M>ÈM2ÈM>È%A4M>ÊM>Ê/M5Ê0AM>Ì M7
ÌM>Ì1M<Ì22M>Í&M>Í)M>Í,M>Í/M>Í2M>Í5M>Í7M>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_completionsr  c                 ó(   <€ S! S P                   4      # r^   ©rÇ  )r  r  s   €€r$   rŒ  ÚQGatewayNotificationsMixin._restore_secondary_completion_ledgers.<locals>.<lambda>
  s   ø€ Ñ;ZÐ[^×[oÑ[oÔ;pr&   ÚRestoredN)rj  r  r  r  Ú_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_completionsr  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)rj  r*  r  r  r   rÇ   rÈ   r4   rÂ   r$  r6   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¿   r5  r6   r   r3   r4   rñ   rÂ   )	rË   r%  Úfnr3  r5  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   Úintervalr?   r    r¯   r"   )r#   s   "r$   r%   r°   *  s   € ÷ 5*ñ 5*¸ð 5*Èñ 5*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        Fº  p	\6        ;QJ d    R V	 4       F  '       g   K   RM	  R	M! R V	 4       4      '       d'   V	 F  pVP                  P+                  V4       K   	  Kc   V P9                  V	4      G Rj  x€L
 p
V
R	J d8   V P;                  V	4       V	 F  pVP                  P+                  V4       K   	  Kº  K¼  	  RRR4       \         P                  ! V4      G Rj  x€L
  EK–  R#  EL« EL ELè  \$         d     EK‹  i ; i LŒ  \$         dG   pT	 F  pTP                  P+                  T4       K   	  \<        P?                  R
T4        Rp?EKS  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_Sr  z"Async delegation watcher error: %srr   rw   c              3  óp   "  € T F,  qP                  R ^ 4      \        P                  ! 4       8„  x € K.  	  R# 5i)r»  N)r_   rF   rG   )ra   rX   s   & r$   rc   ÚFGatewayNotificationsMixin._async_delegation_watcher.<locals>.<genexpr>Q  s)   é € ÐbÑ\aÐUXŸ7™7Ð#9¸1Ó=ÄÇÂÓ@PÖPÓ\aùs   ‚46TFz$Async delegation injection error: %s) rc  rÍ  rj  r<  r  r  Ú_runningr   rÇ   rÈ   rF   rG   rî  r0  rË  rÇ  ÚemptyÚ
get_nowaitr3   r_   r·  rÀ  r  r÷  r©  Ú_ASYNC_GROUP_KEY_FIELDSræ  rk   r  Ú_back_off_refused_completionsr4   r  )rË   r:  r<  r  Úlast_orphan_sweepÚrequeueÚasync_eventsrX   Úgroupsr  rh  rÿ   s   &&          r$   Ú_async_delegation_watcherÚ3GatewayNotificationsMixin._async_delegation_watcher*  s©  é € ô �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ß“sÑbÑ\aÓb—s—s’sÑbÑ\aÓb×bÒbÛ#(˜CØ×0Ñ0×4Ñ4°SÖ9ñ $)á ð	PØ*.×*NÑ*NÈuÓ*U×$U˜	Ø$¨Ó-Ø ×>Ñ>¸uÔEÛ', Ø #× 4Ñ 4× 8Ñ 8¸Ö =ó (-ñ .ñ -÷7 VôT —-’- Ó)×)Ó)ñW ò	 	ò UâKøô %ô Ûðúñ( %Vøô
 %ô PÛ#(˜CØ×0Ñ0×4Ñ4°SÖ9ñ $)äŸ™Ð%KÈQ×OÓOûðPú÷M V×UúñT *ùsË   ‚MœK�$MÁ"MÁ$AL9ÃK
Ã"L9Ã%KÃ&'L9ÄKÄ)CL9È L9È&L9ÉK%ÉK#
É?K%ÊL9Ê!MÊ=MÊ>
MË
L9ËL9ËK ËL9ËK Ë L9Ë#K%Ë%L6	Ë0:L1	Ì*L9Ì1L6	Ì6L9Ì9M		Í	Mc               ó    € V ^8„  d   QhRRRR/# )r   r  rÂ  r    r¯   r"   )r#   s   "r$   r%   r°   b  s   € ÷ Bñ B¨Zð B¸Dñ Br&   c                ó’   € V  F@  p\        VP                  R4      ;'       g    ^ 4      ^,           pW!R&   \        V4      VR&   KB  	  R# )a   Space out an undelivered async group's retries instead of re-offering it every 2 s pass.
The backoff only paces; the durable ledger decides when a row gives up (a permanent refusal
spends a delivery attempt there, so the count survives restarts) (#141153).rÐ  r»  N)r>   r_   rJ   )r  rX   r=   s   &  r$   rC  Ú7GatewayNotificationsMixin._back_off_refused_completionsa  sH   € ó
 ˆCÜ�s—w‘wÐ2Ó3×8Ð8°qÓ9¸AÕ=ˆDØ'+Ð#Ñ$Ü*;¸DÓ*AˆCÐ&Ó'ó r&   c               ó    € V ^8„  d   QhRRRR/# )r   Úlimitr>   r    r   r"   )r#   s   "r$   r%   r°   l  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®  ©Ú
strip_ansi©Útransform_process_outputNr0   ©Úredact_terminal_outputÚcommandÚtask_id©rV  Ú
returncoderW  )r¿   r¯  Útools.ansi_striprQ  r  rS  Úoutput_bufferÚagent.redactrU  r6   r²  )ÚsessionrN  r¯  rQ  rS  Ú
new_outputrU  Ú_commands   &&      r$   Ú_redacted_output_tailÚ/GatewayNotificationsMixin._redacted_output_tailk  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   ÚwatcherrY   r    r    r"   )r#   s   "r$   r%   r°   }  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).r[   r0   FNÚ_active_sessions)r   r_   rh   rc  rî  rµ  r  r6   )rË   r´  rc  r[   r•   rÌ   s   &&&   r$   Ú_launching_turn_activeÚ0GatewayNotificationsMixin._launching_turn_active}  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_textrc  rY   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–  rS  NzWatcher delivery error: %sr*   r,  r½   )
r¿   r%  rc  rî  rµ  r  r   rÇ   ÚERRORrÊ   )
rË   r´  r)   r*   ri  rc  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   rc  rY   rÓ  r   r    r"   )r#   s   "r$   r%   r°   “  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®  rT  rP  rR  rV  r0   rW  rX  iÐ  Nr¶  u'   [â€¦ output truncated â€” showing last z chars]
rr   rs   rÓ  Úowner_task_idr	  r3  r²  r³  r´  Útermination_sourcerµ  r‰   éÿÿÿÿ)r¿   r¯  r\  rU  rZ  rQ  r  rS  r6   r[  r²  rA  ÚfindÚ_WATCHER_ROUTE_FIELDSr_   r   rh   )rc  r]  rÓ  r¯  rU  rQ  rS  r_  Ú_rawÚ_LIMITÚ_tailÚ_nlÚ_outÚks   &&&           r$   Ú_build_process_completion_eventÚ9GatewayNotificationsMixin._build_process_completion_event’  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   rÓ  r   Únotify_moder    r"   )r#   s   "r$   r%   r°   ½  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è  r3  NrA   rV  r0   Úconcise)Úduration_secondszgateway.background.final_output©r  rµ  )r¿   r�  r¯  r`  r6   rÃ   r>   r?   ÚmaxrF   r²  rh   r   )rË   rÓ  r]  r  r�  r¯  r^  Ú_startedÚ_durrV  r  s   &&&&       r$   Ú_format_process_final_messageÚ7GatewayNotificationsMixin._format_process_final_message½  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   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ô  rV  r0   z gateway.background.still_runningu    â€” `Ú`z gateway.background.recent_outputr„  )r¿   r¯  rŒ  r`  r6   r   rh   )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   rc  rY   r    r    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)r4   Úlog_message)r6   Ú
is_runningÚagent.async_utilsr”  Ú_run_process_watcherr4   )rË   rc  Úloopr”  rÝ  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   rc  rY   r    r¯   r"   )r#   s   "r$   r%   r°   ã  s"   € ÷ x_ñ x_°$ð x_¸4ñ x_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Tp \        P                  ! V4      G Rj  x€L
  VP                  V4      pVf   EMgS 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M÷K¨  V	'       d   VP                  '       d   EMÙKÆ  \        VP                  4      pWú8„  pTp
VP                  '       Ed[   V'       Ed‘   VP!                  V4      '       Egy   S P#                  SWÕ4      pV! V4      pV'       g   EMdS P%                  SS4      G Rj  x€L
 pS P'                  VV4      G Rj  x€L
 pVR
JdY   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\.        8  d(   \1        V\3        V^4      ^,          \4        RR7      pEK  \        S RR4      eb   S P7                  V4      eO   ^ RIHp  S P                  V4      ;_uu_4       GRj  x€L
  V! S V4      RJpRRR4      GRj  x€L
  X'       d   EM'\        P?                  RW[V4       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KY  VR8X  g   EKc  V'       d   EKn  S P-                  SSSS PE                  V4      S4      G Rj  x€L
  EK�  \        P                  RV	'       d   R MRV4       R#  EL ELú  + GRj  x€L 
 '       g   i     EL; i ELÉ EL“ ELd  + GRj  x€L 
 '       g   i     EL|; i EL» EL¤ ELK ELÆ EL®  + GRj  x€L 
 '       g   i     ELÆ; i  \<         d    \        P                  RTRR7       R
p ELñi ; i ELR EL, EL  + GRj  x€L 
 '       g   i     EL7; 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.r  )Úformat_process_notificationr½  rÓ  Úcheck_intervalr7   r0   r)   r*   Únotify_on_completeFNzCProcess watcher started: %s (every %ss, notify=%s, agent_notify=%s)r¾  Trq  rW  r‚  Úallr  rA   rB   r—  r˜  z0Process watcher: admission recheck failed for %sr»   zbProcess watcher: completion for %s was refused %d times; falling back to the notify_mode=%s noticeug   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^   )rm  )r)   ri  r´  rË   r*   rc  s   €€€€€€r$   rŒ  Ú@GatewayNotificationsMixin._run_process_watcher.<locals>.<lambda>R  s   ø€  D×$>Ñ$>¸}ÈgÐW`ÐbnÐpwÔ$xr&   )r7   r†   zProcess watcher ended%s: %sz	 (silent)>   r¡  rÏ   r‚  >   Nr–  )#r  r  r|   rž  r½  r_   rÁ  rÂ  r4   r5   rc  rÍ  r6   r´  rA  r[  Úis_completion_consumedr|  rf  rü  r²  rˆ  rm  rÖ  r	   r…  rI   r9  rÃ  r™  r3   rñ   r”  rŠ  r�  )rË   rc  r  rž  r½  rÓ  r:  Úagent_notifyr  ÚsilentÚlast_output_lenÚcompletion_attemptsÚretry_intervalr]  ÚsurfaceÚcurrent_output_lenÚhas_new_outputÚcompletion_evtrÊ  Ú	turn_busyrh  r™  Ú	committedrŠ  r)   ri  r´  r*   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Ø ¨Ó-÷
 %¨+Ð9UÔ*UØ'¨7Ô2°w×7HÑ7HÐPYÔ7Yà+/×+MÑ+MÈjÐclÓ+m˜LØ"&×"<Ñ"<¸]ÈGÐU^Ð`lÐnuÓ"v×vÐvÙð (¨1Õ,Ð'Ø*Ô-OÔOÜ)9Ø/¼CÀÈ!Ó<LÈqÕ<PÜ&KÐZ]ô*_˜ò !Ü Ð&9¸4Ó@ÒLØ $× BÑ BÀ>Ó RÒ ^ÝSð.à'+×'CÑ'CÀN×'S×'SÕ'SÙ,@ÀÀ~Ó,VÐ^bÐ,b 	÷ (T×'S÷ %Ù!Ü—N‘Nð0Ø1;Ð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]Ö^÷S 9×8×8×8úò 0÷ =×<×<×<úò8 !ZÚ oò w÷ (T×'S×'S×'Sûä(ô .ä"ŸL™LÐ)[Ð]gØ26ð )ô 8à(-›Ið	.úò0  Eòc÷  E×D×DÔDúñùs  ˆBU.ÂR%ÂU.ÂR+Â#U.Â.R(Â/'U.Ã(U.Ã?SÄ 8U.Ä8SÄ9U.Ä<#SÅU.Å*SÅ+U.Å7U.Æ	U.ÆU.Æ':U.Ç"U.Ç:9U.È3S.È4U.ÉS1ÉU.É A	U.Ê)S4Ê*A)U.ÌT Ì1S7Ì2T Ì5S=ÍT ÍS:ÍT ÍU.Í/U.Î	A+U.Ï4UÏ5U.Ï8%UÐU	ÐUÐ"U.Ð-UÐ.
U.Ð>U.ÑU.Ñ'U.Ñ:U,Ñ;U.ÒU.Ò(U.Ò+S	Ò1R4Ò2
S	Ò=S	Ò?
U.ÓU.ÓU.ÓS+	ÓSÓ
S+	Ó#S+	Ó%
U.Ó1U.Ó4U.Ó7T Ó:T Ó=T	ÔTÔ
T	ÔT	ÔT ÔU.ÔT Ô%UÔ?U.ÕUÕU.Õ	UÕU.ÕU)	ÕUÕ
U)	Õ!U)	Õ#
U.)rã  rY  )r[   r7   rg   r)   r*   r¹   )r[   r‰   r/  r^   )NNFTNNN)r0   r"   )g       @)Gr¥   r¦   r§   r¨   r©   rô  rB  ÚdataclassesÚ	dataclassr¬   rÐ   r   r  r  r=  rC  rH  rM  rW  rY  rª   rk  re  r—  rµ  rË  ÚstaticmethodrÆ  rÝ  rö  rï  r  rÄ  r9  rF  rM  rR  rQ  rn  rt  r~  rÁ  rì  Úasynccontextmanagerr…  r’  r‘  r©  r¾  rš  rÖ  rÑ  rë  rü  r  r  r  r&  r0  r$  rH  rC  r`  rf  rm  r|  rˆ  r�  rš  r˜  r«   r"   r&   r$   r™   r™   ¬   s_  ‡ Ùrð $oÐ Ú|Ð[wÐxzÕ[{Ñ|Ðà×Ñ÷	ð 	ó ð	õ G÷D;b÷|I÷Võ230òj	:ò6òGõ ð0 <@Ð Ð"8Ó?õ%^ðN)ØOS÷)õV5#õn@
õD'IðR ô"ó ð"õ2õ%õNi÷.Xð,fØHM÷fðP ôó ðõ:FðÀ5÷ ÷Z÷%RðN ôjó ðjõõ><õ|:ð4 ×#Ñ#ôó $ðð
@Ø<>÷
@ð8kØ<>÷8kðt ôDó ðDð ô ó ð õ<@õ4Iðl ô*ó ð*õ
Sõ( õD3õ$LõHõT0õ;õo÷ 5*ðn ôBó ðBð ôó ðõ"Qõ	ð ô(
ó ð(
õT@õAõ"÷ x_ñ x_r&   r™   >   ú.3gpú.aviú.mkvú.movú.mp4ú.webm)r[   r7   rg   r)   r*   r¹   r¦  >   ú.gifú.jpgú.pngú.jpegú.webp>   Ú
turn_leaserZ  Ú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   rc  rì  r±  r/  rÇ   rF   Úpathlibr   Útypingr   r   r   r   Ú
agent.i18nr   Úagent.retry_utilsr	   rÄ   r
   r   rë   r   r   Úgateway.platforms.eventr   r   Úgateway.sessionr   r   r   Úgateway.run_shutdownr   r   r   r   r   Ú gateway.run_notifications_updater   Ú#gateway.run_notifications_ownershipr   Ú	getLoggerr4   r+   r;   rô   ru  rà   Ú	frozensetr’  rÖ  rI   rH   rJ   ri  rU   rV   rl   r   r—   r™   r"   r&   r$   Ú<module>rÒ     s  ðñõ #ã Û Û Û Û Û Ý ß ,Ó ,å Ý .ß =ß Mß =ß EÑ Eß uÕ uÝ LÝ Qð 
×	Ò	˜=Ó	)€õbðÐUY÷ ò  @€àpÐ Ú8€ñ !*Ò*]Ó ^Ð à%&Ð "Ø(*Ð %ð %(Ð !õKð ÐSØÐ\ØÐYØÐbð	Ð ðbð õ8õ Jõõ,ô6o_Ð ?ÐAbö o_r&   