Skip to content

Python: Preserve injected Cosmos memory client configuration ownership - #9990

Open
Shashwat Gupta (LionStone-1) wants to merge 2 commits into
microsoft:mainfrom
LionStone-1:fix/cosmos-memory-injected-client-ownership
Open

Shashwat Gupta (LionStone-1) wants to merge 2 commits into
microsoft:mainfrom
LionStone-1:fix/cosmos-memory-injected-client-ownership

Conversation

@LionStone-1

Copy link
Copy Markdown

Motivation & Context

A preconfigured AsyncCosmosMemoryClient should retain its own configuration when passed to CosmosMemoryContextProvider. Currently, supplying processor cadence options raises during construction, and prompts_dir replaces the supplied client's pipeline loader on entry.

Description & Review Guide

  • What are the major changes? Evaluate cadence options only when constructing a client, ignore prompts_dir for caller-owned clients, and document the injection contract. Regression tests cover ignored construction options, unchanged provider retrieval settings, prompt isolation, and lifecycle ownership.
  • What is the impact of these changes? Injected clients keep their configuration. Provider-created clients still receive cadence and prompt settings. Exiting the provider continues to flush background work without closing caller-owned clients.
  • What do you want reviewers to focus on? Client ownership and the boundary between client construction options and provider retrieval settings.

Related Issue

Fixes #9963

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: OpenAI Codex assisted with issue analysis, implementation, regression tests, documentation, local verification and this draft. The contributor has confirmed personal review, understanding, and responsibility for the change.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • Affected package unit tests pass; regression coverage added (58 passed, 12 live integration tests excluded).
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • 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.

Verification details

The four regressions fail against the original implementation. The final package suite passes 58 unit tests; 12 live integrations were not run. Source/test Pyright checks report zero errors. Ruff formatting passes; lint passes with RUF100 excluded because an existing unused suppression also occurs on the unchanged baseline. No dependency or lockfile changes and no cloud requests.

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.

🟡 Changes recommended

The emulator prompt regression test still combines an injected client with prompts_dir, so the new gate skips its custom template and the marker assertion fails once setup succeeds.

1 open issue
What changed in this PR

This PR addresses #9963 by preserving caller-owned client configuration in the Python Cosmos memory provider while keeping provider-level retrieval settings unchanged.

Changes:

  • Apply cadence and custom prompt settings only to provider-created clients.
  • Document injected-client configuration and lifecycle ownership.
  • Add regression coverage for ignored construction options, prompt isolation, retrieval settings, and flushing without closing injected clients.
File Description
python/​packages/​azure-cosmos-memory/​tests/​test_context_provider.py Adds ownership regressions and updates prompt tests for provider-created clients.
python/​packages/​azure-cosmos-memory/​README.md Explains ignored options and caller responsibility for closing injected clients.
python/​packages/​azure-cosmos-memory/​agent_framework_azure_cosmos_memory/​_context_provider.py Restricts cadence and prompt configuration to provider-created clients and updates documentation.

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues are recorded for the change preserving caller-owned configuration in injected clients.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch was previously deployed

1 inactive deployment
github-app-auth — c94f6de1 Deployed Nov 2, 2026 by LionStone-1 via add_label #26886
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.

Python: [Bug]: Cosmos memory provider does not preserve injected-client configuration ownership

2 participants