Repository navigation
feat: handle partial upload success in document batch upload - #16438
Conversation
- 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
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe 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. ChangesPartial Upload Success Handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
api/apps/restful_apis/document_api.pyweb/src/pages/dataset/dataset/use-upload-document.ts
d0accb3 to
3440fba
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
api/apps/restful_apis/document_api.py
There was a problem hiding this comment.
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
📒 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.messageincludes user-authored conversation content, so a user who knows an artifact filename can mentiondocuments/artifact/<filename>in any session they can access and make_sandbox_artifact_accessible()returnTrue. 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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):construct_json_resultwithRetCode.SERVER_ERRORanddatapopulated).Frontend (
web/src/pages/dataset/dataset/use-upload-document.ts):datacontaining uploaded documents).runDocumentByIds) for successfully uploaded files even in partial-success scenarios whenparseOnCreationis enabled.Type of change