Skip to content

The agent that grows with you

refactor(gateway): promote parse_systemd_duration_to_us to public

Kshitij Kapoora18f90847b46
diff --git a/gateway/shutdown_forensics.py b/gateway/shutdown_forensics.py
index 34836cc6fb1..f93cdc4e584 100644
--- a/gateway/shutdown_forensics.py
+++ b/gateway/shutdown_forensics.py
@@ -382,7 +382,7 @@ def check_systemd_timing_alignment(drain_timeout: float) -> Optional[Dict[str, A
if value.isdigit():
timeout_us = int(value)
else:
- timeout_us = _parse_systemd_duration_to_us(value)
+ timeout_us = parse_systemd_duration_to_us(value)
if timeout_us is not None:
break
if timeout_us is not None:
@@ -406,11 +406,13 @@ def check_systemd_timing_alignment(drain_timeout: float) -> Optional[Dict[str, A
}
-def _parse_systemd_duration_to_us(raw: str) -> Optional[int]:
+def parse_systemd_duration_to_us(raw: str) -> Optional[int]:
"""Parse 'TimeoutStopUSec=1min 30s' / '90s' style values to microseconds.
systemd accepts a wide grammar; we cover the common cases (s, ms, min,
h) and return None on anything unexpected. Never raises.
+
+ Public: also consumed by hermes_cli.gateway's restart-wait sizing.
"""
if not raw:
return None
@@ -460,3 +462,7 @@ def _parse_systemd_duration_to_us(raw: str) -> Optional[int]:
return None
digits = ""
return total_us if total_us > 0 else None
+
+
+# Backward-compat private alias (pre-promotion name).
+_parse_systemd_duration_to_us = parse_systemd_duration_to_us
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py
index 0ae4a523fb4..1cd3d11aaed 100644
--- a/hermes_cli/gateway.py
+++ b/hermes_cli/gateway.py
@@ -1330,7 +1330,7 @@ def _wait_for_systemd_service_restart(
def _systemd_restart_wait_timeout(system: bool = False) -> float:
"""Cover systemd's relaunch delays before applying the runtime wait floor."""
- from gateway.shutdown_forensics import _parse_systemd_duration_to_us
+ from gateway.shutdown_forensics import parse_systemd_duration_to_us
props = _read_systemd_unit_properties(
system=system,
@@ -1340,7 +1340,7 @@ def _systemd_restart_wait_timeout(system: bool = False) -> float:
for name in ("RestartUSec", "TimeoutStartUSec"):
raw = props.get(name, "")
duration_us = (
- int(raw) if raw.isdigit() else _parse_systemd_duration_to_us(raw)
+ int(raw) if raw.isdigit() else parse_systemd_duration_to_us(raw)
)
if duration_us is not None:
supervisor_budget += duration_us / 1_000_000