feat: hive open performance issue

This commit is contained in:
Richard Tang
2026-04-17 20:16:01 -07:00
parent 8c10fc2e1c
commit 651b57b928
3 changed files with 45 additions and 37 deletions
+8 -1
View File
@@ -21,6 +21,7 @@ import os
import shutil
import subprocess
import sys
import threading
from pathlib import Path
from typing import Any
from urllib import error as urlerror, parse as urlparse, request as urlrequest
@@ -214,7 +215,13 @@ def cmd_serve(args: argparse.Namespace) -> int:
def cmd_open(args: argparse.Namespace) -> int:
"""Start the HTTP server and open the dashboard in the browser."""
_ping_hive_gateway_availability("hive-open")
# Don't block local startup on a best-effort analytics probe.
threading.Thread(
target=_ping_hive_gateway_availability,
args=("hive-open",),
daemon=True,
name="hive-open-gateway-ping",
).start()
args.open = True
return cmd_serve(args)
+9 -36
View File
@@ -285,49 +285,22 @@ def create_app(model: str | None = None) -> web.Application:
except Exception as exc:
logger.warning("Could not auto-persist HIVE_CREDENTIAL_KEY: %s", exc)
credential_store = CredentialStore.with_aden_sync()
# Local server startup should not wait on an eager Aden sync.
# The store can still fetch/refresh credentials on demand.
credential_store = CredentialStore.with_aden_sync(auto_sync=False)
except Exception:
logger.debug("Encrypted credential store unavailable, using in-memory fallback")
credential_store = CredentialStore.for_testing({})
app["credential_store"] = credential_store
# Pre-load queen MCP tools once at startup (cached for all sessions)
# This avoids rebuilding the tool registry for every queen session
from framework.loader.mcp_registry import MCPRegistry
from framework.loader.tool_registry import ToolRegistry
_queen_tool_registry: ToolRegistry | None = None
try:
_queen_tool_registry = ToolRegistry()
import framework.agents.queen as _queen_pkg
queen_pkg_dir = Path(_queen_pkg.__file__).parent
mcp_config = queen_pkg_dir / "mcp_servers.json"
if mcp_config.exists():
_queen_tool_registry.load_mcp_config(mcp_config)
logger.info("Pre-loaded queen MCP tools from %s", mcp_config)
registry = MCPRegistry()
registry.initialize()
registry.ensure_defaults()
if (queen_pkg_dir / "mcp_registry.json").is_file():
_queen_tool_registry.set_mcp_registry_agent_path(queen_pkg_dir)
registry_configs, selection_max_tools = registry.load_agent_selection(queen_pkg_dir)
if registry_configs:
_queen_tool_registry.load_registry_servers(
registry_configs,
preserve_existing_tools=True,
log_collisions=True,
max_tools=selection_max_tools,
)
logger.info("Pre-loaded queen tool registry with %d tools", len(_queen_tool_registry.get_tools()))
except Exception as e:
logger.warning("Failed to pre-load queen tool registry: %s", e)
app["queen_tool_registry"] = _queen_tool_registry
# Let queen sessions build their registry lazily on first use instead of
# paying the MCP discovery cost during `hive open`.
app["queen_tool_registry"] = None
app["manager"] = SessionManager(
model=model, credential_store=credential_store, queen_tool_registry=_queen_tool_registry
model=model,
credential_store=credential_store,
queen_tool_registry=None,
)
# Register shutdown hook
+28
View File
@@ -1,5 +1,6 @@
"""Tests for frontend build fallback in the runner CLI."""
import argparse
import subprocess
from framework.loader import cli as runner_cli
@@ -58,3 +59,30 @@ def test_build_frontend_cleans_cache_and_uses_windows_npm_cmd(monkeypatch, tmp_p
["npm.cmd", "install", "--no-fund", "--no-audit"],
["npm.cmd", "run", "build"],
]
def test_cmd_open_starts_gateway_ping_in_background(monkeypatch):
args = argparse.Namespace(open=False)
calls: list[tuple[str, object]] = []
class FakeThread:
def __init__(self, *, target, args, daemon, name):
calls.append(("init", target, args, daemon, name))
self._target = target
self._args = args
def start(self):
calls.append(("start", self._target, self._args))
monkeypatch.setattr(runner_cli.threading, "Thread", FakeThread)
monkeypatch.setattr(runner_cli, "_ping_hive_gateway_availability", lambda source: None)
monkeypatch.setattr(runner_cli, "cmd_serve", lambda incoming: 123)
result = runner_cli.cmd_open(args)
assert result == 123
assert args.open is True
assert calls == [
("init", runner_cli._ping_hive_gateway_availability, ("hive-open",), True, "hive-open-gateway-ping"),
("start", runner_cli._ping_hive_gateway_availability, ("hive-open",)),
]