Skip to content

The agent that grows with you

fix(cron,kanban): a claimed welcome trial runs cron jobs and Kanban workers on a fresh install (review)

alt-glitchc8029f51eb32
diff --git a/cron/scheduler.py b/cron/scheduler.py
index 80182d13e52..6e711cff81c 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -1624,8 +1624,9 @@ class _CronJobConfig:
def _load_cron_job_config(job: dict, job_id: str, job_name: str) -> _CronJobConfig:
"""Load config.yaml and resolve the run's model: per-job pin > cron.model (fleet default) >
- the main agent model (config ``model:``, then HERMES_MODEL). Re-read every tick (no cache) so
- ``hermes cron edit --model`` and ``hermes model`` both apply next tick."""
+ the main agent model (config ``model:``, then HERMES_MODEL) > the claimed welcome trial's. Re-read
+ every tick (no cache) so ``hermes cron edit --model`` and ``hermes model`` both apply next tick."""
+ from hermes_cli.anon_auth import trial_model
model = job.get("model") or cron_env_setting("HERMES_MODEL") or ""
_cron_default_provider = ""
_cfg: dict = {}
@@ -1653,10 +1654,9 @@ def _load_cron_job_config(job: dict, job_id: str, job_name: str) -> _CronJobConf
model = str(_main or "").strip() or model
except Exception as e:
logger.warning("Job '%s': failed to load config.yaml, using defaults: %s", job_id, e)
-
- # Fail fast: an empty model otherwise reaches the provider as an opaque 400.
- # See #23979.
- if not (isinstance(model, str) and model.strip()):
+ model = (model if isinstance(model, str) else "").strip() or trial_model()
+ # Fail fast: an empty model otherwise reaches the provider as an opaque 400 (#23979).
+ if not model:
raise RuntimeError(
f"Cron job '{job_name}' has no model configured "
f"(job.model={job.get('model')!r}, "
diff --git a/gateway/run.py b/gateway/run.py
index e11bbd75cb4..51be63e929a 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -2898,15 +2898,14 @@ from gateway.session_worker_construct import checkpoint_agent_kwargs as _checkpo
def _resolve_gateway_model(config: dict | None = None) -> str:
- """Read model from config.yaml (single source of truth), else temporary AIAgents (e.g. /compress)
- use the hardcoded default, which fails under openai-codex."""
- cfg = config if config is not None else _load_gateway_config()
- model_cfg = cfg.get("model", {})
- if isinstance(model_cfg, str):
- return model_cfg
- elif isinstance(model_cfg, dict):
- return model_cfg.get("default") or model_cfg.get("model") or ""
- return ""
+ """The profile's model when nothing else names one: config.yaml (single source of truth), else the
+ claimed welcome trial's. Temporary AIAgents (e.g. /compress) otherwise use the hardcoded default,
+ which fails under openai-codex."""
+ from hermes_cli.anon_auth import trial_model
+ model_cfg = (config if config is not None else _load_gateway_config()).get("model", {})
+ if isinstance(model_cfg, dict):
+ model_cfg = model_cfg.get("default") or model_cfg.get("model")
+ return (model_cfg if isinstance(model_cfg, str) else "") or trial_model()
def _channel_override_lookup_keys(
diff --git a/gateway/session_local.py b/gateway/session_local.py
index 9d2e9fac050..2cff15e5964 100644
--- a/gateway/session_local.py
+++ b/gateway/session_local.py
@@ -235,14 +235,6 @@ def staged_creation_follows(authority, actor, request_id):
return isinstance(request, dict) and request.get('follow_profile_config') is True
-def _welcome_trial_model():
- """The free model for a chat that has no configured one, while the welcome trial carries this
- activity (the local Desktop, a claimed guest): what the agent pins on the welcome host anyway
- (``anon_auth.pin_model_for_route``). Else None, and the create refuses as before."""
- from hermes_cli import anon_auth
- return anon_auth.GUEST_MODEL if anon_auth.free_inference_active() else None
-
-
def stage_local_session(authority, actor, params, *, trusted_policy=None, trusted_secrets=None, skills_prompt=None,
client_local=False, desktop_local=False):
"""Everything before the creation commit: the existing session's ref on an exact retry, else the
@@ -284,12 +276,11 @@ def stage_local_session(authority, actor, params, *, trusted_policy=None, truste
sort_keys=True))
marks = {LOCAL_DESKTOP_CHAT: True} if desktop_local and policy.source == 'gui' else {}
if policy.model is None:
- configured = _resolve_gateway_model(policy.config())
- model = configured or _welcome_trial_model()
- if model and not configured:
+ from hermes_cli.anon_auth import GUEST_MODEL
+ policy = replace(policy, model=_resolve_gateway_model(policy.config()) or None)
+ if policy.model == GUEST_MODEL:
# Follows its profile, so the provider the user connects later replaces the trial model.
marks[FOLLOW_ADOPTED] = True
- policy = replace(policy, model=model)
if marks:
import json
policy = replace(policy, config_json=json.dumps({**json.loads(policy.config_json), **marks}))
diff --git a/hermes_cli/anon_auth.py b/hermes_cli/anon_auth.py
index 1138212ebe9..62f83fe76a7 100644
--- a/hermes_cli/anon_auth.py
+++ b/hermes_cli/anon_auth.py
@@ -215,6 +215,13 @@ def free_inference_active(state: Any = None) -> bool:
return is_guest_state(state) and state.get(WELCOME_CLAIM_FLAG) is True and guest_allowed()
+def trial_model() -> str:
+ """The last rung of model resolution, below every model the user named (``model.default``, a cron
+ or task pin): ``nous/welcome`` while the welcome trial carries inference, else ''. Never written to
+ config.yaml, so it stops applying the moment the user configures a real model."""
+ return GUEST_MODEL if free_inference_active() else ""
+
+
def has_free_tier_account() -> bool:
"""True when the profile's Nous identity is a guest that carries inference here.
diff --git a/tests/hermes_cli/test_welcome_trial.py b/tests/hermes_cli/test_welcome_trial.py
index 93ce23b74c1..b2ec63be73e 100644
--- a/tests/hermes_cli/test_welcome_trial.py
+++ b/tests/hermes_cli/test_welcome_trial.py
@@ -300,3 +300,72 @@ def test_one_due_answer_walks_the_provider_ladder_once(portal, monkeypatch):
assert welcome_trial.inference_available() is True # fresh: the trial is claimable
assert len(calls) == 1
+
+
+def _cron_model() -> str:
+ from cron.scheduler import _load_cron_job_config
+
+ return _load_cron_job_config({"id": "j", "name": "j", "prompt": "x"}, "j", "j").model
+
+
+def _kanban_worker_model(monkeypatch, tmp_path) -> str:
+ from dataclasses import asdict
+ from types import SimpleNamespace
+ from contextlib import closing
+ from hermes_cli import kanban_db as kb
+ from hermes_cli.config import load_config
+ from hermes_cli.kanban_db_connect import connect
+ from hermes_constants import get_hermes_home
+ from gateway.session_contract import Principal
+ from gateway.session_kanban import build_kanban_policy
+ from gateway.session_policy import restore_policy
+
+ home = str(get_hermes_home())
+ monkeypatch.setenv("HERMES_KANBAN_HOME", str(tmp_path / "kanban"))
+ monkeypatch.delenv("HERMES_KANBAN_DB", raising=False)
+ monkeypatch.setattr("hermes_cli.profiles.resolve_profile_env", lambda name: home)
+ workspace = tmp_path / "workspace"
+ workspace.mkdir()
+ kb.create_board("trial")
+ with closing(connect(board="trial")) as conn:
+ task_id = kb.create_task(conn, title="t", assignee="default", workspace_kind="dir", workspace_path=str(workspace))
+ kb.recompute_ready(conn)
+ task = kb.claim_task(conn, task_id)
+ connection = SimpleNamespace(authority=SimpleNamespace(profile_id=home), native_owner=True,
+ actor=Principal("owner", home, frozenset({"session:create"}), "transport"))
+ params = dict(board="trial", task_id=task.id, run_id=task.current_run_id, claim_lock=task.claim_lock)
+ policy, _ = build_kanban_policy(connection, params, load_config())
+ return restore_policy(asdict(policy)).model
+
+
+def unconfigured_trial(portal, monkeypatch):
+ """A fresh install whose Desktop claimed the trial, read by the scheduler or the Kanban
+ dispatcher (not Desktop work), with no model configured anywhere."""
+ monkeypatch.delenv("HERMES_MODEL", raising=False)
+ claimed_trial(monkeypatch)
+ off_local_desktop(monkeypatch)
+ yield
+ from hermes_cli.config import load_config
+ assert not (load_config().get("model") or {}).get("default") # never persisted: a later provider wins
+
+
+def test_a_claimed_trial_runs_a_default_cron_job_when_no_model_is_configured(unconfigured_trial):
+ assert _cron_model() == anon_auth.GUEST_MODEL
+
+
+def test_a_claimed_trial_runs_a_kanban_worker_when_no_model_is_configured(unconfigured_trial, monkeypatch, tmp_path):
+ assert _kanban_worker_model(monkeypatch, tmp_path) == anon_auth.GUEST_MODEL
+
+
+def test_a_configured_model_beats_the_trial_for_cron_jobs_and_kanban_workers(portal, monkeypatch, tmp_path):
+ from hermes_constants import get_hermes_home
+
+ monkeypatch.delenv("HERMES_MODEL", raising=False)
+ claimed_trial(monkeypatch)
+ off_local_desktop(monkeypatch)
+ (get_hermes_home() / "config.yaml").write_text(
+ "model:\n provider: openrouter\n default: anthropic/claude-sonnet-4\n", encoding="utf-8")
+
+ assert _cron_model() == "anthropic/claude-sonnet-4"
+ assert _kanban_worker_model(monkeypatch, tmp_path) == "anthropic/claude-sonnet-4"