Skip to content

perf(dashboard): keep session-DB, cron, PID-probe and log-tail I/O off the event loop (salvage #58238/#45491/#53511/#58389/#39140/#53966) - #60884

Closed
kshitijk4poor wants to merge 0 commit into
NousResearch:mainfrom
kshitijk4poor:salvage/web-server-event-loop
Closed

perf(dashboard): keep session-DB, cron, PID-probe and log-tail I/O off the event loop (salvage #58238/#45491/#53511/#58389/#39140/#53966)#60884
kshitijk4poor wants to merge 0 commit into
NousResearch:mainfrom
kshitijk4poor:salvage/web-server-event-loop

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Six event-loop / hot-path fixes for the dashboard backend, salvaged from five contributor PRs onto current main with authorship preserved via cherry-pick — the uvicorn event loop stops paying for session-DB reads, cron profile scans, gateway PID lock probes, and unbounded log-tail reads.

Follow-up commits (mine):

  • Cycle guard on the descendant CTE: UNION ALL recurses forever on a corrupted parent chain (a→b→a) — reproduced live, query never returns. The old Python walk was cycle-safe via a seen-set. Switched to UNION (dedups the working set, terminates); regression test added and mutation-verified (UNION ALL hangs the test).
  • Fresh-install guard for the read-only status probe: SessionDB(read_only=True)'s documented contract requires the DB file to exist; on a fresh install every /api/status poll paid an OperationalError. Short-circuit to 0 when state.db is absent, with tests.
  • AUTHOR_MAP entries for the plain-email contributors (+ bare-noreply mapping for sebastianlutycz).

Notes for reviewers:

  • The 1s None-result caching in get_running_pid_cached is safe for gateway-start detection: cache hits require both TTL freshness AND an unchanged file signature (pid/lock/runtime-status mtime_ns+size), so a gateway writing its pid file invalidates immediately. One legacy direct gateway.pid unlink in gateway/run.py --replace bypasses the in-process cache clear but is caught by the signature check.
  • _run_cron_dashboard_io uses run_in_threadpool while two sibling helpers use run_in_executor — consolidation to one offload idiom is a reasonable follow-up sweep, not done here to keep contributor commits intact.

Validation

Check Result
tests/hermes_cli/test_web_server.py + cron_profiles + gateway/test_status.py 476 passed
E2E (real imports, temp HERMES_HOME) 5MB log tail: 1ms bounded read, byte-exact vs naive; PID probe: 1 underlying call for 2 cached reads; active count via read-only DB; CTE resolves root->c1->c2
Cycle repro a->b->a chain: UNION ALL never returns (confirmed twice); UNION returns instantly
ruff / ty vs merge-base clean / 0 net-new (starlette import resolves in the real venv)

@alt-glitch alt-glitch added type/perf Performance improvement or optimization comp/dashboard Web dashboard / control panel UI (dashboard/, landing) comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P3 Low — cosmetic, nice to have labels Jul 8, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Comment (token read-only - high surface area)

PR 60884 moves session-DB, cron, PID-probe and log-tail I/O off the event loop in the dashboard. Substantial performance refactor (7 files, 537 additions, 60 deletions). References multiple prior issues (#58238, #45491, #53511, #58389, #39140, #53966).

Well-scoped performance fix. LGTM - awaiting maintainer approval.

@kshitijk4poor
kshitijk4poor force-pushed the salvage/web-server-event-loop branch from 3aaac17 to c95cf31 Compare July 8, 2026 19:54
kshitijk4poor added a commit to kshitijk4poor/hermes-agent that referenced this pull request Jul 8, 2026
Rebase reconciliation with NousResearch#60884: _count_status_active_sessions (from
NousResearch#58238) now passes compact_rows=True (this branch's NousResearch#47437 projection),
so the fake asserts both.
kshitijk4poor added a commit that referenced this pull request Jul 8, 2026
Rebase reconciliation with #60884: _count_status_active_sessions (from
#58238) now passes compact_rows=True (this branch's #47437 projection),
so the fake asserts both.
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
Rebase reconciliation with NousResearch#60884: _count_status_active_sessions (from
NousResearch#58238) now passes compact_rows=True (this branch's NousResearch#47437 projection),
so the fake asserts both.
justemu pushed a commit to justemu/hermes-agent that referenced this pull request Jul 18, 2026
Rebase reconciliation with NousResearch#60884: _count_status_active_sessions (from
NousResearch#58238) now passes compact_rows=True (this branch's NousResearch#47437 projection),
so the fake asserts both.
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
Rebase reconciliation with NousResearch#60884: _count_status_active_sessions (from
NousResearch#58238) now passes compact_rows=True (this branch's NousResearch#47437 projection),
so the fake asserts both.
@kshitijk4poor
kshitijk4poor deleted the salvage/web-server-event-loop branch August 5, 2026 07:09
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
Rebase reconciliation with NousResearch#60884: _count_status_active_sessions (from
NousResearch#58238) now passes compact_rows=True (this branch's NousResearch#47437 projection),
so the fake asserts both.
randlee pushed a commit to randlee/hermes-agent that referenced this pull request Aug 11, 2026
Rebase reconciliation with NousResearch#60884: _count_status_active_sessions (from
NousResearch#58238) now passes compact_rows=True (this branch's NousResearch#47437 projection),
so the fake asserts both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/dashboard Web dashboard / control panel UI (dashboard/, landing) comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants