Skip to content

feat: handle partial upload success in document batch upload - #16438

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
euvre:feat/handle-partial-upload-success
Jun 29, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
euvre:feat/handle-partial-upload-success

Conversation

@euvre

@euvre euvre commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

When uploading multiple documents in a batch, if any single file failed (e.g., unsupported format, corrupted file), the entire batch was treated as a complete failure. Successfully uploaded documents were discarded and never returned to the caller, forcing users to re-upload everything. Additionally, parsing was never triggered for the documents that did upload successfully.

This PR introduces partial success handling for batch document uploads:

Backend (api/apps/restful_apis/document_api.py):

  • Distinguishes between a complete failure (all files failed) and a partial success (some files succeeded, some failed).
  • On partial success, returns the successfully uploaded documents data alongside the error message (using construct_json_result with RetCode.SERVER_ERROR and data populated).
  • On complete failure (no files uploaded), behavior remains unchanged.

Frontend (web/src/pages/dataset/dataset/use-upload-document.ts):

  • Detects partial success responses (HTTP 500 with data containing uploaded documents).
  • Triggers document parsing (runDocumentByIds) for successfully uploaded files even in partial-success scenarios when parseOnCreation is enabled.
  • Only closes the upload modal if at least some files were uploaded successfully.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)

- Backend: return successfully uploaded documents alongside error message
  when some files in a batch fail, enabling partial success handling
- Frontend: trigger document parsing for successfully uploaded files even
  in partial-success scenarios when parseOnCreation is enabled
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e0a0e61a-85c7-4e09-a046-2be8fbebd9d0

📥 Commits

Reviewing files that changed from the base of the PR and between d0accb3 and 400801f.

📒 Files selected for processing (1)
  • api/apps/restful_apis/document_api.py

📝 Walkthrough

Walkthrough

The document upload flow now returns partial-success results from the backend and starts parsing on the frontend when uploaded data is present, even if some files failed.

Changes

Partial Upload Success Handling

Layer / File(s) Summary
Backend partial success response logic
api/apps/restful_apis/document_api.py
_upload_local_documents now treats mixed success as partial success, returns successful uploads with an aggregated error message and server-error code, and preserves raw-file vs mapped-document response shapes.
Frontend parsing on partial success
web/src/pages/dataset/dataset/use-upload-document.ts
useHandleUploadDocument now calls runDocumentByIds for both full success and partial success when returned data is non-empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Some uploads hopped through, some stayed behind,
But the good little files were still easy to find.
The backend said, “partial,” with errors in tow,
And parsing kept hopping wherever data did go.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: partial upload success handling for batch document uploads.
Description check ✅ Passed The description covers the problem, backend and frontend changes, and change type, though it uses a custom heading instead of the template's Summary section.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@euvre euvre added the ci Continue Integration label Jun 29, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/apps/restful_apis/document_api.py`:
- Around line 631-635: Document the partial-success response contract in
document_api.py so the endpoint schema matches the behavior in the
is_partial_success branch of construct_json_result. Update the response
annotations/schema for the document upload endpoint to explicitly describe the
500 response that still includes doc_data alongside the error message, using the
same response model shape as the 200 success path so generated clients and
consumers see both supported payloads.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 23286dd6-3a89-4f49-be05-1e4c00f3845e

📥 Commits

Reviewing files that changed from the base of the PR and between 6d6e32a and 3440fba.

📒 Files selected for processing (2)
  • api/apps/restful_apis/document_api.py
  • web/src/pages/dataset/dataset/use-upload-document.ts

Comment thread api/apps/restful_apis/document_api.py Resolved
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 29, 2026
@euvre
euvre force-pushed the feat/handle-partial-upload-success branch from d0accb3 to 3440fba Compare June 29, 2026 04:14
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 29, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/apps/restful_apis/document_api.py`:
- Around line 1773-1786: The sandbox artifact access check is currently
authorizing downloads by substring-matching API4Conversation.message, which lets
filename knowledge spoof access. Update _sandbox_artifact_dialog_ids_for_user
and _sandbox_artifact_accessible to যাচ verify against an authoritative artifact
ownership/reference source instead of message.contains(...) on conversation
JSON, and only return true when that record ties the filename to a dialog the
user can access.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e0a0e61a-85c7-4e09-a046-2be8fbebd9d0

📥 Commits

Reviewing files that changed from the base of the PR and between d0accb3 and 400801f.

📒 Files selected for processing (1)
  • api/apps/restful_apis/document_api.py

@coderabbitai coderabbitai Bot 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.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/apps/restful_apis/document_api.py`:
- Around line 1773-1786: The sandbox artifact access check is currently
authorizing downloads by substring-matching API4Conversation.message, which lets
filename knowledge spoof access. Update _sandbox_artifact_dialog_ids_for_user
and _sandbox_artifact_accessible to যাচ verify against an authoritative artifact
ownership/reference source instead of message.contains(...) on conversation
JSON, and only return true when that record ties the filename to a dialog the
user can access.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e0a0e61a-85c7-4e09-a046-2be8fbebd9d0

📥 Commits

Reviewing files that changed from the base of the PR and between d0accb3 and 400801f.

📒 Files selected for processing (1)
  • api/apps/restful_apis/document_api.py
🛑 Comments failed to post (1)
api/apps/restful_apis/document_api.py (1)

1773-1786: 🔒 Security & Privacy | 🔴 Critical | 🏗️ Heavy lift

Do not authorize artifact downloads from message.contains(...) matches.

API4Conversation.message includes user-authored conversation content, so a user who knows an artifact filename can mention documents/artifact/<filename> in any session they can access and make _sandbox_artifact_accessible() return True. That makes filename knowledge sufficient to read from the shared sandbox bucket. Please bind this check to an authoritative artifact ownership/reference record instead of substring matches on conversation JSON.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/apps/restful_apis/document_api.py` around lines 1773 - 1786, The sandbox
artifact access check is currently authorizing downloads by substring-matching
API4Conversation.message, which lets filename knowledge spoof access. Update
_sandbox_artifact_dialog_ids_for_user and _sandbox_artifact_accessible to যাচ
verify against an authoritative artifact ownership/reference source instead of
message.contains(...) on conversation JSON, and only return true when that
record ties the filename to a dialog the user can access.

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (d56c17b) to head (400801f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16438   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit a339e8a into infiniflow:main Jun 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants