+
    jHàj.%  ã                   óº   a € R t0 t R t^ RIHt ^ RIHtHtHtHt ]! RRR7      t	] ^ k ^ RI
HtHt R tR tR	 tR
 tRR ltRRRRRR/R ltR tRRRRR/R lltR# )zLExact execution results commit with settlement, before delivery/publication.)Ú
ContextVar)ÚRuntimeStoreErrorÚ
_admissionÚ_epochÚsettle_session_inputÚexecution_resultN)Údefault)ÚRESULT_PREFIXÚload_resultc                óˆ   € \         P                  4       pVe*   RV9  d#   RRR. RRRRR	\        T ;'       g    R
4      /VR&   V # )zÿThe admitted turn never ran because it failed (agent initialization raised, history
unreadable): commit a failed result for the executing admission, so no surface settles it
``completed`` with the apology as the turn's output. Returns ``reply`` unchanged.ÚresultÚfinal_responseÚ ÚmessagesÚfailedTÚ	completedFÚerrorzThe admitted turn failed.)r   ÚgetÚstr)ÚreplyÚcaptureds   & Ú</home/ubuntu/.hermes/hermes-agent/gateway/session_results.pyÚrecord_unexecuted_failurer   
   sW   € ô  ×#Ñ#Ó%€HØÒ °Ô 8Ø.°°JÀÀHÈdÐT_ÐafØ%¤s¨5×+OÐ+OÐ4OÓ'PðRˆ�Ñà€Ló    c                ó>   € \         P                  4       pVe   WR&   V # )zZRetain an owner-side failure even if an abandoned executor returns while delivery unwinds.Úterminal_result)r   r   )r   r   s   & r   Úrecord_terminal_failurer      s$   € ä×#Ñ#Ó%€HØÒØ&,Ð"Ñ#Ø€Mr   c                óN  € \        V \        4      '       d   ^ RIHp V! V 4      # \        V \        4      '       d/   V P                  4        UUu/ uF  w  r#V\        V4      bK  	  upp# \        V \        4      '       d   V  Uu. uF  p\        V4      NK  	  up# V # u uppi u upi )zàThe stored result is a state.db copy of the model's answer and history: redacted at this
storage boundary like every transcript row (``security.redact_secrets``). The live viewer
prints the completion event, never this copy.)Úredact_sensitive_text)Ú
isinstancer   Úagent.redactr   ÚdictÚitemsÚ	_redactedÚlist)Úvaluer   ÚkÚvs   &   r   r#   r#      s„   € ô �%œ×ÒÝ6Ù$ UÓ+Ð+Ü�%œ×ÒØ,1¯K©K¬MÔ:©M¡D A�”9˜Q“<’©MÒ:Ð:Ü�%œ×ÒÙ&+Ó,¡e ”	˜!–¡eÑ,Ð,Ø€Lùó ;ùâ,s   ÁBÂB"c          
      óP   € \        WVR ,          VR,          R\        V4      R7      # )Úadmission_idÚ
generationr   )Úepochr)   r*   Úoutcomer   )r   r#   )Údbr+   Úrowr   s   &$$$r   Úretain_resultr/   +   s-   € Ü ¸cÀ.Õ>QØ+.¨|Õ+<ÀkÔZcÐdjÓZkômð mr   c           	     ój  € Vf   RRT;'       g    RR. /R/ /pVR,          pVP                  R4      '       d   RpM0VP                  R4      '       g   VP                  R4      '       d   RpVR9   d   R	YBR8X  d   RMR&   R
VR&   ^ RIHp V\        V! W0R,          P                  R4      R7      4      3# )z²``(outcome, stored_result)``: the outcome the result's own flags imply and the compact,
redacted copy settlement stores. Pure CPU work, safe off-loop and outside the stream lock.r   r   r   r   ÚusageÚinterruptedr   r   TFr   )Úcompact_resultÚpayloadÚtext)Úuser_message)r   r2   )r   Úhermes_state_terminalr3   r#   )r.   Úresponser,   r   r%   r3   s   &&&&  r   Úprepare_resultr9   0   sµ   € ð ‚~ØÐ-¨x¯~¨~¸2¸zÈ2ÐNÐPWÐY[Ð\ˆØ�8Õ€EØ‡y�y�×ÒØ‰Ø	�‰�8×	Ò	 §	¡	¨'× 2Ò 2ØˆØÐ+Ô+ØDHˆ XÔ-‰h°=ÑAØ"ˆˆkÑå4Ø”I™n¨VÀiÅ.×BTÑBTÐU[ÓB\Ô]Ó^Ð^Ð^r   r   ÚpreparedÚ	transfersc               ó(  a aaa€ S P                  4       ;_uu_ 4       p\        W�4       \        VSR,          4      p	V	R,          V8w  g   V	R,          SR,          8w  d   \        R4      hV	R,          R8X  dŒ   VP	                  R\
        SR,          ,           34      P                  4       p
V
f   \        R	4      h\        V
^ ,          4      p\        V	4      VR
,          P                  R4      ;'       g    R3uuRRR4       #  RRR4       T;'       g    \        SW4V4      w  rK^ RIHpHp V! WTS4      RuooSf   V! WT4      ;pe   Vw  ooSf   RMV VVV3R lp\        S VSR,          SR,          WKVVR7      pVV3#   + '       g   i     L…; i)a  Delivery failure cannot rewrite an already committed execution outcome.

`result` is the exact structured result captured in-process; the managed
worker path commits its own before this runs and is read back here.
`prepared` is ``prepare_result``'s output computed before the caller took a lock.
`transfers` are the queued steers handed to this claim; they settle in the same write.
r)   Úowner_epochr*   Ústale_generationÚstatusÚterminalú(SELECT value FROM state_meta WHERE key=?NÚstorage_unavailabler   r   r   )Úgateway_refusal_boundaryÚowner_stop_noticec           	      óD   <€ \        SV SSSP                  R 4      SR7      # )Útranscript_mark)Úreplace_afterÚdisplay_metadata)Úclose_discarded_turnr   )ÚconnÚ_currentr-   rH   Únoticer.   s   &&€€€€r   Ú<lambda>Úfinish_result.<locals>.<lambda>b   s%   ø€ Ô@TØ
ˆD�#�v¨S¯W©WÐ5FÓ-GÐZjõAlr   )r+   r)   r*   r,   r   Ú
_transfersÚ_terminal_write)Ú	_read_ctxr   r   r   ÚexecuteÚ_RESULT_PREFIXÚfetchoner
   r!   r   r9   Ú#gateway.session_settlement_recoveryrC   rD   r   )r-   r+   r.   r8   r,   r   r:   r;   rJ   ÚcurrentÚsavedÚstoredrC   rD   ÚrefusalÚwriteÚsettledrH   rL   s   f$d$$$$$         @@r   Úfinish_resultr\   B   s€  û€ ð 
�‰�Œ˜4ÜˆtÔÜ˜T 3 ~Õ#6Ó7ˆØ�=Õ! UÔ*¨g°lÕ.CÀsÈ<ÕGXÔ.XÜ#Ð$6Ó7Ð7Ø�8Õ 
Ô*Ø—L‘LÐ!KÜ"0°3°~Õ3FÕ"FÐ!HóJßJRÉ(Ë*ð àŠ}Ü'Ð(=Ó>Ð>Ü   q¥Ó*ˆFÜ˜“= &¨Õ"2×"6Ñ"6Ð7GÓ"H×"NÐ"NÈBÐN÷ 
Šð
 +÷ 
ð ×PÐP¤.°°hÈÓ"P�O€G÷ `Ù0°À#ÓFÈÐ€FÐØ‚~Ñ&>¸vÓ&OÐO˜7Ò\Ø#*Ñ ˆÐ Ø’N‰D÷ *l€Eä" 2¨UÀÀ^ÕATØ�|Õ$¨gÐQZØô€Gð �HÐÐ÷; 
�ús   �CFÃ5FÆF	c                 óH  € V P                  4       ;_uu_ 4       p\        W!4      pVR ,          R8w  d    RRR4       R# VP                  R\        V,           34      P	                  4       pV'       d   \        V^ ,          4      MRuuRRR4       #   + '       g   i     R# ; i)r?   r@   NrA   )rQ   r   rR   rS   rT   r
   )r-   r)   rJ   r.   rW   s   &&   r   Úadmission_resultr^   j   ss   € Ø	�‰�Œ˜4Ü˜Ó,ˆØˆx�=˜JÔ&Ø÷ 
‰ð —‘ÐGÜ,¨|Õ;Ð=ó?ß?G¹x»zð 	ç(-Œ{˜5 �8Ô$°4÷ 
��‹ús   ™B¾3BÁ2BÂB!	rG   rH   c               ó|  € ^ RI p^ RIHpHp ^ RIHp	 ^ RIHp
 V
! W! WR,          4      4      R,          pVP                  RV34      P                  4       pVen   \        V4      \        J d[   VeW   V^ ,          R8X  dI   V^,          V8X  d;   V^,          V8”  d-   VP                  RW0P                  V4      V^,          34       R	# Vf1   Ve+   V^ ,          R
8X  g   V^ ,          R8X  d   V^,          R9  g   R# RRRT;'       g    TRVP                  4       RV/pV'       d   W]R&   V P                  WV.4       R	# )a  Close a discarded ``unknown`` turn the way a failed turn is closed, on the resolution's
own transaction (``resolve_unknown_session_input(_terminal_write=...)``).

The lost input stays in the transcript for the user to resend, but an open ``user`` tail would be
merged into the follower's provider request by consecutive-user repair, re-sending the discarded
turn as context. A Hermes-authored boundary (``display_kind=failed_turn``, stripped of its type
before the wire) ends it. Its side effects are unknown, so the hedged copy. The boundary lands on
the CURRENT physical transcript (local reset/compression lineage tip), resolved on this
connection. Idempotent on the durable tail, like the gateway and core failed-turn closers.

A turn lost while parked on a tool (an approval or clarify prompt) ends on its assistant
``tool_calls`` row with no result. That tail is open too: repair prunes the unanswered call,
drops the now-empty row and merges the discarded input into the follower's user turn, so it
gets the same boundary (merged onto the call row, whose calls are then pruned).

``notice`` (an unattended automation turn settled by the owner, GW-10) replaces the hedged copy
and is written even on a closed tail: nobody resolved it, so the transcript must say why.

``replace_after`` (the claim's transcript mark, an owner-stop notice): when the tail is a
failed-turn boundary written after that mark, it is THIS turn's own (the agent's core closer
wrote "Send it again" for the interrupted turn), so the notice replaces its copy instead of
stacking a second boundary (#134889 GW-21). An earlier turn's boundary stays.

``display_metadata`` (``{error, error_surface}``) rides the boundary so a reopened chat redraws
the turn's error card from history (``agent.conversation_loop._failed_turn_display_metadata``).N)ÚFAILED_TURN_DISPLAY_KINDÚPARTIAL_FAILED_TURN_NOTICE)Úlocal_physical_target)Ú_canonical_chainÚtarget_session_idzšSELECT role, tool_calls, id, display_kind FROM messages WHERE session_id=? AND active=1 AND role NOT IN ('session_meta','system') ORDER BY id DESC LIMIT 1Ú	assistantz<UPDATE messages SET content=?, display_metadata=? WHERE id=?TÚuserFÚroleÚcontentÚ	timestampÚdisplay_kindrH   éÿÿÿÿ)Nr   z[])ÚtimeÚagent.turn_failure_copyr`   ra   Úhermes_state_local_lineagerb   Úhermes_state_runtimerc   rR   rT   ÚtypeÚintÚ_encode_display_metadataÚ_append_messages_in_transaction)r-   rJ   r.   rL   rG   rH   rl   r`   ra   rb   rc   ÚtargetÚtailÚboundarys   &&&&$$        r   rI   rI   t   s=  € ó4 ß\Ý@Ý5Ù˜dÐ$9¸$ÐDWÕ@XÓ$YÓZÐ[]Õ^€FØ�<‰<ð ]Ø_eÐ^góißiqÑiqÓisð 	àÒœt MÓ2´cÓ9¸dÒ>NÐSWÐXYÕSZÐ^iÔSiØ�Q•Ð3Ô3¸¸Q½À-Ô8OØ�‰ÐSØ×9Ñ9Ð:JÓKÈTÐRSÍWÐUô	WáØ‚~˜4š<Ø��G�vÔ $ q¥'¨[Ô"8¸TÀ!½WÐL\Ô=\ÙØ˜ Y°×0TÐ0TÐ:TÐVaÐcg×clÑclÓcnØÐ 8ð:€HçØ'7Ð#Ñ$Ø×&Ñ& t°h°ZÔ@Ùr   c                ód   € V ^8„  d   Qh/ ^ \         9   d   \        \        R,          ,          ;R&   # )é   Nr   )Ú__conditional_annotations__r   r!   )Úformats   "r   Ú__annotate__r{      s%   € × RÑ R÷
 YÒ X”*œT D�[Õ)Ñ Xò Sr   )N)ry   Ú__doc__Úcontextvarsr   ro   r   r   r   r   r   r7   r	   rS   r
   r   r   r#   r/   r9   r\   r^   rI   r{   )ry   s   @r   Ú<module>r~      sw   øðÞ RÝ "ç \Ó \á,6Ð7IÐSWÔ,XÐ Ó Xß Nòòòòmô
_ð$%¸tð %Èdð %Ð^bô %òP8ñ.Àdð .Ð]a÷ .r   