+
    jHàju(  ã                   ó€   € R t ^ RIt^ RIt^ RIHt ^ RIHtHtHt ^ RI	t	R t
R tR tR tRR/R	 ltR
 tR tR tR tR# )zìLocal physical-target handoff inside the existing publication transaction.

The creation ID remains the admission/execution owner. Transcript rotation must
not re-key idempotency digests, queued inputs, subscribers or uncertain claims.
N)ÚPOLICY_PREFIX)ÚRuntimeStoreErrorÚ_epochÚ_jsonc                 ó�  € ^ RI Hp ^ RIHp RV9  d7   VR,          V! VR,          VR,          VR,          4      8w  d   \	        R4      h^ R	IHp V! W4      pVP                  R
V.4      p\        V\        4      '       dU   V'       dM   \        \        V4      4      \        V4      8w  g+   V^ ,          V8w  g   VR,          VR,          R,          8w  d   \	        R4      h\        P                  ! V4       EF  w  rxV P                  RV34      P                  4       p	V P                  RV34      P                  4       p
V	e   V
e   V
R,          V8w  d   \	        R4      hV	R,          R8X  d;   \         P"                  ! V
R,          ;'       g    R4      P                  R4      V8H  pMLV P                  W'34      P                  4       pV	R,          R8H  ;'       d    VRJ;'       d    VR,          V8H  pV'       d   EK  \	        R4      h	  V P                  W&R,          34      P                  4       e   \	        R4      hVR,          # )é    )Ú_CHAIN_STEP_SQL)Úlocal_identityÚlegacy_session_idÚ
session_idÚ
profile_idÚprincipal_idÚ
request_idÚstorage_unavailable)Úlegacy_lineage_rootÚlineageÚentryz*SELECT end_reason FROM sessions WHERE id=?z>SELECT parent_session_id,model_config FROM sessions WHERE id=?NÚparent_session_idÚ
end_reasonÚsession_resetÚmodel_configz{}Ú_reset_fromÚcompressionÚidéÿÿÿÿ)Úhermes_state_compressionr   Úhermes_state_keysr	   r   Úhermes_state_local_migrationr   ÚgetÚ
isinstanceÚlistÚlenÚsetÚ	itertoolsÚpairwiseÚexecuteÚfetchoneÚjsonÚloads)ÚconnÚreceiptr   r	   r   Úrootr   Ú	parent_idÚchild_idÚparentÚchildÚvalidÚtips   &&           Ú?/home/ubuntu/.hermes/hermes-agent/hermes_state_local_lineage.pyÚvalidate_local_lineager3      sñ  € Ý8Ý0Ø 7Ô*Ø�LÕ!¡^°G¸LÕ4IÈ7ÐSaÕKbÐdkÐlxÕdyÓ%zÔzÜÐ 5Ó6Ð6Ý@Ù˜tÓ-€DØ�k‰k˜) d VÓ,€GÜ�w¤×%Ò%¯W¼¼CÀ»LÓ8IÌSÐQXË\Ô8YØ�q�z˜TÔ! W¨R¥[°G¸GÕ4DÀ\Õ4RÔ%RÜÐ 5Ó6Ð6Ü(×1Ò1°'×:Ñˆ	Ø—‘ÐJÈYÈLÓY×bÑbÓdˆØ—‘Ð]Ð`hÐ_jÓk×tÑtÓvˆØŠ>˜Uš]¨eÐ4GÕ.HÈIÔ.UÜ#Ð$9Ó:Ð:Ø�,Õ ?Ô2Ü—J’J˜u ^Õ4×<Ð<¸Ó=×AÑAÀ-ÓPÐT]Ñ]‰Eà—,‘,˜°Ó=×FÑFÓHˆCØ˜<Õ(¨MÑ9×gÐg¸cÈ¸o×gÐgÐRUÐVZÕR[Ð_gÑRgˆEßŠuÜ#Ð$9Ó:Ð:ñ  ;ð ‡|�|�O¨b¥k ^Ó4×=Ñ=Ó?ÒKÜÐ 5Ó6Ð6Ø�2�;Ðó    c                óè   € V P                  R\        V,           34      P                  4       pVf   V# \        P                  ! V^ ,          4      pVR,          V8w  d   \        R4      h\        W4      # )zGResolve a local owner's current transcript on the caller's transaction.ú(SELECT value FROM state_meta WHERE key=?r   r   )r%   r   r&   r'   r(   r   r3   )r)   r   Úsavedr*   s   &&  r2   Úlocal_physical_targetr8   +   si   € à�L‰LÐCÜ'¨*Õ4Ð6ó8ß8@¹»
ð 
à‚}ØÐÜ�jŠj˜˜q�Ó"€GØˆ|Õ 
Ô*ÜÐ 5Ó6Ð6Ü! $Ó0Ð0r4   c                ó¾   € V P                  RV34      P                  4       pV'       d   \        P                  ! V^ ,          4      MRpVe   VR,          V8X  d   V# R# )z@*route*'s routing entry while it still targets *tip*, else None.zGSELECT entry_json FROM gateway_routing WHERE scope='' AND session_key=?Nr   )r%   r&   r'   r(   )r)   Úrouter1   ÚrowÚrouteds   &&&  r2   Ú_routed_entryr=   7   sR   € à
�,‰,Ð`ÐchÐbjÓ
k×
tÑ
tÓ
v€Cß#&ŒT�ZŠZ˜˜A�Ô¨D€FØÒ'¨F°<Õ,@ÀCÔ,Gˆ6ÐQÈTÐQr4   c                óà   € V P                  R\        V4      VR,          34       V P                  R\        V4      \        VR,          ,           34       V P                  RVR,          34       R# )zaStore *receipt* and its route's entry *routed* and bump the logical revision, in one transaction.zHUPDATE gateway_routing SET entry_json=? WHERE scope='' AND session_key=?r:   z)UPDATE state_meta SET value=? WHERE key=?r   zBUPDATE sessions SET runtime_revision=runtime_revision+1 WHERE id=?N)r%   r   r   )r)   r*   r<   s   &&&r2   Ú_commit_local_targetr?   >   s_   € à‡L�LÐ[Ü˜“- ¨Õ!1Ð2ô4à‡L�LÐ<¼uÀW»~Ì}Ð_fÐgsÕ_tÕOtÐ>uÔvØ‡L�LÐUÐX_Ð`lÕXmÐWoÖpr4   r   c                óâ  € V P                  R V34      P                  4       pV'       d
   VR,          MRpV'       g   R# \        V,           pV P                  RV34      P                  4       pVfZ   ^ RIHp V P                  RW…,           34      P                  4       p	VP                  R4      '       g	   V	'       d   \        R4      hR#  \        P                  ! V^ ,          4      p
V
R,          V8w  g@   V
R	,          R,          V8w  g+   V
R
,          VR,          8w  g   V
R,          VR,          8w  d   \        R4      h\        W
R,          V4      pVf   \        R4      h\        T;'       g    TVR7      pWÊR	&   . V
P                  RV.4      OVNV
R&   \        W
4       \#        Y
T4       R#   \        \        \        3 d)   p\!        T\        4      '       d   h \        R4      ThRp?ii ; i)ú!SELECT * FROM sessions WHERE id=?Úchat_idNr6   )ÚLEGACY_PREFIXz$SELECT 1 FROM state_meta WHERE key=?zlocal-r   r   r   r   Úuser_idr:   Úsession_keyÚadmission_conflict©r   r   )r%   r&   r   r   rC   Ú
startswithr   r'   r(   r=   Údictr   r3   ÚKeyErrorÚ	TypeErrorÚ
ValueErrorr   r?   )r)   r   Úchild_session_idr   r.   Ú
logical_idÚkeyÚrawrC   Úlegacyr*   r<   Ú	candidateÚexcs   &&&$          r2   Úadvance_local_targetrT   F   sº  € Ø�\‰\Ð=Ð@QÐ?SÓT×]Ñ]Ó_€Fß&,�˜	Ö"°$€JßÙÜ
˜*Õ
$€CØ
�,‰,ÐAÀCÀ6Ó
J×
SÑ
SÓ
U€CØ
‚{Ý>Ø—‘ÐDÀ}ÕGaÐFcÓd×mÑmÓoˆØ× Ñ  ×*Ò*¯fÜ#Ð$9Ó:Ð:Ùð@Ü—*’*˜S �VÓ$ˆØ�LÕ! ZÔ/°7¸7Õ3CÀLÕ3QÐUfÔ3fØ˜>Õ*¨f°YÕ.?Ô?À7È7ÕCSÐW]Ð^kÕWlÔClÜ#Ð$9Ó:Ð:Ü˜t¨WÕ%5Ð7HÓIˆØŠ>Ü#Ð$8Ó9Ð9Ü˜Ÿ˜ &Ð5EÔFˆ	Ø$�ÑØV˜wŸ{™{¨9°z°lÓCÐVÐEUÐVˆ�	ÑÜ˜tÔ-ô
 ˜¨	Ö2øô	 ”i¤Ð,ô @Ü�cÔ,×-Ò-ØÜÐ 5Ó6¸CÐ?ûð@ús   ÃB$F0 Å02F0 Æ0G.Ç#G)Ç)G.c                óô   a a€ ^ RI HoHp . 0 VmVkTrep V! VVV 3R l4      R,          pV'       g   V# VP                  V4      '       d   R# VP	                  V4       VP                  V4       VR,          pKf  )ao  Every compression step past *tip*, in order; None when the chain leads back into itself.

One ``_walk_compression_chain`` stops after ``_CHAIN_CAP`` steps, which is not the end of the
chain: walk on from the last step until a walk finds nothing more. Each batch only adds ids never
seen, so the walk ends; a step back into the lineage or an earlier batch is a cycle.
)r   Ú_walk_compression_chainc                 óF   <€ SP                  SV 34      P                  4       # )N)r%   r&   )Úsidr   r)   s   &€€r2   Ú<lambda>Ú"_untracked_steps.<locals>.<lambda>p   s   ø€ ¸T¿\¹\È/Ð\_Ð[aÓ=b×=kÑ=kÔ=mr4   :é   NNNr   )r   r   rV   ÚintersectionÚupdateÚextend)	r)   r1   r   rV   ÚstepsÚseenÚcurrentÚbatchr   s	   f&&     @r2   Ú_untracked_stepsrc   f   so   ù€ ÷ RØ˜ ˜¨#˜°�€EØ
Ù'¨Õ1mÓnÐoqÕrˆßØˆLØ×Ñ˜U×#Ò#ÙØ�‰�EÔØ�‰�UÔØ˜•)Šr4   c           	     ód  € VR,          R,          p\        WVP                  RVR,          .4      4      pV'       g   R# VR,          VR,          VR,          3pV F7  pV P                  RV34      P                  4       p\	        V4      V8w  g   K6   R# 	  \        WR,          V4      pVe   W73# R# )z´``(steps, routed)``: the untracked compression steps *receipt* would adopt and its route's
entry, else None. Read-only; ``adopt_untracked_compression`` repeats it inside its write.r   r   r   Nr:   r   z;SELECT session_key,chat_id,user_id FROM sessions WHERE id=?)rc   r   r%   r&   Útupler=   )r)   r*   r1   ÚchildrenÚidentityr-   r/   r<   s   &&      r2   Úadoptable_compressionrh   z   s°   € ð �'Õ
˜<Õ
(€CÜ ¨7¯;©;°yÀ7È<ÕCXÐBYÓ+ZÓ[€HßÙØ˜Õ  '¨,Õ"7¸ÀÕ9PÐQ€HÛˆØ—‘ÐZÐ]eÐ\gÓh×qÑqÓsˆÜ�‹<˜8Ö#Úñ ô ˜4¨Õ!1°3Ó7€FØ!'Ò!3ˆHÐÐ=¸Ð=r4   c               ó>   aaa€ VVV3R lpV P                  V4       R# )a8  Record, once, compression steps a receipt-unaware build published past the receipt's tip.

0.22.2 (the classic line) resumes a 0.22.1 local session by id. Its compaction ends the tip with
``compression`` and copies the parent's route columns onto the child, but never advances the
receipt, so ``validate_local_lineage`` refused the session forever (#140060). On this owner a
compaction advances the receipt in its own transaction, so such a step comes only from an older
writer. A child carrying the receipt's own route, owner and principal is that session's
continuation: append it to the lineage and move the receipt's and the routing entry's target to
it, nothing else. The stored receipt must still be *expected*, the copy the caller checked
against its owner. Anything else is left for validation to refuse, unchanged.
c           	      ó®  <€ \        V S4       V P                  R \        S,           34      P                  4       p\        P
                  ! V^ ,          4      pVS8w  d   R# \        W4      pVf   R# Vw  rE\        VR,          VR,          R7      VR&   . VP                  RS.4      OVOVR&   \        W4       \        W\        WTR,          R7      4       R# )r6   Nr   rG   r   r   )r   r%   r   r&   r'   r(   rh   rI   r   r3   r?   )	r)   r7   r*   Ú	adoptablerf   r<   ÚepochÚexpectedr   s	   &     €€€r2   ÚwriteÚ*adopt_untracked_compression.<locals>.write–   s¾   ø€ Üˆt�UÔØ—‘ÐGÌ-ÐZdÕJdÐIfÓg×pÑpÓrˆÜ—*’*˜U 1�XÓ&ˆØ�hÔÙÜ)¨$Ó8ˆ	ØÒÙØ$ÑˆÜ ¨Õ 0¸XÀb½\ÔJˆ�ÑØO˜wŸ{™{¨9°z°lÓCÐOÀhÐOˆ�	ÑÜ˜tÔ-Ü˜T¬D°ÈRÅLÔ,QÖRr4   N©Ú_execute_write)Údbrl   r   rm   rn   s   &ddd r2   Úadopt_untracked_compressionrs   Š   s   ú€ ÷Sð ×Ñ�eÖr4   c                óB   a aaa€ V VVV3R  lpS P                  V4       R# )c                 ó,  <€ \        V S	4       V P                  R S
34      P                  4       pVe   VR,          R8X  d   \        R4      hV P                  R\        VR,          ,           34      P                  4       pVf   \        R4      h\
        P                  ! V^ ,          4      pVR,          p\        W4      S
8w  d   \        R4      h^ R	IH	p V! V \        VS
04      4       VR
,          pSP                  WS
SR,          VR,          VR,          RS
/RVR,          VR,          R7
       V P                  R\        P                  ! 4       S
34       SP                  V S
R4       \        V S
SR,          SR7       V P                  RV34       R# )rA   Nr   r   rF   r6   rB   r   r   )Úrequire_not_executingÚpolicyÚsourceÚmodelr   ÚcwdÚprofile_name)r   rM   rx   ry   r   Úsystem_promptrz   r{   zDUPDATE sessions SET ended_at=?,end_reason='session_reset' WHERE id=?r   )r   zFUPDATE sessions SET runtime_generation=runtime_generation+1 WHERE id=?)r   r%   r&   r   r   r'   r(   r3   Úhermes_state_mutation_guardsrv   r    Ú_publish_child_session_rowÚtimeÚ_bump_conversation_generationrT   )r)   r.   r7   r*   rN   rv   rw   rr   r   rl   r   s   &      €€€€r2   rn   Ú!reset_local_target.<locals>.write¨   s‚  ø€ Üˆt�UÔØ—‘ÐAÐDUÐCWÓX×aÑaÓcˆØŠ>˜V LÕ1°]ÔBÜ#Ð$8Ó9Ð9Ø—‘ÐGÜ+¨f°YÕ.?Õ?ÐAóCßCKÁ8Ã:ð 	àŠ=Ü#Ð$9Ó:Ð:Ü—*’*˜U 1�XÓ&ˆØ˜\Õ*ˆ
Ü! $Ó0Ð4EÔEÜ#Ð$8Ó9Ð9ÝFÙ˜d¤D¨*Ð6GÐ)HÓ$IÔJØ˜Õ"ˆØ
×%Ñ% dÐFWØ" <Õ0¸ÀÕ9IÐQWÐX_ÕQ`Ø'Ð):Ð;È4Ø�u•¨F°>Õ,Bð 	&ô 	Dð 	�‰Ð[Ü—i’i“kÐ#4Ð5ô	7à
×(Ñ(¨Ð/@À/ÔRÜ˜TÐ#4°e¸LÕ6IÐQVÕWØ�‰Ð]Ð`jÐ_lÖmr4   Nrp   )rr   rl   r   r   rn   s   fddd r2   Úreset_local_targetr‚   §   s   û€ ÷nð nð2 ×Ñ�eÖr4   )Ú__doc__r'   r   Úhermes_state_localr   Úhermes_state_runtimer   r   r   r#   r3   r8   r=   r?   rT   rc   rh   rs   r‚   © r4   r2   Ú<module>r‡      sU   ðñó
 Û å ,ß AÑ AÛ òò:	1òRòqð3ÈTô 3ò@ò(>ò ô:r4   