fix(cli): open the session store through the state.db registry, not a bare SessionDB()
The classic CLI froze for ~0.7-2s between the banner and the first prompt. py-spy + strace on real PTY startups showed the main/REPL threads inside refuse_deleted_wal_generation -> _iter_proc_fd_targets: a second full SessionDB open. _init_session_store built a bare SessionDB(); a moment later the goal/loop/heartbeat managers acquired the same state.db through hermes_state_registry from the REPL thread, which is a different handle, so the whole open ran again — including the /proc-wide deleted-WAL sidecar scan (~4.4k readlinks). Each readlink drops and re-takes the GIL while the startup threads (plugin discovery, MCP, skill sync, banner git) are busy, so an 11ms scan stretched to 1.3s per pass, and the second pass landed exactly where the prompt should have appeared. Route the CLI's handle (init + the two re-open sites) through the registry so every in-process consumer shares one writer. One scan per startup; live A/B on the same box, interleaved x6: banner->prompt gap 0.37s mean -> 0.15s mean (plain), 1.77s -> 0.39s under strace. The registry release path replaces close(), so /quit, /snapshot restore and /handoff keep their semantics.
This commit is contained in:
8
cli.py
8
cli.py
@@ -2835,8 +2835,12 @@ class HermesCLI(CLIProcessNotificationsMixin, CLIAgentSetupMixin, CLICommandsMix
|
||||
self._session_db = None
|
||||
self._session_db_unavailable = False
|
||||
try:
|
||||
from hermes_state import SessionDB
|
||||
self._session_db = SessionDB()
|
||||
# Registry handle, not a bare SessionDB(): goals/loops/heartbeat acquire the same
|
||||
# path a moment later from the REPL thread, and a second writer repeats the full
|
||||
# open (the /proc-wide deleted-WAL scan, ~4k readlinks) while the render thread
|
||||
# holds the GIL — that repeat was the post-banner freeze before the first prompt.
|
||||
from hermes_state_registry import acquire
|
||||
self._session_db = acquire()
|
||||
except Exception as e:
|
||||
# Without a store the transcript is NOT persisted while the chat looks healthy,
|
||||
# so surface it prominently rather than only logging.
|
||||
|
||||
Reference in New Issue
Block a user