refactor(cron): parameterize liveness warning plurality, drop fragile string replace

Simplify-pass follow-ups on the #87033 fix:
- _gateway_liveness_notice(plural=) authors both wording variants at one
  site; removes the exact-substring .replace() that would silently no-op
  if the create-path text is ever edited.
- Collapse the operator-precedence-trap conditional in list to a plain
  'if jobs' — an empty list has nothing inert and now skips the probe.
- Fix docstring/code mismatch (builder returns gateway_running: True on
  the happy path) and drop the dead try/except in
  _warn_if_gateway_not_running (the helper never raises).
This commit is contained in:
kshitijk4poor
2026-08-24 16:27:46 +05:30
committed by kshitij
parent 5843b2f595
commit ddbd928ee4
2 changed files with 15 additions and 24 deletions
+3 -6
View File
@@ -99,12 +99,9 @@ def _warn_if_gateway_not_running() -> None:
any non-builtin provider; the gateway-process heuristic only speaks to the
built-in ticker's trigger.
"""
try:
if _builtin_gateway_liveness() is not False:
# Active scheduler (gateway up, or an exempt non-builtin provider),
# or the probe failed — stay quiet rather than nag either way.
return
except Exception:
# _builtin_gateway_liveness never raises (it maps probe failures to None),
# so no guard is needed here — False is the only warn-worthy state.
if _builtin_gateway_liveness() is not False:
return
print(color(" ⚠ Gateway is not running — jobs won't fire automatically.", Colors.YELLOW))
+12 -18
View File
@@ -1223,14 +1223,16 @@ def _apply_continuity(
return refs or None
def _gateway_liveness_notice() -> dict:
def _gateway_liveness_notice(plural: bool = False) -> dict:
"""Build the ``gateway_running``/``warning`` payload for tool results.
Thin adapter over the shared CLI helper ``hermes_cli.cron._builtin_gateway_liveness``
(#87033) so the CLI and this tool can never disagree about what "scheduler
active" means. Returns ``{}`` when the scheduler is active (nothing to say),
or carries ``gateway_running: false`` plus a model-facing ``warning`` when
the builtin ticker has no gateway process to run it.
active" means. Returns ``{"gateway_running": False, "warning": ...}`` when
the builtin ticker has no gateway process to run it, ``{"gateway_running":
None}`` when the probe failed, and ``{"gateway_running": True}`` when the
scheduler is active. ``plural`` rewords the warning for multi-job results
(the ``list`` action).
"""
try:
from hermes_cli.cron import _builtin_gateway_liveness
@@ -1238,11 +1240,12 @@ def _gateway_liveness_notice() -> dict:
_gw = _builtin_gateway_liveness()
except Exception:
return {"gateway_running": None}
subject = "these jobs are saved" if plural else "this job is saved"
if _gw is False:
return {
"gateway_running": False,
"warning": (
"The Hermes gateway is not running — this job is saved "
f"The Hermes gateway is not running — {subject} "
"but will NOT fire until the gateway is started "
"(hermes gateway install / hermes gateway start). "
"Tell the user the task is scheduled but not active yet."
@@ -1424,19 +1427,10 @@ def cronjob(
_result = {"success": True, "count": len(jobs), "jobs": jobs}
# Same silent-inert-job class as create (#87033): an agent
# inspecting existing jobs in a gateway-less environment must
# learn they are not firing, not just see a clean list.
_liveness = _gateway_liveness_notice()
if len(jobs) or "gateway_running" in _liveness and _liveness["gateway_running"] is None:
if len(jobs):
_liveness_warning = _liveness.get("warning", "")
if _liveness_warning:
_liveness["warning"] = (
"Note: " + _liveness_warning.replace(
"this job is saved but will NOT fire",
"these jobs are saved but will NOT fire",
)
)
_result.update(_liveness)
# learn they are not firing, not just see a clean list. An empty
# list has nothing inert — stay quiet (and skip the probe).
if jobs:
_result.update(_gateway_liveness_notice(plural=True))
return json.dumps(_result, indent=2)
if not job_id: