Repository navigation
feat(studio): multi-file unstructured seed upload with better backend extraction - #4468
Conversation
Ensures every uploaded file is represented in the preview table by cycling through sources instead of just taking the first N rows.
- Disable pymupdf4llm OCR with write_images=False, show_progress=False - Replace onAllUploaded callback with useEffect that detects uploading→done transition (avoids stale closure reading empty file IDs) - Fix importer to preserve file IDs from saved recipes instead of clearing (clearing only happens at share time via sanitizeSeedForShare)
Validate block_id/file_id with alphanumeric regex to prevent path traversal, use exact stem match for file deletion, add error handling for metadata writes and empty files, fix React stale closures and object mutations in upload loop, and correct validation logic for unstructured seed resolved_paths.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to the data designer by enabling multi-file unstructured seed uploads. It shifts text extraction to the backend for improved performance and security, and enhances the user experience with a more robust and persistent upload process. Input validation and state management improvements ensure a more reliable feature. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a70cf751f3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
…fect Promote legacy source.path into resolved_paths for old unstructured recipes, clear source.paths in share sanitizer to prevent leaking local filesystem paths, and gate file sync effect to dialog open transition so users can actually delete all uploaded files.
06eb527 to
e5deb74
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5deb74283
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 35395d2df6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
35395d2 to
ba4ff1d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba4ff1d771
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
ba4ff1d to
2a2ed37
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a2ed37b82
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
danielhanchen
left a comment
There was a problem hiding this comment.
Review Summary
The fitView changes look good. The multi-file unstructured upload is a solid feature direction, but there are several correctness and backward compatibility issues that should be addressed before merging.
Blocking Issues
-
Legacy
pathbackward compatibility break --UnstructuredSeedSourcenow requirespaths: list[str]with no fallback from the legacypathfield. Any previously persisted recipe with{"seed_type": "unstructured", "path": "..."}will fail validation. Amodel_validator(mode="before")shim that normalizespathintopaths=[path]would fix this server-side. -
Legacy single-file PDF/DOCX inspect flow is broken -- The legacy
inspect-uploadpath forseed_source_type="unstructured"routes through_read_preview_rows_from_unstructured_file->build_unstructured_preview_rows->load_unstructured_text_file, which now only accepts.txt/.md. Any caller still using the legacy single-file base64 upload with.pdfor.docxfiles will getUnsupported unstructured seed file type. -
CSV in-place rewrite is not atomic --
full_df.to_csv(path, ...)writes directly to the original upload file. If the process is interrupted mid-write, the file is left in a corrupt state. The parquet materialization code correctly uses a tmp-then-rename pattern (line 155-157 ofchunking.py); the CSV rewrite should do the same. -
React state updater anti-patterns in
UnstructuredDropZone-- Two issues: (a)handleFilesmutates an outeroverLimitvariable inside asetStateupdater and reads it synchronously after -- React 18 does not guarantee updaters run synchronously before the next line. (b)handleRemovefires a network DELETE request inside asetStateupdater, which violates React's rules (updaters should be pure; strict mode may call them twice, causing double-deletes). -
Stale config spread in unstructured
onUpdate-- The unstructured branch usesonUpdate({ ...config, ... })whilehfandlocalbranches only pass the delta. The...configspread can overwrite interim user edits with stale values captured at callback creation time.
Non-Blocking Issues
tmp.rename(cached)atchunking.py:194should betmp.replace(cached)for consistency with the single-file path (line 157) and for atomicity.- Empty
file_ids=[]passes pydantic validation and causes an unhandledValueError-> HTTP 500; should reject with 400. - On extraction failure,
extracted_pathis not cleaned up ifwrite_text()partially writes before raising. resolved_paths ?? [config.hf_path]inbuilders-seed.ts:74does not handle empty array (empty array is truthy, so??does not trigger the fallback).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a020955819
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
danielhanchen
left a comment
There was a problem hiding this comment.
All 10 previously flagged issues have been addressed. Nice work on the fixes.
What was fixed
- Legacy
pathbackward compat --_normalize_legacy_pathmodel_validator added - Legacy PDF/DOCX inspect -- restricted to
.txt/.mdwith clear error message - CSV atomic rewrite -- now uses tmp-then-replace pattern
- React
overLimitrace -- usesfilesRef.currentinstead of async setState - DELETE inside setState -- side effects moved outside the updater, with
deletedIdsRefguard ...configspread -- removed from unstructuredonUpdatetmp.rename()-- changed to.replace()for consistency- Empty
file_ids=[]-- validated in both model validator and route handler extracted_pathcleanup -- moved assignment beforetry, cleanup inexceptresolved_pathsempty array -- proper length check fallback
Additional improvements
_get_block_total_sizenow only counts raw upload files (excludes derived.extracted.txtand.meta.json)MAX_TOTAL_SIZEreduced from 500MB to 100MBhandleUnstructuredFilesChangewrapper syncs config on file changes- Upload endpoint accepts
existing_file_idsfor quota tracking f.unlink(missing_ok=True)in delete endpoint
Minor non-blocking suggestions for future consideration
handleUnstructuredFilesChangeusesqueueMicrotaskinside asetStateupdater to deferonUpdate. This works correctly in production but fires twice in React 18 Strict Mode (dev). AuseEffectwatchingunstructuredFileswould be the more idiomatic approach.- The pydantic model validator already rejects
file_ids=[]with a 422, making the route-levelHTTPException(400)check unreachable dead code. _LEGACY_UNSTRUCTURED_EXTSis defined inside the function body -- could be moved to module scope for consistency.
… extraction (unslothai#4468) * fix(recipe-studio): prevent fitView from zooming to wrong location on recipe load * feat: add pymupdf/python-docx deps and unstructured uploads storage root * feat: add POST /seed/upload-unstructured-file endpoint * feat: add multi-file chunking with source_file column * feat: update frontend types and API layer for multi-file upload * feat: round-robin preview rows across source files Ensures every uploaded file is represented in the preview table by cycling through sources instead of just taking the first N rows. * fix: disable OCR, fix auto-load timing, fix persistence on reload - Disable pymupdf4llm OCR with write_images=False, show_progress=False - Replace onAllUploaded callback with useEffect that detects uploading→done transition (avoids stale closure reading empty file IDs) - Fix importer to preserve file IDs from saved recipes instead of clearing (clearing only happens at share time via sanitizeSeedForShare) * fix: harden unstructured upload with input validation and state fixes Validate block_id/file_id with alphanumeric regex to prevent path traversal, use exact stem match for file deletion, add error handling for metadata writes and empty files, fix React stale closures and object mutations in upload loop, and correct validation logic for unstructured seed resolved_paths. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: address PR review - legacy path import, share sanitizer, sync effect Promote legacy source.path into resolved_paths for old unstructured recipes, clear source.paths in share sanitizer to prevent leaking local filesystem paths, and gate file sync effect to dialog open transition so users can actually delete all uploaded files. * fix: CSV column fix (BOM + whitespace + unnamed index re-save) for unslothai#4470 * fix: harden unstructured upload flow and polish dialog UX * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
~/.unsloth/studio/assets/datasets/unstructured-uploads/Test plan