Skip to content

The agent that grows with you

fix(hindsight): accept HINDSIGHT_API_LLM_API_KEY vault name in key resolution

red4711778ad6101701
diff --git a/plugins/memory/hindsight/embedded.py b/plugins/memory/hindsight/embedded.py
index 780836f6b25..1a4ffa433a3 100644
--- a/plugins/memory/hindsight/embedded.py
+++ b/plugins/memory/hindsight/embedded.py
@@ -131,8 +131,12 @@ def _embedded_llm_api_key(config: dict[str, Any]) -> str:
"""
if config.get("llmApiKey") or config.get("llm_api_key"):
return config.get("llmApiKey") or config.get("llm_api_key")
+ # NOTE: the vault item is named HINDSIGHT_API_LLM_API_KEY (matching the
+ # daemon's env var), not HINDSIGHT_LLM_API_KEY (the setup-wizard name).
+ # Accept both so vault-fed scopes resolve regardless of which name the
+ # secret source carries.
try:
- scoped = get_secret("HINDSIGHT_LLM_API_KEY", "")
+ scoped = get_secret("HINDSIGHT_API_LLM_API_KEY", "") or get_secret("HINDSIGHT_LLM_API_KEY", "")
except UnscopedSecretError:
# Multiplexed gateway with no profile scope on this thread: never let
# a missing scope read os.environ (another profile's key may live
diff --git a/tests/plugins/memory/test_hindsight_env_perms.py b/tests/plugins/memory/test_hindsight_env_perms.py
index 56ec337d0d6..ff5634b8e4c 100644
--- a/tests/plugins/memory/test_hindsight_env_perms.py
+++ b/tests/plugins/memory/test_hindsight_env_perms.py
@@ -192,6 +192,20 @@ def test_rewrite_allowed_when_build_carries_key():
assert "HINDSIGHT_API_LLM_API_KEY=sk-new\n" in profile_env.read_text(encoding="utf-8")
+def test_api_prefixed_vault_name_resolves(monkeypatch):
+ """The vault item is HINDSIGHT_API_LLM_API_KEY; the wizard name alone misses."""
+ from agent import secret_scope
+ import plugins.memory.hindsight.embedded as hs_embedded
+
+ token = secret_scope.set_secret_scope({"HINDSIGHT_API_LLM_API_KEY": "sk-test-live-key"})
+ monkeypatch.delenv("HINDSIGHT_LLM_API_KEY", raising=False)
+ monkeypatch.delenv("HINDSIGHT_API_LLM_API_KEY", raising=False)
+ try:
+ assert hs_embedded._embedded_llm_api_key(_CONFIG) == "sk-test-live-key"
+ finally:
+ secret_scope.reset_secret_scope(token)
+
+
def test_rewrite_allowed_when_no_key_anywhere(monkeypatch):
"""Keyless providers (ollama) must not brick: empty build + empty disk rewrites."""
from agent import secret_scope