Repository navigation
fix(hindsight): validate and normalize api_url, fail fast on bad config - #78968
Realmagnum wants to merge 1 commit into
Conversation
ed3b349 to
fc0b2b6
Compare
PR #78968: fix(hindsight): validate and normalize api_url, fail fast on bad config
|
A schemeless api_url (e.g. "host:8888") made every hindsight_* tool fail with a cryptic "Failed to search memory: host:8888/v1/..." error because the client concatenates base_url + path into an invalid URL. - _normalize_api_url(): auto-add missing scheme (http for local modes, https for cloud) with a warning; reject invalid schemes (ftp://, ...) with an actionable error naming the config file - is_available(): return False and log the reason when api_url is invalid, so the provider is not registered at all - initialize(): disable the provider on invalid scheme (belt-and-braces) - handle_tool_call(): clear message when the provider is disabled - _diagnose_scheme_mismatch(): detect https-to-http local daemon mixups via a one-shot /version probe (local_external + https only) - tool errors now include the exception type Adds tests/plugins/memory/test_hindsight_api_url_normalization.py (27 tests).
fc0b2b6 to
14f6df0
Compare
|
Closing: the bundled Hindsight provider this PR patches has moved out of this repo. Thanks @Realmagnum for this contribution. In #119888 (merge Triage notes:
If you believe this was closed in error, comment and we will reopen. (Bulk-closed in the hindsight-move close pass.) |
Summary
Fixes #78967 — a schemeless
api_url(e.g."host:8888") made everyhindsight_*tool fail with a crypticFailed to search memory: host:8888/v1/...error, because the hindsight client concatenatesbase_url + pathinto an invalid URL and the plugin never validated the config.This PR makes the provider validate/normalize
api_urland fail fast with actionable messages:_normalize_api_url()— auto-adds a missing scheme (http://for local modes,https://for cloud) with a warning log, and rejects invalid schemes (ftp://, etc.) with an error naming the exact config file to fix.is_available()— validates the effectiveapi_urlup front; an invalid scheme returnsFalseand logs the reason, so the provider is never registered with broken tools (same philosophy as fix(hindsight): log why HindsightMemoryProvider fails to register instead of failing silently #35332).initialize()— disables the provider on an invalid scheme (belt-and-braces, mirroring the existing local-runtime-unavailable path).handle_tool_call()— returns a clear "provider is disabled, fix api_url in config.json" error instead of a cryptic URL failure._diagnose_scheme_mismatch()— forlocal_external+https://, probes/versiononce per session; if the configured scheme fails but the opposite one answers, logs the exact corrected URL (catches the commonhttps://-to-plain-HTTP-daemon mixup that passes validation).Failed to search memory: ValueError: ...).Tests
New file
tests/plugins/memory/test_hindsight_api_url_normalization.py(27 tests): normalization by mode, whitespace/empty handling, invalid-scheme rejection, provider disable,is_available()behavior, disabled-tool error, scheme-mismatch diagnosis (configured works / https-to-http / http-to-https / both down / non-http ignored), and a guard that plain-http://configs never touch the network during init.All existing hindsight tests pass (70 tests in
test_hindsight_provider.py,test_hindsight_config_schema.py,test_hindsight_env_perms.py,test_hindsight_health_grace_timeout.py,test_hindsight_root_guard.py).Compatibility
_load_config(); this PR validates the resolved URL, so it composes in either merge order).is_available()logging — touches a different branch; this PR does not modify the sharedexcepthandler).Test plan
pytest tests/plugins/memory/test_hindsight_api_url_normalization.py -o 'addopts=' -q→ 27 passedFixes #78967