Skip to content

.NET: Add FileAccessProvdider and concurrency fix for FileMemoryProvider - #5583

Merged
westey (westey-m) merged 3 commits into
microsoft:feature-harnessfrom
westey-m:harness-fileaccessprovider-and-concurrency
Apr 30, 2026
Merged

.NET: Add FileAccessProvdider and concurrency fix for FileMemoryProvider#5583
westey (westey-m) merged 3 commits into
microsoft:feature-harnessfrom
westey-m:harness-fileaccessprovider-and-concurrency

Conversation

@westey-m

Copy link
Copy Markdown
Contributor

Motivation and Context

Description

  • Add a FileAccessProvider with a sample to show it's usage
  • Fix a concurrency issues in FileMemoryProvider

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@moonbox3Evan Mattson (moonbox3) added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net labels Apr 30, 2026
@github-actionsgithub-actionsBot changed the title Add FileAccessProvdider and concurrency fix for FileMemoryProvider.NET: Add FileAccessProvdider and concurrency fix for FileMemoryProviderApr 30, 2026
@westey-m
westey (westey-m) marked this pull request as ready for review April 30, 2026 11:16
CopilotAI review requested due to automatic review settings April 30, 2026 11:16

@github-actionsgithub-actionsBot 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.

Automated Code Review

Reviewers: 4 | Confidence: 90%

✓ Correctness

This PR adds a new FileAccessProvider for shared file access, adds thread safety (SemaphoreSlim write lock + IDisposable) to FileMemoryProvider, reorganizes file store classes into a dedicated FileStore directory, and adds a data processing sample. The code is correct: path traversal protection is properly delegated to StorePaths.NormalizeRelativePath, the write lock correctly serializes save/delete operations with index rebuilds, AsyncLocal-backed CurrentRunContext ensures concurrent tests are safe, and the new provider is a clean, minimal wrapper. No correctness issues found.

✓ Security Reliability

This PR adds a new FileAccessProvider for shared file access and improves FileMemoryProvider with a SemaphoreSlim write lock for thread safety. Security-critical areas look solid: path traversal is blocked by StorePaths.NormalizeRelativePath() (rejects .., absolute paths, drive roots) and FileSystemAgentFileStore.ResolveSafePath() (full-path prefix check). Regex from LLM-sourced tool calls has a 5-second timeout in both store implementations to mitigate ReDoS. The SemaphoreSlim is properly guarded with try/finally and disposed via the new IDisposable implementation. No security or reliability issues identified.

✓ Test Coverage

The PR adds a new FileAccessProvider with comprehensive test coverage (577 lines) covering all five tools, constructor validation, path traversal protection, and options. FileMemoryProvider gains IDisposable and a SemaphoreSlim write lock with corresponding thread-safety tests. Test coverage is solid overall with only minor gaps: no test for subdirectory paths through FileAccessProvider tools (e.g., 'reports/summary.md'), and the Dispose test only verifies idempotent dispose without checking post-dispose operation behavior. No blocking issues found.

✓ Design Approach

The change mostly moves the file-store abstraction in a sensible direction, but two design choices look off: the new sample teaches a least-privilege-violating pattern by mounting its bundled input data as a fully mutable store, and the new FileAccessProvider exposes an internally inconsistent contract where agents can write nested paths they cannot later discover via list/search. Both issues are about the chosen abstraction boundary rather than implementation details.


Automated review by westey-m's agents

CopilotAI 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.

Pull request overview

This PR introduces a new FileAccessProvider (plus a harness sample) to give agents persistent/shared file tooling, and adds new AgentFileStore implementations to support file operations. It also updates FileMemoryProvider to address a concurrency issue during writes/index rebuilds.

Changes:

  • Added AgentFileStore abstraction with InMemoryAgentFileStore and FileSystemAgentFileStore, plus shared path/glob utilities (StorePaths) and search result models.
  • Added FileAccessProvider (+ options) and comprehensive unit tests, along with a new harness sample (Harness_Step03_DataProcessing).
  • Fixed FileMemoryProvider concurrent write/index rebuild behavior via a write lock and added thread-safety tests.

Reviewed changes

Copilot reviewed 11 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
dotnet/src/Microsoft.Agents.AI/Harness/FileStore/AgentFileStore.csNew base abstraction for agent file operations
dotnet/src/Microsoft.Agents.AI/Harness/FileStore/StorePaths.csShared normalization + glob matching helpers
dotnet/src/Microsoft.Agents.AI/Harness/FileStore/InMemoryAgentFileStore.csIn-memory AgentFileStore implementation with search support
dotnet/src/Microsoft.Agents.AI/Harness/FileStore/FileSystemAgentFileStore.csDisk-backed AgentFileStore implementation with traversal protection + search
dotnet/src/Microsoft.Agents.AI/Harness/FileStore/FileSearchResult.csDTO for search results
dotnet/src/Microsoft.Agents.AI/Harness/FileStore/FileSearchMatch.csDTO for per-line matches
dotnet/src/Microsoft.Agents.AI/Harness/FileAccess/FileAccessProvider.csNew provider exposing persistent file tools to agents
dotnet/src/Microsoft.Agents.AI/Harness/FileAccess/FileAccessProviderOptions.csOptions for FileAccessProvider instructions
dotnet/src/Microsoft.Agents.AI/Harness/FileMemory/FileMemoryProvider.csConcurrency fix: serialize writes/index rebuild; implements IDisposable
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileStore/StorePathsTests.csUnit tests for StorePaths normalization/globbing
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileStore/InMemoryAgentFileStoreTests.csUnit tests for in-memory store behavior/search
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileStore/FileSystemAgentFileStoreTests.csUnit tests for file-system store behavior/search
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileMemory/FileMemoryProviderTests.csAdded concurrency + dispose tests for FileMemoryProvider
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileAccess/FileAccessProviderTests.csUnit tests for FileAccessProvider tools/instructions
dotnet/samples/02-agents/Harness/README.mdRegisters new Step03 sample in harness index
dotnet/samples/02-agents/Harness/Harness_Step03_DataProcessing/Program.csNew sample wiring FileAccessProvider over a data folder
dotnet/samples/02-agents/Harness/Harness_Step03_DataProcessing/README.mdSample walkthrough and setup
dotnet/samples/02-agents/Harness/Harness_Step03_DataProcessing/data/sales.csvSample dataset shipped to output
dotnet/samples/02-agents/Harness/Harness_Step03_DataProcessing/Harness_Step03_DataProcessing.csprojNew sample project
dotnet/agent-framework-dotnet.slnxAdds the new sample project to the solution

Comment threaddotnet/src/Microsoft.Agents.AI/Harness/FileAccess/FileAccessProvider.cs Outdated
@westey-m
westey (westey-m) merged commit 0295b4c into microsoft:feature-harnessApr 30, 2026
18 of 21 checks passed
pullBot pushed a commit to nagyist/ms-agent-framework that referenced this pull request May 1, 2026
* .NET: Add a TODO AIContextProvider (microsoft#5233)
* Add a TODO AIContextProvider
* Add unit tests
* Address PR comments
* Address PR comments
* Fix test after removing one tool
* .NET: Add a ModeProvider for managing agent modes (microsoft#5247)
* Add a ModeProvider for managing agent modes
* Fix typo
* Fix typo
* Fix typo
* Address PR comments
* .NET: Add sample to show how to build a harness (microsoft#5268)
* Add sample to show how to build a harness
* Improve sample
* Sample max output tokens and model
* Fix encoding
* Fix model name in readme
* Address PR comments
* .NET: Add context window size compaction strategy for harness (microsoft#5304)
* Add context window size compaction strategy for harness
* Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Address PR comments
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* .NET: Add a file memory provider (microsoft#5315)
* Add a file memory provider
* Address PR comments
* Fix review comments.
* Add additional unit tests
* Addressing PR comments.
* .NET: Harness: Improve prompts and add FileSystem store (microsoft#5365)
* Harness: Improve prompts and add FileSystem store
* Address PR comments
* .NET: Harness: Improve path validation (microsoft#5404)
* Harness: Improve path validation
* Address PR comments
* .NET: Add always approve helpers, improve sample and fix bug (microsoft#5451)
* Add always approve helpers, improve sample and fix bug
* Address PR comments
* .NET: Make Todo, Mode and FileMemory providers more configurable (microsoft#5477)
* Make Todo, Mode and FileMemory providers more configurable
* Address PR comments.
* .NET: Add subagents provider and sample (microsoft#5518)
* Add subagents provider and sample
* Addressing PR comments.
* .NET: Harness filememory index plus instructions consistency (microsoft#5540)
* Add FileMemoryProvider index and improve instruction consistency
* Address PR comments.
* Address PR comments
* Address PR comments.
* Apply suggestion from @rogerbarreto
Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
---------
Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
* .NET: Refactor harness console to be more extensible and easy to understand with better UX (microsoft#5573)
* Refactor harness console to be more extensible and easy to understand with better UX.
* Fix formatting issues.
* Allow multiple clarifications in one response
* Address PR comments
* .NET: Add FileAccessProvdider and concurrency fix for FileMemoryProvider (microsoft#5583)
* Add FileAccessProvdider and concurrency fix for FileMemoryProvider
* Address PR comments
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationUsage: [Issues, PRs], Target: documentation in the code base and learn docs.NETUsage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@westey-m@lokitoth@SergeyMenshykh@moonbox3