+
    jHàj¿  ã                  ó²  € R t ^ RIHt ^ RIt^ RIHt ^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIH t H!t!H"t"H#t# ^ RI$H%t% ^ RI&H't' ^ RI(H)t)H*t* ^ RI+H,t, ^ RI-H.t. ^ RIH/t/H0t0H1t1H2t2H3t3H4t4 ^ RI5H6t6 ]'       d   ^ RI7H8t8 ^ RI9H:t: ]Pv                  ! R4      t< ! R R4      t=R# )z;Gateway turn hygiene phases; inherited by GatewayTurnMixin.)ÚannotationsN)ÚTYPE_CHECKING)Út)Úformat_iteration_progress)ÚnullcontextÚsuppress)Úcopy_context)ÚPlatform)Ú(repair_explicit_computer_use_media_paths)ÚBasePlatformAdapter)ÚMessageEvent)ÚSessionSourceÚ_session_key_namespaceÚbuild_channel_continuity_noteÚbuild_session_context)ÚTranscriptReadError)ÚTurnContext)ÚDEFAULT_LEASE_WAITÚTurnLeaseTimeoutError)Úget_hermes_home_override)ÚPath)ÚAnyÚCallableÚDictÚListÚOptionalÚTuple)Úbase_url_hostname)ÚGatewayRunner)Ú
TurnRunnerzgateway.runc                  óØ   € ] tR t^*t]P
                   ! R R4      4       t]R 4       tR t	R t
R tR tR t]R	 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 4       tRtR# )ÚGatewayTurnHygieneMixinc                  óD   € ] tR t^+t$ RtR]R&   R]R&   R]R&   R]R&   RtR	# )
Ú$GatewayTurnHygieneMixin._HygienePlanz'Hygiene pre-check outcome for one turn.ÚboolÚneeds_compressÚintÚapprox_tokensÚ	msg_countÚwarn_token_threshold© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r*   ó    Ú=/home/ubuntu/.hermes/hermes-agent/gateway/run_turn_hygiene.pyÚ_HygienePlanr#   +   s   ‡ á5àÓØÓØ‹Ø!×!r2   r4   c                óŠ  a€ VP                  R/ 4      p\        V\        4      '       d   W n        Mã\        V\        4      '       dÎ   VP                  R4      ;'       g&    VP                  R4      ;'       g    V P                  V n        VP                  R4      pVe6   \        \        \        4      ;_uu_ 4        \        V4      V n	        RRR4       VP                  R4      ;'       g    RV n
        VP                  R4      ;'       g    RV n        VP                  R/ 4      o\        S\        4      '       g   R# \        SP                  RR	4      4      P                  4       R9   V n        RV3R
 llpV! RV P                  \        4      V n        V! RV P                  \         4      V n        V! RV P"                  \         4      V n        \%        V P"                  V P                  4      V n        V! RV P&                  \         4      V n        V! RV P(                  \         R	R7      V n        R#   + '       g   i     ELn; i)zgApply model / compression knobs from the gateway config onto ``hs`` (invalid values keep the defaults).ÚmodelÚdefaultÚcontext_lengthNÚproviderÚbase_urlÚcompressionÚenabledTc                ó®   <€ SP                  V 4      pVf   V#  V! V4      pT'       d
   T^ 8¼  d   T# T^ 8”  d   T# T#   \        \        3 d    Tu # i ; i©N)ÚgetÚ	TypeErrorÚ
ValueError)ÚkeyÚcurrentÚcastÚ
allow_zeroÚrawÚparsedÚ	_comp_cfgs   &&&&  €r3   Ú_knobÚ@GatewayTurnHygieneMixin._hmwa_hygiene_read_config.<locals>._knobJ   sd   ø€ Ø—-‘- Ó$ˆCØŠ{Ø�ðÙ˜c›�÷ .8˜f¨œk�6ÐU¸VÀa¼Z�6ÐUÈgÐUøô œzÐ*ô Ø’ðús   š> ¾AÁAÚhygiene_hard_message_limitÚhygiene_timeout_secondsÚhygiene_total_ceiling_secondsÚhygiene_max_turn_hold_secondsÚ hygiene_failure_cooldown_seconds)rE   >   Ú1ÚyesÚtrue)F)r?   Ú
isinstanceÚstrr6   Údictr   r@   rA   r&   Úconfig_context_lengthr9   r:   ÚlowerÚcompression_enabledÚhard_msg_limitÚtimeout_secondsÚfloatÚtotal_ceiling_secondsÚmaxÚmax_turn_hold_secondsÚfailure_cooldown_seconds)ÚhsÚdataÚ
_model_cfgÚ_raw_ctxrI   rH   s   &&   @r3   Ú_hmwa_hygiene_read_configÚ1GatewayTurnHygieneMixin._hmwa_hygiene_read_config4   s½  ø€ ð —X‘X˜g rÓ*ˆ
Ü�j¤#×&Ò&Ø!�HÜ˜
¤D×)Ò)Ø!—~‘~ iÓ0×WÐW°J·N±NÀ7Ó4K×WÐWÈrÏxÉxˆBŒHØ!—~‘~Ð&6Ó7ˆHØÒ#Üœi¬×4Õ4Ü/2°8«}�BÔ,÷ 5à$Ÿ.™.¨Ó4×<Ð<¸ˆBŒKØ$Ÿ.™.¨Ó4×<Ð<¸ˆBŒKð —H‘H˜]¨BÓ/ˆ	Ü˜)¤T×*Ò*ÙÜ!$ Y§]¡]°9¸dÓ%CÓ!D×!JÑ!JÓ!LÐPdÑ!dˆÔ÷	Vñ "Ð">À×@QÑ@QÔSVÓWˆÔÙ"Ð#<¸b×>PÑ>PÔRWÓXˆÔÙ#(Ð)HÈ"×JbÑJbÔdiÓ#jˆÔ ä#& r×'?Ñ'?À×ASÑASÓ#TˆÔ Ù#(Ð)HÈ"×JbÑJbÔdiÓ#jˆÔ Ù&+Ø.°×0KÑ0KÌUÐ_cô'
ˆÖ#÷7 5×4Ð4ús   Â;H1È1I	c              ƒ  óÞ  "  € ^ RI Hp V P                  RRRRRRRR	R
R
R
R
/ R7      p V! 4       Vn        VP                  '       d   V P	                  WDP                  4       VP
                  VP                  VP                  rvp\        \        4      ;_uu_ 4        T P                  Y\        VP                  \        4      '       d   VP                  MR
R7      w  Vn        pVP                  R4      ;'       g    VP                  Vn        VP                  R4      ;'       g    VP                  Vn        VP                  R4      ;'       g    VP                  Vn        R
R
R
4       VP                  eE    ^ RIHp	 V	! WTP
                  WtP                  WdP                  4      G R
j  x€L
 '       d   R
Vn        VP                  fŒ   VP                  '       dz   \        \$        \&        4      ;_uu_ 4         ^ RIHp
Hp V
! VP                  4      pX! VP
                  VP                  VR7      pV'       d   \1        V4      Vn        R
R
R
4       V# V#   + '       g   i     Lý; i L¿  \         d    R
Tn         LÄi ; i  \         d7    TP                  P                  R4      p\        T\.        4      '       g   . p L°i ; i  + '       g   i     T# ; i  \         d     T# i ; i5i)aa  Resolve model/provider/context-length + hygiene knobs (fail-soft: errors keep defaults).

The 0.85 threshold is deliberately HIGHER than the agent's compressor (0.50): a safety net
for sessions that grew between turns. ``max_turn_hold_seconds`` bounds the TURN wait
(compressor keeps running detached, commit fenced); kept below transport idle-timeouts.)Ú_load_gateway_configzanthropic/claude-sonnet-4.6g333333ë?Tiˆ  g      >@g     À‚@g      $@g     Àr@N)r6   Úthreshold_pctrX   rY   rZ   r\   r^   r_   rV   r9   r:   Úapi_keyra   ©ÚsourceÚsession_keyÚuser_configr9   r:   ri   )Úshould_clear_context_pin_async)Úget_compatible_custom_providersÚ"get_custom_provider_context_lengthÚcustom_providers)r6   r:   rq   )Úgateway.runrg   Ú_HygieneSettingsra   rd   r6   r9   r:   r   Ú	ExceptionÚ_resolve_session_agent_runtimerS   rU   r?   ri   rV   Úhermes_cli.route_identityrn   r@   rA   Úhermes_cli.configro   rp   Úlistr&   )Úselfrk   rl   rg   r`   Úconfigured_modelÚconfigured_providerÚconfigured_base_urlÚ_hyg_runtimern   Ú_gw_gcpÚ_gw_gcclÚ_hyg_custom_providersÚ_hyg_custom_ctxs   &&&           r3   Ú_hmwa_hygiene_settingsÚ.GatewayTurnHygieneMixin._hmwa_hygiene_settings^   sx  é € õ 	5Ø×"Ñ"Ø/¸tÐY]Ø°ÈUØ"&ÀÐ^bØ D°$¸Rð	 #ó 
ˆð.	Ù*Ó,ˆBŒGØ�w�wˆwØ×.Ñ.¨r·7±7Ô;ØIKÏÉÐSU×S^ÑS^Ð`b×`kÑ`kÐ3FÐäœ)×$Õ$Ø)-×)LÑ)LØ!Ü+5°b·g±g¼t×+DÒ+D §¢È$ð *Mó *Ñ&�”˜,ð +×.Ñ.¨zÓ:×IÐI¸b¿k¹k�”Ø*×.Ñ.¨zÓ:×IÐI¸b¿k¹k�”Ø)×-Ñ-¨iÓ8×FÐF¸B¿J¹J�”
÷ %ð ×'Ñ'Ò3ð	4ÝXá;Ø(¯(©(Ð4GÏÉØ+¯[©[ó÷ ö ð 48˜Ô0ð
 ×'Ñ'Ò/°B·K·K°KÜœi¬×4Õ4ð	7÷ñ 18¸¿¹Ó0@Ð-ñ
 '/Ø Ÿh™h°·±ÐOdô'�O÷ 'Ü36°Ó3G˜Ô0÷ 5ð$ ˆ	ˆrˆ	÷S %×$úñøô
 !ô 4Ø/3�BÖ,ð4ûô %ô 7Ø02·±·±Ð<NÓ0OÐ-Ü)Ð*?Ä×FÒFØ46Ð1ùð7ú÷ 5Ö4ð$ ˆ	ûô ô 	ØØˆ	ð	üsä   ‚%K-¨A3K ÂAIÃ;)IÄ%)IÅIÅ!K Å81I+ Æ)I)Æ*	I+ Æ4I+ Æ;K ÇK Ç7KÇ9JÈ&KÈ:KÉ
K ÉK-ÉI&	É!K É)I+ É+J É=K É?J Ê K Ê>KËKËKËKËK	ËK ËK-ËK ËK*Ë&K-Ë)K*Ë*K-c           
   ƒ  óæ  "  € ^ RI HpHp T! VP                  VP                  ;'       g    RVP
                  ;'       g    RVP                  VP                  ;'       g    RR7      G Rj  x€L
 p\        WqP                  ,          4      p\        VR,          4      p	\        V4      p
^ RIHpHp RpV! V! VP                  VP                  4      4      ;_uu_ 4        VP                  ^ 8:  d3   ^ RIHp \#        V RR4      pV! \#        VR	V4      VP$                  V4      pVP                  ^ 8”  d   VP                  R
ppMVe   TRppM
V! V4      RppRRR4       XV8¬  ;'       g    W¡P&                  8¬  pV'       d§   \#        V RR4      p\#        \#        VR	V4      RR4      pVe~   Rp\)        \*        4      ;_uu_ 4        V! VP$                  4      pRRR4       V'       dB   VP-                  R^ 4      ^ 8”  d+   \.        P1                  RVP$                  VR,          4       RpV'       dB   V P3                  V4      G Rj  x€L
 '       d#   \.        P1                  RVP$                  4       RpV'       d<   \.        P1                  RV
VR X\        VP                  ^d,          4      VR VR 4       V P5                  VVW©4      #  ELY  + '       g   i     EL|; i  + '       g   i     EL; i L­5i)z�Decide whether hygiene compression fires this turn (token/message thresholds, DB-backed
failure cooldown, in-flight compression).)Úestimate_messages_tokens_roughÚget_model_context_length_asyncÚ )r:   ri   rV   r9   Ngffffffî?)Úimage_cost_contextÚlearned_image_token_cost)Úpersisted_anchor_tokensÚ_session_dbÚ_dbÚactualÚanchoredÚ	estimatedÚ get_compression_failure_cooldownÚremaining_secondszXSession hygiene: skipping compression for %s; previous failure cooldown active for %.1fsFzVSession hygiene: skipping compression for %s; another compression is already in flightuf   Session hygiene: %s messages, ~%s tokens (%s) â€” auto-compressing (threshold: %s%% of %s = %s tokens)Ú,)Úagent.model_metadatar…   r†   r6   r:   ri   rV   r9   r&   rh   ÚlenÚagent.image_token_costrˆ   r‰   Úlast_prompt_tokensÚagent.usage_anchorrŠ   ÚgetattrÚ
session_idrY   r   rt   r?   ÚloggerÚinfoÚ"_session_has_compression_in_flightr4   )ry   r`   ÚhistoryÚsession_entryrl   r…   r†   Ú_hyg_context_lengthÚ_compress_token_thresholdÚ_warn_token_thresholdÚ
_msg_countrˆ   r‰   Ú	_anchoredrŠ   r‹   Ú_approx_tokensÚ_token_sourceÚ_needs_compressÚ_getterÚ_cooldown_states   &&&&&                r3   Ú_hmwa_hygiene_planÚ*GatewayTurnHygieneMixin._hmwa_hygiene_planœ   s§  é € ÷ 	hÙ$BØ�H‰H˜rŸ{™{×0Ð0¨b¸"¿*¹*×:JÐ:JÈØ"$×":Ñ":ÀRÇ[Á[×EVÐEVÐTVô%
÷ 
Ðô %(Ð(;×>NÑ>NÕ(NÓ$OÐ!Ü #Ð$7¸$Õ$>Ó ?ÐÜ˜“\ˆ
÷ 	XØˆ	áÑ 8¸¿¹À2Ç;Á;Ó O×PÕPØ×/Ñ/°1Ô4ÝFÜ% d¨M¸4Ó@�Ù3Ü˜K¨°Ó<¸m×>VÑ>VÐX_ó�	ð ×/Ñ/°!Ô3Ø0=×0PÑ0PÐRZ � ØÒ&Ø09¸: � á0NÈwÓ0WÐYd �÷ Qð  )Ð,EÑE×hÐhÈ×WhÑWhÑIhˆçô
 " $¨°tÓ<ˆKÜœg k°5¸+ÓFÐHjÐlpÓqˆGØÒ"Ø"&�Üœi×(Õ(Ù&-¨m×.FÑ.FÓ&G�O÷ )ç" ×':Ñ':Ð;NÐPQÓ'RÐUVÔ'VÜ—K‘KðEà%×0Ñ0°/ÐBUÕ2Vôð
 ',�Oç T×%LÑ%LÈ[Ó%Y×YÖYô �K‰Kð;Ø<I×<TÑ<Tôð $ˆOçÜ�K‰Kð6à˜~¨aÐ0°=Ü�B×$Ñ$ sÕ*Ó+Ð0CÀAÐ/FÐLeÐfgÐKhô	ð × Ñ  °.À*ÓdÐdòI
÷ Q×PÐPú÷6 )×(Ð(úñ  Zùs‚   ‚=K1Á K1Á K1Á+KÁ,A1K1ÃA7KÅK1Å(K1Å?AK1ÇKÇK1Ç$AK1È-K1ÉK/É	K1É)K1É6AK1ËK	Ë	K1ËK,	Ë&
K1c           	   ƒ  ón  "  € ^ RI Hp ^ RIHpHp VP
                  p VP                  '       d   \        h\        P                  ! 4       VP                  ,
          pV! WrP                  VP                  4      p	\        \        VP                  VP                  4       ,
          R4      \        W˜,
          R4      4      p
VP                   \        P                  ! 4       VP                  ,
          ,
          pV^ 8:  d   RM\        V
\        VR4      4      p
\        VP                  VP                  4       ,
          R4      p\        V
R4      p
 \"        P$                  ! \"        P&                  ! VP(                  4      V
R7      G Rj  x€L
 w  rÞV#  L  \         Ed    TP                  '       d   h \        P                  ! 4       TP                  ,
          pT! YrP                  TP                  4      p	TP                  4       pY‚P                   8¼  dG   \*        P-                  RTP.                  Y‚P                   4       T! RTP                   R	 R
TR	 R24      hT! YòP                  TY—P                  R7      '       d4   Y¬R,
          8¼  d#   \*        P-                  RTP.                  Y�T	4        EK“  h i ; i5i)aX  Progress-aware inline wait for the detached hygiene compressor. Returns the compressed
transcript; raises ``HygieneTurnHoldExceeded`` (turn-hold budget) or
``asyncio.TimeoutError`` (idle/ceiling/fence cancel) for the caller's handlers. Idle timeout
(fence ticks per streamed token) + hard ceiling (moved back by prompt reading) + turn-hold cap.)Úeffective_ceiling)ÚHygieneTurnHoldExceededÚhygiene_wait_should_extendg{®Gázt?g      Ð?)ÚtimeoutNuž   Session hygiene compression for session %s exceeded the turn-hold budget (%.1fs >= %.1fs) â€” abandoning inline wait, proceeding without compression this turnzturn-hold budget z.1fzs elapsed after Ús)Úidler¯   ÚwaitedÚceilingÚfence_cancelledg•Ö&è.>uƒ   Session hygiene compression for session %s still streaming after %.0fs (last progress %.1fs ago) â€” extending wait (ceiling %.0fs))Ú'agent.conversation_compression_deadliner¬   rr   r­   r®   Úcommit_fenceÚis_cancelledÚTimeoutErrorÚtimeÚ	monotonicÚwait_startedr\   Úminr]   rZ   Úseconds_since_progressr^   ÚasyncioÚwait_forÚshieldÚfuturerš   r›   r™   )ry   Úattemptr`   rž   r¬   r­   r®   ÚfenceÚ_hyg_waitedÚ_ceilingÚ_sliceÚ_turn_hold_remainingÚ
_idle_leftÚ_compressedÚ_Ú_idles   &&&&            r3   Ú_hmwa_hygiene_wait_for_summaryÚ6GatewayTurnHygieneMixin._hmwa_hygiene_wait_for_summaryæ   sP  é € õ
 	NßSØ×$Ñ$ˆØØ×!×!Ð!Ü"Ð"äŸ.š.Ó*¨W×-AÑ-AÕAˆKÙ(¨×0HÑ0HÈ'×J^ÑJ^Ó_ˆHÜœ˜R×/Ñ/°%×2NÑ2NÓ2PÕPÐRWÓXÜ˜XÕ3°UÓ;ó=ˆFð $&×#;Ñ#;¼t¿~º~Ó?OÐRY×RfÑRfÕ?fÕ#gÐ Ø2°aÔ7‘U¼SÀÌÐMaÐchÓIiÓ=jˆFä˜R×/Ñ/°%×2NÑ2NÓ2PÕPÐRWÓXˆJÜ˜ Ó&ˆFð!Ü'.×'7Ò'7¼¿ºÀwÇ~Á~Ó8VÐ`fÔ'g×!g‘�Ø"Ð"ñ "høäõ Ø×%×%Ð%ØÜ"ŸnšnÓ.°×1EÑ1EÕE�Ù,¨U×4LÑ4LÈg×NbÑNbÓc�Ø×4Ñ4Ó6�ð ×":Ñ":Ô:Ü—K‘Kð8ð &×0Ñ0°+×?WÑ?Wô	ñ 2Ø+¨B×,DÑ,DÀSÐ+Ið J)Ø)4°SÐ(9¸ð<óð ñ .Ø×(:Ñ(:À;Ø$×6HÑ6H÷ó ð ¨dÕ!2Ô2ÜŸ™ðaà)×4Ñ4°kÈ(ôó
 Øð=üsH   ‚-J5°DJ5Å9F ÆFÆF ÆJ5ÆF ÆJ2Æ.C>J2Ê,J5Ê0J2Ê2J5c              ƒ  ó>  "  € VP                   pVP                  '       ga   VP                  4       pVf!   \        P                  ! R4      G Rj  x€L
  KF  V'       d$   VP                  4        V P                  W4       R#  VP                  G Rj  x€L
 w  rVV#  LJ L
5i)u®  Cancel the worker at the commit fence; on success release its lease and defer agent
cleanup, returning ``None``. When the worker already crossed into its commit, consume and
return the compressed transcript instead (a successful compaction is never a timeout; the
turn may be held past the budget by up to the commit duration â€” by design). The lock-free
``commit_in_flight`` marker keeps the poll from spinning on a hung commit.Ngš™™™™™™?)r¶   Úcommit_in_flightÚtry_cancel_before_commitr¾   ÚsleepÚ"release_cancelled_compression_lockÚ_hmwa_hygiene_defer_cleanuprÁ   )ry   rÂ   ÚcontextrÃ   Ú	cancelledrÉ   rÊ   s   &&&    r3   Ú_hmwa_hygiene_cancel_or_adoptÚ5GatewayTurnHygieneMixin._hmwa_hygiene_cancel_or_adopt   s…   é € ð ×$Ñ$ˆØ×(×(Ð(Ø×6Ñ6Ó8ˆIØÒ Ü—m’m EÓ*×*Ò*ßØ×8Ñ8Ô:Ø×0Ñ0°ÔBÙàØ&Ÿ~™~×-‰ˆØÐñ +ñ .ùs.   ‚B¡-BÁBÁBÁ3BÂBÂ	BÂBc                ód   € V P                  VP                  VP                  VR7       RVn        R# )zQHand the agent's cleanup to the still-running worker future and mark it deferred.©rÔ   TN)Ú&_defer_agent_cleanup_until_future_donerÁ   ÚagentÚcleanup_deferred)ry   rÂ   rÔ   s   &&&r3   rÓ   Ú3GatewayTurnHygieneMixin._hmwa_hygiene_defer_cleanup4  s(   € à×3Ñ3°G·N±NÀGÇMÁMÐ[bÐ3ÔcØ#'ˆÖ r2   c                	óD   € ^ RI Hp ^ RIHp V! W\	        WB4      V4       R# )é    )ÚActivityProvenance)Ú%_stamp_hygiene_compression_provenanceN)Úagent.session_activityrà   rr   rá   r˜   )rÛ   ÚdescÚprovenance_nameÚdebug_labelrà   rá   s   &&&&  r3   Ú_hmwa_hygiene_stampÚ+GatewayTurnHygieneMixin._hmwa_hygiene_stamp9  s   € å=ÝEÙ-¨e¼7ÐCUÓ;gÐitÖur2   c              ƒ  ó0  "  €  V P                  V4      pV'       dG   VP                  '       d3   VP                  VP                  W2VP                  R7      G Rj  x€L
  R# R# R#  L
  \         d"   p\
        P                  RYF4        Rp?R# Rp?ii ; i5i)zOBest-effort user notice on the hygiene thread; failure is logged, never raised.)ÚmetadataÚlogical_platformNz Failed to deliver %s to user: %s)Ú_delivery_adapter_forÚchat_idÚemit_warningÚplatformrt   rš   Úwarning)ry   rk   ÚmetaÚmessageÚwhatÚ_adapterÚ_werrs   &&&&&  r3   Ú_hmwa_hygiene_notifyÚ,GatewayTurnHygieneMixin._hmwa_hygiene_notify?  s…   é € ð	LØ×1Ñ1°&Ó9ˆHß˜FŸNŸN˜NØ×+Ñ+¨F¯N©N¸GØ=C¿_¹_ð ,ó N÷ Nò Nñ +‰xñNøäô 	LÜ�N‰NÐ=¸t×KÒKûð	LüsE   ‚B„*A' ¯+A' ÁA%ÁA' ÁBÁ%A' Á'BÁ2BÂBÂBÂBc              ƒ  ó¬   "  € ^ RI HpHp VP                  ^ 8  d   R# \        P
                  ! WPW!P                  4      G Rj  x€L
 pV! WWt4       R#  L5i)zNEscalate the failure streak (off-loop) and persist the cooldown, when enabled.©Ú_hygiene_cooldown_for_failureÚ_record_hygiene_cooldownN)rr   rù   rú   r_   r¾   Ú	to_thread)ry   r`   rl   r™   Úreasonrù   rú   Ú_hyg_cooldowns   &&&&&   r3   Ú%_hmwa_hygiene_record_failure_cooldownÚ=GatewayTurnHygieneMixin._hmwa_hygiene_record_failure_cooldownI  sJ   é € çWØ×&Ñ&¨Ô*ÙÜ%×/Ò/Ø)°×>YÑ>Yó
÷ 
ˆñ 	! °=ÖIñ
ùs   ‚A AÁAÁAc              ƒ  óì  aaa"  € ^ RI HoHoHo VP                  p\        \        VRR4      4      ;'       d    VP                  '       * pV'       dU   V P                  VR4       VP                  YAP                  r©pWWš3VVV3R llpVP                  P                  V4       RpM6V P                  VR4      G Rj  x€L
 pVe   V# S! WP                  SR4       R	pV P                  VP                  R
RR4       \        P!                  RVP                  \"        P$                  ! 4       VP&                  ,
          V4       V P)                  WQP*                  \-        R4      R4      G Rj  x€L
  h  L³ L5i)u˜  ``except HygieneTurnHoldExceeded`` body: keep or cancel the worker's commit admission,
notify the user, and re-raise; returns the compressed transcript only when the worker
was already committing.

Turn-hold expiry is an availability boundary, not a failure: the streak must NOT advance,
only flat retry spacing is recorded. A watermark-fenced commit (rows appended after
compression start survive as cloned tail) KEEPS admission: the turn proceeds uncompressed
now and the summary is adopted at the worker's fenced commit â€” always cancelling burned
every attempt for thinking summary models. Without the fence a late commit could clobber
newer turns, so cancel.)Ú_HYGIENE_TURNHOLD_RETRY_SECONDSrú   Ú_reset_hygiene_failure_streakÚcommit_watermark_fencedFzsession hygiene turn-holdc                ó¨  <€  V P                  4       pVR J ;'       d/    \        \        VRR4      4      ;'       g    \        VRV4      V8g  pV'       d"   \        P                  RV4        S
! W4       R # S	! WSR4       R #   \        P                  \
        3 d    Rp LTi ; i  \
         d"   p\        P                  RT4        R p?R # R p?ii ; i)NÚ_last_compaction_in_placeFr™   u™   Session hygiene compression for session %s finished after the turn-hold was released â€” summary adopted at the watermark-fenced commit boundary (#97963)z7hygiene streak reset after deferred adoption failed: %sz^hygiene compression deferred: turn-hold budget expired and the detached attempt did not commit)	Ú	exceptionr$   r˜   r¾   ÚCancelledErrorrt   rš   r›   Údebug)Ú_futÚ_gwÚ_sidÚ_skeyÚ_agentÚ_excÚ
_committedÚ_rs_errr  rú   r  s   &&&&&   €€€r3   Ú_hyg_adopt_or_space_retryÚUGatewayTurnHygieneMixin._hmwa_hygiene_on_turn_hold.<locals>._hyg_adopt_or_space_retryj  sÞ   ø€ ðØŸ>™>Ó+�Dð "&¨ ÷ "ð "ÜœW VÐ-HÈ%ÓPÓQ÷ Gð GÜ" 6¨<¸Ó>À$ÑFð ÷ Ü—K‘Kð3à48ôð
iÙ5°cÖAñ -ØÐ#Bð:öøô)  ×.Ñ.´	Ð:ô 'Ø!&’Jð'ûô %ô iÜŸ™Ð%^Ð`g×hÒhûðiús)   ƒB Á,B% ÂB"Â!B"Â%CÂ0CÃCul    â€” the watermark-fenced worker keeps its commit admission and the summary will be adopted when it finishesNz\hygiene compression deferred: turn-hold budget expired while the summary was still streamingr‡   z%session hygiene compression turn-holdÚAGENT_COMPRESSION_TURNHOLDz3hygiene compression turn-hold activity stamp failedzxSession hygiene compression for session %s exceeded turn-hold budget (%.1fs); proceeding without compression this turn%sz"gateway.compress.turnhold_deferredzcompression-turnhold notice)rr   r  rú   r  r¶   r$   r˜   r·   rÓ   r™   rÛ   rÁ   Úadd_done_callbackrÖ   ræ   rš   r›   r¹   rº   r»   rõ   rð   r   )ry   rÂ   r`   rž   rl   rk   rÃ   Ú_hyg_keep_admissionr  r  r  r  Ú_log_suffixÚ_adoptedr  rú   r  s   &&&&&&        @@@r3   Ú_hmwa_hygiene_on_turn_holdÚ2GatewayTurnHygieneMixin._hmwa_hygiene_on_turn_holdS  sj  úé € ÷	
ñ 	
ð ×$Ñ$ˆÜ"¤7¨5Ð2KÈUÓ#SÓT×oÐoÐ]b×]oÑ]oÔYoÐßØ×,Ñ,¨WÐ6QÔRð #0×":Ñ":¸KÏÉ˜ˆDà48È5÷ ñ ð: �N‰N×,Ñ,Ð-FÔGð3ñ ð
 "×?Ñ?ÀÐIdÓe×eˆHØÒ#Ø�á$Ø×.Ñ.Ð0Oð.ôð
 ˆKØ× Ñ Ø�M‰MÐBØ(Ð*_ô	
ô 	�‰ð9à×$Ñ$¤d§n¢nÓ&6¸×9MÑ9MÕ&MÈ{ô	
ð
 ×'Ñ'Ø—L‘L¤!Ð$HÓ"IÐKhó
÷ 	
ð 	
ð 	ñ- fñ&	
ùs,   …AE4ÁA)E4Â<E0Â=B-E4Å*E2Å+E4Å2E4c              ƒ  ó®  "  € ^ RI Hp VP                  pVP                  pV'       d   VP	                  4        VP
                  p	V P                  VR4      G Rj  x€L
 p
V
e   V
# T P                  Y$VP                  RV	'       d   RMV'       d   RMR,           4      G Rj  x€L
  T P                  VP                  V	'       d   RMR	R
R4       V	'       d"   \        P                  RVP                  4       h \        P                  ! 4       VP                  ,
          pV'       d-   \        P                  RVP                  W·P                   4       M:\        P                  RVP                  VP#                  4       W²P$                  4       V P'                  WQP(                  V! W‹VP*                  VP                   R7      R4      G Rj  x€L
  h  ELs EL0 L5i)zÕ``except asyncio.TimeoutError`` body: cancel at the commit fence, record the failure
cooldown, warn the user, and re-raise; returns the compressed transcript only when the
worker crossed the commit boundary first.)Ú$_hygiene_compression_timeout_messagezsession hygiene timeoutNzsession hygiene compression zcancelled at commit fenceztotal ceiling exhaustedz/timed out with no output from the summary modelú5session hygiene compression cancelled at commit fencez%session hygiene compression timed outÚAGENT_COMPRESSION_TIMEOUTz1hygiene compression timeout activity stamp failedzlSession hygiene compression for session %s was cancelled at the commit fence; continuing without compressionz‡Session hygiene compression for session %s reached its total ceiling after %.1fs (progress observed=%s); continuing without compressionz‡Session hygiene compression for session %s made no progress for %.1fs (total wait %.1fs, ceiling %.1fs); continuing without compression)Útotal_exhaustedÚelapsedÚidle_timeoutÚprogress_observedzcompression-timeout warning)rr   r  r¶   Údeadline_exceededÚ)retain_compression_lock_until_worker_doner·   rÖ   rþ   r™   ræ   rÛ   rš   rï   r¹   rº   r»   r!  r½   r\   rõ   rð   rZ   )ry   rÂ   r`   rž   rl   rk   r  rÃ   Ú_hyg_total_exhaustedÚ_hyg_fence_cancelledr  Ú_hyg_elapseds   &&&&&&      r3   Ú_hmwa_hygiene_on_timeoutÚ0GatewayTurnHygieneMixin._hmwa_hygiene_on_timeout¥  sª  é € õ 	EØ×$Ñ$ˆØ$×6Ñ6Ðßð ×;Ñ;Ô=à$×1Ñ1ÐØ×;Ñ;¸GÐE^Ó_×_ˆØÒØˆOØ×8Ñ8Ø˜]×5Ñ5Ø*ß/CÑ+ß2FÑ.ØFõó
÷ 	
ð 	
ð 	× Ñ Ø�M‰MßG[ÑCØ8Ø'Ð)\ô		
÷  Ü�N‰Nð?Ø@M×@XÑ@Xôð Ü—~’~Ó'¨'×*>Ñ*>Õ>ˆßÜ�N‰NðOà×(Ñ(¨,×8OÑ8Oõô �N‰NðTà×(Ñ(¨%×*FÑ*FÓ*HÈ,×XpÑXpôð
 ×'Ñ'Ø—L‘LÙ0Ø 4Ø×/Ñ/À5×CZÑCZôð *ó
÷ 	
ð 	
ð 	òY `ò	
ñB	
ùsP   ‚AGÁGÁ3GÂGÂ GÂ!!GÃGÃAGÄ$B#GÇGÇGÇGÇGc           	     ób  € ^ RI HpHp VP                  P	                  4        VP
                  '       g   V P                  VR4       VP                  ^ 8¼  d)    V! WP                  V! WVP                  4      R4       R# R#   \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)u
  ``except BaseException`` body (caller re-raises): revoke commit admission BEFORE the host
unwinds so the detached worker can never commit later, and record a cooldown â€” otherwise
the next turn re-arms hygiene and waits up to 600s behind a fence that refuses again.rø   zsession hygiene unwindr  z)hygiene unwind cooldown record failed: %sN)rr   rù   rú   r¶   Úrevoke_commit_admissionrÜ   rÓ   r_   r™   rt   rš   r  )ry   rÂ   r`   rž   rl   rù   rú   Ú_cd_errs   &&&&&   r3   Ú_hmwa_hygiene_on_unwindÚ/GatewayTurnHygieneMixin._hmwa_hygiene_on_unwindà  sš   € ÷ 	XØ×Ñ×4Ñ4Ô6Ø×'×'Ð'Ø×,Ñ,¨WÐ6NÔOØ×&Ñ&¨!Ô+ðSÙ(Ø×2Ñ2Ù1°$ÀR×E`ÑE`ÓaØKöñ ,øô ô SÜ—‘ÐHÈ'×RÒRûðSús   Á%B ÂB.ÂB)Â)B.c             ƒ  óh  "  € ^ RI Hp	 ^ RIHp
 VP                  pVP
                  pWÅP
                  8g  p\        \        VRR4      4      pV
! V4      pV
! V4      pV'       d2   VV8”  d+   \        P                  RVP
                  VR VR 4       RpTpV'       dÀ   V P                  P                  VP
                  WÂ4      G Rj  x€L
 '       g'   \        P                  RVP
                  V4       RpRpMeWÅn        V P                  WxV4       V P                  P                  4       G Rj  x€L
  \        P                   ! V P"                  WeR	R
7      G Rj  x€L
  V'       g	   V'       d"   ^ Vn        W!n        \)        V4      pV
! V4      pM?VP*                  pVP,                  p\        P                  RVP
                  V	! V4      4       \        P/                  RVP*                  VVP,                  R VR 4       VVP0                  8¼  d   \        P                  RVR 4       WÞVV3#  ELe EL LÙ5i)a  Adopt a finished compression (rotation / in-place / refused); publishes the transcript to
continue with on ``attempt.history``. Returns ``(rotated, in_place, new_count, new_tokens)``.

Rewrite only on rotation (NEW session id): in-place compaction already soft-archived the
old rows and rewrite_transcript() would DELETE them; neither rotation nor in-place signals
FAILURE and an unconditional rewrite would leave only the summary. Write-before-repoint:
a repoint-then-failed-rewrite would point the live entry at an empty session.)Úhygiene_no_commit_reason)r…   r  FzGateway hygiene compression for session %s would grow transcript (~%s -> ~%s tokens); keeping the original transcript unchangedr’   Nu©   Session hygiene: failed to persist compressed transcript for rotated session %s â†’ %s; keeping the live entry on the original session so the conversation is not droppedzhygiene-compression)rü   u®   Gateway hygiene compression for session %s did not rotate or compact in place (%s) â€” preserving the original transcript instead of overwriting it with the summary (#21301).u>   Session hygiene: compressed %s â†’ %s msgs, ~%s â†’ ~%s tokensz3Session hygiene: still ~%s tokens after compression)Úgateway.run_turnr/  r“   r…   rÛ   r™   r$   r˜   rš   rï   Úasync_session_storeÚ!persist_rotated_compression_childÚerrorÚ_rebind_turn_leaseÚ_saver¾   rû   Ú_sync_telegram_topic_bindingr–   r�   r”   r(   r'   r›   r)   )ry   rÂ   rÉ   r�   Úplanrž   rk   Ú
_quick_keyÚrun_generationr/  r…   Ú
_hyg_agentÚ_hyg_new_sidÚ_hyg_rotatedÚ_hyg_in_placeÚ_hyg_in_toksÚ_hyg_out_toksÚ
_new_countÚ_new_tokenss   &&&&&$$$$          r3   Ú_hmwa_hygiene_adopt_transcriptÚ6GatewayTurnHygieneMixin._hmwa_hygiene_adopt_transcriptò  s  é € õ 	>ÝGØ—]‘]ˆ
à!×,Ñ,ˆØ#×'?Ñ'?Ñ?ˆÜœW ZÐ1LÈeÓTÓUˆá5°gÓ>ˆÙ6°{ÓCˆß˜M¨LÔ8Ü�N‰NðEà×(Ñ(¨\¸!Ð,<À-ÐPQÐARôð
 !ˆLØ!ˆK÷ à×1Ñ1×SÑSØ!×,Ñ,¨lóI÷ Iö Iä—‘ð2à3@×3KÑ3KÈ\ôð  %�Ø %‘à+7Ô(à×'Ñ'¨
ÀLÔQØ×.Ñ.×4Ñ4Ó6×6Ð6Ü×'Ò'Ø×5Ñ5°vÐUjô÷ ð ÷ Ÿ=à/0ˆMÔ,Ø)ŒOÜ˜[Ó)ˆJÙ8¸ÓE‰Kð Ÿ™ˆJØ×,Ñ,ˆKÜ�N‰Nðjà×(Ñ(Ñ*BÀ:Ó*Nôô 	�‰ØLØ�N‰N˜J¨4×+=Ñ+=¸aÐ*@ÀkÐRSÀ_ô	
ð ˜$×3Ñ3Ô3Ü�N‰NÐPÐU`ÐabÐTcÔeØ¨J¸ÐCÐCòSIò 7ñùsP   ‚BH2Â)H2ÃH*Ã	H2ÃAH2Ä+H-Ä,*H2ÅH0ÅH2Å#H2Å+C H2È-H2È0H2c             ƒ  ó²  "  € ^ RI HpHp V P                  WWEWhWšR7      G Rj  x€L
 w  rÞpp\	        VP
                  RR4      pVRJ;'       d    \	        VRR4      p\        VP                  P                  ;'       d    V'       * ;'       d    V'       * 4      pV'       d   RpV'       gG   V! VWÞVP                  WõP                  VR7      '       d    \        P                  ! W°V4      G Rj  x€L
  V'       d×   T P                  Y'VP                  V'       d   R	M\	        VR
R4      4      G Rj  x€L
  V P                  VP
                  RRR4       V'       gu   ^ RIHp T! \	        VR
R4      ;'       g    \%        R4      RR7      p\&        P)                  RV4       V P+                  W�P,                  \%        R4      R4      G Rj  x€L
  R# R# Vev   \	        VRR4      '       da   \	        VRR4      p\	        VRR4      ;'       g    \%        R4      pV P+                  W�P,                  \%        RVVR7      R4      G Rj  x€L
  R# R# R#  EL' ELa EL" LŒ L5i)zzAdopt a finished hygiene compression, rebind the session + turn lease, record
streak/cooldown, and warn the user on abort.)r  Úhygiene_compaction_recovered)rž   rk   r8  r9  NÚcontext_compressorÚ_last_compress_abortedFT)ÚabortedÚrotatedÚin_placer(   Ú	new_countr'   Ú
new_tokensr  Ú_last_summary_errorz#session hygiene compression abortedÚAGENT_COMPRESSION_COOLDOWNz/hygiene compression abort activity stamp failed)Úredact_sensitive_textzgateway.shared.unknown_error)Úforcez'Session hygiene compression aborted: %szgateway.compress.hygiene_failedzcompression-failure warningÚ_last_aux_model_failure_modelr‡   Ú_last_aux_model_failure_errorzgateway.compress.aux_failed)r6   r3  zaux-model-fallback notice)rr   r  rE  rB  r˜   rÛ   r$   r¶   r·   r(   r'   r¾   rû   rþ   r™   ræ   Úagent.redactrO  r   rš   rï   rõ   rð   )ry   rÂ   r`   rÉ   r�   r7  rž   rl   rk   r8  r9  r  rE  r<  r=  r@  rA  Ú_compÚ_hyg_abortedr%  rO  Ú_errÚ
_aux_modelÚ_aux_errs   &&&&&&$$$$$             r3   Ú_hmwa_hygiene_apply_resultÚ2GatewayTurnHygieneMixin._hmwa_hygiene_apply_resultI  sG  é € ÷ 	\ØEI×EhÑEhØ '¸}Ø!ð Fió F
÷ @
Ñ<ˆ Z°ô ˜Ÿ™Ð';¸TÓBˆØ DÐ(×\Ð\¬W°UÐ<TÐV[Ó-\ˆô  $ G×$8Ñ$8×$EÑ$E×$pÐ$pÈlÔJZ×$pÐ$pÐcpÔ_pÓqÐßØˆL÷ Ñ <Ø ¨,Ø—n‘n°
×J\ÑJ\Ø"÷!
ó !
ô
 ×#Ò#Ð$AÈÓU×UÐUßØ×<Ñ<Ø ×!9Ñ!9ßK_ÑGÜ˜UÐ$9¸4Ó@ó÷ ð ð
 ×$Ñ$Ø—‘ÐDØ,Ð._ô÷ (å>Ù,Ü˜EÐ#8¸$Ó?×dÐdÄ1ÐEcÓCdÐlpôr�ä—‘ÐHÈ$ÔOØ×/Ñ/ØŸL™L¬!Ð,MÓ*NÐPmó÷ ò ñ (ð Ò¤7¨5Ð2QÐSW×#XÒ#XÜ  Ð(GÈÓLˆJÜ˜uÐ&EÀtÓL×qÐqÔPQÐRpÓPqˆHØ×+Ñ+ØŸ™¤aÐ(EÈZÐ_gÔ&hØ+ó÷ ò ñ $YÑòU@
ò* Vòññùs�   ‚!I£I
¤)IÁ/IÁ>IÂIÂ!	IÂ+AIÃ,IÃ-IÃ95IÄ.IÄ/)IÅIÅ5AIÇIÇ?IÈ8IÈ?IÉ IÉIÉIÉIÉIc              ƒ  óè  "  € ^ RI Hp Rp\        VP                  \        4      '       d   VP                  P                  R4      MRp	\        V	\        4      '       d&   \        V	P                  RR4      ;'       g    R4      pV! WVP                  WƒVP                  VP                  VP                  R7      G Rj  x€L
 p
\        P                  RW¤P                  W‚P                  R 4       R#  L35i)	a*  codex app-server runtime: the real context is the server-side thread, not the transcript
mirror. The detached-agent path would only rewrite the mirror and its finally-eviction
would destroy the live thread (next turn starts blank), so use the cached agent's
thread/compact/start and KEEP it cached.)Úrun_codex_hygiene_compactionÚnativer;   NÚcodex_app_server_auto)Ú	auto_moder�   r'   rZ   r_   zHSession hygiene (codex app-server): %s (session=%s, mode=%s, ~%s tokens)r’   )rr   r\  rS   ra   rU   r?   rT   r™   r'   r\   r_   rš   r›   )ry   r`   r7  r�   rž   rl   r}   r\  Ú_hyg_codex_autoÚ_hyg_comp_cfgÚ_hyg_codex_outcomes   &&&&&&&    r3   Ú_hmwa_hygiene_codex_compactionÚ6GatewayTurnHygieneMixin._hmwa_hygiene_codex_compaction‚  sÈ   é € õ
 	=ð #ˆÜ6@ÀÇÁÌ$×6OÒ6O˜Ÿ™Ÿ™ MÔ2ÐUYˆÜ�m¤T×*Ò*Ü! -×"3Ñ"3Ð4KÈXÓ"V×"bÐ"bÐZbÓcˆOÙ#?Ø˜}×7Ñ7À?Ø×,Ñ,¸b×>VÑ>VØ%'×%@Ñ%@ô$
÷ 
Ðô
 	�‰ØVØ× 8Ñ 8¸/×N`ÑN`ÐabÐMcö	
ñ
ùs   ‚A9C2Á<A C2Â<C0Â=4C2c              ƒ  óN  "  € ^ RI HpHp ^ RIHp  V P
                  P                  VP                  4      G Rj  x€L
 p\        V P
                  RV P
                  4      p	^ RIHp
 ^ R	IHp T! V
! 4       ;'       g    / P!                  R
4      ;'       g    / P!                  R4      RR7      pV! R/ VBRVR^RRRV'       * RR.RVP                  RV	/B pV! W×4       WMn        WÙ3#  L«  \         d0   pRp\        P                  RTP                  TRR7        Rp?LÞRp?ii ; i5i)zsBuild the detached hygiene ``AIAgent`` with the live session's system prompt. Returns
``(agent, sync_session_db)``.)Ú_GATEWAY_HYGIENE_PLATFORMÚ_seed_hygiene_system_prompt)ÚAIAgentNzžSession hygiene could not restore the system prompt for session %s: %s. Preserving an empty prompt so the live turn rebuilds it with its configured providers.T)Úexc_inforŒ   )Úload_config)Úis_truthy_valuer;   Úcheckpoint_requiredF)r7   r6   Úmax_iterationsÚ
quiet_modeÚskip_memoryÚenabled_toolsetsÚmemoryr™   Ú
session_dbr*   )rr   rf  rg  Ú	run_agentrh  r‹   Úget_sessionr™   rt   rš   rï   r˜   rw   rj  Úutilsrk  r?   rî   )ry   Ú
_hyg_modelr}   rž   rf  rg  rh  Ú_hyg_session_rowÚexcÚ_hyg_session_dbÚ	_load_cfgÚ
_is_truthyÚ_hyg_checkpoint_requiredr:  s   &&&&          r3   Ú_hmwa_hygiene_build_agentÚ1GatewayTurnHygieneMixin._hmwa_hygiene_build_agent˜  sL  é € ÷ 	WÝ%ð	Ø%)×%5Ñ%5×%AÑ%AÀ-×BZÑBZÓ%[×[Ðô " $×"2Ñ"2°E¸4×;KÑ;KÓLˆõ 	?Ý7á#-Ù‹k×Ð˜R×$Ñ$ ]Ó3×9Ð9°r×>Ñ>Ð?TÓUÐ_dô$
Ð ñ ñ 
Øñ
Ø",ð
Ø=>ð
ØKOð
à4Ô4ð
àHPÀzð
ð %×/Ñ/ð
ð =Lò
ˆ
ñ
 	$ JÔAð 8ÔØÐ*Ð*ñ7  \øÜô 	Ø#ÐÜ�N‰Nð(à)6×)AÑ)AÀ3ÐQUð ÷ ñ ûð	üsJ   ‚D%’(C( ºC&»C( ¿<D%Á<D%ÂAD%Ã&C( Ã(D"Ã3%DÄD%ÄD"Ä"D%c              ƒ  ó¾  aaa	aa"  € ^ RI Hp ^ RIHp V P	                  WgS	4      G Rj  x€L
 w  opSVn         RSn        \        \        SRR4      RR4      p\        V4      '       d   V! VS	P                  4       RSn
        R Sn        \        P                  ! 4       pV! VP                  R	7      oSVn        VP!                  R\#        4       P$                  VVVVV	3R
 l4      Vn        V P)                  VP&                  S4       \*        P,                  ! 4       Vn         V P1                  WS	4      G Rj  x€L
 pT P=                  YTTSS	Y¨TTR7
      G Rj  x€L
  T P?                  T
4       TP@                  '       g   T PC                  SRR7      G Rj  x€L
  R# R#  ELw Lj  T d     T P3                  YS	Y¨4      G Rj  x€L 
 p L�\4         d     T P7                  YS	Y¨4      G Rj  x€L 
 p Lµ\8         d    T P;                  YS	T
4       h i ; i Lº L~  T P?                  T
4       TP@                  '       g   T PC                  SRR7      G Rj  x€L 
  i i ; i5i)z“Run one detached hygiene compression attempt end to end; publishes the transcript to
continue with (compressed or original) on ``attempt.history``.©r­   )ÚCompressionCommitFenceNTrF  Úbind_session_stateFc                 ó   € R # r>   r*   )ÚaÚkws   *,r3   Ú<lambda>ÚHGatewayTurnHygieneMixin._hmwa_hygiene_detached_attempt.<locals>.<lambda>Î  s   € ±Dr2   )r\   c            	     ón   <€ S P                  SR SP                  SSP                  ;'       g    RRR7      # )r‡   r7   Úgateway_hygiene)r'   r¶   Útask_idÚtrigger)Ú_compress_contextr'   r™   )r:  Ú_hyg_commit_fenceÚ	_hyg_msgsr7  rž   s   €€€€€r3   r†  r‡  Þ  s9   ø€ ˜
×4Ñ4Ø˜r°×1CÑ1CÐRcØ)×4Ñ4×AÐA¸	ÐK\ð 5ô r2   )rž   rl   rk   r8  r9  zsession hygienerÙ   )"rr   r­   Úagent.conversation_compressionr�  r}  rÛ   Úcompression_in_placer˜   Úcallabler™   Ú_end_session_on_closeÚ	_print_fnr¾   Úget_running_loopr\   r¶   Úrun_in_executorr   ÚrunrÁ   Ú_track_deferred_agent_workerr¹   rº   r»   rÌ   r  r¸   r'  ÚBaseExceptionr,  rY  Ú_evict_cached_agentrÜ   Ú!_cleanup_agent_resources_off_loop)ry   rÂ   r`   r7  r�   rŽ  rv  r}   rk   rž   rl   r8  r9  r­   r�  ry  Ú_bind_hyg_stateÚlooprÉ   r:  r�  s   &&&f&f&&&f&&&      @@r3   Ú_hmwa_hygiene_detached_attemptÚ6GatewayTurnHygieneMixin._hmwa_hygiene_detached_attempt»  sJ  üé € õ 	8ÝIØ,0×,JÑ,JÈ:ÐerÓ,s×&sÑ#ˆ
�OØ"ˆŒð6	dð /3ˆJÔ+Ü%¤g¨jÐ:NÐPTÓ&UÐWkÐmqÓrˆOÜ˜×(Ò(Ù °×1IÑ1IÔJà/4ˆJÔ,Ù#8ˆJÔ ä×+Ò+Ó-ˆDÙ 6ÈR×MeÑMeÔ fÐð $5ˆGÔ Ø!×1Ñ1Øô “×"Ñ"÷ð óˆGŒNð" ×-Ñ-¨g¯n©n¸jÔIÜ#'§>¢>Ó#3ˆGÔ ðØ$(×$GÑ$GÈÐUbÓ$c×c�ð ×1Ñ1Ø˜[¨'°4À}Ø'À:Ø-ð 2ó ÷ ð ð ×$Ñ$ [Ô1Ø×+×+Ð+Ø×<Ñ<¸ZÐQbÐ<Óc×cÒcñ ,òo 'tñL døØ*ô uØ$(×$CÑ$CÀGÐQ^Ð`kÓ$t×tÐt’Üô sØ$(×$AÑ$AÀ'È}Ð^iÓ$r×rÐr’Ü ô Ø×,Ñ,¨W¸-ÈÔUØðúññ døð ×$Ñ$ [Ô1Ø×+×+Ð+Ø×<Ñ<¸ZÐQbÐ<Óc×cÒcð ,üs·   ‡"I©F ªI¹C)H Ä#F% Ä8F#Ä9F% Ä=H ÅHÅH Å9IÆHÆ	IÆ#F% Æ%HÇGÇHÇH Ç
HÇHÇ*G-Ç+HÇ0H Ç2HÇ;HÈH ÈIÈ:IÉIÉIÉIc              ƒ  ór  "  € ^ RI Hp V'       d   \        V4      ^8  d   V# V P                  W$4      G Rj  x€L
 p	V	P                  '       g   V P                  WYV4      # V P                  W•W44      G Rj  x€L
 p
V
P                  '       g   V P                  WYV4      # V P                  RV P                  W4      VR7      p T P                  Y$\        V	P                  \        4      '       d   V	P                  MRR7      w  rÍ\        VP                  R4      ;'       g    R4      P!                  4       R8X  d   V P#                  WšWSWM4      G Rj  x€L
  MnVP                  R4      '       dX   V Uu. uF  qîP                  R	4      R9   g   K  VNK  	  pp\        V4      ^8¼  d    V P%                  W¹W¥WüVW#WFV4      G Rj  x€L
  VP,                  VJ d   V P                  WYV4      # VP,                  #  EL» EL€ L§u upi  L?  T d     LF\&         d!   p\(        P+                  R
T4        Rp?LkRp?ii ; i5i)záAuto-compress pathologically large transcripts before the agent starts so oversized
histories don't cause repeated truncation/context failures. Token source: the API's
prompt_tokens from the last turn, else a char/4 estimate.r€  N)rÛ   rð   r�   rj   Úapi_moder‡   Úcodex_app_serverri   Úrolez(Session hygiene auto-compress failed: %s>   ÚtoolÚuserÚ	assistant)rr   r­   r”   r‚   rX   Ú_bound_hygiene_payloadr©   r%   Ú_HygieneAttemptÚ_event_thread_metadataru   rS   ra   rU   rT   r?   rW   rc  r�  rt   rš   rï   r�   )ry   Úeventrk   rž   rl   r�   r8  r9  r­   r`   r7  rÂ   rv  r}   ÚmrŽ  Úes   &&&&&&&&         r3   Ú_hmwa_run_session_hygieneÚ1GatewayTurnHygieneMixin._hmwa_run_session_hygieneý  s  é € õ 	8ßœ#˜g›,¨Ô*ØˆNà×.Ñ.¨vÓC×Cˆà×%×%Ð%Ø×.Ñ.¨w¸MÓJÐJØ×,Ñ,¨R¸-ÓU×Uˆð ×"×"Ð"Ø×.Ñ.¨w¸MÓJÐJà×&Ñ&¨T¸×8SÑ8SÐTYÓ8bÐlsÐ&Ótˆð	JØ'+×'JÑ'JØÜ'1°"·'±'¼4×'@Ò'@˜BŸGšGÀdð (Kó (Ñ$ˆJô �<×#Ñ# JÓ/×5Ð5°2Ó6×<Ñ<Ó>ÐBTÔTØ×9Ñ9¸"ÀGÐ\gÓv×vÑvØ×!Ñ! )×,Ò,ñ )0Ób© 1·5±5¸³=ÐDaÑ3aŸQ˜Q©�	ÐbÜ�y“> QÔ&Ø×=Ñ=Ø T°IÈ<Ø¨{Èó÷ ð ð �?‰?˜gÓ%Ø×.Ñ.¨w¸MÓJÐJØ�‰ÐòO Dò Vñ wùò cñøð 'ô 	ñ Üô 	JÜ�N‰NÐEÀq×IÑIûð	Jüs¸   ‚5H7·G2¸H7Á'H7Á5G5Á6H7Â5H7ÃAH Ä 0H ÅG8ÅH ÅH7ÅH Å-H Å1G:ÆG:Æ,H Æ?G?Ç H Ç/H7Ç5H7Ç8H Ç:H ÈH4ÈH7È
H4ÈH4ÈH/È*H7È/H4È4H7c                ó¾   € ^ RI Hp V! WP                  4      pW@Jd@   \        P	                  RVP
                  \        V4      \        V 4      VP                  4       V# )u·   ``bound_model_input_without_hygiene`` over ``hs.hard_msg_limit``, with one INFO line when the
cut is real. Below the limit this is the identity â€” no allocation, no behaviour change.)Ú!bound_model_input_without_hygieneu‹   Session hygiene did not land for %s: bounding the model payload to %s of %s messages (hard limit %s) â€” the stored transcript is unchanged)r0  r¯  rY   rš   r›   r™   r”   )r�   r`   rž   r¯  Úboundeds   &&&  r3   r¦  Ú.GatewayTurnHygieneMixin._bound_hygiene_payload0  sT   € õ 	GÙ3°G×=NÑ=NÓOˆØÓ!Ü�K‰KðRà×(Ñ(¬#¨g«,¼¸G»Àb×FWÑFWôð
 ˆr2   r*   N)r+   r,   r-   r.   ÚdataclassesÚ	dataclassr4   Ústaticmethodrd   r‚   r©   rÌ   rÖ   rÓ   ræ   rõ   rþ   r  r'  r,  rB  rY  rc  r}  r�  r¬  r¦  r1   r*   r2   r3   r!   r!   *   sÂ   † Ø×Ñ÷"ð "ó ð"ð ñ'
ó ð'
òR<ò|HeòT8òtò((ð
 ñvó ðvò
LòJòPòd9òvSò$UDòn7òr
ò,!+òF@dòD1ðf ñó ôr2   r!   )>r/   Ú
__future__r   ÚloggingÚtypingr   r¾   r²  ÚinspectÚjsonÚosÚqueueÚ	threadingr¹   Ú
agent.i18nr   râ   r   Ú
contextlibr   r   Úcontextvarsr   Úgateway.configr	   Úgateway.media_repairr
   Úgateway.platforms.baser   Úgateway.platforms.eventr   Úgateway.sessionr   r   r   r   Úgateway.session_transcriptr   Úgateway.turn_contextr   Úgateway.turn_leaser   r   Úhermes_constantsr   Úpathlibr   r   r   r   r   r   r   ru  r   rr   r   Úgateway.run_turn_runnerr   Ú	getLoggerrš   r!   r*   r2   r3   Ú<module>rÌ     sŒ   ðÙ AÝ "ã Ý  Û Û Û Û Û 	Û Û Û Ý Ý <ß ,Ý $Ý #Ý IÝ 6Ý 0÷ó õ ;Ý ,ß HÝ 5Ý ß =× =Ý #çÝ)Ý2ð 
×	Ò	˜=Ó	)€÷Ró Rr2   