Hermes plugin fails to load on Windows with non-UTF-8 locale (UnicodeDecodeError in _plugin_version)
Title: Hermes plugin fails to load on Windows with non-UTF-8 default locale (UnicodeDecodeError in _plugin_version)
Summary
The Hermes integration plugin fails to initialize on Windows when the system's default text encoding is not UTF-8 (e.g. Chinese/Japanese/Korean Windows, where locale.getpreferredencoding() returns cp936/gbk). The provider silently fails to load and Hermes logs:
plugins.memory: Memory provider 'hindsight' loaded but no provider instance found
No traceback is shown because the failure is swallowed by the loader's contextlib.suppress.
Root cause
hindsight-integrations/hermes/__init__.py, _plugin_version():
def _plugin_version() -> str:
"""Read the version from plugin.yaml — Hermes loads this directory, not a pip package."""
try:
text = (Path(__file__).resolve().parent / "plugin.yaml").read_text()
except OSError:
return "0.0.0"
Path.read_text() is called without encoding=, so Python uses locale.getpreferredencoding(False). On a Chinese Windows install that is cp936/gbk.
plugin.yaml line 3 contains a UTF-8 em-dash (U+2014, bytes e2 80 94):
description: "Hindsight — long-term memory with knowledge graph, ..."
GBK cannot decode byte 0x94 at that position, so read_text() raises:
UnicodeDecodeError: 'gbk' codec can't decode byte 0x94 in position 57: illegal multibyte sequence
Note that UnicodeDecodeError is not a subclass of OSError, so the except OSError guard does not catch it — the exception propagates out of _plugin_version(), out of module import at line 102 (_USER_AGENT = f"hindsight-hermes/{_plugin_version()}"), and the plugin module fails to import entirely.
Environment
- OS: Windows 10 (Chinese locale,
cp936) - Python: 3.14.7 (also reproducible on the bundled 3.11 environment)
- hermes-agent: 0.22.2
- hindsight integration: 1.2.2 and 1.2.3 (bug present in both —
read_text()still has noencoding=ond952b6e6)
Suggested fix
Pass the encoding explicitly (the file is UTF-8):
text = (Path(__file__).resolve().parent / "plugin.yaml").read_text(encoding="utf-8")
Optionally, also widen the guard to except (OSError, UnicodeDecodeError) so a future encoding surprise degrades to "0.0.0" instead of taking the whole provider down.
Impact
On any CJK Windows host the plugin cannot load at all, which means: no recall/reflect/retain tools, no automatic per-turn capture — external memory is silently off. Because the loader suppresses the exception, users get a one-line warning with no actionable detail and no obvious link to an encoding problem.
I can open a PR with the one-line fix if that's welcome.
Confirmed against the shipped files, and the except OSError miss is the part that turns this from a degraded version string into a dead plugin.
I reproduced it on Linux by forcing a non-UTF-8 default locale, using _plugin_version() extracted unmodified from main (lines 91-100) and the real plugin.yaml:
--- 2. UTF-8 default locale (works) ---
preferred: UTF-8 -> 1.2.3
--- 3. same code, non-UTF-8 default locale ---
preferred: ANSI_X3.4-1968
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 55: ordinal not in range(128)
caught by `except OSError`? False
MRO: ['UnicodeDecodeError', 'UnicodeError', 'ValueError', 'Exception', 'BaseException', 'object']
--- 4. the shipped plugin.yaml bytes under CJK Windows codecs ---
non-ASCII byte offsets: [55, 56, 57, 492, 493, 494]
gbk 'gbk' codec can't decode byte 0x94 in position 57: illegal multibyte sequence
cp932 'cp932' codec can't decode byte 0x94 in position 57: illegal multibyte sequence
cp949 'cp949' codec can't decode byte 0xe2 in position 55: illegal multibyte sequence
utf-8 OK
--- 5. proposed guard (AST, same files tests/test_local_runtime.py already walks) ---
FAILURES:
__init__.py:94 read_text() without encoding=
--- 5b. same guard after `read_text(encoding="utf-8")` ---
FAILURES:
none
guard exit=0
--- 6. interpreter-level guard, env-var form (works under pytest) ---
EncodingWarning: 'encoding' argument not specified
Step 4 is byte-for-byte the string in your report. Three things the issue doesn't cover:
-
plugin.yamlhas two non-ASCII runs, at byte offsets 55 and 492 — the second is the em-dash inside the# ... lands — display, not installationcomment. So sanitizing thedescription:line would leave the file just as undecodable under cp936; theencoding=argument is the only fix that holds. -
__init__.py:94is the only text access in the plugin's runtime modules that doesn't name an encoding. Every other one already does:setup.py:58,66,194andembedded.py:280useutf-8-sig(the latter witherrors="replace"),settings.py:234,241,289useutf-8, and the two bareopen()calls at__init__.py:1461,1469passencoding="utf-8". The one-liner is therefore complete — no sibling site rides along with it. Since the house convention for files a user might re-save on Windows isutf-8-sig, that spelling would match; I checked that it makes no functional difference here, because a BOM lands on line 1 (name:) andversion:still parses either way. -
On widening the guard: the base class is
ValueError, notOSError(MRO in step 3), soexcept (OSError, UnicodeDecodeError)is the correct spelling if you want the belt and braces. Withencoding=explicit it is no longer load-bearing.
For keeping it out: tests/test_local_runtime.py:134 already AST-walks exactly __init__.py, embedded.py and setup.py for banned imports, and the same walk catches this class:
for node in ast.walk(tree):
if isinstance(node, ast.Call):
fn = node.func.attr if isinstance(node.func, ast.Attribute) else getattr(node.func, "id", None)
if fn in ("read_text", "write_text") and not any(k.arg == "encoding" for k in node.keywords):
raise AssertionError(f"{name}:{node.lineno} {fn}() without encoding=")
Step 5 above is that check run for real: it fails on __init__.py:94 against current main and passes after the one-line change. If you want coverage beyond those three files, step 6 is the interpreter-level equivalent — PYTHONWARNDEFAULTENCODING=1 plus filterwarnings = ["error::EncodingWarning"] under your existing [tool.pytest.ini_options] — firing on the same call.
The shape is worth separating from the one-line bug: per your note the loader's contextlib.suppress converted a hard import failure into loaded but no provider instance found, so external memory was off with no traceback and nothing pointing at an encoding. We keep a field catalog of that exact failure class (agents that go quiet instead of crashing), and the "break the check on purpose, watch it fail, only then call it wired" rule behind step 5 is from it (ours): https://github.com/aron-intframe/agent-guards/blob/main/guards/guard-selftest.py
Independent confirmation from a Windows 11 / zh-CN (cp936) host, plus three details not yet captured in this thread.
Environment: Hermes Agent v0.22.2 (2026.9.24), Python 3.14.7, plugin 1.2.3 (pinned d952b6e), mode local_external. Symptoms match the report exactly: WARNING plugins.memory: Memory provider 'hindsight' loaded but no provider instance found on startup, registered = 0 across every log file ever written, and hermes plugins doctor hindsight → ERROR: Plugin registration failed: 'gbk' codec can't decode byte 0x94 in position 57: illegal multibyte sequence / registrations: 0 tool(s).
Three additions:
-
PYTHONUTF8=1does not rescue this on a real Hermes install. Hermes starts Python aspython.exe -I(see$HERMES_HOME/hermes-agent/.hermes/bin/hermes.cmd), and-Iimplies-E, so everyPYTHON*environment variable is ignored. Verified:PYTHONUTF8=1 hermes plugins doctor hindsightfails identically. Users on CP936/CP932/CP949 hosts therefore have no env-var workaround — theencoding=fix is the only path. -
Blast radius is larger than "external memory off for hindsight". Hermes registers at most ONE external memory provider at a time (
agent/memory_manager.py: "only ONE external plugin provider may be registered at a time";plugins/memory/__init__.py: activated by name undermemory.provider, "one at a time"). Withmemory.provider: hindsightset, this import failure does not fall back to another provider — the user is left with no external memory tools whatsoever, silently. A plugin that cannot import removes the user's memory entirely, not merely its own. -
The one-line fix is sufficient, verified against the live plugin. With
read_text(encoding="utf-8")at__init__.py:94,hermes plugins doctor hindsightgoes fromERROR: Plugin registration failed: 'gbk' ...toOK: runtime discovery, manifest parsing, import, and registration passed. This matches @aron-intframe's AST scan: line 94 is the only unencoded text read among the plugin's runtime modules.
Also worth noting for anyone debugging the same symptom: the registration gate runs before is_available(), so a perfectly healthy sidecar does not help — /health returned {"status":"healthy","database":"connected"} and /version api_version 1.0.0 the whole time, while registration still failed, because the crash happens at import time.
Byte-offset confirmation (matches the report): offset 57 is the third byte of the em dash in description: —
head -c 70 plugin.yaml | od -An -tx1 -v → ... 64 73 69 67 68 74 20 e2 80 94 20 6c 6f 6e 67 2d (0x94 at offset 57).
Independent confirmation from Windows 11 24H2 zh-CN, plus a note that the proposed two-line fix is verified end-to-end.
Environment: Hermes Agent 0.22.x, Python 3.14.7, plugin 1.2.3 (catalog), Hindsight 0.10.3 self-hosted, mode local_external.
Reproduction: same as above. hermes plugins doctor hindsight reports:
ERROR: Plugin registration failed: 'gbk' codec can't decode byte 0x94 in position 57: illegal multibyte sequence
registrations: 0 tool(s), 0 hook(s)
One diagnostic detail worth adding: hermes memory status only shows Plugin: NOT installed, which reads like a missing install rather than an import failure. hermes plugins doctor hindsight is what surfaces the actual UnicodeDecodeError. That mismatch sent me looking at plugin directories before the encoding.
Fix verified: applying both changes locally makes the plugin import and the provider work again — recall and retain confirmed against a live bank (161 memory nodes), and hermes plugins doctor hindsight returns:
OK: runtime discovery, manifest parsing, import, and registration passed
Diff used (on top of d952b6e):
--- a/hindsight-integrations/hermes/__init__.py
+++ b/hindsight-integrations/hermes/__init__.py
@@ -91,8 +91,8 @@
def _plugin_version() -> str:
"""Read the version from plugin.yaml — Hermes loads this directory, not a pip package."""
try:
- text = (Path(__file__).resolve().parent / "plugin.yaml").read_text()
- except OSError:
+ text = (Path(__file__).resolve().parent / "plugin.yaml").read_text(encoding="utf-8")
+ except (OSError, UnicodeDecodeError):
return "0.0.0"
for line in text.splitlines():
if line.startswith("version:"):
The except widening matters independently: UnicodeDecodeError is a ValueError, so without it any future manifest encoding surprise still takes down the whole provider rather than degrading the version string to 0.0.0.
Also confirming the earlier note: PYTHONUTF8=1 does not help on a real Hermes install, because the runtime is started as python -I (which implies -E) and ignores every PYTHON* variable.
Confirmed on another machine — same root cause, still present in v1.2.3 (d952b6e6).
Environment: Windows 11 26H1, Chinese locale (cp936/GBK), Hermes store Python 3.14.7, plugin hindsight-integrations/hermes 1.2.3.
Exact failure (module import dies before any provider logic runs):
File ".../plugins/hindsight/__init__.py", line 103, in <module>
_USER_AGENT = f"hindsight-hermes/{_plugin_version()}"
File ".../plugins/hindsight/__init__.py", line 94, in _plugin_version
text = (Path(__file__).resolve().parent / "plugin.yaml").read_text()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x94 in position 57
Byte 0x94 is the third byte of the UTF-8 em-dash (—, e2 80 94) in plugin.yaml's description. read_text() without encoding= uses the locale default (GBK here).
Why this is expensive to debug — the failure is completely silent at the surface:
plugins/plugin_loader.load_named()logs onlyWARNING ... Memory provider 'hindsight' loaded but no provider instance found(the module import error itself is swallowed at debug level)._instantiate_subclass()additionally suppresses constructor exceptions (except Exception: pass).- Net effect: the Hermes dashboard shows the provider as
unavailable(with a misleading "install dependencies" hint in some states), while the backend service itself is perfectly healthy — so the first instinct is to chase dependency/env issues instead of an encoding bug. On my side this cost several hours.
Repro that actually surfaces the error (a plain venv-python import passes on a dev box and will mislead you): replicate the runtime bootstrap, then import the plugin directly —
import os, sys
os.environ.pop('PYTHONHOME', None); os.environ.pop('PYTHONPATH', None); os.environ.pop('VIRTUAL_ENV', None)
sys.path.insert(0, r"C:\Users\<user>\AppData\Local\hermes\hermes-agent")
import hermes_bootstrap
import importlib.util
spec = importlib.util.spec_from_file_location("hindsight_probe", r"...\plugins\hindsight\__init__.py",
submodule_search_locations=[r"...\plugins\hindsight"])
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod) # <- UnicodeDecodeError here
Fix (verified — after patching, _discover_memory_provider_statuses() returns available: true / status: ready in the runtime-shaped probe):
- text = (Path(__file__).resolve().parent / "plugin.yaml").read_text()
- except OSError:
+ text = (Path(__file__).resolve().parent / "plugin.yaml").read_text(encoding="utf-8")
+ except (OSError, UnicodeError):
Note the except OSError doesn't even catch this (UnicodeDecodeError is a ValueError), so the "graceful fallback to 0.0.0" intent never triggers — widening the except is worth doing in the same patch.
Suggestion: this is the third GBK-locale file-read bug in this repo family (#3747, #3837, #4344 are the same class). A repo-wide audit for bare read_text() / open(...) without encoding= (production code, not tests) would close the class; on the hermes plugin only line 94 is affected today.
Confirming on Windows 11 / zh-CN (cp936) / plugin 1.2.3 (d952b6e) in local_embedded mode — every report above is local_external or self-hosted, so here is the embedded path, plus two follow-on failures that the import fix alone does not clear.
1. The import crash also prevents the profile env from ever being written
local_embedded needs ~/.hindsight/profiles/hermes.env (HINDSIGHT_API_LLM_PROVIDER/API_KEY/MODEL/BASE_URL). That file is produced by the plugin. Because __init__.py dies at import (line 103 _USER_AGENT = f"hindsight-hermes/{_plugin_version()}"), the plugin never reaches the point where it builds that env, so it stays 0 bytes.
Consequence for anyone applying only the two-line import fix: hermes memory status flips to installed ✓ / available ✓, but hindsight-embed -p hermes daemon start still fails, because the daemon has no LLM settings. The profile env has to be generated (hermes memory setup) or written by hand before local_embedded can start. Worth calling out in the fix's release note — otherwise the symptom just moves one step later.
2. uvx is not on PATH, so the daemon start fails separately
With no hindsight-api binary installed, hindsight-embed falls back to:
uvx [email protected] --idle-timeout 0 --port 9177
On a Hermes package-manager install this fails with Command not found: uvx. Hermes ships its own uvx.exe under $HERMES_HOME/tools/uv-0.12.3-win32-x64/, but that directory is not on PATH. The plugin's _managed_uvx_dir() fixes PATH for the spawn path the plugin itself owns, so a session-driven start works; a direct hindsight-embed ... daemon start (which is what the docs tell a user to run, and what a user does when debugging) does not. Copying uv.exe + uvx.exe next to a PATH directory resolved it here.
Also, HINDSIGHT_DEFAULT_LOCAL_URL in hermes-memory-ui and the README both assume :8888, but the shipped daemon came up on :9177. On this host :8888 is taken by an unrelated container, so the documented default is misleading for anyone who resolves the endpoint from the README rather than from the SDK manager.
3. Verified end-to-end after the patch
Same two-line change as in the diff above. With it applied, local_embedded runs green on the embedded PostgreSQL:
GET /health→{"status":"healthy","database":"connected"}- retain (LLM extraction through an OpenAI-compatible endpoint,
glm-5.3-flash):{"result": "Memory queued for storage."}, thenSTREAMING RETAIN COMPLETE: 1 units across 1 batches, extracted fact plus entities hindsight_recallreturns the fact withsemantic 0.53hermes plugins doctor hindsight→ import, manifest parse and registration all pass
So the encoding fix is necessary and sufficient for loading; it is just not sufficient for local_embedded to boot, for the reason in §1.
Cross-referencing #5554: the catalog still pins hindsight-client/hindsight-embed 0.10.1 while 0.10.3 is current, so a catalog install lands one minor behind the versions this report was verified against.