+
    jHàj F  ã                  óV   € R t ^ RIHt ^ RIt]P                  ! R4      t ! R R4      tR# )z@Writable runner initialization, separate from process ownership.)ÚannotationsNzgateway.runc                  ó^   € ] tR t^tR R ltR R ltR R ltR R ltR	 R
 ltR R lt	Rt
R# )ÚGatewayRuntimeInitMixinc               ó   € V ^8„  d   QhRR/# ©é   ÚreturnÚNone© )Úformats   "Ú=/home/ubuntu/.hermes/hermes-agent/gateway/run_runtime_init.pyÚ__annotate__Ú$GatewayRuntimeInitMixin.__annotate__	   s   € ÷ ;ñ ;¨ñ ;ó    c                ó  € ^ RI HpHpHp V P	                  4       V n        V P                  4       V n        V P                  4       V n	        V P                  4       V n        V P                  4       V n        V P                  4       V n        / V n        / V n        V P%                  V! 4       4      V n        / V n        V P+                  V! 4       4      V n        / V n        V P1                  4       V n        RV n        V P7                  V P2                  4      V n        V P;                  4       V n        V P?                  4       V n         V PC                  4       V n"        V PG                  4       V n$        V PK                  4       V n&        R# )zSLoad ephemeral per-call config (prefill, reasoning, busy modes, timeouts, routing).)ÚDictÚOptionalÚ_load_gateway_configFN)'Úgateway.runr   r   r   Ú_load_prefill_messagesÚ_prefill_messagesÚ_load_reasoning_configÚ_reasoning_configÚ_load_service_tierÚ_service_tierÚ_load_show_reasoningÚ_show_reasoningÚ_load_busy_input_modeÚ_busy_input_modeÚ_load_busy_text_modeÚ_busy_text_modeÚ_busy_input_modes_by_profileÚ_busy_text_modes_by_profileÚ_busy_text_timing_from_configÚ_busy_text_timingÚ_busy_text_timing_by_profileÚ_human_delay_from_configÚ_human_delayÚ_human_delay_by_profileÚ_load_restart_drain_timeoutÚ_restart_drain_timeoutÚ_stop_requested_by_signalÚ_load_launchd_exit_timeoutÚ_launchd_exit_timeout_sÚ _load_restart_after_turn_timeoutÚ_restart_after_turn_timeoutÚ_load_cron_drain_timeoutÚ_cron_drain_timeoutÚ$_load_signal_interrupt_grace_timeoutÚ_signal_interrupt_grace_timeoutÚ_load_provider_routingÚ_provider_routingÚ_load_fallback_modelÚ_fallback_model)Úselfr   r   r   s   &   r   Ú_init_runtime_settingsÚ.GatewayRuntimeInitMixin._init_runtime_settings	   sE  € çFÑFØ!%×!<Ñ!<Ó!>ˆÔØ!%×!<Ñ!<Ó!>ˆÔØ!×4Ñ4Ó6ˆÔØ#×8Ñ8Ó:ˆÔØ $× :Ñ :Ó <ˆÔØ#×8Ñ8Ó:ˆÔà<>ˆÔ)Ø;=ˆÔ(Ø!%×!CÑ!CÑDXÓDZÓ![ˆÔØLNˆÔ)Ø ×9Ñ9Ñ:NÓ:PÓQˆÔØMOˆÔ$Ø&*×&FÑ&FÓ&HˆÔ#ð */ˆÔ&Ø'+×'FÑ'FÀt×GbÑGbÓ'cˆÔ$Ø+/×+PÑ+PÓ+RˆÔ(Ø#'×#@Ñ#@Ó#BˆÔ Ø/3×/XÑ/XÓ/ZˆÔ,Ø!%×!<Ñ!<Ó!>ˆÔØ#×8Ñ8Ó:ˆÖr   c               ó   € V ^8„  d   QhRR/# r   r
   )r   s   "r   r   r   %   s   € ÷ 
;ñ 
; Tñ 
;r   c                óè   a€ ^ RI HpHpHp ^ RIHo V! V P                  P                  V P                  V3R lR7      V n        V! V P                  4      V n	        V! V P                  4      V n
        R# )z\Build the SessionStore (with process-registry reset guard), its async facade and the router.)ÚAsyncSessionStoreÚDeliveryRouterÚSessionStore)Úprocess_registryc                ó&   <€ SP                  V 4      # ©N)Úhas_active_for_session)Úkeyr@   s   &€r   Ú<lambda>Ú=GatewayRuntimeInitMixin._init_session_store.<locals>.<lambda>+   s   ø€ Ð0@×0WÑ0WØô1r   )Úhas_active_processes_fnN)r   r=   r>   r?   Útools.process_registryr@   ÚconfigÚsessions_dirÚsession_storeÚ_async_session_storeÚdelivery_router)r8   r=   r>   r?   r@   s   &   @r   Ú_init_session_storeÚ+GatewayRuntimeInitMixin._init_session_store%   sW   ø€ çQÑQÝ;Ù)Ø�K‰K×$Ñ$ d§k¡kô%ôˆÔñ
 %6°d×6HÑ6HÓ$IˆÔ!Ù-¨d¯k©kÓ:ˆÖr   c               ó   € V ^8„  d   QhRR/# r   r
   )r   s   "r   r   r   1   s   € ÷ T?ñ T? tñ T?r   c                óf  € ^ RI HpHpHpHpHpHpHpHpH	p	H
p
HpHpHp R;V n        ;V n        ;V n        V n        RV n        V
P'                  4       V n        RV n        RV n        / V n        RV n        RV n        R;V n        ;V n        V n        R;V n        ;V n        V n        RV n         VP                  4       V n!        RV n"        RV n#        RV n$        VPK                  4       V n&        RV n'        RV n(        RV n)        / V n*        V	! 4       V n+        / V n,        / V n-        RV n.        . V n/        . V n0        RV n1        V! 4       V n2        RV n3        VPK                  4       V n4        \k        4       V n6        V! 4       V n7        RV n8        / V n9        / V n:        \k        4       V n;        RV n<        RV n=        R# )zZInitialise run/exit/restart flags, per-session state, and completion-delivery bookkeeping.)r   ÚListÚMessageEventr   ÚOrderedDictÚPlatformÚSessionSourceÚSessionStateÚSessionTurnLeaseRegistryÚasyncioÚ
concurrentÚ	threadingÚtimeFNi   i   gš™™™™™¹?)>r   r   rR   rS   r   rT   rU   rV   rW   rX   rY   rZ   r[   r\   Ú_runningÚ_exit_cleanlyÚ_exit_with_failureÚ	_drainingÚ_gateway_loopÚEventÚ_shutdown_eventÚ_exit_reasonÚ
_exit_codeÚ_profile_failed_platformsÚ_systemd_watchdogÚ_external_drain_activeÚ_restart_requestedÚ_signal_initiated_shutdownÚ_restart_task_startedÚ_restart_detachedÚ_restart_via_serviceÚ _detached_restart_helper_startedÚ_restart_command_sourceÚ_startup_timeÚ_booted_from_restartÚ
_stop_taskÚ_restart_taskÚLockÚ_executor_lockÚ	_executorÚ_housekeeping_executorÚ_executor_closingÚ	_sessionsÚ_turn_leasesÚ_session_stall_notifiedÚ_transcript_lag_streaksÚ_startup_restore_in_progressÚ_startup_restore_queueÚ_startup_restore_tasksÚ _platform_lock_takeover_on_startÚ_session_sourcesÚ_session_sources_maxÚ_completion_delivery_lockÚsetÚ_completion_deliveries_inflightÚ _completion_deliveries_deliveredÚ_completion_delivery_retentionÚ _completion_notification_batchesÚ$_completion_notification_batch_tasksÚ*_completion_notification_batch_flush_tasksÚ%_completion_notification_batch_windowÚ)_completion_notification_batches_stopping)r8   r   rR   rS   r   rT   rU   rV   rW   rX   rY   rZ   r[   r\   s   &             r   Ú_init_lifecycle_stateÚ-GatewayRuntimeInitMixin._init_lifecycle_state1   s¾  € ÷ 	y÷  	y÷  	yõ  	yØX]Ð]ˆŒÐ]˜Ô*Ð]¨TÔ-DÀtÄ~ØBFˆÔØ&Ÿ}™}›ˆÔØ+/ˆÔØ)-ˆŒØRTˆÔ&Ø!%ˆÔð ',ˆÔ#ð bgÐfˆÔÐf $Ô"AÀDÔD^ØejÐjˆÔÐj Ô!:¸TÔ=bØ@DˆÔ$à$(§I¡I£KˆÔð +0ˆÔ!Ø26ˆŒØ59ˆÔØ'Ÿn™nÓ.ˆÔØJNˆŒàW[ˆÔ#à!&ˆÔà24ˆŒñ 5Ó6ˆÔð( 9;ˆÔ$ð 8:ˆÔ$ð -2ˆÔ)Ø:<ˆÔ#Ø:<ˆÔ#ð 16ˆÔ-ñ BMÃˆÔØ$'ˆÔ!ð *3¯©Ó)9ˆÔ&ÜMPËUˆÔ,Ù\gÓ\iˆÔ-Ø.2ˆÔ+ð prˆÔ-ØY[ˆÔ1ÜMPËUˆÔ7Ø58ˆÔ2Ø9>ˆÖ6r   c               ó   € V ^8„  d   QhRR/# r   r
   )r   s   "r   r   r   ‡   s   € ÷ 9ñ 9 dñ 9r   c                ó\  € ^ RI HpHpHpHpHpHp V! 4       V n        VP                  4       V n	        V P                  4       pWpn        \        V P                  RR4      '       d   RMTV n        RV n        RV n        / V n        \%        4       V n        ^ RIpVP+                  ^4      V n        R# )z^Agent cache, profile identity, Teams runtime, failed-platform tracking, slash-confirm counter.)ÚAnyr   r   rT   rU   r[   Úmultiplex_profilesFÚdefaultN)r   r‘   r   r   rT   rU   r[   Ú_agent_cachert   Ú_agent_cache_lockÚ_active_profile_nameÚ_kanban_notifier_profileÚgetattrrI   Ú_primary_profile_nameÚ_teams_pipeline_runtimeÚ_teams_pipeline_runtime_errorÚ_failed_platformsr„   Ú_fatal_handler_tasksÚ	itertoolsÚcountÚ_slash_confirm_counter)	r8   r‘   r   r   rT   rU   r[   Úlaunchrž   s	   &        r   Ú_init_runtime_cachesÚ,GatewayRuntimeInitMixin._init_runtime_caches‡   s•   € çW×Wñ 6A³]ˆÔØ!*§¡Ó!1ˆÔð
 ×*Ñ*Ó,ˆØ(.Ô%ä  §¡Ð.BÀE×JÒJ‰IÐPVð 	Ô"ð (,ˆÔ$Ø<@ˆÔ*àACˆÔä),«ˆÔ!ó 	Ø&/§o¡o°aÓ&8ˆÖ#r   c               ó   € V ^8„  d   QhRR/# r   r
   )r   s   "r   r   r   £   s   € ÷ &\ñ &\ $ñ &\r   c                óÄ  a a
aa€ ^ RI HpHpHpHpHpHoHpHp VS n	        / S n
        VP                  4       S n        ^ RIHp V! S P                  S P                  R7      S n         S P!                  RR7       ^ R	IHo
 V! S P0                  4      oV! R
V
VVV 3R l4       R#   \"         d3   p	\$        P'                  RT	RR7       \)        T	4      S n         Rp	?	LbRp	?	ii ; i)zaOpen the session DB for the active scope and run opportunistic state.db / checkpoint maintenance.)r‘   r   ÚPathÚ_SESSION_DB_UNPINNEDÚ_housekeeping_choreÚ"_housekeeping_state_db_maintenanceÚ_launch_sessions_dirr[   )ÚRecoverableHandleCache)ÚhandlesÚlockT)Úraise_on_errorz&SQLite session store not available: %s)Úexc_infoN)Ú_for_each_served_profilezstate.db startup maintenancec                 ó    <€ S ! SVV3R  l4      # )c                ó   <€ S! S4      # rB   r
   )Ú_labelr©   Ú_launch_sessionss   &€€r   rE   ÚLGatewayRuntimeInitMixin._init_session_db.<locals>.<lambda>.<locals>.<lambda>É   s   ø€ Ñ%GÐHXÔ%Yr   r
   )r°   r©   r´   r8   s   €€€€r   rE   Ú:GatewayRuntimeInitMixin._init_session_db.<locals>.<lambda>È   s   ø€ Ñ,ØÕYô[r   )r   r‘   r   r¦   r§   r¨   r©   rª   r[   Ú_session_db_pinnedÚ_session_db_handlesrt   Ú_session_db_handles_lockÚgateway.session_db_recoveryr«   Ú_session_db_handle_cacheÚ!_open_session_db_for_active_scopeÚ	ExceptionÚloggerÚwarningÚstrÚ_session_db_init_errorÚgateway.run_profile_reconciler°   rI   )r8   r‘   r   r¦   r§   r¨   rª   r[   r«   Úer°   r©   r´   s   f         @@@r   Ú_init_session_dbÚ(GatewayRuntimeInitMixin._init_session_db£   sÊ   û€ ÷ 	b÷  	bó  	bð (<ˆÔØ46ˆÔ Ø(1¯©Ó(8ˆÔ%ÝFÙ(>Ø×,Ñ,°4×3PÑ3Pô)RˆÔ%ð	1Ø×2Ñ2À$Ð2ÔGõ" 	KÙ/°·±Ó<ÐÙØ*÷[ö	\øô% ô 	1ä�N‰NÐCÀQÐQUˆNÔVÜ*-¨a«&ˆD×'Ñ'ûð	1ús   Á&B" Â"CÂ-(CÃCc               ó   € V ^8„  d   QhRR/# r   r
   )r   s   "r   r   r   Ï   s   € ÷ Añ A¨Tñ Ar   c                óv  € ^ RI HpHpHpHpHp ^ RIHp ^ RIH	p V! 4       V n
        / V n        V! 4       V n        V P                  4       V n        / V n        \!        4       V n        VP                  4       V n        RV n        R;V n        V n        VP                  4       V n        RV n        RV n        RV n        R# )zZPairing stores, hook registry, voice modes, background-task set, liveness and idle clocks.)r   rR   r   rY   r\   )ÚPairingStore)ÚProfileHookRegistriesNg        F)r   r   rR   r   rY   r\   Úgateway.pairingrÈ   Úgateway.hooksrÉ   Úpairing_storeÚpairing_storesÚhooksÚ_load_voice_modesÚ_voice_modeÚ_recent_voice_transcriptsr„   Ú_background_tasksÚ_gateway_started_atÚ_loop_heartbeat_taskÚ_loop_floor_timer_handleÚ_loop_liveness_watchdogÚ_last_inbound_atÚ_scale_to_zero_cooldown_untilÚ _scale_to_zero_no_suspend_loggedÚ%_scale_to_zero_direct_platform_logged)r8   r   rR   r   rY   r\   rÈ   rÉ   s   &       r   Ú_init_registries_and_clocksÚ3GatewayRuntimeInitMixin._init_registries_and_clocksÏ   s¡   € çEÕEõ 	1Ý7Ù)›^ˆÔØ79ˆÔá*Ó,ˆŒ
à+/×+AÑ+AÓ+CˆÔàOQˆÔ&ä&)£eˆÔð +/¯)©)«+ˆÔ Ø<@ˆÔ!ØGKÐKˆÔ%¨Ô(Dð (,§y¡y£{ˆÔð 58ˆÔ*Ø6;ˆÔ-Ø;@ˆÖ2r   )`r”   r•   rL   rÒ   rq   r   r!   r    r"   r$   r%   r†   r…   rƒ   r‡   rŠ   r‰   r‹   rˆ   rŒ   r1   rn   r`   rv   rx   ru   r^   re   rd   r_   rh   rœ   r7   r�   ra   rÓ   rw   r'   r(   r—   r×   r-   rÕ   rÔ   rÖ   r€   r   r™   rf   r5   r   rÑ   r/   ro   rl   r*   ri   rs   rk   rm   r]   rØ   rÚ   rÙ   r   r»   r¸   r¹   rÁ   r·   r�   r‚   r{   ry   r   rc   rj   r3   r    r}   r~   r   rp   r+   rr   rg   rš   r›   r|   rz   rÐ   rM   rÎ   rÌ   rÍ   rK   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r9   rN   r�   r¢   rÄ   rÛ   Ú__static_attributes__r
   r   r   r   r      s+   † õ;õ8
;õT?õl9õ8&\÷XAñ Ar   r   )Ú__doc__Ú
__future__r   ÚloggingÚ	getLoggerr¾   r   r
   r   r   Ú<module>ræ      s,   ðÙ FÝ "ã à	×	Ò	˜=Ó	)€÷eAó eAr   