Skip to content

fix(dashboard): offload PTY spawn/close off the event loop - #53227

Merged
teknium1 merged 2 commits into
NousResearch:mainfrom
IAvecilla:fix-chat-dashboard-block
Jun 26, 2026
Merged

fix(dashboard): offload PTY spawn/close off the event loop#53227
teknium1 merged 2 commits into
NousResearch:mainfrom
IAvecilla:fix-chat-dashboard-block

Conversation

@IAvecilla

Copy link
Copy Markdown
Contributor

What does this PR do?

The in-dashboard chat tab could make the entire dashboard slow and intermittently unreachable, other tabs would hang and the instance would flip to "reconnecting."

Root cause: the /api/pty WebSocket handler (pty_ws) did two blocking operations directly on the single asyncio/uvicorn event loop:

  • PtyBridge.spawn(...) — forks + execs a full TUI child process (blocking) on every connect.
  • bridge.close() — escalates SIGHUP → SIGTERM → SIGKILL with up to ~1.5 s of blocking waits on every teardown.

Because the dashboard runs a single worker, each of these froze every other request, including the public /api/status liveness probe, for their duration. This was amplified by the PTY auto-reconnect added in #52962: a dropped chat socket now respawns the child, so on a resource-tight machine the connect/teardown cycle (and therefore the event-loop stalls) repeats, dragging the whole dashboard down.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • hermes_cli/web_server.py (pty_ws): wrap PtyBridge.spawn(argv, cwd=cwd, env=env) in await asyncio.to_thread(...) so the fork+exec no longer blocks the event loop on connect.
  • hermes_cli/web_server.py (pty_ws finally): wrap bridge.close() in await asyncio.to_thread(...) so the SIGHUP→SIGTERM→SIGKILL teardown (up to ~1.5 s) no longer blocks the event loop on disconnect.

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix.
  • I've run the dashboard/PTY test suites and they pass.
  • I've added tests for my changes
  • I've tested on my platform: macOS 15 (build/local)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — N/A (no public surface change; added explanatory comments inline)
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A
  • I've considered cross-platform impact (Windows, macOS) — asyncio.to_thread is stdlib/cross-platform; no platform-specific behavior changed
  • I've updated tool descriptions/schemas if I changed tool behavior — N/A

@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 P3 Low — cosmetic, nice to have labels Jun 26, 2026
@teknium1
teknium1 merged commit f509f6e into NousResearch:main Jun 26, 2026
27 checks passed
pai-scaffolde pushed a commit to pai-scaffolde/hermes-agent that referenced this pull request Jun 28, 2026
…arch#53227)

* Fix blocking tasks on the dashboard

* Remove unnecessary comments
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…arch#53227)

* Fix blocking tasks on the dashboard

* Remove unnecessary comments
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…arch#53227)

* Fix blocking tasks on the dashboard

* Remove unnecessary comments
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…arch#53227)

* Fix blocking tasks on the dashboard

* Remove unnecessary comments
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…arch#53227)

* Fix blocking tasks on the dashboard

* Remove unnecessary comments
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Aug 2, 2026
- homeassistant_tool: _async_get_state (single entity), _async_call_service
- dashboard_auth routes: api_auth_me (session JSON), login_page (next
  same-origin validation)
- mcp_oauth: set_client_info (cold-start refresh persistence)
- run: _prepare_profile_scoped_inbound_message_text (multiplex scope),
  _echo_pending_stt_transcripts_once (🎙️ once-flag),
  _send_goal_status_notice, _handle_reaction_event (hook fan-out),
  _finish_startup_restore (gather + drain)
- yuanbao: dispatch_msg_body (lock + group:/direct: routing)
- weixin: _maybe_fetch_typing_ticket (getConfig cache),
  _download_voice (.silk 60s), _download_image (aeskey hex→b64),
  _download_remote_media (SSRF gate + wait_for)
- signal: remove_reaction (empty emoji + remove=True)
- qqbot: _heartbeat_loop (op 1 @ 80% hello interval)
- pty_session: attach_or_spawn (reuse/spawn off-loop NousResearch#53227)
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…arch#53227)

* Fix blocking tasks on the dashboard

* Remove unnecessary comments
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) P3 Low — cosmetic, nice to have type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants