+
    iHàjÏ+  ã            
      ó*  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ]P                  ! R4      t]! RR04      tR R	 ltR
 R ltRRRR/R R lltR R ltR#tRRRRRRRRRR/R R lltR$R R lltRRRRRR/R R  lltR! R" ltR# )%aB  Content-free per-attempt compression telemetry (attempt log line, Relay mark, shared metric).

Sibling of ``agent/conversation_compression.py`` (the facade), which imports it at module level; this
module must never import the facade (import cycle). It logs under the facade's logger name so log
consumers keep one source.
)ÚannotationsN)ÚAny)Úpublish_attemptzagent.conversation_compressionÚno_progressÚsummary_generation_abortedc               ó$   € V ^8„  d   QhRRRRRR/# )é   ÚmessagesÚlistÚverbatim_tailúlist | NoneÚreturn© )Úformats   "ÚM/home/ubuntu/.hermes/hermes-agent/agent/conversation_compression_telemetry.pyÚ__annotate__r       s"   € ÷ 
ñ 
°ð 
Àkð 
ÐVañ 
ó    c                ó°   €  V'       g   V # ^ RI Hp V! V \        P                  ! V4      4      #   \         d    \
        P                  RRR7        R# i ; i)zZContent-only snapshot for final effect accounting; telemetry must never break compression.©Úrejoin_compressed_head_and_tailz+failed to snapshot compression effect inputT©Úexc_infoN)Úhermes_cli.partial_compressr   ÚcopyÚdeepcopyÚ	ExceptionÚloggerÚdebug)r	   r   r   s   && r   Ú"_snapshot_compression_effect_inputr       sK   € ðßØˆOÝOá.¨x¼¿ºÀ}Ó9UÓVÐVøÜô Ü�‰ÐBÈTˆÔRÚðús   ‚/ Š/ Œ"/ ¯"AÁAc               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )r   Úagentr   Úmessages_beforer   Úmessages_afterr
   r   Úsplit_statusÚstrr   ÚNoner   )r   s   "r   r   r   -   sD   € ÷ Uñ UØðUØ!,ðUØ>BðUØS^ðUØnqðUà	ñUr   c                ó  € Vf   R#  V'       d   VR8X  d   ^ RI Hp V! W#4      p\        V P                  RR4      p\	        V4      '       d   V! W4       R# R#   \
         d    \        P                  RRR7        R# i ; i)zRFinalize effect fields from the transcript shape that crossed the commit boundary.NÚnot_applicabler   Ú$_record_committed_compression_effectz-failed to record committed compression effectTr   )r   r   ÚgetattrÚcontext_compressorÚcallabler   r   r   )r    r!   r"   r   r#   r   Úrecorders   &&&&&  r   Ú _record_committed_attempt_effectr-   -   s}   € ð ÒÙð
Uß˜\Ð-=Ô=ÝSñ =¸^Ó[ˆNÜ˜5×3Ñ3Ð5[Ð]aÓbˆÜ�H×ÒÙ�_Ö5ñ øäô UÜ�‰ÐDÈtˆ×TðUús   ˆA �AA Á"A?Á>A?Úattempt_beganTÚattempt_seedc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r    r   r.   Úboolr/   údict[str, Any] | Noner   údict[str, Any]r   )r   s   "r   r   r   @   s,   € ÷ ñ ØðØ"&ðØ=Rðàñr   c               óÞ   € V'       d   \        V4      # V'       d   \        V RR4      MRpRT;'       g     \        P                  ! 4       P                  R\        V RR4      ;'       g    RRR/# )ar  This attempt's id, the session it started in, and its trigger.

``attempt_seed`` is the attempt's own copy and wins: the agent's current-attempt fields belong to the newest
attempt, so a stalled attempt unwinding after its fallback began would otherwise log the fallback's identity.
An emit with no attempt begun (pool saturation) gets a fresh id and an unknown trigger.Ú_compression_attempt_idNÚ
attempt_idÚ
session_idÚ Útrigger_sourceÚunknown)Údictr)   ÚuuidÚuuid4Úhex)r    r.   r/   r6   s   &$$ r   Ú_attempt_seedr?   @   sf   € ÷ Ü�LÓ!Ð!ßDQ”˜Ð 9¸4Ô@ÐW[€Jà�j×4Ð4¤D§J¢J£L×$4Ñ$4°lÄGÈEÐS_ÐacÓDd×DjÐDjÐhjØ˜)ðð r   c               ó    € V ^8„  d   QhRRRR/# )r   Úpayloadr3   r   r%   r   )r   s   "r   r   r   Q   s   € ÷ yñ y ð y°Dñ yr   c           	     ó`   € \         P                  R\        P                  ! V RRR7      4       R# )zTThe one attempt log line; ``scripts/micro_compaction_report.py`` parses this prefix.z)context compression attempt telemetry: %sT)Ú	sort_keysÚ
separatorsN)Ú,Ú:)r   ÚinfoÚjsonÚdumps)rA   s   &r   Ú_log_attempt_recordrJ   Q   s    € ä
‡K�KÐ;¼T¿ZºZÈÐ[_ÐlvÔ=wÖxr   Úfailure_classÚcommit_started_atÚinclude_last_telemetryÚhistory_rewrittenc               ó@   € V ^8„  d   QhRRRRRRRRRR	R
RRRRRRRRR/
# )r   r    r   Ú
started_atÚfloatÚcommit_statusr$   r#   rK   ú
str | NonerL   zfloat | NonerM   r1   r/   r2   rN   zbool | Noner   r%   r   )r   s   "r   r   r   Z   sp   € ÷ <]ñ <]Øð<]Ø$ð<]Ø58ð<]ØHKð<]Ø\fð<]à#ð<]àDHð<]ð (ð<]ð DOð<]ð 
ñ	<]r   c          	     ój  €  V P                   p	V'       d   \        V	RR4      MRp
\        WVR7      p\        V
\        4      ;'       d    V
P                  R4      VR,          8H  pV'       g	   / VCRR/Cp
\	        V
4      pVP                  RR4       VP                  R	R
4       VP                  RVR,          4       VP                  RVR,          4       VP                  \        \        P                  ! 4       V,
          R,          4      VVR7       Ve   W�R&   VR8w  d(   V'       g    \         F  pVP                  VR4       K  	  Ve?   \        ^ \        \        P                  ! 4       V,
          R,          4      4      ;V
R&   VR&   V'       d/   V\        9   d    V'       d   VP                  R4      '       g   WMR&   VP                  RR4       VP                  R^ 4       \        VP                  R4      ;'       g-    T;'       d#    \        V	RR4      ;'       g    \        V	RR4      4      VR&   \!        V4       \#        W4       ^ RIHp V! W-P                  R4      \        V P                   RR4      V R7       R#   \(         d$   p\*        P-                  RTRR7        Rp?R# Rp?ii ; i)aé  Emit one content-free JSON log line for a compression attempt.

``include_last_telemetry=False`` is for emits that fire without an attempt having begun
(pool-saturation refusals): they must not hydrate from the previous attempt's numbers.
``attempt_seed`` is the emitting attempt's own seed (see ``_attempt_seed``).
``history_rewritten`` (commit path only) says whether the returned transcript replaced the input, which
a split that failed after publishing the compacted history still did.Ú_last_compression_telemetryN)r.   r/   r6   ÚmethodÚnoneÚeventÚcompression_attemptÚrouteÚhermesr7   éè  )Útotal_duration_msrR   r#   rN   Ú	committedÚ	commit_msrK   ÚchunkingFÚchunk_countÚfallback_usedÚ_last_summary_fallback_usedÚ_last_aux_model_failure_model)Úfinish_compression_attemptÚcontext_length)r    ú0failed to emit compression attempt telemetry: %sTr   )r*   r)   r?   Ú
isinstancer;   ÚgetÚ
setdefaultÚupdateÚintÚtimeÚ	monotonicÚ_CANDIDATE_EFFECT_FIELDSÚpopÚmaxÚ_GENERIC_ABORT_VERDICTSr1   rJ   r   Ú.hermes_cli.observability.shared_metrics_eventsre   r   r   r   )r    rP   rR   r#   rK   rL   rM   r/   rN   Ú
compressorÚ	telemetryÚseedÚownrA   Úkeyre   Úexcs   &$$$$$$$$        r   Ú#_emit_compression_attempt_telemetryrz   Z   sl  € ð0]Ø×-Ñ-ˆ
ßPf”G˜JÐ(EÀtÔLÐlpˆ	Ü˜UÐWcÔdˆÜ˜¤DÓ)×_Ð_¨i¯m©m¸LÓ.IÈTÐR^ÕM_Ñ._ˆßð 3˜4Ð2 ¨6Ñ2ˆIÜ�y“/ˆØ×Ñ˜7Ð$9Ô:Ø×Ñ˜7 HÔ-Ø×Ñ˜<¨¨lÕ);Ô<Ø×Ñ˜<¨¨lÕ);Ô<Ø�‰Ü!¤4§>¢>Ó#3°jÕ#@ÀDÕ"HÓIÐYfØ%ð 	ô 	
ð Ò(Ø+<Ð'Ñ(Ø˜KÔ'×0Aç/�Ø—‘˜C Ö&ñ 0àÒ(Ü<?ÀÄ3ÌÏÊÓHXÐ[lÕHlÐptÕGtÓCuÓ<vÐvˆI�kÑ" W¨[Ñ%9ç -Ô3JÔ"JÏsÐW^×WbÑWbÐcr×WsÒWsØ'4�OÑ$Ø×Ñ˜: uÔ-Ø×Ñ˜=¨!Ô,ä#'Ø�K‰K˜Ó(÷ ð Ø÷ ð Ü˜
Ð$AÀ5ÓI÷ Nð NÜ˜:Ð'FÈÓMó	$
ˆ�Ñ ô 	˜GÔ$Ü˜Ô'Ý]á"ØŸ;™; Ó7¼À×AYÑAYÐ[kÐmqÓ9rÐz÷	
øô ô ]Ü�‰ÐGÈÐW[ˆ×\Ò\ûð]úsQ   ‚J –AJ Á-B=J Ä+A(J ÆJ Æ'J Æ>AJ È	J ÈJ È"A J ÊJ2ÊJ-Ê-J2c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   r    r   rP   rQ   rK   rS   r/   r2   r   r%   r   )r   s   "r   r   r   ™   s4   € ÷ ñ ØðØ!ðØ2<ðØLaðà	ñr   c           	     ó&   € \        WR R VVR7       R# )Úaborted)rP   rR   r#   rK   r/   N)rz   )r    rP   rK   r/   s   &&&&r   Ú_emit_aborted_attempt_telemetryr~   ™   s   € ô (Ø°IÈIÐerØ!÷r   rZ   r[   rV   rW   c               ó<   € V ^8„  d   QhRRRRRRRRR	RR
RRRRRRR/	# )r   r    r   rP   rQ   rR   r$   rK   rS   Úapprox_tokensrZ   rV   r/   r2   r   r%   r   )r   s   "r   r   r   ¢   sa   € ÷ "Yñ "YØð"YØ!ð"YØ58ð"YØISð"YØdgð"Yàð"Yà#&ð"Yà?Tð"Yð 
ñ"Yr   c               óê  €  \        V RR4      pRRRVRVRV/\        WR7      CR	\        V R
R4      ;'       g    RR\        V RR4      ;'       g    RR\        VRR4      R\        VRR4      R\        V\        4      '       d   TMRR\        \        P
                  ! 4       V,
          R,          4      RVRRRR/	Cp	\        V	4       \        W	4        ^ RIHp V! 4        R#   \         d#   p
\        P                  RT
RR7        Rp
?
L8Rp
?
ii ; i  \         d    \        P                  RRR7        R# i ; i   ^ RIHp T! 4        i   \         d    \        P                  RRR7        i i ; i; i)aY  Log one attempt that never reached the local compressor: an automatic gate blocked it, Codex owns the
thread, or the session lease showed another path already owns the work. The compressor's telemetry still
describes an earlier attempt, so this record starts from the attempt seed. Shared metrics have never
counted these exits and still do not.r*   NrX   rY   rZ   rV   rK   )r/   Úmain_providerÚproviderr8   Ú
main_modelÚmodelÚmain_context_limitÚ_resolved_context_lengthÚeffective_thresholdÚ_threshold_tokensÚcurrent_estimated_tokensr]   r\   rR   r#   r'   rb   Frg   Tr   )Údiscard_compression_attemptz-failed to discard bypassed compression metric)r)   r?   rh   rl   rm   rn   rJ   r   r   r   r   rs   r‹   )r    rP   rR   rK   r€   rZ   rV   r/   rt   rA   ry   r‹   s   &&$$$$$$    r   Ú _emit_bypassed_attempt_telemetryrŒ   ¢   su  € ðYÜ˜UÐ$8¸$Ó?ˆ
àÐ*¨G°U¸HÀfÈoÐ_lð

ä˜EÔ=ð

ð œW U¨J¸Ó;×AÐA¸rÀ<ÔQXÐY^Ð`gÐikÓQl×QrÐQrÐprà ¤'¨*Ð6PÐRVÓ"WØ!¤7¨:Ð7JÈDÓ#QØ&¼ÀMÔSV×9WÒ9W©Ð]aØ¤¤d§n¢nÓ&6¸Õ&CÀtÕ%KÓ!LÈoÐ_lØÐ,¨o¸uñ

ˆô 	˜GÔ$Ü˜Ô'ð	YÝbá'Ö)øô ô ]Ü�‰ÐGÈÐW[ˆ×\Ñ\ûð]ûô ô 	YÜ�L‰LÐHÐSWˆL×Xð	Yûð		YÝbá'Õ)øÜô 	YÜ�L‰LÐHÐSWˆLÖXð	Yýsg   ‚AC! ÁBC! ÃD Ã!DÃ,D	ÄD: Ä	DÄD: Ä"D7Ä6D7Ä:E2Ä<E
Å	E2Å
"E/Å,E2Å.E/Å/E2c               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )r   r    r   rP   rQ   r€   r/   r2   Úreasonr$   r   r%   r   )r   s   "r   r   r   Ç   s<   € ÷ 	ñ 	Øð	Ø!ð	Ø25ð	ØEZð	Ødgð	à	ñ	r   c           
     óX   € \        WRRVP                  R^4      ^ ,           2W#R7       R# )zèRecord an automatic attempt the breaker gate refused for ``reason`` (the gate's block reason). The class keeps
only the guard's name (``blocked:cooldown``, ``blocked:structural_backoff``, ``blocked:ineffective``), never its
seconds.Úblockedzblocked:rF   )rR   rK   r€   r/   N)rŒ   Úsplit)r    rP   r€   r/   rŽ   s   &&&&&r   Ú_emit_blocked_attempt_telemetryr’   Ç   s1   € ô %Ø¨ÀHÈVÏ\É\ÐZ]Ð_`ÓMaÐbcÕMdÐLeÐBfØ#÷r   )r"   Útokens_afterÚtokens_reclaimedÚitems_dropped)N)Ú__doc__Ú
__future__r   r   rH   Úloggingrm   r<   Útypingr   Úagent.compaction_eventsr   Ú	getLoggerr   Ú	frozensetrr   r   r-   r?   rJ   ro   rz   r~   rŒ   r’   r   r   r   Ú<module>r�      sÝ   ðñõ #ã Û Û Û Û Ý å 3à	×	Ò	Ð;Ó	<€ñ $ ]Ð4PÐ$QÓRÐ õ
õUð&Ø)-ðØUY÷õ"yð cÐ ð<]Øimð<]à&*ð<]àKOð<]ð +/ð<]ð RV÷<]÷~ð"Yàð"Yà)/ð"YàW[÷"Y÷J	r   