+
    jHàjã  ã                  óx   € R t ^ RIHt ^ RIt^ RIHt ]P                  ! ]4      tR R lt	R t
R R ltR	 R
 ltR# )a°  An ``unknown`` turn nobody is waiting on settles as interrupted (#134889 GW-10, #139532).

A turn lost across an owner restart is fenced ``unknown`` and pauses its session's FIFO, because
only the person who sent it knows whether to resend it. An automation delivery has no such person:
a cron run (``CRON_PRINCIPAL_ID``), a process completion or heartbeat (``automation:<route>``,
``local_automation_v1``, a native envelope's ``automation`` block) or a webhook delivery
(``webhook_delivery``) or a Kanban card attempt (``kanban_card_v1``, set by the dispatcher). Pausing on it stalls every message queued behind it until an operator
notices (a Bot Chat sat ten hours behind one).

Such a row settles through the same fenced resolution a person's Discard uses
(``resolve_unknown_session_input``): terminal ``interrupted``, never requeued or replayed, with a
Hermes transcript notice committed in the same transaction. No second recovery store.
)ÚannotationsN)ÚCRON_PRINCIPAL_IDc               ó   € V ^8„  d   QhRR/# ©é   ÚreturnÚbool© )Úformats   "ÚG/home/ubuntu/.hermes/hermes-agent/gateway/session_unattended_unknown.pyÚ__annotate__r      s   € ÷ Gñ G˜$ñ Gó    c                óD  € V P                  R4      ;'       g    RpV\        8X  g   VP                  R4      '       d   R# V P                  R4      ;'       g    / pVP                  R4      ;'       g    / pRV9   ;'       g     RV9   ;'       g    R	V9   ;'       g    R
V9   # )zPTrue for an admission no person submitted (so nobody can be asked to resend it).Úprincipal_idÚ zautomation:TÚpayloadÚnative_text_v1Úlocal_automation_v1Úkanban_card_v1Ú
automationÚwebhook_delivery)Úgetr   Ú
startswith)ÚrowÚ	principalr   Únatives   &   r   Úis_unattendedr      s­   € à—‘˜Ó'×-Ð-¨2€IØÔ%Ô%¨×)=Ñ)=¸m×)LÒ)LÙØ�g‰g�iÓ ×&Ð& B€GØ�[‰[Ð)Ó*×0Ð0¨b€Fð " WÑ,÷ Fð FÐ0@ÀGÑ0K÷ Fð FØ˜vÑ%÷Fð FØ);¸vÑ)EðGr   c                ót   € V  Uu. uF'  qR ,          R8X  g   K  \        V4      '       g   K%  VNK)  	  up# u upi )ÚstatusÚunknown)r   )Úrowsr   s   & r   Ú_unattended_unknownr!   %   s/   € ÙÓU™4�C x¥=°IÑ#=ŒCÄ-ÐPS×BT�CˆC™4ÑUÐUùÒUs   …5™5¬5c               ó   € V ^8„  d   QhRR/# )r   r   Úintr	   )r
   s   "r   r   r   )   s   € ÷ ñ ¨cñ r   c           
     ó|  a aa€ ^ RI Ho ^ RIHp ^ RIHo ^ RIHpHpH	p S P                  4       ;_uu_ 4       pVP                  R4      P                  4        Uu. uF
  qt! V4      NK  	  ppRRR4       ^ p	\        X4       Fb  p
 V! S WR,          V
R,          VVV 3R	 lR
7       T! S T
R,          4       T	^,          p	\        P#                  RT
R,          T
R,          4       Kd  	  V	# u upi   + '       g   i     LŠ; i  T d4   p\        P                  RT
R,          TP                   4        Rp?Kµ  Rp?ii ; i)z¸Boot recovery, right after ``recover_session_inputs`` fenced lost turns ``unknown`` and before
any FIFO is scheduled: settle every unattended one. Synchronous; runs off the owner loop.©ÚAUTOMATION_INTERRUPTED_NOTICE)Úrelease_admission_media)Úclose_discarded_turn)ÚRuntimeStoreErrorÚ_rowÚresolve_unknown_session_inputzDSELECT * FROM session_admissions WHERE status='unknown' ORDER BY seqNÚadmission_idÚ
generationc                ó   <€ S! SWS4      # )Nr	   )ÚconnÚlostr&   r(   Údbs   &&€€€r   Ú<lambda>Ú-settle_recovered_unattended.<locals>.<lambda>8   s   ø€ Ñ3GÈÈDÐXuÔ3vr   )Úepochr,   r-   Ú_terminal_writeú-Lost automation admission %s left unknown: %szMLost automation admission %s on session %s settled interrupted (not replayed)Útarget_session_id)Úagent.turn_failure_copyr&   Úgateway.session_ingress_mediar'   Úgateway.session_resultsr(   Úhermes_state_runtimer)   r*   r+   Ú	_read_ctxÚexecuteÚfetchallr!   ÚloggerÚwarningÚreasonÚinfo)r1   r4   r'   r)   r*   r+   r/   Úrr    Úsettledr   Úexcr&   r(   s   f&          @@r   Úsettle_recovered_unattendedrF   )   s#  ú€ õ FÝEÝ<ß[Ñ[Ø	�‰�Œ˜4Ø!%§¡ØRó"TßT\ÑT\ÓT^ð"_ó `ñ "_˜A��Q–ñ "_ˆð `÷ 
ð €GÜ" 4Ö(ˆð	Ù)Ø˜%°.Õ.AÈcÐR^ÕN_Þ võxñ 	   C¨Õ$7Ô8Ø�1�ˆÜ�‰ÐcØ˜Õ'¨Ð-@Õ)Aö	Cñ )ð €Nùò`÷ 
�ûð !ô 	Ü�N‰NÐJÈCÐP^ÕL_Ðad×akÑakÔlÝûð	ús5   ¸"C.ÁC)Á*C.Â DÃ)C.Ã.C>	ÄD;Ä(D6Ä6D;c               ó   € V ^8„  d   QhRR/# r   r	   )r
   s   "r   r   r   C   s   € ÷ ñ °tñ r   c              ƒ  ó”  "  € ^ RI p^ RIHp ^ RIHpHp VP                  WPP                  VP                  R7      G Rj  x€L
 pRp\        V4       F0  p V P                  WR,          VR,          VR7      G Rj  x€L
  R
pK2  	  V#  LG L  T d4   p	\        P                  R	TR,          T	P                  4        Rp	?	Ko  Rp	?	ii ; i5i)a  The drain found an ``unknown`` head (fenced in this owner, e.g. a lost managed worker):
settle the unattended ones through the owner's resolution. True when any settled, so the
drain re-reads its FIFO instead of pausing; a person's ``unknown`` row still pauses it.Nr%   )r)   Úlist_session_admissions)Ú
session_idFr,   r-   )Únoticer6   T)Úasyncior8   r&   r;   r)   rI   Ú	to_threadr1   rJ   r!   Úresolve_unknown_as_ownerr?   r@   rA   )
Ú	authorityÚrefrL   r&   r)   rI   r    rD   r   rE   s
   &&        r   Úsettle_unattended_unknownrQ   C   sÉ   é € ó åEßOØ×"Ñ"Ð#:¿L¹LÐUX×UcÑUcÐ"Ód×d€DØ€GÜ" 4Ö(ˆð	Ø×4Ñ4°S¸nÕ:MÈsÐS_ÕO`Ø<Yð 5ó [÷ [ð [ð
 Šñ )ð €Nñ eñ[øà ô 	Ü�N‰NÐJÈCÐP^ÕL_Ðad×akÑakÔlÝûð	üsL   ‚=C¿BÁ CÁ%BÁ:B	Á;BÁ?	CÂ	BÂCÂ(C Â:CÃ CÃC)Ú__doc__Ú
__future__r   ÚloggingÚhermes_state_keysr   Ú	getLoggerÚ__name__r?   r   r!   rF   rQ   r	   r   r   Ú<module>rX      s;   ðñõ #ã å /à	×	Ò	˜8Ó	$€õGòVõ÷4r   