Skip to content

fix: merging dev to main - #715

Open
Priyanka2-Microsoft wants to merge 22 commits into
mainfrom
dev
Open

Priyanka2-Microsoft wants to merge 22 commits into
mainfrom
dev

Conversation

@Priyanka2-Microsoft

Copy link
Copy Markdown
Contributor

Purpose

  • ...
    This pull request introduces several important improvements to document import handling, concurrency, and user experience in both the backend and frontend. The main focus is to ensure that duplicate document uploads are handled safely and efficiently, preventing race conditions and providing better feedback to users.

Backend: Document Import Concurrency and Idempotency

Concurrency-safe document import and deduplication:

  • Added a content-based hashing mechanism to identify documents by their SHA256 hash, ensuring that duplicate uploads are detected and only one import is processed at a time (KernelMemory.cs).
  • Introduced a ConcurrentDictionary to track in-progress imports and prevent concurrent processing of the same document.
  • Implemented a distributed lease system using MongoDB to coordinate document import concurrency across instances, including lease acquisition, renewal, and release logic (DocumentRepository.cs). [1] [2] [3] [4]
  • Refactored document registration to upsert (insert or update) existing documents, ensuring idempotency and atomicity.

Frontend: User Experience and Robustness

Improved answer formatting and display:

  • Enhanced the chat answer parsing logic to robustly extract and clean up answers, handling various formats and fallback scenarios for better user-facing responses (chatService.ts). [1] [2]

File upload feedback and error handling:

  • Improved the upload dialog to track upload status per file, provide clearer error messages (including parsing backend error summaries), and prevent duplicate uploads from being processed simultaneously (uploadButton.tsx). [1] [2]

UI polish for filters:

  • Added a utility to format filter labels for better readability in the UI (filter.tsx). [1] [2]

These changes collectively make document imports more reliable and user interactions more intuitive and informative.

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

What to Check

Verify that the following are valid

  • ...

Other Information

VishalSh-Microsoft and others added 22 commits September 3, 2026 14:48
…rove error message parsing in the upload dialog
…e existing document handling in the repository
…er JSON parsing and fallback for string replacements
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
fix: Duplicate Document Upload Creates Multiple UI components and Database Entries
fix: enhance the response in UI
fix: Add formatLabel function to format category labels in filter component
Comment on lines +222 to +225
catch (Exception exception)
{
_logger?.LogWarning(exception, "Failed to renew the import lease for document {DocumentId}", documentId);
}
Comment on lines +231 to +234
catch (Exception exception)
{
_logger?.LogWarning(exception, "Failed to release the import lease for document {DocumentId}", documentId);
}

private static FileStream CreateTemporaryFileStream()
{
var temporaryFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Comment on lines +219 to +221
catch (OperationCanceledException) when (leaseRenewalCancellation.IsCancellationRequested)
{
}
Comment on lines +196 to +198
catch (MongoWriteException exception) when (exception.WriteError?.Category == ServerErrorCategory.DuplicateKey)
{
}
Comment on lines +199 to +201
catch (MongoCommandException exception) when (exception.Code == 11000)
{
}

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.

🟡 Changes recommended

One or more issues must be addressed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves document import deduplication and concurrency while enhancing upload, chat, and filter UX.

Changes:

  • Adds SHA256-based document IDs and MongoDB import leases.
  • Improves upload status/error handling and chat answer parsing.
  • Formats filter labels and displays all cached categories.
File summaries
File Description
App/frontend-app/src/components/uploadButton/uploadButton.tsx Updated as part of this pull request.
App/frontend-app/src/components/filter/filter.tsx Updated as part of this pull request.
App/frontend-app/src/api/chatService.ts Updated as part of this pull request.
App/backend-api/Microsoft.GS.DPS/Storage/Documents/DocumentRepository.cs Updated as part of this pull request.
App/backend-api/Microsoft.GS.DPS/API/KernelMemory/KernelMemory.cs Updated as part of this pull request.
Review details

Suppressed comments (1)

App/frontend-app/src/api/chatService.ts:30

  • These replacements also run on the actual Markdown answer: getDisplayAnswer is called for response.answer, and the backend returns answerObject.Response, whose contract permits Markdown. A legitimate answer consisting of a fenced code block will therefore lose both fences and render as plain text. Limit fence removal to the outer JSON wrapper or preserve the extracted answer text.
        .replace(/^```[a-z0-9_-]*\s*/i, "")
        .replace(/\s*```\s*$/, "");
  • Files reviewed: 5/5 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

importStream.Position = 0;
var contentHash = await SHA256.HashDataAsync(importStream);
importStream.Position = 0;
var documentId = Convert.ToHexString(contentHash).ToLowerInvariant();
Comment on lines +248 to +250
if (!renewed)
{
throw new InvalidOperationException($"The import lease for document {documentId} is no longer owned by this process.");
Comment on lines +154 to +158
var existingDocument = await FindByDocumentIdAsync(document.DocumentId);
if (existingDocument != null)
{
document.id = existingDocument.id;
document.__partitionkey = existingDocument.__partitionkey;
onToggle={handleAccordionToggle}
>
{keywordFilterInfo && Object.entries(keywordFilterInfo).slice(0,10).map(([category, keywords], index) => (
{keywordFilterInfo && Object.entries(keywordFilterInfo).map(([category, keywords], index) => (

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants