Skip to content

fix(copilot): upload sandbox-rendered bytes for docx/pptx/pdf creation#4636

Closed
TheodoreSpeaks wants to merge 1 commit into
stagingfrom
fix/create-file
Closed

fix(copilot): upload sandbox-rendered bytes for docx/pptx/pdf creation#4636
TheodoreSpeaks wants to merge 1 commit into
stagingfrom
fix/create-file

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

Summary

  • workspace_file:create and edit_content called runSandboxTask('docx-generate' | 'pptx-generate' | 'pdf-generate', ...) but discarded the returned Buffer and uploaded Buffer.from(content, 'utf-8') instead — so .docx/.pptx/.pdf files contained the model's source code (or whatever string it emitted) labeled with the correct binary MIME, causing "Failed to load file content" in the viewer and rejection by Word
  • Capture the sandbox-rendered Buffer and upload that; non-doc paths unchanged

Type of Change

  • Bug fix

Testing

Will test on staging. bun run lint and bun run check:api-validation:strict clean; vitest run lib/copilot/tools/server/files/ passes.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 16, 2026 10:38pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 16, 2026

PR Summary

Medium Risk
Changes how workspace_file:create and edit_content persist generated document formats, which can impact all Copilot-created .docx/.pptx/.pdf files; failures would surface as corrupt uploads or viewer errors. The change is localized and preserves the existing UTF-8 path for non-document files.

Overview
Fixes Copilot document uploads so .docx/.pptx/.pdf files store the binary output returned by runSandboxTask instead of uploading Buffer.from(content, 'utf-8').

Both workspace_file (create) and edit_content now capture the sandbox-rendered Buffer for doc formats and only fall back to UTF-8 encoding for non-doc files, preventing corrupted “source code as binary” documents.

Reviewed by Cursor Bugbot for commit d2074e4. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 16, 2026

Greptile Summary

This PR fixes a bug where the Buffer returned by runSandboxTask (the rendered binary for docx/pptx/pdf) was silently discarded and then Buffer.from(content, 'utf-8') was unconditionally used — uploading raw source-code text labeled as a binary document format.

  • In both workspace-file.ts (create) and edit-content.ts (edit_content), let fileBuffer: Buffer is now declared before the if (docInfo.isDoc) branch; the sandbox-rendered bytes are captured in the if branch, and the UTF-8 fallback is assigned in the else branch.
  • The fix is minimal and correct: catch blocks return early in both files, so definite assignment is satisfied; the contentType = docInfo.sourceMime! assignment and all other surrounding logic are unchanged.

Confidence Score: 5/5

Safe to merge — the change is a minimal, self-contained fix that correctly routes the sandbox-rendered binary Buffer to the upload call in both affected tools.

Both files receive the same small structural change: capture the return value of runSandboxTask and gate the UTF-8 fallback to the else branch. The catch blocks return early in both files, so the uninitialized let is always assigned before use. No surrounding logic was changed, and the fix is consistent across the two call sites.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/tools/server/files/edit-content.ts Bug fix: captures the Buffer returned by runSandboxTask instead of discarding it, then assigns the UTF-8 fallback in the else branch; logic is correct and TypeScript definite-assignment is satisfied because the catch block always returns early
apps/sim/lib/copilot/tools/server/files/workspace-file.ts Same fix applied to the create path: fileBuffer now holds the rendered binary bytes from the sandbox; contentType assignment to docInfo.sourceMime! is unchanged and still correct

Reviews (1): Last reviewed commit: "fix(copilot): upload sandbox-rendered by..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 deleted the fix/create-file branch May 17, 2026 07:09
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.

1 participant