-
Notifications
You must be signed in to change notification settings - Fork 944
.NET: Fix flaky vector store integration tests - race condition on indexing #2586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: rogerbarreto <[email protected]>
Co-authored-by: rogerbarreto <[email protected]>
Co-authored-by: rogerbarreto <[email protected]>
There was a problem hiding this comment.
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 fixes a race condition in two flaky integration tests that were failing intermittently because they queried vector stores immediately after creation, before asynchronous file indexing completed. The fix introduces polling logic to wait for indexing completion before proceeding with agent queries.
Key Changes:
- Added
WaitForVectorStoreReadyAsynchelper methods that poll vector store status every second (with 30s timeout) - Implemented status validation checking for
Completedstatus, zero failed files, and handlingExpiredstatus - Applied the fix to both OpenAI and Azure AI Agents integration tests
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| dotnet/tests/OpenAIAssistant.IntegrationTests/OpenAIAssistantClientExtensionsTests.cs | Added System.Diagnostics import, WaitForVectorStoreReadyAsync static helper method, and call to wait for vector store indexing before agent queries |
| dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentCreateTests.cs | Added System.Diagnostics import, WaitForVectorStoreReadyAsync instance helper method, and call to wait for vector store indexing before agent queries |
dotnet/tests/OpenAIAssistant.IntegrationTests/OpenAIAssistantClientExtensionsTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentCreateTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/OpenAIAssistant.IntegrationTests/OpenAIAssistantClientExtensionsTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentCreateTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentCreateTests.cs
Outdated
Show resolved
Hide resolved
…view Co-authored-by: rogerbarreto <[email protected]>
Fix Flaky Vector Store Integration Tests - Race Condition
WaitForVectorStoreReadyAsyncto OpenAI integration testsCreateAIAgentAsync_WithHostedFileSearchTool_SearchesFilesAsyncin OpenAIAssistantClientExtensionsTestsWaitForVectorStoreReadyAsyncto Azure AI Persistent integration testsCreateAgent_CreatesAgentWithVectorStoresAsyncin AzureAIAgentsPersistentCreateTestsOriginal prompt
This section details on the original issue you should resolve
<issue_title>.NET: [BUG] Flaky Integration Test: CreateAIAgentAsync_WithHostedFileSearchTool_SearchesFilesAsync - Vector Store Indexing Race Condition</issue_title>
<issue_description>## Summary
The integration test CreateAIAgentAsync_WithHostedFileSearchTool_SearchesFilesAsync in OpenAIAssistantClientExtensionsTests is flaky and intermittently fails due to a race condition with OpenAI's vector store indexing process.
Test Failure
Root Cause
The test creates a vector store with file content and immediately queries the AI agent:
The Problem: Vector stores require time to index files before they're searchable. The test doesn't wait for indexing completion, creating a race condition.
Evidence of Race Condition
The agent responds with:
"I couldn't find any documented code for '"This indicates the agent attempted file search but the vector store wasn't fully indexed yet, so no results were found.
Similar Pattern Found
The same pattern exists in AzureAIAgentsPersistentCreateTests.CreateAgent_CreatesAgentWithVectorStoresAsync (line 68-127), which also creates a vector store and immediately queries without waiting for indexing:
Impact
• ❌ CI/CD pipelines fail intermittently which makes the PR pipeline a bottleneck...
• ❌ False test failures waste developer time...
• ❌ Difficult to reproduce locally (timing-dependent)
• ❌ Reduces confidence in test suite
• ❌ Uses valuable compute and Developers time
Proposed Solutions
Solution 1: Wait for Vector Store Indexing Status (Recommended)
Add polling logic to wait until the vector store status is Completed:
Affected Tests
• OpenAIAssistantClientExtensionsTests.CreateAIAgentAsync_WithHostedFileSearchTool_SearchesFilesAsync
• Location: tests/OpenAIAssistant.IntegrationTests/OpenAIAssistantClientExtensionsTests.cs:129-189
• AzureAIAgentsPersistentCreateTests.CreateAgent_CreatesAgentWithVectorStoresAsync
• Location: tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentCreateTests.cs:68-127
Recommendation
Implement Solution 1 (wait for vector store status) for both tests:
Related Information
• Test Run Log: GitHub Actions run showing failure
• OpenAI API Docs: Vector store indexing is asynchronous
• Similar Issues: Azure AI services...
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.