Skip to content

fix: deduplicate files by destination before sandbox validation - #247

Open
proseer-lars wants to merge 2 commits into
LibreChat-AI:mainfrom
proseer-lars:fix/deduplicate-files-before-validation
Open

proseer-lars wants to merge 2 commits into
LibreChat-AI:mainfrom
proseer-lars:fix/deduplicate-files-before-validation

Conversation

@proseer-lars

@proseer-lars proseer-lars commented Sep 23, 2026 •

Copy link
Copy Markdown

Problem

Some callers (e.g. LibreChat) send the same file more than once per exec request when a user re-uploads a file in the same conversation. The sandbox's validateExecuteFiles() rejects duplicate destinations, which causes every tool call in that conversation to fail with:

Error from sandbox: [bad_request] files contains duplicate destination "filename.pdf"

This surfaces to the end user as a confusing "the code-execution sandbox appears to be down" error — the sandbox itself is healthy, it's just rejecting the duplicate file list.

Fix

Add deduplicateFilesByDestination() in getJob() before final validation. It bounds and validates every raw entry, then keeps the latest file at each exact destination so re-uploads replace older copies. It preserves original implicit file${index}.code destinations across compaction, matching signed manifest claims, and emits one aggregated warning when duplicates are dropped.

validateExecuteFiles() still rejects duplicate and ancestor-conflicting destinations (e.g. results vs results/out.csv) when called directly. Its per-file validation is shared with the dedup step so malformed entries cannot be concealed by a later duplicate.

Test plan

  • Existing tests pass (validateExecuteFiles still rejects duplicates when called directly)
  • New tests cover latest-wins ordering, original-index implicit names and manifest scope, malformed duplicates, raw-count limits, and the /execute route
  • Focused Bun tests: 36 passed across file validation, request route, and execution manifest
  • Follow-up commit has not been deployed; the original duplicate-destination fix was reported by the author as production-verified (self-hosted LibreChat + code-interpreter)
  • tsc --noEmit still reports diagnostics in unrelated pre-existing API files; no diagnostics in the three changed files

proseer-lars and others added 2 commits September 23, 2026 10:43
Some callers (e.g. LibreChat) send the same file more than once per
exec request when a user re-uploads a file in the same conversation.
The sandbox's validateExecuteFiles() rejects duplicate destinations,
which causes every tool call in that conversation to fail with:

  Error from sandbox: [bad_request] files contains duplicate destination "filename.pdf"

This surfaces to the end user as a confusing "sandbox is down" error
when the sandbox itself is fine - it is just rejecting the duplicate
file list.

Fix: add deduplicateFilesByDestination() and call it in getJob()
before validateExecuteFiles(). Keeps the first file for each
destination, silently drops subsequent duplicates, and logs a warning.
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.

2 participants