Skip to content

Python: Allow RedisHistoryProvider to borrow a Redis client - #8883

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
eavanvalkenburg:redis-history-client
Sep 30, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
eavanvalkenburg:redis-history-client

Conversation

@eavanvalkenburg

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Motivation & Context

RedisHistoryProvider currently constructs and owns its Redis client, so applications cannot supply connection policies such as bounded timeouts and health checks, and cannot share an existing connection pool.

Description & Review Guide

  • What are the major changes? Added a keyword-only caller-provided async Redis client option, validated its required decoded-string response mode, and preserved provider ownership only for internally constructed clients. Added focused lifecycle and validation tests plus Redis package documentation.
  • What is the impact of these changes? Existing URL and credential-provider construction remains unchanged. Applications can now configure and own a Redis client while RedisHistoryProvider uses it without closing it. Retry behavior remains caller-controlled; the documentation notes that transcript appends are not idempotent across ambiguous write replays.
  • What do you want reviewers to focus on? The connection-source validation, decode_responses=True invariant, and owned-versus-borrowed close behavior.

Related Issue

Fixes #8764

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Retry-enabled clients can replay a committed transcript append and duplicate messages.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

This PR lets RedisHistoryProvider borrow an application-owned Redis client, so applications can configure transcript connections without changing existing URL or credential-provider construction.

Changes:

  • Add a keyword-only client option with connection-source and decoded-response validation.
  • Close only provider-owned clients, and add validation and lifecycle tests.
  • Document client configuration and ownership.
File Description
python/​packages/​redis/​tests/​test_providers.py Tests borrowed-client validation and close behavior.
python/​packages/​redis/​README.md Shows how to configure and close a borrowed client.
python/​packages/​redis/​AGENTS.md Documents the ownership contract.
python/​packages/​redis/​agent_framework_redis/​_history_provider.py Adds client borrowing and conditional closing.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/packages/redis/agent_framework_redis/_history_provider.py

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAF Automated Review — Iteration 1

Result: Findings reported
Scope: full PR (1 commit(s)): 249d6ae14431
Model: gpt-5.6-sol

Overview

The PR cleanly separates owned and borrowed Redis clients, rejects ambiguous connection sources and incompatible response decoding, and adds focused ownership tests and documentation. One residual risk remains: accepting caller retry policies without making transcript writes idempotent can replay a committed append after an ambiguous timeout, duplicating conversation history.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: python/packages/redis/agent_framework_redis/_history_provider.py

Comment thread python/packages/redis/agent_framework_redis/_history_provider.py

@jpalvarezl Jose Alvarez (jpalvarezl) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the Redis client ownership and cleanup changes. The implementation, validation, documentation, and tests look good to me.

Merged via the queue into microsoft:main with commit 4b0e3d8 Sep 30, 2026
46 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the redis-history-client branch September 30, 2026 11:37

This branch was previously deployed

1 inactive deployment
github-app-auth — 452e9ea9 Deployed Sep 30, 2026 by eavanvalkenburg via add_label #24082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Feature]: RedisHistoryProvider owns its client construction and exposes no connection options, so a host cannot bound transcript I/O

3 participants