# Cron model-auth failure pattern

Session learning: a Hermes cron job can fail even when its script and delivery are healthy if the LLM provider configured on the job is invalid/exhausted.

## Example symptom

Cron delivery reported:

```text
RuntimeError: Error code: 401 - {'error': {'message': 'User not found.', 'code': 401}}
```

The affected job was `847bdbc26edf` (`Morgen-Briefing optimiert`) with:

- `provider: openrouter`
- `model: openrouter/auto`
- script: `morning_briefing.py`

Diagnosis showed OpenRouter auth was invalid/exhausted while the job script itself was not the cause.

## Diagnosis checklist

1. List jobs and inspect provider/model/last_status:
   ```bash
   hermes cron list
   ```
2. Inspect recent cron output for the job:
   ```bash
   ls -lt ~/.hermes/cron/output/<job_id>/ | head
   tail -n 80 ~/.hermes/cron/output/<job_id>/<latest>.md
   ```
3. Check provider auth status without printing secrets:
   ```bash
   python3 - <<'PY'
   import json, pathlib
   p=pathlib.Path.home()/'.hermes/auth.json'
   data=json.loads(p.read_text())
   for k,v in data.items():
       print(k, {x:v.get(x) for x in ('last_status','last_error_code','last_error_message','base_url')})
   PY
   ```
4. If the provider is bad and another approved provider is healthy, update only provider/model and test-run.

## Minimal fix pattern

Use the cron update mechanism or CLI to move the job to a healthy approved provider/model. For the morning briefing case, switching to `openai-codex` / `gpt-5.5` resolved the 401.

Then trigger and verify:

```bash
hermes cron run <job_id> --accept-hooks
sleep 75
hermes cron list
```

Expected verification: `Last run: ... ok` and next run reset to the normal schedule.

## Pitfalls

- Do not assume a cron failure is a script bug; provider auth failures surface as runtime errors after script context collection.
- Do not print `.env`, raw tokens, or full auth files into chat.
- For critical jobs, prefer an approved strong model; do not silently downgrade model quality if the job performs critical reasoning.
