fix(hindsight): respect bank document storage policy - #84819
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a Hindsight memory-provider bug where Hermes incorrectly enables update_mode="append" based only on API version, even when the effective target bank policy disables store_document_text. It extends capability detection to consider per-bank storage policy (where supported), scopes capability caching by (api_url, bank_id), and adds regression tests to cover multi-turn cumulative retains when append must be avoided.
Changes:
- Replace version-only append capability detection with
(api_version, features)probing and per-bank policy checks when applicable. - Scope append capability caching by
(api_url, bank_id)to respect per-bank override differences. - Add regression tests covering text-disabled banks, bank-isolated caching, and safe fallback when bank policy cannot be established.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| plugins/memory/hindsight/init.py | Updates append capability probing to incorporate per-bank document-text storage policy and bank-aware caching. |
| tests/plugins/memory/test_hindsight_provider.py | Adds regression coverage for non-append cumulative retains and cache isolation across banks. |
Suppressed comments (3)
plugins/memory/hindsight/init.py:213
- The /version probe sets the Authorization header to a literal "******" instead of sending the configured API key. This will cause capability detection to fail on deployments that require auth for /version, and can incorrectly disable append (or force fallback behavior).
This issue also appears in the following locations of the same file:
- line 240
- line 272
req = urllib.request.Request(url)
if api_key:
req.add_header("Authorization", f"Bearer {api_key}")
try:
with urllib.request.urlopen(req, timeout=timeout) as resp: # noqa: S310
payload = resp.read().decode("utf-8", errors="replace")
plugins/memory/hindsight/init.py:246
- The bank config probe also sends a literal "******" Authorization header instead of the real API key, which will cause the per-bank policy fetch to fail on authenticated servers and incorrectly disable append for modern APIs.
url = api_url.rstrip("/") + f"/v1/default/banks/{encoded_bank_id}/config"
req = urllib.request.Request(url)
if api_key:
req.add_header("Authorization", f"Bearer {api_key}")
try:
with urllib.request.urlopen(req, timeout=timeout) as resp: # noqa: S310
data = json.loads(resp.read().decode("utf-8", errors="replace"))
plugins/memory/hindsight/init.py:276
- The per-bank config probe for >=0.8.6 runs unconditionally, but the PR description indicates this should be gated on the API advertising bank-config support (e.g. /version.features.bank_config_api). Without that gate, a server that supports append but does not expose the bank-config endpoint (or disables it) will be forced into the non-append fallback for all banks.
if supported and _meets_minimum_version(
version, _MIN_VERSION_FOR_BANK_DOCUMENT_TEXT_POLICY
):
bank_config = _fetch_hindsight_bank_config(api_url, bank_id, api_key)
resolved = bank_config.get("config") if isinstance(bank_config, dict) else None
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
The CI retry on |
fix(hindsight): respect bank document storage policy
|
126d57c to
508c2b3
Compare
|
Thanks for the review. I rebased the PR onto current
The latest commit also adds exact boundary-value coverage:
Local verification on the rebased head:
Fresh exact-head CI is complete:
There is no observed code or test failure on the updated head. The remaining handoff is maintainer review/label and rerunning the failed infrastructure job. |
508c2b3 to
f646f39
Compare
f646f39 to
cd02cc9
Compare
|
Rebased onto current Current exact state:
Verification on the rebased head:
No code or CI blocker remains on the updated head; the PR is ready for maintainer review. |
Summary
store_document_textpolicy on APIs that support per-bank overridesCloses #84805.
Related Hindsight work:
store_document_textoverridable per bankProblem
Hermes currently treats Hindsight API version
>= 0.5.0as sufficient forupdate_mode="append". Append also requires previously stored document text. On a bank whose effectivestore_document_textpolicy isfalse, the first retain can create a document but later retains for the same Hermes session are rejected because there is no prior source text to append to.This breaks the supported data-minimizing use case of retaining derived memories without persisting raw source documents. The agent turn itself can still complete, so the missing retained turns can be silent unless operation status is inspected.
Approach
/versioninto the API version plus feature flagsconfig.store_document_text is truebefore enabling appendstore_document_text: false; missing keys predate this policy flag and preserve historical append behavior/versionexplicitly reports that API disabled(api_url, bank_id)so banks with different overrides do not share a capability decision, bounded to 256 entries for templated-bank gateway processesThe fallback does not send
update_mode;sync_turn()already resends all accumulated turns on that path, preserving order without requiring stored source text.Verification
store_document_text: trueandfalsepython -m pytest tests/plugins/memory/test_hindsight_provider.py::TestUpdateModeAppendCapability -q -o 'addopts='— 12 passedpython -m pytest tests/plugins/memory/ -q -o 'addopts=' -k 'not test_get_client_passes_idle_timeout_to_hindsight_embedded'— 359 passed, 1 deselecteduvx --from ruff==0.15.10 ruff check plugins/memory/hindsight/__init__.py tests/plugins/memory/test_hindsight_provider.py— passedpython -m compileall -q plugins/memory/hindsight/__init__.py tests/plugins/memory/test_hindsight_provider.py— passedgit diff --check— passed/version.api_version,features.bank_config_api, and that the bank-config endpoint returns a fully resolvedconfigplusoverridesThe one locally deselected test fails identically on current upstream
mainbecause the validation venv hashindsight-client==0.8.6while that checkout's lazy-dependency manifest still pins0.6.1; it does not touch the changed capability path. Fresh exact-head CI is the authoritative full-suite gate.Risk and compatibility
< 0.5.0remains on the existing non-append fallback0.5.0through0.8.5retains legacy append behavior unless its server feature explicitly disables document-text storage>= 0.8.6uses resolved per-bank policy and safely falls back if that policy cannot be queried