+
    iHàjœ  ã                  ó>   € R t ^ RIHt ^ RIHtHt RRR/R R llltR# )	a¦  The held-row watermark cap and its lease-less staleness gate (#124102).

Split out of :mod:`agent.conversation_compression` (FILE_LINES ratchet): the watermark math the
in-place compaction commit, the proactive prune and micro-compaction share. The origin module
imports :func:`held_archive_watermark` from here; ``_held_watermark`` (the agent-bound wrapper)
stays with its only caller in the origin module's commit path.
)Úannotations)ÚAnyÚOptionalNÚstale_raisesFc               ó4   € V ^8„  d   QhRRRRRRRRR	R
RRRR/# )é   Ú
session_dbr   Ú
session_idÚstrÚ	watermarkúOptional[int]ÚmessagesÚlistÚverbatim_tailzOptional[list]r   ÚboolÚreturn© )Úformats   "ÚM/home/ubuntu/.hermes/hermes-agent/agent/conversation_compression_watermark.pyÚ__annotate__r      sO   € ÷ K'ñ K'ØðK'Ø!$ðK'Ø1>ðK'ØJNðK'Ø_mðK'àðK'ð ñK'ó    c          
     óN  a€ Vf   R# ^ RI HoHp R V3R llpV Uu. uF$  p\        V\        4      '       g   K  V! VR4      NK&  	  p	pY”;'       g    R Uu. uF$  p\        V\        4      '       g   K  V! VR4      NK&  	  up,          p	V	 U
u. uF
  qªf   K  V
NK  	  pp
V'       d…   V'       d}   \        V RR4      p\        V4      '       d_   T! TV Uu. uF*  p\        V\        4      '       g   K  V! VR4      f   K(  VNK,  	  up4      pV'       d   V! R\        V4       R	V R
24      hV	'       d   V	R,          f   V# \        V4      pWâ8¼  d   V'       g   V# V P                  W4      f   V'       d   V! RV R	V R24      hV# \        Wâ4      # u upi u upi u up
i u upi )uT
  The in-place archive watermark, capped at the newest durable row the compressor was handed.

The lease watermark is the newest row in state.db, but a surface compacts the history it holds, and that
can be older: a Desktop/TUI or CLI ``/compress`` does not hold turns another surface appended to the same
session since it loaded. Archived under the watermark, those rows would leave every surface's
history and search, and the summary never saw them. Above the cap they take the concurrent-append path
instead (cloned after the compacted set).

Only while the held history is a live prefix of the session: its LAST row names an exact ``_row_id``, and
that row is still active (after another surface compacted, the held rows are archived and every live row
would be cloned beside the new summary). An id is exact while its dict is unchanged since it was loaded: a
dict loaded from the DB is born carrying both the id and the persist marker, and a pass that rewrote its
content drops the marker and keeps the id (the user/assistant merges in ``repair_message_sequence``, or a
context engine that rewrites in place). Such a row absorbed later durable rows whose ids are gone from the
held set, so its id no longer names what the summary covered: capped there, those rows would be cloned
live beside a summary that already contains them. A trailing row of unknown provenance may be durable
under the lease watermark without any stamp (the TUI model-switch marker, written with a bare
``append_message``); capped below it, the clone would land beside its own carried copy. A ``here N`` tail
is marker-swept copies, so ``compress_now`` keeps a copy's id only when its source still carried the
marker; their ids are trusted as given.

*stale_raises*: the newest exact held row being inactive means another compaction already committed.
Under the in-place lease that cannot overlap a live compaction, so the lease watermark is returned; a
lease-less caller (prune, micro-compaction) passes ``True`` and gets :class:`StaleHeldHistory` instead,
because for it the fallback would publish a stale generation beside the winner. It also catches the
generation change an id/activity check cannot see: an in-place prune rewrites a row's body under its
own id, so ``stale_raises`` additionally compares each exact persisted held row against its stored
payload (through the store's row-version CAS / loader-lens compare â€” never raw storage bytes against
a loaded view). That comparison runs for every exact persisted held row, so an unstamped trailing
message (which caps the watermark through the early return below) cannot suppress it for the durable
prefix.
N)Ú_DB_PERSISTED_MARKERÚStaleHeldHistoryc               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚmÚdictÚcopiedr   r   r   r   )r   s   "r   r   Ú,held_archive_watermark.<locals>.__annotate__6   s&   € ÷ Fñ F�Tð F 4ð F¨Mñ Fr   c                óÖ   <€ V P                  R 4      p\        V\        4      '       d   \        V\        4      '       g   V^ 8:  d   R# V'       g   V P                  S4      '       d   V# R# )Ú_row_idN)ÚgetÚ
isinstanceÚintr   )r   r   Úridr   s   && €r   Ú	_exact_idÚ)held_archive_watermark.<locals>._exact_id6   sO   ø€ Ø�e‰e�IÓˆÜ˜#œs×#Ò#¤z°#´t×'<Ò'<ÀÀqÄÙß §¡Ð&:× ;Ò ;ˆsÐEÀÐEr   FTÚrewritten_held_row_idsz	held row z of session z was rewritten in placez is no longer activer   éÿÿÿÿ)
Úagent.context_compressorr   r   r"   r   ÚgetattrÚcallableÚminÚmaxÚget_message_role)r   r	   r   r   r   r   r   r%   r   Úidsr$   ÚheldÚrewritten_ofÚ	rewrittenÚnewest_heldr   s   &&&&&$         @r   Úheld_archive_watermarkr4      s¡  ø€ ðH ÒÙßO÷Fð Fñ )1Ó
H© 1´J¸qÄ$×4GÔ‰9�Q˜Ö©€CÐ
HØ×)<Ð)<¸"Ð)<ÓUÑ)< 1ÄÈAÌt×ATÔ‰I�a˜ÖÑ)<ÑUÕU€CÙÓ2™3�C�CˆC™3€DÐ2ßŸô ˜zÐ+CÀTÓJˆÜ�L×!Ò!Ù$ ZÙ#ó2LÙ#�aÜ˜a¤×&ô Ù+4°Q¸Ó+>÷ �™8ñ2Ló MˆI÷ Ù&Ø¤ I£Ð/¨|¸J¸<ÐG^Ð_óað aç�#�b•'’/ØÐÜ�d“)€Kð Ô¯ØÐØ×"Ñ" :Ó;ÒCßÙ" Y¨{¨m¸<È
À|ÐSgÐ#hÓiÐiØÐÜˆ{Ó&Ð&ùò; IùÚUùÚ2ùò2Ls4   �FºFÁFÁ4FÂFÂFÃF"
Ã2F"
Ã?F"
)N)Ú__doc__Ú
__future__r   Útypingr   r   r4   r   r   r   Ú<module>r8      s'   ðñõ #ç  ñK'à!÷K'ò K'r   