+
    jHàj„–  ã                   ó˜  € R t ^ RIHt ^ RIHtHt ^ RIt^ RIt^ RIHt ^ RI	H
t
Ht ^ RIHt ^ RIHtHtHt ]P$                  ! ]4      tR tR	 tR
 tR tR tR tR tR tR tR tR tR t R t!R t"R t#R t$R t%R t&Rt'R t(])! 0 R-m4      t*R t+R t,R t-R t.R  t/R! t0R"R/R# lt1R$ t2R.R% lt3])! R&R'04      t4R( t5R) t6R* t7R+ t8R.R, lt9R# )/zôTrusted producer admission; not a client-selectable internal input flag.

Reuse the private native route envelope and FIFO, retaining nonhuman turn semantics.
A producer ACK means committed input, not successful inference or outbound delivery.
)Údeepcopy)ÚUTCÚdatetimeN)ÚPlatform)ÚMessageEventÚMessageType)Ú
SessionRef)ÚRuntimeStoreErrorÚadmit_session_inputÚlist_session_admissionsc                 ór   € V P                  V4      pVf   \        R4      h\        P                  ! VRR7      # )NÚinvalid_params©Ú
separators©Ú,Ú:)Ú_completion_delivery_identityr	   ÚjsonÚdumps)ÚrunnerÚeventÚidentitys   && Ú?/home/ubuntu/.hermes/hermes-agent/gateway/session_automation.pyÚproducer_identityr      s5   € Ø×3Ñ3°EÓ:€HØÒÜÐ 0Ó1Ð1Ü�:Š:�h¨:Ô6Ð6ó    c                 ó  € ^ RI Hp V! V 4      pVf   R# V P                  P                  \	        VP                  R4      ;'       g    R4      4      pVf   R# ^ RIHp \        W4      pV! VP                  \        W44      RR7       Fv  pVR,          P                  R	4      ;'       g*    VR,          P                  R
/ 4      P                  R/ 4      pWhP                  RVP                  R4      .4      9   g   Kt  Vu # 	  R# )é    ©Úactive_authorityNÚsession_keyÚ ©r   F©Ú
session_idÚpending_onlyÚpayloadÚlocal_automation_v1Únative_text_v1Ú
automationÚ
identitiesr   )Úgateway.session_authoritiesr   Úsession_storeÚlookup_by_session_keyÚstrÚgetÚhermes_state_runtimer   r   ÚdbÚ_route_owner)	r   r   r   Ú	authorityÚentryr   r   ÚrowÚ
descriptors	   &&       r   Úcompletion_admissionr7      sè   € Ý<Ù  Ó(€IØÒÙØ× Ñ ×6Ñ6´s¸5¿9¹9À]Ó;S×;YÐ;YÐWYÓ7ZÓ[€EØ‚}ÙÝ<Ü  Ó/€HÙ& y§|¡|ÄÈYÓ@^Ðmr×sˆØ˜•^×'Ñ'Ð(=Ó>÷  Að  AÀ#ÀiÅ.×BTÑBTÐUeÐgiÓBj×BnÑBnÐo{Ð}ó  CAˆ
Ø—~‘~ l°Z·^±^ÀJÓ5OÐ4PÓQÖQØŠJñ tñ r   c              ƒ  ó  "  € ^ RI Hp \        V 4      ;_uu_4       GRj  x€L
  \        ^4       Fª  p \	        W4      G Rj  x€L
 pT;'       d	    T! T4      pT'       g    RRR4      GRj  x€L
  R#  T P                  YT4      G Rj  x€L
 pTRJ d   YAJd   TP                  R4      TR&   TRJg   \        Y4      '       d   K–  Tu uuRRR4      GRj  x€L
  # 	   RRR4      GRj  x€L
  R#  LÐ L°  \
         d,    \        P                  R4         RRR4      GRj  x€L 
  R# i ; i LÀ L¦  \
         d,    \        P                  R4         RRR4      GRj  x€L 
  R# i ; i L” L‚  + GRj  x€L 
 '       g   i     R# ; i5i)aJ  Prepare, format and admit one liveness tick as one critical section with a completion's
admit-and-withdraw (``admit_process_notice``): a completion that lands while this tick is on its
way in withdraws it once it is in, and a tick checked after it sees it. True when admitted, None
to drop it, False to requeue the original event.)Ú$_format_gateway_process_notificationNz1Heartbeat preparation error; the tick is requeuedFz"Watch notification injection errorÚ_refusal_permanent)Úgateway.runr9   Ú_heartbeat_lockÚrangeÚprepare_heartbeatÚ	ExceptionÚloggerÚ	exceptionÚ_inject_watch_notificationr/   Ú_replaced_tick_claimed)r   r   r9   Ú_attemptÚpreparedÚtextÚ	delivereds   &&     r   Údeliver_heartbeatrH   +   sD  é € õ
 AÜ˜v×&×&Õ&Ü˜ažˆHðÜ!2°6Ó!A×A�ð
 ×NÐNÑ DÀXÓ NˆDßØ÷ '×&Ñ&ðØ"(×"CÑ"CÀDÓ"S×S�	ð ˜EÓ! hÓ&;Ø.6¯l©lÐ;OÓ.P�Ð*Ñ+Ø Ó%Ô-CÀF×-UÔ-UØ Ñ ÷' '×&Ò&Ù ð( ÷+ '×&Ó&ñ BøÜô ä× Ñ Ð!TÔUÙ÷ '×&Ò&ðúñ	 'ñ TøÜô Ü× Ñ Ð!EÔFÙ÷ '×&Ò&ðú÷ '×&×&Õ&üs!  ‚F C1¡F¤E/´C5ÁC3
ÁC5ÁE/ÁE/Á!E/Á"FÁ-D.Á.FÁ5D2Â	D0
Â
D2Â3E/ÃE/Ã	FÃE+ÃFÃE/ÃFÃ*E-Ã+FÃ3C5Ã5 D+	ÄE/ÄFÄ"D%Ä#FÄ*D+	Ä+E/Ä.FÄ0D2Ä2 E(	ÅE/ÅFÅE"Å FÅ'E(	Å(E/Å+FÅ-FÅ/F		Å5E8Å6
F		ÆF		Æ	Fc                 óÚ   € ^ RI Hp ^ RIHp VP	                  R4      pV'       d	   V! V 4      MRpT;'       d    V! VP
                  VR7      p\        V4      ;'       d    VR,          R8g  # )r   r   )Úget_session_admissionÚ	_replacesN)Úadmission_idÚstatusÚqueued)r+   r   r0   rJ   r/   r1   Úbool)r   rE   r   rJ   Úreplacedr3   r5   s   &&     r   rC   rC   I   sY   € Ý<Ý:Ø�|‰|˜KÓ(€Hß,4Ñ  Ô(¸$€IØ
×
RÐ
RÑ-¨i¯l©lÈÔR€CÜ�‹9×2Ð2˜˜X�¨(Ñ2Ð2r   c              ƒ  óØ  "  € \        W4      pVP                  R4      R8X  d‘   R\        VP                  R4      ;'       g    R4      R\        VP                  R4      ;'       g    ^ 4      /VP                  R&   VP                  R4      '       d#   VP                  W#WTR,          R7      G R	j  x€L
 # VP                  R4      R
8w  d   VP                  W#V4      G R	j  x€L
 # \        V 4      ;_uu_4       GR	j  x€L
  VP                  W#V4      G R	j  x€L
 p\        W4      G R	j  x€L
  TuuR	R	R	4      GR	j  x€L
  #  L‘ Lc LI L1 L  L  + GR	j  x€L 
 '       g   i     R	# ; i5i)z©Admit a process notice. A completion and the withdrawal of its process's waiting ticks hold
the heartbeat lock together; a tick already holds it (``deliver_heartbeat``).ÚtypeÚ	heartbeatÚoutputr!   ÚomittedÚheartbeat_tickrK   )ÚreplacesNÚ
completion)r   r/   r.   ÚintÚmetadataÚadmit_automationr<   Úwithdraw_process_ticks)r   r3   Úadapterr   Úevtr   Úreceipts   &&&&&  r   Úadmit_process_noticer`   R   s  é € ô ! Ó-€HØ
‡w�wˆvƒ˜+Ô%à,4´c¸#¿'¹'À(Ó:K×:QÐ:QÈrÓ6RØ,5´s¸3¿7¹7À9Ó;M×;RÐ;RÐQRÓ7Sð,Uˆ�‰Ð'Ñ(à�7‰7�;×ÒØ"×3Ñ3°GÀHÐ[fÕWgÐ3Óh×hÐhØ
‡w�wˆvƒ˜,Ô&Ø×/Ñ/°ÀÓI×IÐIÜ˜v×&×&Õ&Ø!×2Ñ2°7À8ÓL×LˆÜ$ VÓ1×1Ð1Ø÷ '×&Ò&ñ iáIÙ&ÙLÙ1÷ '×&×&Ó&üs§   ‚?E*Á#E*Á&+E*ÂE*Â/EÂ0/E*ÃEÃ E*Ã;EÃ<E*Ã?EÄEÄEÄ(E	Ä)EÄ.E*Ä;EÄ<E*ÅE*ÅE*ÅEÅ	EÅE*ÅE'	ÅEÅ
E'	ÅE'	Å!	E*c           
   ƒ  ó¶  aa"  € ^ RI p^ RIHp V! V 4      pV'       d>   V P                  P	                  \        VP                  R4      ;'       g    R4      4      MRoSf   V# \        VS4      \        VP                  R4      ;'       g    R4      upoVP                  \        WWQ4      G Rj  x€L
 '       d)   \        P                  RVP                  R4      S4       R# ^ RIHp VP                  WdP                  R	SP                  ,           V\!        W4      R
7      G Rj  x€L
 '       d   R# VP                  \"        VP                  VR7      G Rj  x€L
 p\%        VV3R lV 4       R4      pT;'       d"    \'        VR,          4      P                  R4      p	\)        V	\*        4      '       g   V# ^ RIHp
 / VCV
! W‘4      CRVR,          /C#  EL# L° L€5i)aç  The liveness tick to admit for ``event``, or None to drop it because its process's completion
is already in the session: a later tick would be a stale "still running" turn. The caller holds
the heartbeat lock.

Otherwise a tick of the same process still queued is replaced: this one carries its stored
output, and ``_replaces`` names it, so its cancellation commits in this tick's own admission
(``admit_automation``) and a refused replacement leaves it queued. A tick's output is never sent
again, so a busy session gets one waiting turn holding every tick's output instead of one turn
per tick. A queued tick that started or settled first ran with its own output, and this one
queues behind it. A retry of a tick already admitted is dropped.Nr   r    r!   r$   zFDropped heartbeat %s of process %s: its completion is already admittedÚevent_id)Úfind_session_admissionúautomation:)Úprincipal_idr$   Ú
request_id©r$   c              3   óf   <"  € T F&  p\        VSSP                  4      '       g   K"  Vx € K(  	  R # 5i©N©Ú_queued_tickr    )Ú.0r5   r4   Úprocesss   & €€r   Ú	<genexpr>Ú$prepare_heartbeat.<locals>.<genexpr>   s$   øé € Ð\¡7˜C¬l¸3ÀÈ×IZÑIZ×.[—C’C£7ùs   ƒ1§
1r&   Útick)Újoin_heartbeat_outputsrK   rL   )Úasyncior+   r   r,   r-   r.   r/   r2   Ú	to_threadÚ_process_completedr@   Údebugr0   rc   r1   r    r   r   ÚnextÚ_descriptorÚ
isinstanceÚdictÚ$tools.process_registry_notificationsrq   )r   r   rr   r   r3   Úownerrc   ÚpendingÚwaitingÚearlierrq   r4   rm   s   &&         @@r   r>   r>   d   sœ  ùé € ó Ý<Ù  Ó(€Iß_hˆF× Ñ ×6Ñ6´s¸5¿9¹9À]Ó;S×;YÐ;YÐWYÓ7ZÔ[Ðnr€EØ‚}ØˆÜ! )¨UÓ3´S¸¿¹À<Ó9P×9VÐ9VÐTVÓ5W€N€Eˆ7Ø×ÑÔ1°6ÀeÓS×SÖSÜ�‰Ð]Ø—Y‘Y˜zÓ*¨Gô	5áÝ;Ø×ÑÐ5·|±|ÐR_Ðbg×bsÑbsÕRsØ*/Ô<MÈfÓ<\ð ó ^÷ ^ö ^áØ×%Ñ%Ô&=¸y¿|¹|ÐX]Ð%Ó^×^€GÜÕ\¡7Ó\Ð^bÓc€GØ×EÐEœ+ g¨iÕ&8Ó9×=Ñ=¸fÓE€GÜ�gœt×$Ò$ØˆÝKØdˆeÐdÑ-¨gÓ=Ðd¸{ÈGÐTbÕLcÑdÐdò Tñ
^ñ _ùsV   „AGÁ:GÂ#GÂ/GÂ0	GÂ:A*GÄ$GÄ%	GÄ/'GÅGÅ#GÅ;AGÇGÇGc                 óœ   € V P                  R 4      ;'       g5    V P                  R4      ;'       g    / P                  R4      ;'       g    / # )r'   r(   r)   )r/   )r&   s   &r   rw   rw   ‡   sB   € Ø�;‰;Ð,Ó-×nÐn°'·+±+Ð>NÓ2O×2UÐ2UÐSU×1ZÑ1ZÐ[gÓ1h×nÐnÐlnÐnr   c                ó:  € V P                  R4      pVf   / # \        V\        4      '       dX   \        V4      RR08w  gF   \        VR,          \        4      '       d)   \        VR,          4      \        Jg   VR,          ^ 8  d   \        R4      hR\        V4      /# )zQA liveness tick's stored output (``heartbeat_tick``): what a later tick folds in.rV   rT   rU   r   rp   )r/   rx   ry   Úsetr.   rR   rY   r	   )rZ   rp   s   & r   Ú_tick_metadatar‚   ‹   s„   € à�<‰<Ð(Ó)€DØ‚|Øˆ	Ü�tœT×"Ò"¤c¨$£i°H¸iÐ3HÔ&HÔPZÐ[_Ð`hÕ[iÔkn×PoÒPoÜ�D˜•OÓ$¬CÓ/°4¸	µ?ÀQÔ3FÜÐ 0Ó1Ð1Ø”D˜“JÐÐr   c                ó   a aa€ V VV3R lpV# )z¯Write guard: cancel the replaced queued tick in the replacement's own transaction; refuse the
replacement when that tick was claimed or settled first (its output already ran).c                 ót   <€ V P                  R SS34      P                  pV^8w  d   \        R4      hS.SR&   R# )z„UPDATE session_admissions SET status='terminal',outcome='cancelled' WHERE admission_id=? AND target_session_id=? AND status='queued'Ústale_generation:NNNN)ÚexecuteÚrowcountr	   )ÚconnÚchangedrL   rP   r$   s   & €€€r   ÚguardÚ_replace_queued.<locals>.guard™   sG   ø€ Ø—,‘,ð  bà ,¨jÐ9ó;ç;C¹8ð 	ð �aŒ<Ü#Ð$6Ó7Ð7Ø#�nˆ�‹r   © )rL   r$   rP   rŠ   s   fff r   Ú_replace_queuedr�   –   s   ú€ ÷%ð €Lr   c              ƒ  óP  aa	"  € ^ RI p^ RIHp  V! V 4      pV'       d>   V P                  P	                  \        VP                  R4      ;'       g    R4      4      MRoSf   R# \        \        W4      .VP                  R4      ;'       g    RO4       Uu0 uF.  pV^ ,          R8X  g   K  \        V4      ^8”  g   K%  V^,          kK0  	  ppVP                  \        VP                  \        VS4      R7      G Rj  x€L
 pV F[  o	\        ;QJ d     VV	3R lV 4       F  '       g   K   R	M	  R
M! VV	3R lV 4       4      '       g   KG  \        VS	4      G Rj  x€L
  K]  	  R# u upi  Ll L  \          d,    \"        P%                  RTP                  R4      R	R7        R# i ; i5i)aŸ  A process's completion is in the session: its ticks still queued there would run after it as
stale "still running" turns, and the completion carries the final output, so they are cancelled.
A tick that already started is left alone. Never raises: the completion is already admitted, and
a retry of it takes the lost-acknowledgement path, not this one. The caller holds the heartbeat
lock (``admit_process_notice``).Nr   r    r!   Ú_automation_identitiesrX   rg   c              3   óR   <"  € T F  p\        SVSP                  4      x € K  	  R # 5iri   rj   )rl   rm   r4   r5   s   & €€r   rn   Ú)withdraw_process_ticks.<locals>.<genexpr>¶   s%   øé € ÐYÑPXÀW”<  W¨e×.?Ñ.?×@Ð@ÓPXùs   ƒ$'TFz@Could not withdraw the waiting heartbeats of finished process %sr$   )Úexc_inforŒ   )rr   r+   r   r,   r-   r.   r/   Ú_identitiesr   Úlenrs   r   r1   r2   ÚanyÚ	_withdrawr?   r@   Úwarning)
r   r   rr   r   r3   r   Úfinishedr|   r4   r5   s
   &&      @@r   r\   r\   £   sy  ùé € ó Ý<ð?Ù$ VÓ,ˆ	ßcl�×$Ñ$×:Ñ:¼3¸u¿y¹yÈÓ?W×?]Ð?]Ð[]Ó;^Ô_ÐrvˆØŠ=ÙÜ0;Ü˜vÓ-Ð\°·±Ð;SÓ1T×1ZÐ1ZÐXZÐ\ô1^ó Bñ 1^ Hà˜�{˜lÑ*ô  ä/2°8«}¸qÑ/@ô  �H˜Q—K�Kñ 1^ˆð Bð  ×)Ñ)Ü# Y§\¡\¼lÈ9ÐV[Ó>\ð *ó ^÷ ^ˆãˆCß‹sÕYÑPXÓY�s�sŠsÕYÑPXÓY×YÔYÜ 	¨3Ó/×/Ò/ó ùòBñ^ñ 0øÜô ?Ü�‰ÐYØ—y‘y Ó.¸ð 	÷ 	?ð?üsƒ   „F&�AE- ÁE- Á#F&Á%2E- ÂE$Â,E$Â>E$Ã1E- Ã<E)Ã=)E- Ä)E- Å
E- ÅE+ÅE- Å"F&Å$E- Å+E- Å-2F#ÆF&Æ"F#Æ#F&c                 óˆ   € ^ RI pV P                  P                  R4      pVf   VP                  4       ;q P                  R&   V# )r   Nr<   )rr   Ú__dict__r/   ÚLock)r   rr   Úlocks   &  r   r<   r<   ½   s>   € ó Ø�?‰?×ÑÐ0Ó1€DØ‚|Ø4;·L±L³NÐBˆ�‰Ð0Ñ1Ø€Kr   c           
     ó¢  € V P                  RRRVP                  R4      RVP                  R4      /4      pVf   R# \        P                  ! VRR7      pVP                  P                  4       ;_uu_ 4       pVP                  RW%34      P                  4       '       d    RRR4       R	#  RRR4       \        VP                  VRR
7       Fn  pVR,          P                  R4      ;'       g*    VR,          P                  R/ 4      P                  R/ 4      pYXP                  R4      ;'       g    R9   g   Km   R	# 	  R#   + '       g   i     Lœ; i)a   Whether the completion of tick ``event``'s process is admitted into the session ``owner``: by
its exact identity (``started_at`` names the process incarnation), or as a sibling in a batch,
pending or settled: only the batch's primary is its ``request_id``.rR   rX   r$   Ú
started_atNFr   zKSELECT 1 FROM session_admissions WHERE target_session_id=? AND request_id=?Tr#   r&   r'   r(   r)   r*   r   rŒ   )	r   r/   r   r   r1   Ú	_read_ctxr†   Úfetchoner   )	r   r3   r{   r   rX   r   rˆ   r5   r6   s	   &&&&     r   rt   rt   Ç   s+  € ð ×5Ñ5Ø	�˜|¨U¯Y©Y°|Ó-DÀlÐTY×T]ÑT]Ð^jÓTkÐlón€JàÒÙÜ�zŠz˜*°Ô<€HØ	�‰×	Ñ	×	!Ô	! TØ�<‰<ÐeØÐ)ó+ß+3©8«:ö6à÷ 
"Ñ	!ð6÷ 
"ô ' y§|¡|ÀÐTY×ZˆØ˜•^×'Ñ'Ð(=Ó>÷  Að  AÀ#ÀiÅ.×BTÑBTÐUeÐgiÓBj×BnÑBnÐo{Ð}ó  CAˆ
ØŸ™ |Ó4×:Ð:¸Ö;Úñ [ñ ÷ 
"×	!ús   Á6)D>Ä>E	c                 óà   € . pV  FM  p \         P                  ! V4      p\	        T\
        4      '       g   K2  T'       g   K<  TP                  T4       KO  	  V#   \        \        3 d     Kg  i ; iri   )r   ÚloadsÚ	TypeErrorÚ
ValueErrorrx   ÚlistÚappend)ÚrawsÚparsedÚrawr   s   &   r   r“   r“   Û   sb   € Ø€FÛˆð	Ü—z’z #“ˆHô �h¤×%Ô%¯(©(Ø�M‰M˜(Ö#ñ ð €Møô	 œ:Ð&ô 	Úð	ús   ‰AÁA-Á,A-c                ó  a€ V R,          R8w  g   V R,          RV,           8w  d   R# \         ;QJ d0    V3R l\        V R,          .4       4       F  '       g   K   R# 	  R# ! V3R l\        V R,          .4       4       4      # )	zúWhether *row* is the gateway's own queued liveness tick of *process* on *route*: the route's
producer admitted ``["heartbeat", process, event_id]``. A client input whose id merely looks like
one, and the ``/heartbeat`` wake (four parts), never match.rM   rN   re   rd   Fc              3   ól   <"  € T F)  p\        V4      ^8H  ;'       d    VR,          RS.8H  x € K+  	  R# 5i)é   :Né   NrS   N)r”   )rl   r   rm   s   & €r   rn   Ú_queued_tick.<locals>.<genexpr>í   s;   øé € ð AÙ?�8ô �8‹} Ñ!×LÐL h¨r¥l°{ÀGÐ6LÑ&LÔLÛ?ùs   ƒ4�4rf   T)r•   r“   )r5   rm   Úroutes   &f&r   rk   rk   ç   s‚   ø€ ð ˆ8…}˜Ô  C¨Õ$7¸=È5Õ;PÔ$PÙß‹3ô AÜ*¨C°Õ,=Ð+>Ô?óA�3Œ3ð AŠ3ð Aˆ3ô AÜ*¨C°Õ,=Ð+>Ô?óAó Að Ar   c              ƒ  ó&  "  € ^ RI Hp V! VR,          V P                  \        0 R	m4      R4      p V P	                  V\        V P                  VR,          4      VR,          4      G Rj  x€L
 pTP                  R8H  #  L  \         d     R# i ; i5i)
z]Cancel the gateway's own queued automation *row*; False when it was claimed or settled first.©Ú	Principalre   zproducer-withdrawÚtarget_session_idrL   NFÚ	cancelled>   úsession:submitúsession:controlúsession:operator)Úgateway.session_contractr²   Ú
profile_idÚ	frozensetÚcancel_queuedr   r	   Úoutcome)r3   r5   r²   Úactorr_   s   &&   r   r–   r–   ñ   s’   é € å2á�c˜.Õ)¨9×+?Ñ+?ÜÒ YÓZÐ\oóq€EðØ!×/Ñ/Ø”:˜i×2Ñ2°CÐ8KÕ4LÓMÈsÐSaÕObód÷ dˆð �?‰?˜kÑ)Ð)ñ	døäô Úðüs:   ‚.B±8A? Á)A=Á*A? Á.BÁ=A? Á?BÂ
BÂBÂBc                 ó¶   € VP                   P                  \        P                  8X  d   VP                   P                  # V P                  VP                  4      # ri   )ÚoriginÚplatformr   ÚLOCALÚchat_idÚlogical_ownerr$   )r3   r4   s   &&r   r2   r2   ÿ   sB   € à$)§L¡L×$9Ñ$9¼X¿^¹^Ô$KˆE�L‰L× Ñ ð <Ø×(Ñ(¨×)9Ñ)9Ó:ð<r   c                 ó^  € VP                   P                  R 4      ;'       g&    V P                  P                  VP                  4      pV P                  P                  V4      pVe   VP                  '       d   \        R4      hV P                  P                  VP                  4      V8w  d   \        R4      hVP                   P                  R4      pV'       g   \        R4      hWTP                  8w  d6   VP                  P                  V4      VP                  8w  d   \        R4      hV# )Úgateway_session_keyÚ	not_foundÚadmission_conflictÚgateway_session_id)rZ   r/   r,   Ú_generate_session_keyÚsourcer-   Ú	suspendedr	   r$   r1   Úget_compression_tip)r   r   r3   r¯   r4   Úexpecteds   &&&   r   Ú_ownerrÎ     sì   € Ø�N‰N×ÑÐ4Ó5×qÐq¸×9MÑ9M×9cÑ9cÐdi×dpÑdpÓ9q€EØ× Ñ ×6Ñ6°uÓ=€EØ‚}˜ŸŸ˜Ü Ó,Ð,Ø×Ñ×1Ñ1°%·,±,Ó?À5ÔHÜÐ 4Ó5Ð5Ø�~‰~×!Ñ!Ð"6Ó7€HßÜÐ 4Ó5Ð5Ø×#Ñ#Ô#à�<‰<×+Ñ+¨HÓ5¸×9IÑ9IÔIÜ#Ð$8Ó9Ð9Ø€Lr   c                ód   € V P                  RR4      pVR9  d   \        R4      hVR8X  d   RV/# / # )zKValidate trusted producer category; omit the default from old fingerprints.Únotification_categoryÚresultÚ
diagnosticr   )rÑ   rÒ   )r/   r	   )rZ   Úcategorys   & r   Ú automation_notification_metadatarÔ     sA   € à�|‰|Ð3°XÓ>€HØÐ/Ô/ÜÐ 0Ó1Ð1Ø2:¸lÔ2JÐ# XÐ.ÐRÐPRÐRr   iÐ  c                ó  € RV 9  d
   RV 9  d   / # ^ RI Hp V P                  R4      V P                  R4      r2W!9  gA   \        V\        4      '       d+   VP                  4       '       d   \        V4      \        8”  d   \        R4      hRVRV/# )z�Validate a producer's card (an async result, or a liveness tick's one-line receipt): both keys
or neither, kind from the closed producer set.Údisplay_kindÚdisplay_text)ÚPRODUCER_CARD_KINDSr   )	Úgateway.response_filtersrØ   r/   rx   r.   Ústripr”   Ú_DISPLAY_TEXT_LIMITr	   )rZ   rØ   ÚkindrF   s   &   r   Úautomation_display_metadatarÝ   !  sx   € ð ˜XÔ%¨.ÀÔ*HØˆ	Ý<Ø—‘˜nÓ-¨x¯|©|¸NÓ/Kˆ$ØÔ'¬z¸$Ä×/DÒ/DÈDÏJÉJÏLÊLÜ�4‹yÔ.Ô.ÜÐ 0Ó1Ð1Ø˜D .°$Ð7Ð7r   c           
     óØ  € V P                  R4      ;'       g5    V P                  R4      ;'       g    / P                  R4      ;'       g    / pVP                  R4      VP                  R4      r2V'       d-   \        V\        4      '       d   VP                  4       '       g   / # RTRTR\        V P                  R4      ;'       g    R4      /pVP                  R4      R	8X  d   R	VR&   V# )
a3  An automation admission's async-result card (plus its model text) for the claim's
``message.start``: a viewer that did not submit the turn (the classic CLI, idle while a
background process it started finishes in the gateway) paints the same header the submitting
surface would. ``{}`` for every other input.r'   r(   r)   rÖ   r×   rF   r!   rÐ   rÒ   )r/   rx   r.   rÚ   )r&   r6   rÜ   rF   Úcards   &    r   Úadmission_displayrà   :  sÆ   € ð
 —‘Ð2Ó3×tÐt¸¿¹ÐDTÓ8U×8[Ð8[ÐY[×7`Ñ7`ÐamÓ7n×tÐtÐrt€JØ—‘ Ó/°·±ÀÓ1Oˆ$ß”z $¬×,Ò,°D·J±J·L²LØˆ	Ø˜D .°$¸ÄÀGÇKÁKÐPVÓDW×D]ÐD]Ð[]Ó@^Ð_€DØ‡~�~Ð-Ó.°,Ô>Ø(4ˆÐ$Ñ%Ø€Kr   c                 ó„   € V P                  4       P                  4        UUu/ uF  w  rVR 8w  g   K  WbK  	  upp# u uppi )Ú
message_id)Úto_dictÚitems)rÊ   ÚkeyÚvalues   &  r   Ú_route_identityrç   I  s9   € Ø)/¯©Ó)9×)?Ñ)?Ô)AÔYÑ)A™:˜3ÀSÈLÑEXŒJˆCŠJÑ)AÒYÐYùÓYs   ¢<²<c                óÀ   € ^ RI Hp V! V P                  V P                  VP                  4      RR7      p\        R \        V4       4       R4      pVe
   RV9   d   V# R# )z›The route's last committed native envelope with connector provenance (what a producer turn
borrows), or ``None`` while no human message was admitted there.r"   Fr#   c              3   ób   "  € T F%  pR VR,          9   g   K  VR,          R ,          x € K'  	  R# 5i)r(   r&   NrŒ   )rl   Úrs   & r   rn   Ú+committed_route_envelope.<locals>.<genexpr>T  s0   é € ð :¹_¸Ø(¨A¨i­LÑ8ô 4�Q�y•\Ð"2×3Ò3»_ùs   ‚/—/NÚ
provenance)r0   r   r1   rÃ   r$   rv   Úreversed)r3   r4   r   ÚpriorÚenvelopes   &&   r   Úcommitted_route_enveloperð   M  sc   € õ =á# I§L¡L¸Y×=TÑ=TÐUZ×UeÑUeÓ=fØ16ô8€Eäñ :¼XÀe¼_ó :Ø;?óA€HàÒ+°ÀÔ0Hˆ8ÐRÈdÐRr   c                 óÜ  € V P                   pVP                  '       dÑ   VP                  \        P                  8w  g²   VP                  4       '       gœ   \        VP                  \        4      '       d|   V'       dt   VP                  '       gb   VP                  '       gP   VP                  P                  \        P                  8X  g'   \        VP                   4      \"        ,
          '       d   \%        R 4      h\'        VP                   4      \)        VP                   4      ,          \+        VP                   4      ,          p\-        WBV 4      pVP                  P                  \        P.                  8X  d   \1        WW#V4      # ^ RIHp V P7                  VP8                  4      p\;        W4      p	V	f   \%        R4      hT! RVP                  RV	P=                  4        U
Uu/ uF  w  r«V
R8w  g   K  W«bK  	  upp
/V4      p\?        VP                  4      \?        VP                  4      8w  g    VPA                  VP                  4      VJd   \%        R4      h\C        V	R,          4      p\C        V	R	,          4      pVPE                  R
R4       R	VRVPF                  R\H        PJ                  ! ^ \L        4      PO                  4       RR
V/RVRRVRV//p	V	R,          PQ                  V4       \S        VRR4      '       d   VPT                  V	R,          R&   VP                   PW                  R4      pV'       d   \Y        \        V4      4      V	R,          R&   RVP                  RV	/V3# u upp
i )r   ©Úrestore_nativeNrÆ   rF   r(   ÚmediarÇ   rì   rÊ   râ   r¯   Ú	timestampr   r)   r   r{   Ú_heartbeat_session_idrS   Úautomation_identitiesr*   )-r   ÚinternalÚmessage_typer   ÚTEXTÚ
is_commandrx   rF   r.   Ú
media_urlsÚprompt_responserÊ   rÀ   r   Ú
API_SERVERr�   rZ   Ú_AUTOMATION_METADATAr	   rÔ   rÝ   r‚   rÎ   rÁ   Úsnapshot_local_automationÚgateway.session_enveloperó   rÃ   r$   rð   rä   rç   Ú_adapter_for_sourcer   Úpopr    r   Úfromtimestampr   Ú	isoformatÚupdateÚgetattrrö   r/   Úsorted)r3   r]   r   r   r   Únotificationr4   ró   r{   rï   rå   ræ   Úrestoredrì   rÊ   r*   s   &&&&            r   Úsnapshot_automationr  Y  sÄ  € Ø×Ñ€FØ�N�NˆN˜e×0Ñ0´K×4DÑ4DÔDÈ×HXÑHX×HZÒHZÜ˜eŸj™j¬#×.Ò.·hØ××Ð 5×#8×#8Ð#8¸E¿L¹L×<QÑ<QÔU]×UhÑUhÔ<hÜ�5—>‘>Ó"Ô%9×9Ô9ÜÐ 0Ó1Ð1Ü4°U·^±^ÓDÔGbÐch×cqÑcqÓGrÕrÜ$ U§^¡^Ó4õ5€Lä�6 )Ó,€EØ‡|�|×Ñ¤§¡Ô.Ü(¨¸UÈeÓTÐTÝ7Ø×#Ñ# E×$4Ñ$4Ó5€EÜ'¨	Ó9€HØÒÜ Ó,Ð,ñ ˜v u§z¡zÐ3CØ%-§^¡^Ô%5ôFIÙ%5‘z�s¸À¹Œ
ˆŠ
Ñ%5òFIð JØKQóS€Hô 	˜Ÿ™Ó(¬O¸E¿L¹LÓ,IÔIØ×)Ñ)¨(¯/©/Ó:À'ÓIÜÐ 4Ó5Ð5Ü˜( <Õ0Ó1€JÜ�h˜xÕ(Ó)€Fà
‡J�Jˆ|˜TÔ"ð ˜& '¨5×+<Ñ+<Ø”X×+Ò+¨A¬sÓ3×=Ñ=Ó?Ø�, Ð)¨<¸Ø�z 8¨W°eÐ<ð>€Hð ˆ\Õ×!Ñ! ,Ô/ÜˆuÐ-¨t×4Ò4Ø.3×.IÑ.Iˆ�Õ˜{Ñ+Ø—‘×#Ñ#Ð$;Ó<€JßÜ/5´c¸*³oÓ/Fˆ�Õ˜|Ñ,Ø�E—J‘JÐ 0°(Ð;¸UÐBÐBùó/FIs   Ç"M(Ç2M(c                 óÌ  € ^ RI Hp V! W4      pVR,          p^ RIHp V! V 4      p	V	f   \	        R4      h\        WV	4      p
V
P                  V8w  gr   VR,          R,          V	P                  V4      8w  gN   V P                  P                  V4      V
P                  8w  g$   Ve    V P                  VP                  4      VJd   \	        R4      hVP                  V
P                  3# )r   rò   r(   r   rÆ   r)   r{   rÇ   )r  ró   r+   r   r	   rÎ   r$   rÃ   r,   rÉ   r    r  rÊ   )r   r&   r$   Úavailable_sourcer]   ró   r   rï   r   r3   r4   s   &&&&&      r   Úcheck_automation_router  ‡  sÌ   € Ý7Ù˜7Ó+€EØÐ'Õ(€HÝ<Ù  Ó(€IØÒÜ Ó,Ð,Ü�6 )Ó,€EØ×Ñ˜JÔ&Ø˜Õ% gÕ.°)×2IÑ2IÈ*Ó2UÔUØ×#Ñ#×9Ñ9Ð:JÓKÈu×O`ÑO`Ô`ØŠ &×"<Ñ"<¸U¿\¹\Ó"JÐRYÓ"YÜÐ 4Ó5Ð5Ø�<‰<˜×*Ñ*Ð*Ð*r   c                 ó*  € ^ RI Hp V! WP                  P                  4      pV P                  VP
                  ,          pVP                  VP                  JgK   VP                  VP                  4      '       d*   V P                  P                  VP                  4      VJd   \        R4      hRVRVP
                  RVP                  RVP
                  /pVP                  \        VP                  4      4       VP                  \        VP                  4      4       VP                  \        VP                  4      4       VP                  P!                  R4      e9   ^ R	IHp	 V	! VP                  R,          4      VR&   VR,          f   \        R
4      hVP                  P!                  R4      '       d)   \'        \)        VP                  R,          4      4      VR&   \+        VRR4      '       d   VP,                  VR&   RVP.                  RV/V3# )r   )Úrestore_local_sessionÚpermission_deniedr   r{   r¯   ÚtargetÚturn_authorN)Úparse_turn_authorr   r÷   r*   rö   rS   rF   r'   )Úgateway.session_local_recoveryr  rÊ   rÂ   Úsessionsr$   Úauthorize_sourcer   r  r	   r    r  rÔ   rZ   rÝ   r‚   r/   Úagent.turn_authorr  r  r�   r  rö   rF   )
r3   r]   r   r   r4   r  ÚrefÚliver6   r  s
   &&&&&     r   r   r   ˜  sŸ  € ÝDÙ
 	¯<©<×+?Ñ+?Ó
@€CØ×Ñ˜cŸn™nÕ-€DØ�‰˜5Ÿ<™<Ó'¨w×/GÑ/GÈÏÉ×/UÒ/UØ×Ñ×3Ñ3°D·K±KÓ@ÈÓOÜÐ 3Ó4Ð4Ø˜h¨°·±Ø˜5×,Ñ,¨h¸×8HÑ8HðJ€Jà×ÑÔ6°u·~±~ÓFÔGØ×ÑÔ1°%·.±.ÓAÔBØ×Ñ”n U§^¡^Ó4Ô5Ø‡~�~×Ñ˜-Ó(Ò4Ý7Ù$5°e·n±nÀ]Õ6SÓ$Tˆ
�=Ñ!Ø�mÕ$Ò,Ü#Ð$4Ó5Ð5Ø‡~�~×ÑÐ1×2Ò2Ü#)¬#¨e¯n©nÐ=TÕ.UÓ*VÓ#Wˆ
�<Ñ ÜˆuÐ-¨t×4Ò4Ø"'×"=Ñ"=ˆ
�;ÑØ�E—J‘JÐ 5°zÐBÀEÐIÐIr   r¯   c                ó¸  € V P                   P                  VP                  4      pT;'       g    Ve   VP                  MR pVR,          pVR,          pV'       dc   \	        V4      RR08w  gQ   VR,          RV,           8w  g<   VR,          VP                  8w  g$   VR,          V8w  g   VR,          VR	,          8w  d   \        R
4      hV P                  P                  P                  V4      pVe\   VP                  '       gJ   VP                  VR,          8w  d?   V P                  P                  VR,          4      VP                  8w  d   \        R4      hR # R # )Nr&   r'   rF   re   rd   r{   r¯   r   rf   r  r  rÇ   )r  r/   r$   r¯   r�   r	   r   r,   r-   rË   r1   rÌ   )r3   r  r5   r¯   r  r&   r6   r4   s   &&&$    r   Úcheck_local_automationr  °  s  € Ø×Ñ×!Ñ! #§.¡.Ó1€DØ×?Ð? DÒ$4�d—j’j¸$€EØ�)�n€GØÐ.Õ/€Jß”S˜“\ fÐ.CÐ%DÔDØ�>Õ" m°eÕ&;Ô;Ø˜'Õ" c§n¡nÔ4¸
À7Õ8KÈuÔ8TØ˜*Õ%¨¨\Õ):Ô:ÜÐ 3Ó4Ð4Ø×Ñ×*Ñ*×@Ñ@ÀÓG€EØŠ˜ŸŸ˜¨U×-=Ñ-=ÀÈHÕAUÔ-UØ—‘×0Ñ0°¸HÕ1EÓFÈ%×JZÑJZÔZÜÐ 4Ó5Ð5ñ [ñ .Vr   c           
      ó¢  € \        WV4       V P                  VP                  ,          pVR ,          R,          pV P                  P                  P                  VP                  4      p\        VR ,          R,          VP                  RVR,          RVP                  RVP                  /R7      pVP                  P                  \        V4      4       VP                  P                  \        V4      4       VP                  R4      e    \        VR,          4      VP                  R&   VP                  R	4      '       d   VR	,          Vn        V# )
r&   r'   rF   Tr   rÅ   rÈ   )rF   rÊ   rø   râ   rZ   r  rS   )r  r  r$   r   r,   r-   r¯   r   rÊ   rZ   r  rÔ   rÝ   r/   r   rö   )r3   r  r5   r  r6   r4   r   s   &&&    r   Úrestore_local_automationr  À  s  € Ü˜9¨3Ô/Ø×Ñ˜cŸn™nÕ-€DØ�Y•Ð 5Õ6€JØ×Ñ×*Ñ*×@Ñ@ÀÇÁÓL€EÜ˜c )�n¨VÕ4¸T¿[¹[ÐSWØ˜jÕ)Ð5JÈDÏJÉJØ  %×"2Ñ"2ð54ô5€Eð 
‡N�N×ÑÔ:¸:ÓFÔGØ	‡N�N×ÑÔ5°jÓAÔBØ‡~�~�mÓ$Ò0Ü(0°¸MÕ1JÓ(Kˆ�‰�}Ñ%Ø‡~�~�k×"Ò"Ø&0°Õ&=ˆÔ#Ø€Lr   c              ƒ  ó  a aaa"  € S P                  4        \        S WV4      w  rV^ RIHp VP	                  R4      ;'       g    VR,          R,          R,          p\        S P                  V4      oS P                  P                  SP                  V! VP                  VP                  4      4       ^ RIHp	 ^ RIHp
 V	! S P                   SV4      . upoSe   V3V VVV3R	 llpT
! S T	! \"        S P$                  S P&                  R
VP                  ,           SP                  T\)        V4      S P+                  S;'       d    \-        SSP                  S4      4      R7      VRV	! S P.                  S4      R7      G Rj  x€L
 #  L5i)zñ``replaces``: a queued automation row of the same session this input supersedes (a liveness
tick carrying the output of the one still waiting). Its cancellation commits in this admission's
own transaction, so neither lands without the other.©ÚLiveSessionr'   r(   r)   r{   ©Úpartial©Útracked_writeNc                 óH   <€ S'       d   SP                  SS4       V! V 4      # ri   )Ú_settle_cancelled)r5   Úadmittedr3   r  rP   rW   s   &&€€€€r   r(  Ú"admit_automation.<locals>.admittedß  s    ø€ ßØ×+Ñ+¨C°Ô:Ù˜C“=Ð r   rd   ©Úepochre   r$   rf   r&   Ú_authorize_writeT©ÚthenÚorderedÚafter)Ú_require_admission_openr  Úgateway.session_authorityr!  r/   r   r¹   r  Ú
setdefaultr$   rÊ   r    Ú	functoolsr#  Úgateway.session_runtime_workersr%  Ú	_admittedr
   r1   r+  r   Ú_admission_gater�   Ú_schedule_admitted)r3   r]   r   r   rW   r&   r4   r!  Úsidr#  r%  r(  r  rP   s   f&&&f       @@r   r[   r[   Ñ  sS  ûé € ð ×%Ñ%Ô'Ü(¨°GÀHÓM�N€GÝ5Ø�;‰;Ð,Ó-×XÐX°Ð9IÕ1JÈ<Õ1XÐZaÕ
b€CÜ
�Y×)Ñ)¨3Ó
/€CØ×Ñ×!Ñ! #§.¡.±+¸e¿l¹lÈE×L]ÑL]Ó2^Ô_Ý!Ý=Ù  ×!4Ñ!4°c¸5ÓAÀ2Ð€HˆhØÒØ#+÷ 	!ò 	!ñ ˜y©'Ü˜YŸ\™\°·±È}Ð_d×_pÑ_pÕOpØ—>‘>¨hÄÈÓ@QØ"×2Ñ2°8×3sÐ3sÄÐPXÐZ]×ZhÑZhÐjrÓ@sÓtô+vð ˜t©7°9×3OÑ3OÐQTÓ+Uô	W÷ Wð Wñ Wùs   †D;FÅ=FÅ?FÆ Fzkanban-wakez	loop-tickc              ƒ  óì  "  € ^ RI Hp V! V 4      pVe   V P                  P                  V4      MRpVe	   V'       g   R# ^ RIp^ RIHp ^ RIHp ^ RI	H
p	 ^ RIHp
 ^ RIHp \        VP                   VP#                  V4      4      p\        VP                   VP#                  VP$                  4      4      pVP$                  VP&                  9  g   WÍ8X  d   R# VP)                  W´P*                  VP$                  R7      G Rj  x€L
 p\,        ;QJ d    R	 V 4       F  '       g   K   R
M	  RM! R	 V 4       4      '       d   R# V	! RVP                   \/        RR04      R4      pV EFì  pVR,          P1                  R/ 4      P1                  R/ 4      pV'       d<   VR,          P3                  R4      '       d   \4        P6                  ! VR,          4      MRpVR,          R8w  gE   VR,          RV,           8w  g0   \9        V\:        4      '       d   VR,          R \<         4       9  d   KÆ   VP?                  WüVR,          4      G Rj  x€L
  \C        TR,          4      pTP$                  TR,          R,          R&   TP&                  PE                  TP$                  T! TP&                  TP$                  ,          PF                  T4      4       T
! YG! \H        TP*                  TPJ                  TR,          TP$                  TR,          TTPM                  4       R7      T! TPN                  TR4      R
T! TPP                  T4      R7      G Rj  x€L
  EKï  	  R#  ELV EL  \@         d     EK  i ; i L$5i)aÀ  After the route rotated (/new, /reset, compression-exhaustion reset), carry the old owner's
still-queued route wakes to the fresh session, as main's #114456 kept a parked internal wake
across /new. Left behind, the old drain refuses them (``admission_conflict``) and they stay
queued forever. Completions pinned to the closed conversation are not moved (they fail closed,
#55578), nor anything behind an ``unknown`` head (the operator's to resume).r   Nr"  r   r±   r$  r"   rg   c              3   ó8   "  € T F  qR ,          R8H  x € K  	  R# 5i)rM   ÚunknownNrŒ   )rl   r5   s   & r   rn   Ú#move_route_wakes.<locals>.<genexpr>  s   é € Ð
6±¨#ˆx�=˜IÖ%³ùs   ‚TFzmessaging-controlrµ   r¶   Úresetr&   r(   r)   rf   Ú[rM   rN   re   rd   :Né   Nc              3   ó&   "  € T F  q.x € K	  	  R # 5iri   rŒ   )rl   Úps   & r   rn   r=  
  s   é € ÐImÑWlÐRSÍ#ÓWlùs   ‚rL   r{   r*  r-  ))r+   r   r,   r-   rr   r4  r#  r2  r!  r¸   r²   r5  r%  r0   r   r   r¹   rÃ   r$   r  rs   r1   r•   rº   r/   Ú
startswithr   r¢   rx   r¥   Ú_ROUTE_WAKE_PRODUCERSr»   r	   r   r3  rÊ   r
   r+  r7  r6  r8  )r   r    Úold_session_idr   r3   r4   rr   r#  r!  r²   r%  r   ÚoldÚnewÚrowsr½   r5   r)   r   r&   s   &&&                 r   Úmove_route_wakesrI  í  sÓ  é € õ =Ù  Ó(€IØGPÒG\ˆF× Ñ ×6Ñ6°{ÔCÐbf€EØ‚}ŸNÙÛÝ!Ý5Ý2Ý=Ý<Ü
�Y×)Ñ)¨9×+BÑ+BÀ>Ó+RÓ
S€CÜ
�Y×)Ñ)¨9×+BÑ+BÀ5×CSÑCSÓ+TÓ
U€CØ
‡~�~˜Y×/Ñ/Ô/°3´:ÙØ×"Ñ"Ð#:¿L¹LÐUX×UcÑUcÐ"Ód×d€Dß
ƒsÑ
6±Ó
6‡s‡s‚sÑ
6±Ó
6×6Ò6ÙÙÐ)¨9×+?Ñ+?ÄÐL\Ð^oÐKpÓAqÐszÓ{€EÜˆØ˜•^×'Ñ'Ð(8¸"Ó=×AÑAÀ,ÐPRÓSˆ
ß4>À3À|ÕCT×C_ÑC_Ð`c×CdÒCd”4—:’:˜c ,Õ/Ô0ÐjnˆØ��M˜XÔ%¨¨^Õ)<ÀÐP[Õ@[Ô)[Ü! (¬D×1Ò1°X¸bµ\ÑImÕWlÓImÔ5mÙð	Ø×)Ñ)¨%°c¸.Õ6IÓJ×JÐJô ˜3˜y�>Ó*ˆØ;>¿>¹>ˆÐ Õ! ,Õ/°Ñ8Ø×Ñ×%Ñ% c§n¡n±kÀ)×BTÑBTÐUX×UcÑUcÕBd×BkÑBkÐmxÓ6yÔzÙ˜I wÜ §¡°Y·_±_ÐSVÐWeÕSfØ—~‘~°#°lÕ2CÈWØ&×6Ñ6Ó8ô(:ñ AHÈ	×H[ÑH[Ð]`ÐbfÓ@gØ¡¨	×(DÑ(DÀcÓ Jô	L÷ 	Ló 	Ló ò	 eò KøÜ ô 	Ûð	úñ
	Lùst   ‚;M4¾CM4ÄMÄM4ÄM4Ä'M4ÅA6M4Æ9A3M4È-MÉ	MÉ
MÉC?M4ÍM2ÍM4ÍMÍM/Í*M4Í.M/Í/M4c                ó  € \        V P                  P                  4       4       FZ  w  r#VP                  V8X  g   K  \	        VP
                  RR4      \        P                  8X  g   KD  \        V P                  V4      u # 	  R# )zZThe LOCAL FIFO serving ``session_key`` (its owner is the receipt id, which a reset keeps).rÀ   N)
r¥   r  rä   r¯   r  rÊ   r   rÁ   r   r¹   )r3   r    r9  r  s   &&  r   Ú_local_ownerrK    sa   € ä˜)×,Ñ,×2Ñ2Ó4Ö5‰	ˆØ�:‰:˜Ö$¬°·±¸jÈ$Ó)OÔS[×SaÑSaÖ)aÜ˜i×2Ñ2°CÓ8Ò8ñ 6ñ r   c              ƒ  ó|  a aaaaa
"  € ^ RI Hp ^ RIHo
 S P                  SP
                  ,          pV VVV
VV3R lpVP                  ;_uu_4       GRj  x€L
  V! S VRR7      G Rj  x€L
 w  r‰RRR4      GRj  x€L
  X	'       d   S P                  S4       X#  LD L3 L#  + GRj  x€L 
 '       g   i     L:; i5i)a»  A LOCAL route (the Bot Chat ``hermes peer dm`` lands in) keeps its FIFO owner across the
reset, so nothing moves between FIFOs. Its queued automation rows (a DM that arrived while the
exhausted turn ran) still name the pre-reset transcript and are retargeted at the fresh one,
in the same ordered worker step as the rotation; left stale, the drain refuses them
(``admission_conflict``) and the Bot Chat's FIFO pauses for good, across restarts.r$  )Úretarget_local_automationc            
      ó4  <€ SP                   P                  S4      ;'       g    S.p SP                  P                  S4      pVe   VP                  V 9   d   V. 3# VS! SP                   SP
                  SP                  RS,           WP                  R7      3# )Nrd   )r+  r$   re   Úold_targetsÚ
new_target)r1   Úget_compression_lineager,   Úreset_sessionr$   r+  )rO  r4   r3   rE  r{   rM  r   r    s     €€€€€€r   Úrotate_and_retargetÚ6_reset_and_retarget_local.<locals>.rotate_and_retarget,  s‘   ø€ Ø—l‘l×:Ñ:¸>ÓJ×^Ð^È~ÐN^ˆØ×$Ñ$×2Ñ2°;Ó?ˆØŠ=˜E×,Ñ,°Ô;Ø˜"�9ÐØÑ/Ø�L‰L 	§¡¸E×<LÑ<LØ&¨Õ4À+×ZjÑZjôlð lð 	lr   NT©r/  )r5  r%  r0   rM  r  r$   Úmutation_lockÚ_publish_pending)r3   r   r    rE  r{   r%  r  rS  r4   ÚmovedrM  s   fffff     @r   Ú_reset_and_retarget_localrY  "  sŠ   ýé € õ >Ý>Ø×Ñ˜e×.Ñ.Õ/€D÷lò lð ×!×!×!Ó!Ù*¨9Ð6IÐSWÔX×X‰ˆ÷ "×!çØ×"Ñ" 5Ô)Ø€Lñ	 "ÙX÷ "×!×!Ò!üsf   ˆAB<ÁBÁB<ÁB Á(BÁ)B Á/B<Á:BÁ;B<ÂB<ÂB ÂB<Â B9	Â&B)Â'
B9	Â2B9	Â4B<c              ƒ  ó  a aaaaaaaaa"  € ^ RI Hp V! S 4      oS'       d&   \        SP                  SP	                  V4      4      MRoS'       d.   V'       d&   SP
                  P                  SP                  4      MRoS'       d   \        SS4      MRpVe   \        SS SW$4      G Rj  x€L
 R 3# Sf'   S P                  P                  S4      G Rj  x€L
 R 3# ^ RIp^ RIHo ^ RIHp ^ RIHo VVVVV V3R lpVVVV3R	 lpSP&                  ;_uu_4       GRj  x€L
  VP)                  V! SWxR
R7      4      p	 VP+                  V	4      G Rj  x€L
 w  w  p
opoRRR4      GRj  x€L
  Sf   X
R 3# X'       d#   SP1                  S4       SP1                  S4       . oTTTT3R lpX
T3#  EL LÞ L– Ld  TP,                   d    T3R lpT	P/                  T4       h i ; i L|  + GRj  x€L 
 '       g   i     L“; i5i)ax  The compression-exhaustion auto-reset: rotate the route to a fresh session and move the old
owner's still-queued native ``messaging:*`` rows onto it, same order and request ids. Left
behind they pause the old FIFO (``admission_conflict``) and never run, while a later message
runs ahead of them. /new and /stop cancel these rows instead (the user asked for a clean break);
the exhausted turn itself is started, so it is never moved.

The rotation (sessions.json) and the move (one SQLite transaction) run in one worker step
ordered with native admissions, not atomically across the two stores: a redelivery that
resolves the route to the fresh session commits after the move and dedupes onto the moved row,
and one that reserved the old route before the rotation is retargeted at commit
(``_admit_native_write``). Returns ``(entry, release)``. Until the caller runs ``release()``
(once, after its conversation cleanup and topic binding sync, also on failure) the fresh
session's ``claim_gate`` is held, so no scheduler (a redelivery, a moved route wake, this
move) starts a turn there against stale state; ``release()`` then schedules its FIFO.r   Nc                  ó   € R # ri   rŒ   rŒ   r   r   Ú<lambda>Ú+reset_and_rehome_messages.<locals>.<lambda>Q  s   € Ñosr   c                  ó   € R # ri   rŒ   rŒ   r   r   r\  r]  S  s   € ÑTXr   r   r$  )Úrehome_queued_inputsc            
      ó:  <€ SP                   P                  S4      p V f   R R . 3# \        SP                  SP	                  V P
                  4      4      pVS8X  d   V R . 3# SP                  P                  VP
                  4      fF   SP                  P                  VP
                  SP                  P                  P                  R7       SSP                  SP
                  &   WS! SP                  SP                  SP
                  VP
                  RR7      3# )N)rÊ   z
messaging:)r+  rE  Únew_session_idÚprincipal_prefix)r,   rR  r   r¹   rÃ   r$   r1   Úget_sessionÚcreate_sessionrÊ   rÀ   ræ   Úrotated_ownersr+  )r4   rG  r3   r  rF  r_  r   r    s     €€€€€€r   Úrotate_and_moveÚ2reset_and_rehome_messages.<locals>.rotate_and_moveY  sì   ø€ Ø×$Ñ$×2Ñ2°;Ó?ˆØŠ=Ø˜˜r�>Ð!Ü˜×-Ñ-¨y×/FÑ/FÀu×GWÑGWÓ/XÓYˆØ�#Œ:Ø˜$ �?Ð"Ø�<‰<×#Ñ# C§N¡NÓ3Ò;Ø�L‰L×'Ñ'¨¯©¸t¿{¹{×?SÑ?S×?YÑ?YÐ'ÔZà3>ˆ	× Ñ  §¡Ñ0ØÑ/Ø�L‰L 	§¡ÀÇÁØŸ>™>¸LôJð Jð 	Jr   c              “   óê   <"  € V ^,          pVf   V R3# SP                   P                  VP                  S! SP                  S4      4      pVP                  P                  4       G Rj  x€L
  W3#  L5i)r@  N)r  r3  r$   rÊ   Ú
claim_gateÚacquire)rÑ   rG  Úfreshr!  r3   r  r    s   &  €€€€r   ÚfenceÚ(reset_and_rehome_messages.<locals>.fenceh  sk   øé € à�Q�iˆØŠ;Ø˜4�<ÐØ×"Ñ"×-Ñ-¨c¯n©n¹kÈ$Ï+É+ÐWbÓ>cÓdˆØ×Ñ×&Ñ&Ó(×(Ð(Øˆ}Ðñ 	)ùs   ƒA&A3Á)A1Á*A3TrU  c                 ó,  <€ V P                  4       '       g   V P                  4       '       d   R MV P                  4       ^,          pVeJ   VP                  P	                  4        SP                  V P                  4       ^ ,          ^,          4       R # R # ri   )r´   rA   rÑ   ri  ÚreleaseÚ	_schedule)ÚdoneÚgater3   s   & €r   ÚliftÚ'reset_and_rehome_messages.<locals>.liftw  sg   ø€ Ø#Ÿ~™~×/Ò/°4·>±>×3CÒ3C‘tÈÏÉËÐWXÕIY�ØÒ#Ø—O‘O×+Ñ+Ô-Ø×'Ñ'¨¯©«°aÕ(8¸Õ(;Ö<ñ $r   c                  ó   € R # ri   rŒ   rŒ   r   r   r\  r]    s   € ™dr   c                  óê   <€ S'       gj   SP                  R 4       SP                  P                  4        S P                  P	                  SP
                  4      SJ d   S P                  S4       R# R# R# )TN)r¦   ri  ro  r  r/   r$   rp  )r3   rk  rG  Úreleaseds   €€€€r   ro  Ú*reset_and_rehome_messages.<locals>.release†  sY   ø€ ßØ�O‰O˜DÔ!Ø×Ñ×$Ñ$Ô&Ø×!Ñ!×%Ñ% c§n¡nÓ5¸Ó>Ø×#Ñ# CÖ(ñ ?ñ r   )r+   r   r   r¹   rÃ   r  r/   r$   rK  rY  Úasync_session_storerR  rr   r2  r!  r5  r%  r0   r_  rV  Úensure_futureÚshieldÚCancelledErrorÚadd_done_callbackrW  )r   r    rE  r   Úlocalrr   r%  rf  rl  Úwriter4   rX  rs  ro  r!  r3   rk  r  rG  rF  r_  rw  s   ff&           @@@@@@@@r   Úreset_and_rehome_messagesr€  <  sÀ  ÿùé € õ =Ù  Ó(€IßW`Œ*�Y×)Ñ)¨9×+BÑ+BÀ>Ó+RÔ
SÐfj€Cß58¿^ˆ9×Ñ×!Ñ! #§.¡.Ô1ÐQU€Dß4=ŒL˜ KÔ0À4€EØÒÜ.¨y¸&À+È~Óe×eÑgsÐsÐsØ‚|Ø×/Ñ/×=Ñ=¸kÓJ×JÉLÐXÐXÛÝ5Ý=Ý9÷Jò J÷ð ð ×!×!×!Ó!Ø×%Ñ%¡m°I¸Ð_cÔ&dÓeˆð
	Ø/6¯~©~¸eÓ/D×)DÑ&ÑˆU�C˜ ÷ "×!ð ‚}Ø‘lÐ"Ð"ßØ×"Ñ" 3Ô'Ø×"Ñ" 3Ô'à€H÷)ð )ð �'ˆ>Ðòw fáJñ< "ñ *EøØ×%Ñ%ô 	õ=ð
 ×#Ñ# DÔ)Øð	ú÷	 "×!×!Ò!üs¯   ŒAHÁHÁ.HÂ	#HÂ,F2Â-)HÃF5ÃA	HÄ F7Ä!HÄ$G*Å F;ÅF9ÅF;Å HÅ+G(Å,HÆ2HÆ5HÆ7HÆ9F;Æ;*G%Ç%G*Ç(HÇ*H	Ç0G3Ç1
H	Ç<H	Ç>Hc              ƒ  óò  "  € ^ RI Hp V! V 4      pV P                  V4      pVe   V P                  P	                  V4      MRp	Ve   V	f   R# ^ RIp
\        P                  ! WHV
P                  4       P                  .RR7      pVP                  \        P                  8X  dœ   VP                  P                  VP                  4      pVe   VP                   V8w  d   R# \#        T\$        P&                  VP(                  RTRVRV	P*                  /T;'       g    / CR7      pVP-                  WV4      G Rj  x€L
  R# ^ R	IHp \3        Wy4      pVf   R# T! R
TRVP5                  4        UUu/ uF  w  ppVR8w  g   K  VVbK  	  upp/V 4      p\#        T\$        P&                  VP(                  RTRVRV	P*                  /T;'       g    / CR7      pVP-                  WV4      G Rj  x€L
  R#  L¶u uppi  L5i)aµ  Commit a producer wake (Kanban push wake, /loop tick) for ``source``'s route into the
authority FIFO, like heartbeats and process completions, instead of a classic turn that
interrupts or races the admitted one. ``False`` when no authority serves the scope or the
route holds no committed human turn to borrow provenance from: the caller keeps the adapter
path (nothing is queued there either). Raises ``RuntimeStoreError`` on a refusal.r   NFr   TrÅ   rÈ   )rF   rù   rÊ   rø   râ   rZ   rò   rF   r(   rô   r   )r+   r   Ú_session_key_for_sourcer,   r-   Úuuidr   r   Úuuid4ÚhexrÀ   r   rÁ   r  r/   rÂ   r¯   r   r   rú   rÊ   r$   r[   r  ró   rð   rä   )r   r]   rÊ   rF   ÚproducerrZ   r   r3   rå   r4   rƒ  r   r  r   ró   rï   ÚkÚvr
  s   &&&&&&             r   Úadmit_route_waker‰  �  sè  é € õ =Ù  Ó(€IØ
×
(Ñ
(¨Ó
0€CØ?HÒ?TˆF× Ñ ×6Ñ6°sÔ;ÐZ^€EØÒ˜EšMÙÛÜ�zŠz˜8¨$¯*©*«,×*:Ñ*:Ð;È
ÔS€HØ‡�œ(Ÿ.™.Ô(ð ×!Ñ!×%Ñ% f§n¡nÓ5ˆØŠ<˜4Ÿ:™:¨Ô,ÙÜ $´[×5EÑ5EÈdÏkÉkÐdhØ(0Ð<QÐSVØ<PÐRW×RbÑRbð<Pà?G¿~¸~È2ð<PôQˆð ×(Ñ(¨¸ÓB×BÐBÙÝ7Ü'¨	Ó9€HØÒÙá˜v tÐ-=Ø!Ÿ™Ô)ô@;Ù)‘��A¨Q°'©\Œˆˆ1ŠÑ)ò@;ð <Ø=CóE€Hä˜d´×1AÑ1AÈ(Ï/É/ÐdhØ$,Ð8MÈsØ8LÈe×N^ÑN^ð8Là;C¿>¸>Àrð8LôM€Eð ×
$Ñ
$ W°XÓ
>×>Ð>Ùñ 	Cùó@;ñ ?ùsC   ‚DG7ÄG7Ä6G-Ä75G7Å,G/Å=G/ÆAG7ÇG7Ç&G5Ç'G7Ç/G7>   r  rÖ   r×   rV   rÈ   rÅ   Únotification_originr÷   rÐ   Úgateway_completion_idsÚgateway_proven_session_idÚoriginal_trigger_message_idri   ):Ú__doc__Úcopyr   r   r   r   ÚloggingÚgateway.configr   Úgateway.platforms.eventr   r   r¸   r   r0   r	   r
   r   Ú	getLoggerÚ__name__r@   r   r7   rH   rC   r`   r>   rw   r‚   r�   r\   r<   rt   r“   rk   r–   r2   rÎ   rÔ   rÛ   rÝ   rº   rÿ   rà   rç   rð   r  r  r   r  r  r[   rD  rI  rK  rY  r€  r‰  rŒ   r   r   Ú<module>r•     s   ðñõ
 ß "Û Û å #ß =Ý /ß `Ñ `à	×	Ò	˜8Ó	$€ò7òò"ò<3òò$ eòFoò ò
ò?ò4òò(	òAò*ò<òò"Sð Ð ò
8ñ( !ò "mó nÐ ò
òZò	Sò+Cò\+ò"Jð06¸ô 6ò ô"Wñ2 " =°+Ð">Ó?Ð ò*LòZòò4Pöf&r   