fix(hindsight): preserve existing key on blank local_embedded setup - #15309
fix(hindsight): preserve existing key on blank local_embedded setup#15309poruru-code wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a local_embedded setup regression in the Hindsight memory provider where leaving the LLM API key prompt blank could overwrite an existing key, by resolving and reusing the prior key from .env or the saved embedded profile env.
Changes:
- Preserve
HINDSIGHT_LLM_API_KEYwhen local_embedded setup key input is blank by falling back to$HERMES_HOME/.env, then the resolved embedded profile env. - Add a regression test covering preserve-on-blank behavior when the existing key is only present in a non-default embedded profile env.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
plugins/memory/hindsight/__init__.py |
Adds fallback resolution for an existing LLM API key during local_embedded post-setup to avoid wiping keys on blank input. |
tests/plugins/memory/test_hindsight_provider.py |
Adds a test ensuring blank key input preserves a key stored in a non-default embedded profile env. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Closing this as a duplicate of #15233. |
|
Salvaged into #15503 — your key preservation logic, config hardening, and test cases were cherry-picked onto current main with your authorship preserved. Combined with the masked-key UX from #15233. Thank you @poruru-code! |
Summary
This fixes a local_embedded setup bug in the Hindsight provider.
Re-running the setup wizard with a blank LLM API key input was wiping an existing key from the generated embedded profile env. This PR preserves the existing key instead of overwriting it with an empty value.
This is intended as a bugfix, not a new behavior change: the expected preserve-on-blank behavior was already covered by the existing post-setup test contract.
I split this out from the auto-prefetch tag redesign work so the fix can be reviewed independently.
The default preserve-on-blank expectation was already encoded in the existing post-setup test contract. This PR aligns the implementation with that contract, adds coverage for the non-default saved-profile fallback path, and hardens setup against malformed non-dict saved config.
Root Cause
In
plugins/memory/hindsight/__init__.py,HindsightMemoryProvider.post_setup()wrote an emptyHINDSIGHT_LLM_API_KEYinto the setup env writes, then rewrotehermes_home/.env, and only after that materialized the embedded profile env.That order destroyed the fallback source before the later profile-env materialization step could reuse it.
What Changed
HINDSIGHT_LLM_API_KEYwhen the local_embedded setup prompt is left blank.hermes_home/.env.hindsight/config.jsoncontent during setup recovery instead of crashing.How To Test
Run:
For a direct setup-path check, exercise
HindsightMemoryProvider.post_setup()in local_embedded mode with a blank key input and an existingcoder.env, and verify both the generated profile env andhermes_home/.envstill contain the existing key.Validation
Results:
existing-keyincoder.envon LinuxPlatforms Tested
Related