+
    jHàj?  ã                  óä   a € 0 t $ R t^ RIHt ^ RIt^ RIHt ^ RIHtH	t	 ^ RI
HtHtHt ^ RIHt ]! RRR7      tR	]R
&    ! R R]4      t] ! R R4      4       tR R ltR R ltR R ltR R ltR# )a  Messaging ``/retry`` under a session authority: the transcript rewrite commits in the re-sent
turn's own admission transaction (#139257 step 2, MSG-11).

``/retry`` drops the last exchange and re-sends its user text. Rewriting first and admitting
afterwards loses the turn whenever admission refuses (a drain or retirement that begins after the
pre-check, a full FIFO). Here the handler only PLANS the rewrite: it reads the transcript, pins the
active row ids it read, and binds the plan to the re-send. ``admit_native`` takes the binding and
runs the rewrite as a write guard after its own admission gate and queue cap, in the same
``BEGIN IMMEDIATE`` that inserts the row. A refusal rolls both back; a transcript that changed since
the read refuses both (``RetryRewriteRefused``).
)ÚannotationsN)Ú
ContextVar)Ú	dataclassÚfield)ÚAnyÚCallableÚOptional)ÚRuntimeStoreErrorÚretry_rewrite)Údefaultz"ContextVar[Optional[RetryRewrite]]Ú_boundc                  ó   € ] tR t^tRtRtR# )ÚRetryRewriteRefusedz±The planned rewrite no longer applies (the transcript changed since the read, a turn lease is
live, the session closed): the re-send was refused with it and nothing was written.© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__static_attributes__r   ó    ÚD/home/ubuntu/.hermes/hermes-agent/gateway/session_retry_admission.pyr   r      s   † õ[r   r   c                  ó€   € ] tR t^t$ RtR]R&   R]R&   R]R&   R]R&   R	]R
&   RtR]R&   ]! RRR7      tR]R&   R t	Rt
R# )ÚRetryRewritezROne ``/retry`` rewrite, applied at most once inside the re-send's admission write.r   ÚdbÚstrÚ
session_idÚsourcezCallable[[Any], None]ÚwritezCallable[[], None]Ú	on_commitFÚboolÚapplied)r   ÚreprÚtakenc                	óÌ   € R V n          V P                  V4       RT n         R#   \        \        P                  3 d    h \
         d   p\        \        T4      4      ThRp?ii ; i)FNT)r!   r   r	   Úsqlite3ÚOperationalErrorÚ	Exceptionr   r   )ÚselfÚconnÚexcs   && r   ÚguardÚRetryRewrite.guard(   s\   € ØˆŒð	9Ø�J‰J�tÔð
 ˆŽøô	 "¤7×#;Ñ#;Ð<ô 	ØÜô 	9Ü%¤c¨#£hÓ/°SÐ8ûð	9ús   ‰# £$A#ÁA#Á	AÁA#)r!   N)r   r   r   r   r   Ú__annotations__r!   r   r#   r+   r   r   r   r   r   r      s@   ‡ á\ØƒGØƒOØƒKØ Ó Ø!Ó!Ø€GˆTÓÙ ¨EÔ2€Eˆ4Ó2ör   r   c               ó   € V ^8„  d   QhRR/# )é   Úrewriter   r   )Úformats   "r   Ú__annotate__r2   3   s   € ÷ ñ �,ñ r   c                ó,   € \         P                  V 4      # ©N)r   Úset)r0   s   &r   Úbindr6   3   s   € Ü�:‰:�gÓÐr   c               ó   € V ^8„  d   QhRR/# )r/   ÚreturnÚNoner   )r1   s   "r   r2   r2   7   s   € ÷ ñ �Tñ r   c                ó0   € \         P                  V 4       R # r4   )r   Úreset)Útokens   &r   Úunbindr=   7   s   € Ü
‡L�L�Ör   c               ó   € V ^8„  d   QhRR/# )r/   r8   úOptional[RetryRewrite]r   )r1   s   "r   r2   r2   ;   s   € ÷ ñ Ð-ñ r   c                óÂ   € \         P                  4       pVe>   VP                  '       g,   \        V RR4      VP                  Jg   VP
                  VJd   R# RVn        V# )z²The bound rewrite for this native admission, once, and only for the re-send itself (the same
source object on the same store). A drain task inheriting the context never takes it.Nr   T)r   Úgetr#   Úgetattrr   r   )Úeventr   r0   s   && r   ÚtakerD   ;   sN   € ô �j‰j‹l€GØŠ˜7Ÿ=Ÿ=˜=¬G°E¸8ÀTÓ,JÐRY×R`ÑR`Ó,`Ø�z‰z Ó#ÙØ€G„MØ€Nr   c               ó   € V ^8„  d   QhRR/# )r/   r0   r?   r   )r1   s   "r   r2   r2   F   s   € ÷ ñ Ð+ñ r   c                ó$   a a€ S f   S# VV 3R lpV# )zU``authorize`` (the admission gate) first, then the rewrite, in one write transaction.c                ó:   <€ S! V 4       SP                  V 4       R # r4   )r+   )r)   Ú	authorizer0   s   &€€r   r+   Úcompose.<locals>.guardK   s   ø€ Ù�$ŒØ�‰�dÖr   r   )r0   rH   r+   s   ff r   ÚcomposerJ   F   s   ù€ à‚ØÐöð €Lr   )Ú__conditional_annotations__r   Ú
__future__r   r%   Úcontextvarsr   Údataclassesr   r   Útypingr   r   r   Úhermes_state_runtimer	   r   r-   ÚRuntimeErrorr   r   r6   r=   rD   rJ   )rK   s   @r   Ú<module>rR      sp   øðô
õ #ã Ý "ß (ß *Ñ *å 2á-7¸ÐQUÔ-V€Ð*Ó Vô[˜,ô [ð
 ÷ð ó ðõ*õõ÷r   