.NET: Add AgentSessionStore.DeleteSessionAsync to the Abstraction - #8801
Marco Minerva (marcominerva) wants to merge 3 commits into
Conversation
Bring session deletion back to the shared AgentSessionStore contract, so the store handles a session's whole lifecycle again. It was removed when the abstraction moved to Agents.AI.Abstractions (microsoft#7991). [PREVIEW BREAKING] DeleteSessionAsync is abstract: custom stores must implement it. - In-box stores implement it; deleting a missing session is a no-op - Decorators forward it, adding the isolation partition when needed - Update PublicAPI.Unshipped.txt, unit tests, ADR-0039 and spec 003 Fixes microsoft#8586
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Filesystem deletion can silently succeed without deleting an inaccessible stored session, and Foundry in-memory deletion lacks direct coverage.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Restores session deletion to the shared .NET AgentSessionStore lifecycle contract and implements it across built-in stores.
Changes:
- Adds
DeleteSessionAsyncto the abstraction and API baselines. - Implements idempotent deletion across storage backends and decorators.
- Updates tests, specifications, and ADR documentation.
| File | Description |
|---|---|
dotnet/tests/Microsoft.Agents.AI.UnitTests/DelegatingAgentSessionStoreTests.cs |
Tests delete delegation. |
dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/IsolationKeyScopedAgentSessionStoreTests.cs |
Tests isolation-scoped deletion. |
dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/InMemoryAgentSessionStoreTests.cs |
Tests local and no-op deletion. |
dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/ResponseSessionRegressionTests.cs |
Updates test store implementation. |
dotnet/tests/Microsoft.Agents.AI.Hosting.AzureStorage.UnitTests/AzureBlobAgentSessionStoreTests.cs |
Tests blob deletion. |
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/ResilientTwoLifetimeIntegrationTests.cs |
Forwards deletion in test store. |
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/FoundryAgentSessionStoreTests.cs |
Tests Foundry deletion. |
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/FileSystemAgentSessionStoreTests.cs |
Tests filesystem deletion. |
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/AgentFrameworkResponseHandlerResilienceTests.cs |
Updates test implementations. |
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentSessionStoreTests.cs |
Updates abstraction test store. |
dotnet/src/Microsoft.Agents.AI/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt |
Records delegating API. |
dotnet/src/Microsoft.Agents.AI/PublicAPI/net9.0/PublicAPI.Unshipped.txt |
Records delegating API. |
dotnet/src/Microsoft.Agents.AI/PublicAPI/net8.0/PublicAPI.Unshipped.txt |
Records delegating API. |
dotnet/src/Microsoft.Agents.AI/PublicAPI/net472/PublicAPI.Unshipped.txt |
Records delegating API. |
dotnet/src/Microsoft.Agents.AI/PublicAPI/net10.0/PublicAPI.Unshipped.txt |
Records delegating API. |
dotnet/src/Microsoft.Agents.AI/DelegatingAgentSessionStore.cs |
Forwards delete operations. |
dotnet/src/Microsoft.Agents.AI.Hosting/NoopAgentSessionStore.cs |
Adds no-op deletion. |
dotnet/src/Microsoft.Agents.AI.Hosting/Local/InMemoryAgentSessionStore.cs |
Adds local-memory deletion. |
dotnet/src/Microsoft.Agents.AI.Hosting/IsolationKeyScopedAgentSessionStore.cs |
Applies isolation to deletion. |
dotnet/src/Microsoft.Agents.AI.Hosting.AzureStorage/Blob/AzureBlobAgentSessionStore.cs |
Deletes session blobs. |
dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/InMemoryAgentSessionStore.cs |
Adds Foundry-memory deletion. |
dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FoundryAgentSessionStore.cs |
Deletes Foundry state items. |
dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FileSystemAgentSessionStore.cs |
Deletes session files. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt |
Records shared API. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net9.0/PublicAPI.Unshipped.txt |
Records shared API. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net8.0/PublicAPI.Unshipped.txt |
Records shared API. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net472/PublicAPI.Unshipped.txt |
Records shared API. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net10.0/PublicAPI.Unshipped.txt |
Records shared API. |
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSessionStore.cs |
Defines deletion contract. |
docs/specs/003-dotnet-hosting-protocol-helpers.md |
Documents deletion behavior. |
docs/decisions/0039-shared-agent-session-store.md |
Updates lifecycle decision. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- FileSystemAgentSessionStore: delete without a File.Exists precheck so access and I/O failures surface; a missing agent directory stays a no-op. - Add unit tests for the Foundry InMemoryAgentSessionStore delete path.
| catch (DirectoryNotFoundException) | ||
| { | ||
| // No directory for this agent means nothing was ever stored. | ||
| } |
There was a problem hiding this comment.
Check if the directory exists instead of relying in the exception to ignore it.
| catch (FoundryStorageNotFoundException) | ||
| { | ||
| // Nothing stored for this key, so deletion remains idempotent. | ||
| } |
There was a problem hiding this comment.
Exceptions that are swallowed should have a log at least, lets bring a debug level logging or similar level we already have in the repo for exceptions that are ignored.
There was a problem hiding this comment.
Please also include UT validating the Logs were emitted.
| catch (RequestFailedException ex) when (ex.ErrorCode == BlobErrorCode.ContainerNotFound.ToString()) | ||
| { | ||
| // A missing container cannot contain the requested session, so deletion remains idempotent. | ||
| } |
There was a problem hiding this comment.
Similar as the other comment, please log the exception swelling when the container is not found, is this the only server error that could be gracefully handled?
| ArgumentNullException.ThrowIfNull(agent); | ||
| ArgumentNullException.ThrowIfNull(key); |
There was a problem hiding this comment.
nit, for consistency (check any other change on this PR)
| ArgumentNullException.ThrowIfNull(agent); | |
| ArgumentNullException.ThrowIfNull(key); | |
| _ = Throw.IfNull(agent); | |
| _ = Throw.IfNull(key); |
Roger Barreto (rogerbarreto)
left a comment
There was a problem hiding this comment.
Overall LGTM, some comments
| catch (FoundryStorageNotFoundException) | ||
| { | ||
| // Nothing stored for this key, so deletion remains idempotent. | ||
| } |
There was a problem hiding this comment.
Please also include UT validating the Logs were emitted.


Bring session deletion operation to the shared
AgentSessionStoreabstract contract, so specialized stores also share a complete set of lifecycle methods. It was not initially considered when the abstractions moved toAgents.AI.Abstractions(#7991).API and Abstraction Changes:
DeleteSessionAsyncto theAgentSessionStorebase class, requiring all implementations to provide a way to delete sessions. The method is documented to treat missing sessions as a no-op. [1] [2]DeleteSessionAsyncmethod.Implementation Updates:
DeleteSessionAsyncin all major agent session store classes, includingFileSystemAgentSessionStore,FoundryAgentSessionStore,InMemoryAgentSessionStore(both Foundry and Local),AzureBlobAgentSessionStore,IsolationKeyScopedAgentSessionStore, andNoopAgentSessionStore. Each implementation ensures deletion is idempotent and handles resource-specific details. [1] [2] [3] [4] [5] [6] [7]Documentation Updates:
DelegatingAgentSessionStoreto note that delete operations are now forwarded to the inner store by default.Fixes #8586