Skip to content

Fix per-block ID collisions and add block cleanup for unstructured uploads - #6944

Merged
danielhanchen merged 13 commits into
unslothai:mainfrom
NilayYadav:unstructured-upload-quota-scope
Jul 9, 2026
Merged

danielhanchen merged 13 commits into
unslothai:mainfrom
NilayYadav:unstructured-upload-quota-scope

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Fixes #6921 the users hit 413: Total upload limit (1GB) exceeded on small files (6.7MB) because upload quota accounting wasn't correctly scoped per block.

Core issue: config.id for a seed block resets to n1 on recipe import, so unstructured upload blocks from different recipes could collide on the same server-side block_id. Stale/orphaned files from old or unrelated blocks kept counting toward the shared quota, so new small uploads got rejected even though they were nowhere near 1GB on their own.

@NilayYadav
NilayYadav requested a review from danielhanchen as a code owner July 7, 2026 17:31

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a mechanism to clean up unstructured block upload directories, adding a backend DELETE endpoint, frontend API integration, and a stable per-block UID (unstructured_upload_uid) to prevent ID collisions. Feedback on these changes highlights a directory traversal vulnerability in the backend path handling, a critical safety issue where legacy block cleanup could delete active files of other recipes, a React useEffect dependency optimization, and a UX improvement to maintain file list order when restoring files after a failed deletion.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 704faf7b64

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e43d2aba77

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf261e0e14

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4f424205a

ℹ️ 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".

@Imagineer99

Copy link
Copy Markdown
Member

Ran a focused check on this PR: https://github.com/Imagineer99/unsloth/actions/runs/28894496624

Looks good, the focused checks pass here. This covered the per-block upload quota, UID-only block cleanup, legacy node ID protection, and the frontend cleanup wiring.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aebb69ff78

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: abe3350605

ℹ️ 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".

@Imagineer99

Copy link
Copy Markdown
Member
image

CI passing on staging fork.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cedfbfcbf

ℹ️ 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".

// Still exists server-side (counts toward quota); restore it at its
// original position.
deletedIdsRef.current.delete(entry.id);
onFilesChange((prev) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid restoring files after the drop zone is stale

When the DELETE fails after the user has switched this seed away from the old unstructured block (or the drop zone has unmounted with a different blockId), this stale catch still calls onFilesChange. Because addSeedNode reuses the same seed config id while clearing the UID/file list, the restore can write the old file ID back into the new/non-unstructured seed, leaving saved UI state that points at the wrong upload block and causing later inspect/cleanup to operate on the wrong directory. Guard the restore with the current block/mounted state, or skip restoration once the drop zone is no longer active.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 17d14fa: guarded the failed-delete restore with a mounted ref plus a blockId ref, so a late DELETE rejection after the drop zone unmounts or its block uid changes no longer writes the stale file id back into the wrong block. Verified with a React runtime test covering same-block restore, unmount, and blockId-change.

@danielhanchen

Copy link
Copy Markdown
Member

Pushed a small follow-up to the drop zone (unstructured-drop-zone.tsx).

The failed-delete restore branch could reinsert a file id into the wrong block. If removeUnstructuredFile rejects after the seed source was switched (drop zone unmounted, or its block got a fresh uid via addSeedNode), the .catch still ran onFilesChange, writing a stale unstructured_file_ids entry into a config that no longer owns that file. The deferred cleanup would then delete the old directory and a later inspect under the new uid could not find it.

Guarded the restore so it is skipped once the drop zone unmounts (mountedRef) or its blockId changes (blockIdRef). Normal same-block failures still restore at the original index as before. Typecheck and build pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17d14fa11b

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 18db740e5f

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 3b73cd8 into unslothai:main Jul 9, 2026
44 checks passed
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.

[Bug] Status code 413: Total upload limit (1GB) exceeded

3 participants