Repository navigation
Python: keep Foundry injected clients caller-owned on cleanup - #10000
Open
NingLin Liu (ninglinLiu) wants to merge 3 commits into
Open
NingLin Liu (ninglinLiu) wants to merge 3 commits into
NingLin Liu (ninglinLiu) wants to merge 3 commits into
Conversation
NingLin Liu (ninglinLiu)
requested review from
SergeyMenshykh,
Eduard van Valkenburg (eavanvalkenburg) and
Roger Barreto (rogerbarreto)
as code owners
November 3, 2026 00:45
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
November 3, 2026 00:45 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
requested review from
Darren Cohen (dargilco),
Jose Alvarez (jpalvarezl),
sophia-ramsey and
westey (westey-m)
as code owners
November 3, 2026 00:45
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
November 3, 2026 00:46 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Direct imports of typing.Self break package imports and test collection on supported Python 3.10, and two existing lifecycle tests fail because their expectations no longer match injected-client behavior.
3 open issues
What changed in this PR
This PR addresses #9964 by preserving caller ownership of injected SDK clients in the Python Foundry embedding and memory integrations.
Changes:
- Tracks ownership of embedding transports and closes only wrapper-owned clients.
- Limits memory-provider context management to internally created project clients.
- Documents ownership behavior and adds injected-client lifecycle regression tests.
| File | Description |
|---|---|
python/packages/foundry/tests/foundry/test_foundry_injected_client_lifecycle.py |
Adds tests that injected clients are not closed or entered/exited. |
python/packages/foundry/agent_framework_foundry/_memory_provider.py |
Guards project-client lifecycle calls by ownership and documents the contract. |
python/packages/foundry/agent_framework_foundry/_embedding_client.py |
Tracks text/image client ownership and guards cleanup accordingly. |
Review effort: Balanced
| import sys | ||
| from contextlib import AbstractAsyncContextManager | ||
| from typing import TYPE_CHECKING, Any, ClassVar | ||
| from typing import TYPE_CHECKING, Any, ClassVar, Self, TypedDict |
| clients remain caller-owned. | ||
| """ | ||
| if ( | ||
| self._owns_project_client |
Comment on lines
+6
to
+9
| from typing import Any, Self | ||
| from unittest.mock import AsyncMock | ||
|
|
||
| import pytest |
… tests Keep the version-gated typing_extensions Self and TypedDict import so FoundryMemoryProvider loads on Python 3.10, import Self from typing_extensions in the injected-client lifecycle tests, and construct the aenter/aexit delegation tests through a patched AIProjectClient. Co-authored-by: NingLin Liu <x07514475479@gmail.com>
Import Self from typing so pyupgrade --py311-plus leaves the lifecycle test unchanged, and assert injected project-client entry and exit against patched AsyncMocks. Co-authored-by: NingLin Liu <x07514475479@gmail.com>
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.

Fixes #9964
Description
RawFoundryEmbeddingClient.close()no longer closes caller-suppliedtext_client/image_client.FoundryMemoryProviderno longer enters/exits an injectedproject_client. Only clients created by the wrappers are lifecycle-managed.Tests
Added focused unit tests for injected embedding and memory client ownership.
AI assistance: used an AI coding assistant to implement and draft this change. I reviewed the diff.