mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-24 10:52:21 +00:00
Cron jobs created without an explicit `model` are stored as `model: null`.
At fire time `run_job` resolved `model = job.get("model") or os.getenv(
"HERMES_MODEL") or ""` and then `_model_cfg.get("default", model)`, so when
config.yaml had no `model.default` (or `model: {default: null}`) an empty
string flowed straight to the provider and surfaced as an opaque HTTP 400
("Model parameter is required" / "model: String should have at least 1
character"). The operator had to inspect jobs.json to discover the job was
stored with a null model.
This change makes cron model resolution robust and symmetric with the CLI:
- Coerce `model: null`/missing config to `{}` so a falsy default never
overwrites an already-resolved env value with `None`.
- Only overwrite `model` from `model.default` when the resolved value is
truthy; accept a `model.model` alias key, mirroring the sibling resolvers
in hermes_cli/oneshot.py, fallback_cmd.py and prompt_size.py.
- Resolve AFTER the managed-scope overlay so an administrator-pinned model
still wins.
- Fail fast with an actionable error (caught by run_job's outer handler and
recorded as the job's last_error — the cron ticker is unaffected) instead
of letting an empty model reach the API.
- The per-job model is re-read every tick, so a `cronjob action=update
model=...` after a failed run takes effect on the next tick (no cache).
Adds tests/cron/conftest.py pinning a default HERMES_MODEL so existing
run_job tests don't trip the new guard, plus regression tests covering env
fallback, config.default fallback, string-form config, the model alias key,
null-default-no-clobber, corrupt-config graceful degradation, fail-fast,
and the no-cache re-read property.
Salvaged from #24005, rebased onto current main, with additional test
coverage folded in from #45550 and the alias-key behavior from #43952.
Fixes #43899
Fixes #23979
Fixes #22761
Co-authored-by: szzhoujiarui-sketch <szzhoujiarui@gmail.com>
Co-authored-by: rayjun <rayjun0412@gmail.com>
21 lines
834 B
Python
21 lines
834 B
Python
"""Cron-test fixtures.
|
|
|
|
Provides a default ``HERMES_MODEL`` for cron run_job tests so each one
|
|
doesn't have to spell out a model. The global conftest blanks
|
|
HERMES_MODEL hermetically; without this autouse fixture every cron test
|
|
that exercises ``run_job`` would hit the fail-fast guard added in
|
|
``cron/scheduler.py`` (see issue #23979) and have to be rewritten.
|
|
|
|
Tests that specifically need ``HERMES_MODEL`` unset — model-resolution
|
|
edge cases — call ``monkeypatch.delenv("HERMES_MODEL", raising=False)``
|
|
inside the test, which overrides this fixture's value for that scope.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _default_cron_test_model(monkeypatch):
|
|
"""Pin a default HERMES_MODEL so cron run_job tests have a resolvable model."""
|
|
monkeypatch.setenv("HERMES_MODEL", "test-cron-default-model")
|
|
yield
|