Skip to content

The agent that grows with you

perf(gateway): parse readiness and bundled-manifest YAML with the C loader

kshitijk4poor157283618493
diff --git a/gateway/config.py b/gateway/config.py
index 0ff264aaf87..e484102a9a1 100644
--- a/gateway/config.py
+++ b/gateway/config.py
@@ -19,7 +19,7 @@ from gateway.shutdown_watchdog import (
DEFAULT_LOOP_WATCHDOG_MAX_STRIKES,
DEFAULT_LOOP_WATCHDOG_TIMEOUT_S,
)
-from utils import is_truthy_value
+from utils import fast_safe_load, is_truthy_value
logger = logging.getLogger(__name__)
@@ -177,12 +177,11 @@ _Platform__bundled_plugin_aliases: Optional[dict] = None # manifest ``name:`` (
def _bundled_platform_manifest_name(plugin_dir: Path) -> Optional[str]:
"""Lowercased ``name:`` from a bundled platform's plugin manifest (None when absent/unreadable)."""
try:
- import yaml
manifest_file = next(
(plugin_dir / m for m in ("plugin.yaml", "plugin.yml") if (plugin_dir / m).exists()), None)
if manifest_file is None:
return None
- data = yaml.safe_load(manifest_file.read_text(encoding="utf-8")) or {}
+ data = fast_safe_load(manifest_file.read_text(encoding="utf-8")) or {}
name = data.get("name") if isinstance(data, dict) else None
return str(name).strip().lower() or None
except Exception:
diff --git a/gateway/readiness.py b/gateway/readiness.py
index 0507b8a743b..3de2f60eb49 100644
--- a/gateway/readiness.py
+++ b/gateway/readiness.py
@@ -8,9 +8,8 @@ from contextlib import closing
from pathlib import Path
from typing import Any
-import yaml
-
from hermes_constants import get_hermes_home
+from utils import load_yaml_file_readonly
_DISK_DEGRADED_PERCENT = 90.0
@@ -55,7 +54,7 @@ def _probe_config(home: Path) -> dict[str, Any]:
if not path.exists():
return _check("ok", "using defaults")
try:
- raw = yaml.safe_load(path.read_text(encoding="utf-8"))
+ raw = load_yaml_file_readonly(path)
except Exception as exc:
return _check("degraded", f"invalid config ({type(exc).__name__})")
return _check("ok") if raw is None or isinstance(raw, dict) else _check("degraded", "top level is not a mapping")
diff --git a/hermes_cli/managed_scope.py b/hermes_cli/managed_scope.py
index 8f9b0804ece..0cf20e33bed 100644
--- a/hermes_cli/managed_scope.py
+++ b/hermes_cli/managed_scope.py
@@ -23,7 +23,7 @@ from hermes_cli.stale_modules import drop_stale_root_modules
drop_stale_root_modules()
-from utils import file_signature
+from utils import fast_safe_load, file_signature
logger = logging.getLogger(__name__)
@@ -106,7 +106,6 @@ def _load_managed_file(name: str, cache: Dict[str, tuple], parse) -> dict:
def load_managed_config() -> dict:
"""Parsed managed config.yaml, or {} when absent/malformed (fail-open)."""
- from utils import fast_safe_load
return _load_managed_file("config.yaml", _CONFIG_CACHE, lambda p: fast_safe_load(p.read_text(encoding="utf-8")) or {})