Skip to content

.NET: Add AgentSessionStore.DeleteSessionAsync to the Abstraction - #8801

Open
Marco Minerva (marcominerva) wants to merge 3 commits into
microsoft:mainfrom
marcominerva:dotnet-readd-session-store-delete
Open

Marco Minerva (marcominerva) wants to merge 3 commits into
microsoft:mainfrom
marcominerva:dotnet-readd-session-store-delete

Conversation

@marcominerva

@marcominerva Marco Minerva (marcominerva) commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Bring session deletion operation to the shared AgentSessionStore abstract contract, so specialized stores also share a complete set of lifecycle methods. It was not initially considered when the abstractions moved to Agents.AI.Abstractions (#7991).

API and Abstraction Changes:

  • Added the abstract method DeleteSessionAsync to the AgentSessionStore base 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]
  • Updated the public API files for all supported .NET targets to include the new DeleteSessionAsync method.

Implementation Updates:

  • Implemented DeleteSessionAsync in all major agent session store classes, including FileSystemAgentSessionStore, FoundryAgentSessionStore, InMemoryAgentSessionStore (both Foundry and Local), AzureBlobAgentSessionStore, IsolationKeyScopedAgentSessionStore, and NoopAgentSessionStore. Each implementation ensures deletion is idempotent and handles resource-specific details. [1] [2] [3] [4] [5] [6] [7]

Documentation Updates:

  • Updated the architectural decision record and specification documents to describe the new deletion capability, its contract, and its impact on implementers and consumers. [1] [2] [3] [4]
  • Clarified documentation for DelegatingAgentSessionStore to note that delete operations are now forwarded to the inner store by default.

Fixes #8586

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

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

Filesystem deletion can silently succeed without deleting an inaccessible stored session, and Foundry in-memory deletion lacks direct coverage.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

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 DeleteSessionAsync to 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.
Comment on lines +254 to +257
catch (DirectoryNotFoundException)
{
// No directory for this agent means nothing was ever stored.
}

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.

Check if the directory exists instead of relying in the exception to ignore it.

Comment on lines +200 to +203
catch (FoundryStorageNotFoundException)
{
// Nothing stored for this key, so deletion remains idempotent.
}

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.

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.

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.

Please also include UT validating the Logs were emitted.

Comment on lines +137 to +140
catch (RequestFailedException ex) when (ex.ErrorCode == BlobErrorCode.ContainerNotFound.ToString())
{
// A missing container cannot contain the requested session, so deletion remains idempotent.
}

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.

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?

Comment on lines +74 to +75
ArgumentNullException.ThrowIfNull(agent);
ArgumentNullException.ThrowIfNull(key);

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.

nit, for consistency (check any other change on this PR)

Suggested change
ArgumentNullException.ThrowIfNull(agent);
ArgumentNullException.ThrowIfNull(key);
_ = Throw.IfNull(agent);
_ = Throw.IfNull(key);

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.

Overall LGTM, some comments

Comment on lines +200 to +203
catch (FoundryStorageNotFoundException)
{
// Nothing stored for this key, so deletion remains idempotent.
}

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.

Please also include UT validating the Logs were emitted.

@rogerbarreto Roger Barreto (rogerbarreto) changed the title .NET: Re-add AgentSessionStore.DeleteSessionAsync .NET: Add AgentSessionStore.DeleteSessionAsync to the Abstraction Sep 29, 2026

This branch was successfully deployed

2 active deployments
github-app-auth — c40748fa Deployed Sep 29, 2026 by rogerbarreto via add_label #23934
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 .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Why has DeleteSessionAsync been removed from AgentSessionStore?

3 participants