Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion hermes_cli/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,26 @@ def run_doctor(args):
# repaired in place with --fix).
from hermes_state import _db_opens_cleanly, repair_state_db_schema

_write_reason = _db_opens_cleanly(state_db_path)
# _db_opens_cleanly runs PRAGMA integrity_check which can take
# minutes on large databases (2000+ sessions). Wrap in a thread
# with a timeout so hermes doctor doesn't hang indefinitely.
# See: #72441
import concurrent.futures
_probe_timeout = 30.0 # seconds
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as _ex:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This context manager calls shutdown(wait=True) on exit. After result(timeout=...) raises, it still waits for _db_opens_cleanly() to finish, so the command remains blocked and the timeout warning is not observable at 30 seconds. Use a genuinely cancellable SQLite boundary and add an elapsed-time regression.

_fut = _ex.submit(_db_opens_cleanly, state_db_path)
try:
_write_reason = _fut.result(timeout=_probe_timeout)
except concurrent.futures.TimeoutError:
_write_reason = None
check_warn(
f"{_DHH}/state.db write-health probe timed out",
f"(>{_probe_timeout:.0f}s — database may be locked or very large)",
)
issues.append(
"state.db health probe timed out — close other Hermes "
"instances and retry, or run 'hermes sessions repair'"
)
if _write_reason is not None:
check_warn(
f"{_DHH}/state.db fails a write-health probe (FTS index may be corrupt)",
Expand Down
Loading