+
    jHàj^d  ã                   ó2  a € R5 t-0 t R 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 R lt
R tR tR tR	t]tR
t ! R R]4      tR R ltR R ltR R ltR R ltR R lt ! R R]4      t ! R R4      tR6R R lltRtRt ! R R ]P:                  4      tR! R" ltR# R$ lt ]PB                  ! 4       t"/ t#] ^ k / t$] ^k R% R& lt% ! R' R(]4      t&]PN                  R) R* l4       t(]PN                  R+ R, l4       t)R- R. lt*R/ R0 lt+R1R2/R3 R4 llt,R# )7aÞ  Additive state.db schema drift: detection, the one-shot browse reconcile, and explicit repair.

Drift (a declared table/column missing) is not corruption. Browsing catches an unowned store up
once, additive DDL only (:func:`reconcile_drift_for_browse`); ``hermes sessions repair`` reconciles
a protected snapshot so failed DDL never leaves the store partly upgraded or escalates into FTS
surgery (:func:`repair_declarative_schema`). Neither runs while a gateway owns the store.
N)Úclosing©ÚPathc                ó$   € V ^8„  d   QhR\         /# ©é   Úpathr   )Úformats   "Ú;/home/ubuntu/.hermes/hermes-agent/hermes_state_reconcile.pyÚ__annotate__r      s   € ÷ ñ œdñ ó    c                óÌ  € ^ RI Hp ^ RIHp \	        V! V P                  4       P                  4       R,           RV R7      4      ;_uu_ 4       p V! 4        F"  pVP                  V4      P                  4        K$  	   RRR4       R#   \        P                   d5   p^ RIHp T! T4      '       d   \        T4      u Rp?uuRRR4       # h Rp?ii ; i  + '       g   i     R# ; i)zCReturn a missing declared table/column, not a corruption diagnosis.)Úschema_read_probe_statements©Úconnect_trackedú?mode=roT©ÚuriÚtracking_path©Ú_schema_not_builtN)Úhermes_state_schemar   Úhermes_cli.sqlite_safe_readr   r   ÚresolveÚas_uriÚexecuteÚfetchoneÚsqlite3ÚOperationalErrorÚhermes_state_repairr   Ústr)r   r   r   ÚconnÚ	statementÚexcr   s   &      r
   Úschema_drift_reasonr$      s²   € å@Ý;ä	‘ §¡£×!6Ñ!6Ó!8¸:Õ!EÈ4Ð_cÔd×	eÔ	eÐimð	Ù9Ö;�	Ø—‘˜YÓ'×0Ñ0Ö2ò <÷ 
fñ øô ×'Ñ'ô 	Ý=Ù  ×%Ò%Ü˜3“x”÷ 
fÒ	eð ûð		ú÷	 
fÖ	eñ ús<   ÁCÁ-BÂCÂC
Â9CÂ:CÃ	C
Ã
CÃCÃC#	c                 ó8  € ^ RI HpHpHpHpHp ^ RIHp V P                  V P                  R,           4      pV! V 4      ;p	'       d   \        V	4      hV! V4      ;p	'       d   \        V	4      h V! WVR7       V! V4      ;_uu_ 4       p
\        V
4       V! V
P                  4       4       V
P                  4        RRR4       \        V4      ;p'       d   \        RV 24      hV! V4      ;p'       d   \        RV 24      hV! W€VR7       V! V4      ;p	'       d-   \        P                   ! \"        4      P%                  R	V	4       R# R#   + '       g   i     L—; i  T! T4      ;p	'       d,   \        P                   ! \"        4      P%                  R	T	4       i i ; i)
é    )Ú_copy_database_snapshotÚ_db_opens_cleanlyÚ_repair_connÚ_repair_scratch_space_errorÚ_unlink_db_triple)Úapply_declared_schemaz.reconcile-scratch)Úsource_connectionNz"schema reconciliation incomplete: z"reconciled snapshot is unhealthy: )Údestination_connectionz,Could not remove reconciliation snapshot: %s)r   r'   r(   r)   r*   r+   r   r,   Ú	with_nameÚnameÚRuntimeErrorÚ_require_history_tablesÚcursorÚcommitr$   ÚloggingÚ	getLoggerÚ__name__Úwarning)r   Úguardr'   r(   r)   r*   r+   r,   ÚscratchÚerrorr!   Úreasons   &&          r
   Ú_reconcile_snapshotr=   "   sb  € ÷õ õ :à�n‰n˜TŸY™YÐ)=Õ=Ó>€GÙ+¨DÓ1Ð1€uÖ1Ü˜5Ó!Ð!Ù! 'Ó*Ð*€uÖ*Ü˜5Ó!Ð!ðgÙ ÀÕGÙ˜'×"Ô" dÜ# DÔ)á! $§+¡+£-Ô0Ø�K‰KŒM÷	 #ô
 )¨Ó1Ð1ˆ6Ö1ÜÐ!CÀFÀ8ÐLÓMÐMÙ& wÓ/Ð/ˆ6Ö/ÜÐ!CÀFÀ8ÐLÓMÐMÙ ÀeÕLá% gÓ.Ð.ˆ5Ö.Ü×ÒœhÓ'×/Ñ/Ð0^Ð`eÖfñ /÷ #×"ûñ & gÓ.Ð.ˆ5Ö.Ü×ÒœhÓ'×/Ñ/Ð0^Ð`eÕfð /ús*   Á.E Â2E	Â:8E Ã3E Å	E	ÅE Å=Fc                 ó”   € V P                  R 4       Uu0 uF  q^ ,          kK  	  ppRR0V,
          '       d   \        R4      hR# u upi )z1SELECT name FROM sqlite_master WHERE type='table'ÚsessionsÚmessageszWcanonical history tables are missing; use sessions recover, not additive reconciliationN)r   r1   )r!   ÚrowÚtabless   &  r
   r2   r2   ?   sM   € Ø $§¡Ð-`Ô aÓbÑ a˜�!�fˆfÑ a€FÐbØ�JÐ &×(Ô(ÜÐtÓuÐuñ )ùò cs   ”Ac                 óÄ  € ^ RI HpHpHpHp V! V 4      '       d   \        R4      h^ RIHp \        V! V P                  4       P                  4       R,           RV R7      4      ;_uu_ 4       p\        V4       RRR4       \        V 4      f   VP                  RRR	7       R# V! V 4      ;p	'       d   \        V	4      hV'       d+   V! V 4      w  r«V
f   \        R
V 24      h\        V
4      VR&   V! V 4      ;_uu_ 4       w  rËVf   \        RV 24      h\        W4       VP                  RRR	7       RRR4       R#   + '       g   i     LÌ; i  + '       g   i     R# ; i)r&   )Ú_backup_db_filer(   Ú_exclusive_repair_db_guardÚ_live_writer_holds_dbz5a live writer still holds state.db; stop it and retryr   r   Tr   NÚalready_healthy)ÚrepairedÚstrategyzpre-repair backup refused: Úbackup_pathz7could not acquire exclusive state.db repair ownership: Úreconcile_declarative_schema)r   rD   r(   rE   rF   r1   r   r   r   r   r   r2   r$   Úupdater    r=   )r   ÚbackupÚreportrD   r(   rE   rF   r   r!   r<   Úbpathr;   r9   s   &&&          r
   Ú_reconcile_lockedrP   E   s1  € ÷ó ñ
 ˜T×"Ò"ÜÐRÓSÐSÝ;Ü	‘ §¡£×!6Ñ!6Ó!8¸:Õ!EÈ4Ð_cÔd×	eÔ	eÐimÜ Ô%÷ 
fä˜4Ó Ò(Ø�‰˜tÐ.?ˆÔ@Ùá" 4Ó(Ð(€vÖ(Ü˜6Ó"Ð"ßÙ& tÓ,‰ˆØŠ=ÜÐ!<¸U¸GÐDÓEÐEÜ # E£
ˆˆ}ÑÙ	# D×	)Ô	)©^¨eØŠ=ÜÐ!XÐY^ÐX_Ð`ÓaÐaÜ˜DÔ(Ø�‰˜tÐ.LˆÔM÷	 
*Ñ	)÷ 
f×	eú÷ 
*×	)Ð	)ús   Á+D;Ã>3EÄ;E	ÅE	g      @iè  c                   óJ   a a€ ] tR t^wt oRtRR/V3R lV 3R llltRtVtV ;t# )ÚDeclarativeDriftErrorzTThe store lags SCHEMA_SQL (missing table/column) and browsing could not catch it up.ÚownedFc                ó&   <€ V ^8„  d   QhRS[ RS[/# )r   ÚdetailrS   )r    Úbool)r	   Ú__classdict__s   "€r
   r   Ú"DeclarativeDriftError.__annotate__z   s   ø€ ÷ ñ ™sð ©dñ r   c               ó2   <€ \         SV `  V4       W n        R # ©N)ÚsuperÚ__init__rS   )ÚselfrU   rS   Ú	__class__s   &&$€r
   r\   ÚDeclarativeDriftError.__init__z   s   ø€ Ü‰Ñ˜Ô ØŽ
r   ©rS   ©	r7   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r\   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r^   rW   s   @@r
   rR   rR   w   s   ù‡ € Ù^ð°U÷ ÷ õ r   rR   c                ó0   € V ^8„  d   QhR\         R\        /# )r   r#   Úreturn)ÚBaseExceptionrV   )r	   s   "r
   r   r      s   € ÷ Pñ P¤Mð P´dñ Pr   c                ób   € ^ RI Hp \        V \        P                  4      ;'       d	    V! V 4      # )zK``no such table/column`` from a schema read probe: drift, never corruption.r   )r   r   Ú
isinstancer   r   )r#   r   s   & r
   Úis_declarative_drift_errorro      s&   € å5Ü�cœ7×3Ñ3Ó4×OÐOÑ9JÈ3Ó9OÐOr   c                ó0   € V ^8„  d   QhR\         R\        /# ©r   Úhomerk   ©r   r    )r	   s   "r
   r   r   …   s   € ÷ 8ñ 8œ$ð 8¤3ñ 8r   c                óX   € ^ RI Hp V! V 4      pVR8X  d   R# V'       d   RV R2# RV  R2# )z[The `hermes sessions repair` invocation that targets *home* (no time limit, additive only).©Ú_profile_label_for_homeÚdefaultzhermes sessions repairú
hermes -p z sessions repairzHERMES_HOME=z hermes sessions repair)Úgateway.statusrv   ©rr   rv   Úlabels   &  r
   Ú_repair_commandr|   …   s=   € å6Ù# DÓ)€EØ�	ÔÙ'ßØ˜E˜7Ð"2Ð3Ð3Ø˜$˜Ð6Ð7Ð7r   c                óR   € V ^8„  d   QhR\         R\        \        \        3,          /# rq   )r   Útupler    )r	   s   "r
   r   r   �   s"   € ÷ 8ñ 8œð 8¤¤s¬C x¥ñ 8r   c                 óz   € ^ RI Hp V! V 4      pV'       d   VR8w  d	   VRV R23# T;'       g    \        V 4      R3# )r&   ru   rw   rx   z gateway restartúhermes gateway restart)ry   rv   r    rz   s   &  r
   Ú_owner_remedyr�   �   sF   € Ý6Ù# DÓ)€Eß�˜)Ô#Ø˜
 5 'Ð)9Ð:Ð:Ð:Ø×Ð”C˜“IÐ7Ð7Ð7r   c                ó0   € V ^8„  d   QhR\         R\        /# rq   rs   )r	   s   "r
   r   r   ˜   s   € ÷ 
"ñ 
"¤$ð 
"¬3ñ 
"r   c                óH  € ^ RI Hp ^ RIHp V! V! V 4      R,          4      ;'       g    / pVP	                  R4      p\        V\        4      '       d@   V'       d8   V! \        V4      4      V! V 4      8w  d   \        \        V4      4      ^,          # \        V 4      ^,          # )a  Restart command for the gateway that holds *home*'s lock. A multiplexer launched from another
home (usually the default) records that home in ``hermes_home``; `hermes -p <named> gateway
restart` is refused there ("Manage the host gateway instead"), so name the owner's own command.)Úcanonical_home)Ú_read_gateway_lock_recordzgateway.lockÚhermes_home)	Úgateway.runtime_ownershipr„   ry   r…   Úgetrn   r    r   r�   )rr   r„   r…   ÚrecordÚ
owner_homes   &    r
   Ú_owning_gateway_restartr‹   ˜   s�   € õ 9Ý8Ù&¡~°dÓ';¸nÕ'LÓM×SÐSÐQS€FØ—‘˜MÓ*€JÜ�*œc×"Ò"§z±nÄTÈ*ÓEUÓ6VÑZhÐimÓZnÔ6nÜœT *Ó-Ó.¨qÕ1Ð1Ü˜Ó˜qÕ!Ð!r   c                ó>   € V ^8„  d   QhR\         R\        R,          /# )r   r   rk   Nrs   )r	   s   "r
   r   r   ¥   s   € ÷ ñ ¤4ð ¬C°$­Jñ r   c                ór  € ^ RI HpHpHpHp V! V 4       Fz  w  rVV^ 8:  d   K  V! V4      pVf/    ^ RIpVP                  V4      P                  4       ;'       g    RpV'       g   KR  V! V4      '       g   Kb  RVR,          9   g   Kr  V! V4      u # 	  R#   \        \        XP                  3 d    Rp LXi ; i)aq  A Hermes gateway process holding *path* open without this profile's gateway.lock: a pre-v0.22.1
multiplexer serves named profiles without reserving their per-profile lock, so the lock alone
misses it. Only holders whose command line is a Hermes ``gateway`` run count; plain readers
(Desktop, sibling browses, CLI reads) are not owners. Returns a description, else None.)Ú_looks_like_hermesÚ_read_proc_argvÚdescribe_holder_pidÚforeign_state_db_holdersNÚgateway:é   NN)Úhermes_state_holdersrŽ   r�   r�   r‘   ÚpsutilÚProcessÚcmdlineÚImportErrorÚOSErrorÚError)	r   rŽ   r�   r�   r‘   ÚpidÚ_targetÚargvr•   s	   &        r
   Ú_lockless_gateway_holderrž   ¥   sª   € ÷
 xÓwÙ0°Ö6‰ˆØ�!Œ8ÙÙ˜sÓ#ˆØŠ<ðÛØ—~‘~ cÓ*×2Ñ2Ó4×<Ð<¸�÷ ‰4Ñ& t×,Ô,°¸dÀ2½hÖ1FÙ& sÓ+Ò+ñ 7ñ øô	  ¤¨&¯,©,Ð7ô Ø’ðús   °)BÁBÂB6Â5B6c                   ó   € ] tR t^ºtRtRtR# )ÚBrowseBudgetExceededz\The browse reconcile could not finish inside BROWSE_RECONCILE_BUDGET_S; nothing was written.© N©r7   rb   rc   rd   re   rf   r¡   r   r
   r    r    º   s   † Ýfr   r    c                   ó~   a € ] tR t^¾t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	Rt
V tR# )Ú_BudgetzSOne monotonic deadline for everything a browse does while holding ``gateway.lock``.c                ó    <€ V ^8„  d   QhRS[ /# )r   Úseconds©Úfloat)r	   rW   s   "€r
   r   Ú_Budget.__annotate__Á   s   ø€ ÷ ñ ¡ñ r   c                óv   € ^ RI pVP                  V n        V P                  4       V,           V n        RV n        R# )r&   NF)ÚtimeÚ	monotonicÚ_clockÚdeadlineÚexpired)r]   r¦   r«   s   && r
   r\   Ú_Budget.__init__Á   s)   € ÛØ—n‘nˆŒØŸ™›¨Õ/ˆŒØˆŽr   c                ó    <€ V ^8„  d   QhRS[ /# ©r   rk   r§   )r	   rW   s   "€r
   r   r©   Ç   s   ø€ ÷ 7ñ 7™5ñ 7r   c                óX   € \        V P                  V P                  4       ,
          R 4      # )g        )Úmaxr®   r­   ©r]   s   &r
   Ú	remainingÚ_Budget.remainingÇ   s   € Ü�4—=‘= 4§;¡;£=Õ0°#Ó6Ð6r   c                ó    <€ V ^8„  d   QhRS[ /# r²   r§   )r	   rW   s   "€r
   r   r©   Ê   s   ø€ ÷ +ñ +™eñ +r   c                ó6   € \        V P                  4       R 4      # )gš™™™™™©?)r´   r¶   rµ   s   &r
   Úbusy_timeoutÚ_Budget.busy_timeoutÊ   s   € Ü�4—>‘>Ó# TÓ*Ð*r   c                ó   <€ V ^8„  d   QhRR/# ©r   rk   Nr¡   )r	   rW   s   "€r
   r   r©   Í   s   ø€ ÷ Bñ B˜4ñ Br   c                ó@   a € V 3R  lpVP                  V\        4       R# )c                  óX   <€ S P                  4       S P                  8¼  d
   R S n        ^# ^ # )T©r­   r®   r¯   rµ   s   €r
   ÚprogressÚ_Budget.arm.<locals>.progressÎ   s"   ø€ Ø�{‰{‹} §¡Ô-Ø#�”ÙÙr   N)Úset_progress_handlerÚ_BUDGET_PROGRESS_OPS)r]   r!   rÁ   s   f& r
   ÚarmÚ_Budget.armÍ   s   ø€ õ	ð
 	×!Ñ! (Ô,@ÖAr   c                ó   <€ V ^8„  d   QhRR/# r½   r¡   )r	   rW   s   "€r
   r   r©   Õ   s   ø€ ÷ Zñ Z�tñ Zr   c                óx   € V P                   '       g   V P                  4       ^ 8:  d   RV n         \        R4      hR# )r&   Tú/browse schema catch-up exceeded its time budgetN)r¯   r¶   r    rµ   s   &r
   ÚcheckÚ_Budget.checkÕ   s1   € Ø�<�<ˆ<˜4Ÿ>™>Ó+¨qÔ0ØˆDŒLÜ&Ð'XÓYÐYñ 1r   rÀ   N)r7   rb   rc   rd   re   r\   r¶   rº   rÅ   rÊ   rf   rg   )rW   s   @r
   r¤   r¤   ¾   s>   ø‡ € Ù]÷ð ÷7ð 7÷+ð +÷Bð B÷Zö Zr   r¤   c                óB   € V ^8„  d   QhR\         R\        R,          RR/# )r   r   ÚbudgetNrk   ©r   r¤   )r	   s   "r
   r   r   Û   s%   € ÷ %ñ %¤ð %¬w¸­~ð %Èñ %r   c           
     ó  € ^ RI Hp ^ RIHpHp ^ RIHpHp T;'       g    \        \        4      pVP                  4        \        V! W VP                  4       RR7      4      ;_uu_ 4       pV! V4       VP                  V4       VP                  R4        VP                  4       pV! V4       V! 4        F#  p	 VP                  V	4      P!                  4        K%  	  VP                  4        VP                  R4        RRR4       R#   \"        P$                   d*   p
T! T
4      '       d   \'        \)        T
4      4      T
hh Rp
?
ii ; i  \*         dŸ   p
\,        P.                  ! \"        P0                  4      ;_uu_ 4        TP                  R4       RRR4       M  + '       g   i     M; iTP2                  '       d-   \5        T
\"        P$                  4      '       d   \7        R	4      T
hh Rp
?
ii ; i  + '       g   i     R# ; i)
aì  Missing SCHEMA_SQL tables and columns, in ONE ``BEGIN IMMEDIATE`` transaction.

No data migration, no FTS work, no schema_version stamp (that stays the owner's: the
version gates data migrations this path does not run). Every statement is additive and
idempotent. The declared shape is verified inside the transaction before COMMIT: a column
the shared reconciler could not add (it logs and continues) or an expired budget rolls the
store back to exactly what it was, never a partial upgrade.r   )Ú_reapply_durability_barriersr   )r,   r   N)r   ÚtimeoutÚisolation_levelzBEGIN IMMEDIATEÚCOMMITÚROLLBACKrÉ   )r   r   r   rÐ   r   r   r,   r   r¤   ÚBROWSE_RECONCILE_BUDGET_SrÊ   r   rº   rÅ   r   r3   r   r   r   rR   r    rl   Ú
contextlibÚsuppressrš   r¯   rn   r    )r   rÍ   r   rÐ   r   r,   r   r!   r3   r"   r#   s   &&         r
   Ú_apply_additive_schemarØ   Û   s†  € õ <ßSßWà×9Ð9”wÔ8Ó9€FØ
‡L�L„NÜ	‘ À6×CVÑCVÓCXØ15ô7÷ 
8ô 
8Ø;?Ù$ TÔ*Ø�
‰
�4ÔØ�‰Ð&Ô'ð	Ø—[‘[“]ˆFÙ! &Ô)á9Ö;�	ðØ—N‘N 9Ó-×6Ñ6Ö8ñ <ð �L‰LŒNØ�L‰L˜Õ"÷#
8ñ 
8øô ×/Ñ/ô Ù(¨×-Ò-Ü3´C¸³HÓ=À3ÐFØûðûô ô 	Ü×$Ò$¤W§]¡]×3Õ3Ø—‘˜ZÔ(÷ 4×3×3Ð3úà�~�~ˆ~¤*¨S´'×2JÑ2J×"KÒ"KÜ*Ð+\Ó]ÐcfÐfØûð	ú÷%
8÷ 
8ð 
8úsl   Á*+G5Â"E	Â9DÃ%E	ÄE	Ä$E	ÅE	ÅE	Å	G2Å,G-Æ FÆ	G-ÆF+Æ&G-Ç -G-Ç-G2Ç2G5Ç5H	Úbrowse_schema_reconcilegš™™™™™¹?c                   óB   a a€ ] tR tRt oRtV3R lV 3R lltRtVtV ;t# )ÚCorruptStoreErrori  z¿The lagging store is also damaged: browsing must not write DDL into it. Worded like sqlite's
own malformed-image error so every caller maps it to the corrupt-store status (``hermes doctor``).c                ó    <€ V ^8„  d   QhRS[ /# )r   rU   )r    )r	   rW   s   "€r
   r   ÚCorruptStoreError.__annotate__  s   ø€ ÷ Zñ Z™sñ Zr   c                ó.   <€ \         SV `  R V R24       R# )z3database disk image is malformed (integrity_check: Ú)N)r[   r\   )r]   rU   r^   s   &&€r
   r\   ÚCorruptStoreError.__init__  s   ø€ Ü‰ÑÐNÈvÈhÐVWÐXÖYr   r¡   ra   ri   s   @@r
   rÛ   rÛ     s   ù‡ € ñj÷Z÷ Zó Zr   rÛ   c                ó0   € V ^8„  d   QhR\         R\        /# )r   r   rÍ   rÎ   )r	   s   "r
   r   r     s   € ÷ +ñ +œTð +¬7ñ +r   c           	     ó4  € ^ RI Hp VP                  4         \        V! V P	                  4       P                  4       R,           RV VP                  4       R7      4      ;_uu_ 4       pVP                  V4       VP                  R4      P                  4       pRRR4       TP                  4        X Uu. uFE  qw'       g   K  \!        T^ ,          4      P#                  4       R	8w  g   K3  \!        T^ ,          4      NKG  	  ppR
P%                  TR,          4      ;'       g    R#   + '       g   i     L“; i  \        P                   dI   pTP                  '       d   \        R4      Th^ RIHp T! T4      '       d   \!        T4      u Rp?# h Rp?ii ; iu upi )ag  ``PRAGMA integrity_check`` on a read-only connection under *budget*: None when ``ok``, else the
first problems. Full integrity_check, not quick_check: quick_check skips index-vs-table content,
so an index with the right entry count but the wrong keys passes it. Raises
:class:`BrowseBudgetExceeded` when the scan cannot finish in time (fail closed: no write).r   r   T)r   r   rÑ   zPRAGMA integrity_check(3)Nz/integrity check exceeded the browse time budget)Úis_malformed_db_errorÚokz; :Né   N)r   r   rÊ   r   r   r   rº   rÅ   r   Úfetchallr   ÚDatabaseErrorr¯   r    Úhermes_state_errorsrã   r    ÚlowerÚjoin)	r   rÍ   r   r!   Úrowsr#   rã   ÚrÚproblemss	   &&       r
   Ú_integrity_problemrî     s9  € õ
 <Ø
‡L�L„NðÜ‘_ T§\¡\£^×%:Ñ%:Ó%<¸zÕ%IÈtÐcgØ-3×-@Ñ-@Ó-BôD÷ Eô EØHLØ�J‰J�tÔØ—<‘<Ð ;Ó<×EÑEÓGˆD÷Eð ‡L�L„NÙ#'ÓK¡4˜a«1”	´°Q°qµT³·±Ó1BÀdÑ1J”	”�A�a•D–	¡4€HÐKØ�9‰9�X˜b•\Ó"×*Ð* dÐ*÷E÷ Eûô × Ñ ô Ø�>�>ˆ>Ü&Ð'XÓYÐ_bÐbÝ=Ù  ×%Ò%Ü�s“8�OØûðüò LsZ   ˜AD5 Á&1D"ÂD5 Â3	FÃ"FÃ(FÄ"D2	Ä-D5 Ä2D5 Ä5FÅ
1FÅ<
FÆFÆFÆFc                ó$   € V ^8„  d   QhR\         /# r   r   )r	   s   "r
   r   r   '  s   € ÷ 	ñ 	œ4ñ 	r   c                ó&  € . pW P                  V P                  R,           4      3 F;  p VP                  4       pVP                  VP                  VP
                  34       K=  	  \        V4      #   \         d    TP                  R4        Ki  i ; i)zW(size, mtime_ns) of the main file and its WAL: any committed write changes one of them.z-walN)r/   r0   ÚstatÚappendÚst_sizeÚst_mtime_nsÚFileNotFoundErrorr~   )r   ÚoutÚpÚsts   &   r
   Ú_store_signaturerù   '  sx   € à
€CØ—N‘N 4§9¡9¨vÕ#5Ó6Ó7ˆð	Ø—‘“ˆBØ�J‰J˜Ÿ
™
 B§N¡NÐ3Ö4ñ 8ô �‹:Ðøô !ô 	Ø�J‰J�t×ð	ús   ª7A0Á0BÂBc                óD   € V ^8„  d   QhR\         R\        P                  /# ©r   r   rk   )r   Ú	threadingÚLock)r	   s   "r
   r   r   :  s   € ÷ =ñ =œ$ð =¤9§>¡>ñ =r   c                 óà   € \        V P                  4       4      p\        ;_uu_ 4        \        P	                  V\
        P                  ! 4       4      uuR R R 4       #   + '       g   i     R # ; irZ   )r    r   Ú_scan_guardÚ_scan_locksÚ
setdefaultrü   rý   )r   Úkeys   & r
   Ú_path_scan_lockr  :  s:   € Ü
ˆd�l‰l‹nÓ
€Cß	ŽÜ×%Ñ% c¬9¯>ª>Ó+;Ó<÷ 
��‹ús   ¨)AÁA-	c                   ó   € ] tR tRtRtRtR# )Ú_SiblingStillBusyi@  z[Another browse/maintenance holder kept gateway.lock past its own budget; carries the drift.r¡   Nr¢   r¡   r   r
   r  r  @  s   † Ýer   r  c                ó$   € V ^8„  d   QhR\         /# )r   rr   r   )r	   s   "r
   r   r   E  s   € ÷ ñ ”Tñ r   c           	   #  ó  "  € ^ RI Hp \        P                  ! 4       ;_uu_ 4       p VP	                  V! V .\
        R7      4       Rx € RRR4       R#   \         d   p\        RT R24      ThRp?ii ; i  + '       g   i     R# ; i5i)z¯``exclusive_maintenance`` for a browse. A lock this user cannot open at all (a root-run
gateway's, #42685) is not drift and not a crash: refuse by name with its recovery text.)Úexclusive_maintenance)ÚpurposezRSession store is behind this Hermes version, but its gateway.lock cannot be used (z); nothing was changed.N)r‡   r  rÖ   Ú	ExitStackÚenter_contextÚBROWSE_RECONCILE_PURPOSEr™   rR   )rr   r  Ústackr#   s   &   r
   Ú
_reservingr  D  s†   é € õ @Ü	×	Ò	×	Ô	 5ð	;Ø×ÑÑ 5°t°fÔF^Ô _Ô`ó
 	÷ 
 Ñ	øô ô 	;Ü'ðØ�5Ð/ð1ó2à7:ð;ûð	;ú÷ 
 ×	Ð	üs?   ‚$B¦A7¨AÁA7Á

BÁA4ÁA/Á/A4Á4A7Á7B	Â	Bc                ó0   € V ^8„  d   QhR\         R\         /# )r   rr   r   r   )r	   s   "r
   r   r   T  s   € ÷ 0ñ 0œ4ð 0¤tñ 0r   c              #  ó  "  € ^ RI p^ RIHpHp VP	                  4       \
        ,           R,           p\        P                  ! 4       ;_uu_ 4       p  VP                  \        V 4      4        \        T4      RJ x € RRR4       R#   T dj   p\        T4      p	T	f    Rp?K5  T! T 4      e
   T! T	4      ThTP	                  4       T8¼  d   \        T	4      ThTP                  \        4        Rp?K¡  Rp?ii ; i  + '       g   i     R# ; i5i)aº  Hold gateway.lock for the DDL. A sibling holder (another browse's flock probe or DDL, never a
gateway) is retried, bounded by its own budget, rather than waited on passively: a probe holds
the lock for no work and a sibling's DDL finishes inside BROWSE_RECONCILE_BUDGET_S. Yields True
when the store is already current (nothing to do). Raises ``owned(drift)`` when a gateway turns
out to own it, and :class:`_SiblingStillBusy` past the bound.N©ÚOwnershipConflictÚlive_runtime_ownerg      à?)r«   r‡   r  r  r¬   rÕ   rÖ   r
  r  r  r$   r  ÚsleepÚ_BROWSE_SIBLING_POLL_S)
rr   r   rS   r«   r  r  r®   r  r#   Úpendings
   &&&       r
   Ú_reserve_for_ddlr  S  sß   é € ó ßOØ�~‰~ÓÔ";Õ;¸cÕA€HÜ	×	Ò	×	Ô	 5Øð3Ø×#Ñ#¤J¨tÓ$4Ô5Øô " $Ó'¨4Ð/Ò/÷! 
 Ñ	øð
 %ô 3Ü-¨dÓ3�Ø’?ÝÙ% dÓ+Ò7Ù ›.¨cÐ1Ø—>‘>Ó# xÔ/Ü+¨GÓ4¸#Ð=Ø—
‘
Ô1×2Ò2ûð3ú÷ 
 ×	Ð	üsU   ‚ADÁC8ÁBÁ+C8Á;
DÂC5ÂC0ÂC8Â!A	C0Ã*C8Ã0C5Ã5C8Ã8D		Ä	Dc                ó$   € V ^8„  d   QhR\         /# r   r   )r	   s   "r
   r   r   p  s   € ÷ ñ ¤Dñ r   c                óª  € ^ RI HpHpHpHp V! V 4      V8X  d   \        V! V 4      ;'       g    R4      h\        V P                  4       4      p\        V 4      p\        P                  V4      V8X  d   V! 4       h \        V \        \        4      4      pT'       d   T! Y4       \        T4      hT#   \         d   p	T\        T&   T! 4       T	hRp	?	ii ; i)aÜ  The pre-lock phase of the browse catch-up: a full read-only integrity scan OUTSIDE gateway.lock
(it may be slow on a large store and must never block a gateway boot). Returns the file signature
the scan vouches for. Raises :class:`CorruptStoreError` for a damaged store (latched, so polls do
not rescan it) and ``too_slow()`` when the scan cannot finish in its budget (remembered for the
same signature, so a polling sidebar does not rescan a multi-GB file every few seconds).)ÚSTORAGE_CORRUPTÚmark_storage_corruptÚstorage_corrupt_reasonÚstorage_statezlatched corruptN)Úhermes_state_healthr  r  r  r  rÛ   r    r   rù   Ú_scan_too_slowrˆ   rî   r¤   ÚBROWSE_INTEGRITY_BUDGET_Sr    )
r   Útoo_slowr  r  r  r  r  Ú	signatureÚproblemr#   s
   &&        r
   Ú_verify_clean_before_lockr$  p  sÄ   € ÷ qÓpÙ�TÓ˜oÔ-ÜÑ 6°tÓ <× QÐ QÐ@QÓRÐRÜ
ˆd�l‰l‹nÓ
€CÜ  Ó&€IÜ×Ñ˜#Ó )Ô+Ù‹jÐð"Ü$ T¬7Ô3LÓ+MÓNˆ÷ ñ 	˜TÔ+Ü Ó(Ð(ØÐøô  ô "Ø'Œ�sÑÙ‹j˜cÐ!ûð"ús   Á;B1 Â1CÂ<CÃCc                ó0   € V ^8„  d   QhR\         R\        /# rû   ©r   rV   )r	   s   "r
   r   r   Š  s   € ÷ gñ g¤Tð g¬dñ gr   c                óF  aaaaa€ ^ RI HpHo \        V 4      oSf   R# ^ RIHp \        V! V P                  4       P                  4       R,           RV R7      4      ;_uu_ 4       p \        V4        RRR4       T P                  o\        S4      w  opRTT3R
 lloTTTTT3R lp \        S4      ;_uu_ 4         RRR4       \        T 4      ;p'       d
   S! ST4      h\!        T 4      ;_uu_ 4        \        T 4      f    RRR4       R# \#        Y4      p \%        ST S4      ;_uu_ 4       p	T	'       d    RRR4       RRR4       R# \'        \(        4      p
\        T 4      ;p'       d
   S! ST4      h\+        T 4      T8w  d   \        RS RS R24      hTT3R lpY P                  3 F?  p\,        P.                  ! T\,        P0                  4      '       d   K0  T! \3        T4      4      h	   \5        Y
4        RRR4       RRR4       \        T 4      ;p'       d   \        RS RT R24      h\@        PB                  ! \D        4      PG                  RT S4       R#   \         d   p\        RS R	24      ThRp?ii ; i  + '       g   i     EL; i  + '       g   i     ELà; i  T d   pS! S4      e
   S! S4      Th Rp?ELRp?ii ; i  \6        P8                   d7   pR\3        T4      P;                  4       9   d   T! \3        T 4      4      Thh Rp?i\         d   p\        RS RT R24      ThRp?ii ; i  + '       g   i     ELM; i  \<         d   pT! 4       ThRp?i\>         d   p\        RS RT R24      ThRp?ii ; i  + '       g   i     EL•; i)a¡  Catch a lagging store up for a read-only browse; True when DDL ran, False when already current.

Raises :class:`DeclarativeDriftError` (``owned=True`` when a running gateway owns the store)
with a user-facing detail naming the drift and the remedy, and :class:`CorruptStoreError`
when the lagging store is also damaged. Never touches a store missing its history tables:
recreating them empty would hide lost sessions.r  NFr   r   Tr   z-Session store is missing its history tables (z<); this is not upgrade drift. Run `hermes sessions recover`.c                 ó‚   <€ V'       d   R M
\        S4      pV'       d   RV R2MRp\        RS RV  RV RV R2	R	R
7      # )r€   z (rß   Ú úSession store for profile 'ú!' is behind this Hermes version (z ), and a running gateway owns itz;, so browsing will not write to it. Restart that gateway (`z!`) to bring the store up to date.Tr`   )r‹   rR   )ÚdriftÚholderÚrestartÚwhorr   r{   s   &&  €€r
   rS   Ú)reconcile_drift_for_browse.<locals>.owned¡  sd   ø€ ß.4Ñ*Ô:QÐRVÓ:Wˆß &��6�(˜!‰n¨BˆÜ$Ø)¨%¨Ð0QÐRWÐQXð Y&Ø&) Uð +Ø�	Ð:ð<àCGôIð 	Ir   c                  ót   <€ S! S 4      e	   S! S4      # \        RS RS R\        R R\        S 4       R2	4      # )Nr*  r+  z/) and is too large to verify and update within z.0fzds while browsing. Your history is untouched: nothing was changed and the list was not cleared. Run `z=` to bring it up to date (it has no time limit), then reload.)rR   rÕ   r|   )rr   r{   r  rS   r<   s   €€€€€r
   r!  Ú,reconcile_drift_for_browse.<locals>.too_slow©  sa   ø€ á˜dÓ#Ò/Ù˜“=Ð ô %Ø)¨%¨Ð0QÐRXÐQYð Z1Ü1JÈ3Ð0Oð Pä Ó%Ð&Ð&cðeófð 	fr   r*  z&' changed while browsing verified it (zD); nothing was changed. Retry in a moment; the list was not cleared.c           	      ó.   <€ \        R S RS RV  R24      # )r*  r+  z), but zˆ is not writable by this user, so browsing cannot add the missing tables/columns; nothing was changed. Fix the permissions, then reload.)rR   )Úwhyr{   r<   s   &€€r
   Únot_writableÚ0reconcile_drift_for_browse.<locals>.not_writableÐ  s9   ø€ Ü0Ø5°e°WÐ<]Ð^dÐ]eð fØ"˜eð $aðbócð cr   Úreadonlyz<' is behind this Hermes version and could not be caught up (zF); nothing was changed. Run `hermes sessions repair` for that profile.z9' is being brought up to date by another Hermes process (z/). Retry in a moment; the list was not cleared.z1). Run `hermes sessions repair` for that profile.zTstate.db at %s lagged SCHEMA_SQL (%s); added the missing tables/columns for browsingrZ   )$r‡   r  r  r$   r   r   r   r   r   r2   r1   rR   Úparentr�   r  rž   r  r$  r  r¤   rÕ   rù   ÚosÚaccessÚW_OKr    rØ   r   r   ré   r    r  r5   r6   r7   r8   )r   r  r   r!   r#   Ú_r!  r-  r"  ÚcurrentrÍ   r5  ÚtargetÚafterrr   r{   r  rS   r<   s   &             @@@@@r
   Úreconcile_drift_for_browser@  Š  s‘  ü€ ÷ Pä  Ó&€FØ‚~ÙÝ;Ü	‘ §¡£×!6Ñ!6Ó!8¸:Õ!EÈ4Ð_cÔd×	eÔ	eÐimð	;Ü# DÕ)÷ 
fð �;‰;€DÜ˜TÓ"�H€Eˆ1÷Ið I÷
fñ 
fð)Ü˜×ÕØ÷ ô
 *¨$Ó/Ð/€vÖ/Ù�F˜FÓ#Ð#Ü	˜×	Õ	Ü˜tÓ$Ò,Ø÷ 
Ñ	ô .¨dÓ=ˆ	ð'	[Ü! $¨¨e×4Ô4¸ßØ ÷ 5÷ 
Ñ	ô !Ô!:Ó;�Ü5°dÓ;Ð;�6Ö;Ù ¨Ó/Ð/Ü# DÓ)¨YÔ6ô 0Ø5°e°Wð =Ø"˜8Ð#gðiójð jöcð  $§[¡[Ó1�FÜŸ9š9 V¬R¯W©W×5Ô5Ù*¬3¨v«;Ó7Ð7ñ 2ð
-Ü*¨4Õ8÷/ 5÷ 
ôX $ DÓ)Ð)€uÖ)Ü#Ø)¨%¨ð 1Ø˜Ð QðSóTð 	Tô ×Ò”hÓ×'Ñ'Ø^Ð`dÐflônáøôo ô 	;Ü'Ø?À¸xð H1ð 1ó2à7:ð;ûð	;ú÷ 
f×	eÐ	eú÷B ×Ðûàô )Ù˜dÓ#Ò/Ù˜“- SÐ(õ 0ûð)ûôD ×/Ñ/ô Ø!¤S¨£X§^¡^Ó%5Ô5Ù*¬3¨t«9Ó5¸3Ð>ØûÜ,ô -Ü/Ø5°e°Wð =)Ø),¨ð .#ð#ó$ð *-ð-ûð-ú÷9 5×4Ð4ûôB $ô 	&Ù“* #Ð%ûÜ ô 	[Ü'Ø-¨e¨Wð 5Ø˜5Ð OðQóRàWZð[ûð	[ú÷Q 
×	Ð	ús	  Á$J Á&IÂ(J( Â;JÂ=J( Ã4NÄNÄMÄ.
L?	Ä8MÅ
BL?	ÇL?	Ç/KÇ;MÉI=É(I8É8I=É=J Ê J	ÊJ%	ÊJ( Ê%J( Ê(KÊ/KËKËL<Ë%1LÌL<Ì#L<Ì$L7Ì7L<Ì<L?	Ì?MÍ
MÍNÍMÍNÍM&Í&NÍ3NÍ4NÎNÎNÎN 	rM   Tc                ó0   € V ^8„  d   QhR\         R\        /# )r   r   rM   r&  )r	   s   "r
   r   r   ô  s   € ÷ ñ ¤Dð ´Tñ r   c          	     óÂ  € ^ RI HpHp ^ RIHp RRRRRRRR/p V! V P
                  .4      ;_uu_ 4        V! V 4      ;_uu_ 4       pV'       g   \        R	4      h\        WV4       RRR4       RRR4       V#   + '       g   i     L; i  + '       g   i     T# ; i  T\        \        P                  \        \        3 d   p\        T4      TR&    Rp?T# Rp?ii ; i)
zHReuse repair's snapshot/SQLite exclusion beneath the runtime owner lock.)r  r  )Ú_cross_process_repair_lockrH   FrI   NrJ   r;   z)could not obtain the state.db repair lock)r‡   r  r  r   rC  r8  r1   rP   r™   r   rš   ÚTimeoutErrorr    )r   rM   r  r  rC  rN   Úholdingr#   s   &$      r
   Úrepair_declarative_schemarF  ô  s·   € çRÝ>à˜% ¨T°=À$ÈÐQUÐV€Fð#Ù" D§K¡K =×1Õ1Ù+¨D×1Ô1°WßÜ&Ð'RÓSÐSÜ! $°Ô7÷ 2÷ 2ð €M÷ 2×1ú÷ 2Ö1ð €Mûð œw¬¯©´|Ä\ÐRô #Ü˜c›(ˆˆw�Ø€Mûð#úsL   šB µBÁ A8	Á&BÁ.B Á8BÂBÂB	ÂB ÂB Â&CÃCÃCc                óÀ   € V ^8„  d   Qh/ ^ \         9   d%   \        \        \        P                  3,          ;R&   ^\         9   d   \        \        \
        3,          ;R&   # )r   r   r  )Ú__conditional_annotations__Údictr    rü   rý   r~   )r	   s   "r
   r   r      sK   € ÷ ñ ÷f	 ,Ò +ŒT”#”y—~‘~Ð%Õ&Ñ +ñg	÷l	 &Ò %””Sœ%�ZÕ Ñ %òm	r   rZ   ).rH  re   rÖ   r5   r9  r   rü   r   Úpathlibr   r$   r=   r2   rP   rÕ   r   rÄ   r1   rR   ro   r|   r�   r‹   rž   r    r¤   rØ   r  r  rç   rÛ   rî   rù   rý   rÿ   r   r  r  r  Úcontextmanagerr  r  r$  r@  rF  r   )rH  s   @r
   Ú<module>rL     sD  øðöó Û Û 	Û Û Ý Ý õò"gò:vòNðZ  Ð Ø5Ð ØÐ ô˜Lô õPõ8õ8õ
"õô*g˜<ô g÷Zñ Z÷:%ðP 5Ð ØÐ ôZ˜×-Ñ-ô Zõ+õ0	ð �nŠnÓ€Ø)+€Ó +ð $&€Ó %õ=ôf˜ô fð ×Ñôó ðð ×Ñô0ó ð0õ8õ4gðT¸D÷ ñ r   