fix(openviking): refresh client from env on /reload#21138
Open
0xDevNinja wants to merge 1 commit into
Open
Conversation
Collaborator
1455b3f to
c54626d
Compare
Contributor
|
First fix. Should be resolve with setting account and user as “”. Then headers won’t be sent to ov. This is fixed in some PR recently. For omitting header when unset. second Lgtm. |
c54626d to
822dbb1
Compare
Contributor
Author
|
Thanks for the review. You're right — #21232 already landed the omit-when-unset/legacy- |
initialize() snapshots OPENVIKING_* into self._api_key/_endpoint 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 .env after startup. Add _ensure_client() that re-reads env on each access and rebuilds the client when any OPENVIKING_* value changed; cached otherwise so the per-call cost stays at one dict comparison + zero network calls on the hot path. Replace every `if not self._client:` guard with `if not self._ensure_client():` across system_prompt_block, queue_prefetch, sync_turn, on_session_end, on_memory_write, and handle_tool_call. Refs NousResearch#21130
822dbb1 to
971ee77
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes the env-reload half of #21130:
OPENVIKING_*env values were snapshotted ininitialize()and never refreshed, so/reload(which only updatesos.environ) leftviking_*tools running against stale auth — users had to restart hermes to pick up keys added to.envafter startup.Fix
Introduce
_ensure_client()that re-reads env on each access and rebuilds the client when anyOPENVIKING_*value changed; the same client is reused otherwise so the per-call cost stays at one dict comparison + zero network calls on the hot path. Everyif not self._client:guard insystem_prompt_block,queue_prefetch,sync_turn,on_session_end,on_memory_write, andhandle_tool_callbecomesif not self._ensure_client():.Note on the header-collision bug
The original PR also carried a fix for
_VikingClient._headers()colliding with API-key auth. That is now redundant — #21232 already landed the omit-empty/legacy-defaulttenant header behavior upstream, which resolves the same 403. That commit has been dropped; this PR is scoped to the env-reload fix only.Related Issue
Refs #21130 (env-reload half; header-collision half handled by #21232)
Type of Change
Changes Made
plugins/memory/openviking/__init__.py_ensure_client()— re-readsOPENVIKING_ENDPOINT/API_KEY/ACCOUNT/USER/AGENTon each access, rebuilds + health-checks the client only when a value changed.initialize()no longer snapshots env directly; delegates to_ensure_client().if not self._client:guard withif not self._ensure_client():.tests/openviking_plugin/test_openviking.py— coverage for env-change rebuild, no-rebuild on unchanged config, and stale-client behavior across/reload.Testing
Both suites green (13 + 20 passed).