Repository navigation
Python: fix(redis): prefer an injected history client over connection settings - #9977
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits intoNov 3, 2026
Conversation
… settings RedisHistoryProvider treated redis_client, redis_url and credential_provider as mutually exclusive, so a working caller-owned client could not be passed alongside any other connection source without construction raising. Those settings describe how to build a client. When one is supplied there is nothing to build and nothing to validate. An injected client now takes precedence. redis_url, credential_provider, host, port, ssl and username are ignored rather than treated as a conflict, and they are only validated when the provider creates a client itself. The checks that describe the client rather than its construction still run, so a borrowed client must still be a standalone redis.asyncio.Redis with decode_responses=True, and its lifetime stays with the caller: aclose leaves it open. This is the precedence the Redis vector stores already apply in _create_client, which bypasses URL and env settings entirely once a client is injected. Provider-level storage settings are untouched, so key scope, key_format and retention behave exactly as before in both modes. self.redis_url now reports the source the provider actually used, so it is None when a client was injected rather than advertising a URL that was never opened. Owned-client construction is unchanged, including the existing errors for a missing source, for redis_url alongside credential_provider, and for a credential provider without a host. Fixes microsoft#9966
Yufeng He (he-yufeng)
temporarily deployed
to
github-app-auth
November 2, 2026 14:13 — with
GitHub Actions
Inactive
Yufeng He (he-yufeng)
requested review from
Darren Cohen (dargilco),
Jose Alvarez (jpalvarezl) and
sophia-ramsey
as code owners
November 2, 2026 14:13
Yufeng He (he-yufeng)
temporarily deployed
to
github-app-auth
November 2, 2026 14:13 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The package guide still documents the removed restriction, and tests omit borrowed-client cases that would catch lingering owned-client validation.
2 open issues
What changed in this PR
This PR addresses #9966 by making RedisHistoryProvider prefer an injected Redis client over redundant connection settings, aligning it with the package’s vector stores.
Changes:
- Limits connection-source validation to provider-created clients while retaining injected-client compatibility checks and caller ownership.
- Sets
redis_urltoNonewhen an injected client is used and documents the precedence behavior. - Adds regression tests for client precedence, compatibility checks, and provider scoping and retention settings.
| File | Description |
|---|---|
python/packages/redis/tests/test_providers.py |
Adds coverage for injected-client precedence and preserved provider settings. |
python/packages/redis/agent_framework_redis/_history_provider.py |
Updates connection validation, URL reporting, and constructor documentation. |
Review effort: Balanced
Yufeng He (he-yufeng)
temporarily deployed
to
github-app-auth
November 3, 2026 00:16 — with
GitHub Actions
Inactive
Yufeng He (he-yufeng)
temporarily deployed
to
github-app-auth
November 3, 2026 00:17 — with
GitHub Actions
Inactive
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 3, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation & Context
RedisHistoryProvidertreatsredis_client,redis_urlandcredential_provideras mutually exclusive, so a working caller-owned client cannot be passed alongside any other connection source without construction raisingredis_client, redis_url, and credential_provider are mutually exclusive. A caller that already has a configured client has to know to strip the settings it also passes everywhere else, and a config layer that always forwards a URL breaks the moment a test or a deployment injects a client.Those settings describe how to build a client. When one is supplied there is nothing to build and nothing to validate, so supplying them is redundant rather than conflicting. The Redis vector stores already behave this way:
_create_clientbypasses URL and.envsettings entirely once aredis_clientis injected, and only runs the checks that describe the client itself. The history provider is the odd one out in the same package.Fixes #9966, which is labelled
ready-for-implementationand lists focused acceptance tests. No other PR is open for it.Description & Review Guide
What are the major changes?
An injected
redis_clienttakes precedence overredis_url,credential_provider,host,port,sslandusername. Those are ignored rather than treated as a conflict, and they are validated only in the branch that builds a client. A borrowed client must still be a standaloneredis.asyncio.Rediswithdecode_responses=True; those checks describe the client rather than its construction, so they still run in both modes.aclosestill leaves a borrowed client open, which was already true and is now pinned alongside the redundant settings.self.redis_urlnow reports the source the provider actually used. When a client was injected it isNone, because a URL passed alongside it was never opened and advertising it would claim a connection that was not made. This mirrorstest_credential_provider_with_host, which already assertsredis_url is Nonewhen the credential path builds the client.The package guide now documents the same precedence. Constructor coverage includes a credential provider without a host and URL plus credential provider alongside a borrowed client, proving that neither owned-client validation remains active. All four precedence cases fail against the current upstream base and pass with this change.
What is the impact of these changes?
Beta construction stops raising for redundant connection sources and matches the vector-store behaviour in the same package. Owned-client construction is unchanged: the errors for no source at all, for
redis_urlalongsidecredential_provider, and for a credential provider without ahostall still fire exactly as before. Provider-level storage settings, meaningkey_prefix,key_format, the scoped identifiers andmax_messages, are untouched and keep working in both modes.What do you want reviewers to focus on?
Whether ignoring the connection settings outright is the behaviour you want, versus validating them for consistency and then discarding. I went with ignore, since validating settings that cannot be used turns a redundant argument into a source of spurious failures, and the issue asks for them to be checked only when a client is created. The
self.redis_url is Nonechoice is the same reasoning and is the one place where a caller could observe a difference beyond construction not raising.Related Issue
Fixes #9966
AI Assistance
AI assistance details: implementation, tests and this description. The change was written, run and checked locally before submission.
Contribution Checklist
pytest packages/redis/tests, 335 passed, 58 skipped)ruff checkandruff format --checkare clean on both touched Python files