fix(openviking): read .env BOM-tolerantly when rewriting credentials - #78940
Closed
Drexuxux wants to merge 1 commit into
Closed
fix(openviking): read .env BOM-tolerantly when rewriting credentials#78940Drexuxux wants to merge 1 commit into
Drexuxux wants to merge 1 commit into
Conversation
f1ea4a5 ("cover the remaining setup-time .env reads with utf-8-sig", following 75afc47 for mem0/hindsight) swept this class; openviking's _write_env_vars was missed and still reads with strict utf-8. It copies every existing line through on each update, so the read decides whether a credential update lands: BOM'd .env -> the first key never matches, so the old line survives and the new value is appended as a duplicate. .env loaders keep the first occurrence, so the update silently does nothing. cp1252 .env -> UnicodeDecodeError aborts setup outright. Read exactly like the canonical hermes_cli/config.py save_env_value (utf-8-sig + errors="replace"). A plain UTF-8 file rewrites byte-identically. Scope: hermes_cli/memory_setup.py has the same read but is already the subject of NousResearch#30281 / NousResearch#60587, so it is left alone here.
19 tasks
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
75afc47 (2026-07-10, fix(memory): read/write .env as UTF-8 in mem0 and hindsight setup) and then f1ea4a5 (2026-07-12, fix(memory): cover the remaining setup-time .env reads with utf-8-sig) hardened this exact class.
plugins/memory/openviking/__init__.py::_write_env_varswas missed and still reads with strict UTF-8:The function copies every existing line through on each update, so the read decides whether a credential update actually lands. Two failure modes, both on
.env— the file that holds API keys. Real writer, real files:\ufeffOPENAI_API_KEY, so it never matches. The stale line survives and the new value is appended as a duplicate..envloaders keep the first occurrence, so the user changes their key, setup reports success, and the old key is still what gets loaded.CONTRIBUTING.md calls out both cases explicitly under Cross-Platform Compatibility, and the sibling writer in
plugins/memory/mem0/_setup.pyalready carries a comment explaining precisely this hazard — it just never reached this file.The fix
Read exactly like the canonical
.envreader,hermes_cli/config.py::save_env_value:utf-8-sigstrips a BOM if present and is a no-op otherwise;errors="replace"keeps a mis-encoded neighbouring line from aborting the write. A plain UTF-8.envrewrites byte-identically.One consequence worth naming: on a cp1252 file, an unrelated non-ASCII value is rewritten with a replacement character rather than its original bytes. That is the same trade the canonical writer already makes — the alternative is the current behaviour, where setup fails outright and nothing is written at all.
Scope:
hermes_cli/memory_setup.pyhas the same read, but it is already the subject of #30281 and #60587, so it is deliberately left alone here.plugins/memory/mem0/_setup.pywas fixed by f1ea4a5;hermes_cli/doctor.pyandhermes_cli/main.pyalready guard the decode.Tests
Added
TestOpenVikingEnvWritertotests/plugins/memory/test_openviking_provider.py:.envupdates the key in place — exactly oneOPENAI_API_KEYline, no leftover=old.envno longer aborts the write.envcomes out with the same lines in the same order — the guard against the read change altering ordinary filesResults:
That is the whole file; the 51 pre-existing tests are unchanged.
Red without the source change:
The third test passes on both sides, which is what it is for.
Regression over
tests/plugins/memory/against the same files on main:Set difference is empty — no new failures. The 7 are identical before and after and sit in the hindsight and holographic suites, unrelated to this change.