hermes-agent/tests/openviking_plugin
0xDevNinja 040e18ad90 fix(openviking): refresh client from env across every gated access
initialize() snapshots OPENVIKING_* into the provider once, so /reload
(which only updates os.environ) leaves viking_* tools running against
stale auth — users have to restart hermes to pick up keys added to
~/.hermes/.env after startup (#21130).

Add _ensure_client(), which re-resolves the connection settings via the
same _resolve_connection_settings/_load_hermes_openviking_config path
initialize() uses and rebuilds + health-checks the client only when an
OPENVIKING_* value actually changed; otherwise it reuses the cached
client (or a cached None for a known-down target) so the hot path stays
at one dict comparison with no network calls.

Route every live client-gated path through it: system_prompt_block,
prefetch (pre-turn recall), sync_turn, on_session_end, on_session_switch
(session rotation), on_memory_write and handle_tool_call. The
unreachable branch calls _handle_runtime_openviking_unreachable() so a
newly-resolved but not-yet-up LOCAL endpoint keeps initialize()'s
recovery — (re)start the server and attach in the background — instead of
silently disabling memory.

Refreshing is gated behind a flag set at the end of initialize() so the
baseline is established before any env re-resolution happens — callers
that wire up a client directly (e.g. tests) keep it untouched.

Refs #21130
2026-07-13 12:14:08 +05:30
..
test_openviking.py fix(openviking): refresh client from env across every gated access 2026-07-13 12:14:08 +05:30