Skip to content

fix(gateway): reload .env on /restart so new env keys are picked up#18582

Open
gulivan wants to merge 1 commit into
NousResearch:mainfrom
gulivan:fix/restart-env-reload
Open

fix(gateway): reload .env on /restart so new env keys are picked up#18582
gulivan wants to merge 1 commit into
NousResearch:mainfrom
gulivan:fix/restart-env-reload

Conversation

@gulivan

@gulivan gulivan commented May 1, 2026

Copy link
Copy Markdown

Problem

After editing ~/.hermes/.env (e.g. adding OLLAMA_API_KEY) and running /restart, the Gateway process does not see the new environment variables. Consequently, tools whose check_fn depends on env vars (such as ollama_web_search) remain hidden.

Root cause

gateway/run.py loads .env once at import time (lines ~255-260). On /restart the Python module is often cached/reimported, so load_hermes_dotenv() is skipped and stale / missing env values persist. In addition, registry.py caches check_fn results, so even if env changes later the tool definitions are not recalculated.

Fix

  • Move load_hermes_dotenv() from module level into Gateway.start() so it runs on every gateway start (including restarts).
  • Call invalidate_check_fn_cache() immediately after loading env, forcing tools to re-evaluate availability with fresh env values.
  • Preserve module-level _env_path variable because the agents' own credential reload logic (~line 11956) references it.

Files changed

  • gateway/run.py

No breaking changes.

Moves load_hermes_dotenv() from module import time to Gateway.start()
so that /restart re-evaluates .env contents. Also invalidates the
check_fn cache so tool availability (e.g. OLLAMA_API_KEY) is recalculated.

Previously .env was loaded once when the gateway Python process
started; adding a key later required a full shell-level restart.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery area/config Config system, migrations, profiles labels May 2, 2026
Cyrene963 pushed a commit to Cyrene963/hermes-agent that referenced this pull request May 3, 2026
Community PRs applied:
- NousResearch#18596: Enable secret redaction by default (SECURITY)
- NousResearch#18650: Sanitize malformed tool messages + auto-recover on API 400
- NousResearch#18607: Emergency compression before max_iterations exhaustion
- NousResearch#18603: Compression fallback to main model on 413 rate limit
- NousResearch#18638: Pass threshold_percent on model switch
- NousResearch#18663: Strip extra_content from tool_calls for strict APIs
- NousResearch#18618: Forward explicit_api_key to OpenRouter
- NousResearch#18632: Show cache tokens in /insights breakdown
- NousResearch#18614: Add idempotency guard for patch duplicate loops
- NousResearch#18600: Raise ValueError when HERMES_HOME unset in profile mode
- NousResearch#18616: Allow ZWJ emoji in context files
- NousResearch#18582: Reload .env on /restart
- NousResearch#18547: Stabilize system prompt prefix for KV cache reuse
- NousResearch#18692: Strip FTS5 operators from session search truncation terms

Fix: Add order_by_last_active=True to list_sessions_rich call
(pre-existing commit 142b4bf code sync)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants