Skip to content

fix(media): validate upload paths before generation#5615

Open
j15z wants to merge 10 commits into
stagingfrom
feat/media-upload-path-validation
Open

fix(media): validate upload paths before generation#5615
j15z wants to merge 10 commits into
stagingfrom
feat/media-upload-path-validation

Conversation

@j15z

@j15z j15z commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Chat uploads can now be passed directly to media tools and to function_execute / run_code; callers no longer need to materialize an upload into files/ before using it. Explicit input and output declarations are validated before provider or FFmpeg work begins, and chat uploads are rejected if they do not belong to the active workspace.

Generated image, video, audio, and FFmpeg outputs keep their automatic files/... destinations when outputs is omitted. When an explicit destination is supplied, it must be a writable files/... path; create-mode writes retain automatic parent-folder creation.

Related: https://github.com/simstudioai/mothership/pull/352

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • 48 focused Vitest tests passed across sandbox upload mounting, image generation, media path resolution, and media-tool preflight behavior.
  • GitHub's lint/test and application-build checks passed on the final head.
  • Reviewers should focus on the uploads/ workspace boundary, explicit-output preflight ordering, and automatic-output fallbacks.

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)

Screenshots/Videos

Not applicable; this is server-side file resolution, validation, and sandbox-mounting behavior.


Compound Engineering
Codex

@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 23, 2026 2:13am

Request Review

@cursor

cursor Bot commented Jul 12, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes touch copilot media execution, sandbox file mounting, and workspace/upload authorization; mistakes could block valid workflows or allow cross-workspace upload access, though tests cover the main boundaries.

Overview
Chat uploads as media inputs — Image, video, audio, and FFmpeg tools resolve uploads/... via resolveChatUpload (chat-scoped, workspace-checked) instead of treating uploads as unmountable or silently skipping missing references. Function execute mounts the same upload paths into the sandbox with presigned URLs when chatId is present.

Preflight path policy — New media/file-paths helpers require at least one input file when an inputs block is present, exactly one output when declared, reject uploads/ write targets, and run canonical workspace writer validation before Gemini, Fal, or FFmpeg runs.

Generated tool contractstool-catalog-v1 / tool-schemas-v1 document uploads in mount descriptions, add minItems / required: ['files'] on relevant input/output shapes, and cap single-file outputs with maxItems: 1 where applicable.

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

@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR tightens media tool path handling for generated outputs and uploaded inputs. The main changes are:

  • Shared validation for media input and output paths.
  • Explicit output declarations for generated image, video, and audio tools.
  • Chat-scoped uploads/... support for media inputs.
  • Early output validation before Gemini, Fal, or FFmpeg work starts.
  • ffmpeg probe behavior that skips unused output validation.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/tools/server/media/file-paths.ts Adds shared helpers for media input resolution and output validation.
apps/sim/lib/copilot/tools/server/media/ffmpeg.ts Validates declared outputs before non-probe operations and lets probe return metadata without output validation.
apps/sim/lib/copilot/tools/server/image/generate-image.ts Validates output paths before image generation and resolves declared reference files through the shared media helper.
apps/sim/lib/copilot/tools/server/media/generate-audio.ts Validates output paths before audio generation and resolves an optional voice sample through the shared media helper.
apps/sim/lib/copilot/tools/server/media/generate-video.ts Validates output paths before video generation and resolves an optional start-frame input through the shared media helper.
apps/sim/lib/copilot/generated/tool-catalog-v1.ts Updates generated tool metadata for the new media input and output path boundary.
apps/sim/lib/copilot/generated/tool-schemas-v1.ts Updates generated runtime schemas for explicit media outputs and constrained file declarations.

Reviews (2): Last reviewed commit: "fix(media): preflight all writable outpu..." | Re-trigger Greptile

Comment thread apps/sim/lib/copilot/tools/server/media/file-paths.ts Outdated
Comment thread apps/sim/lib/copilot/tools/server/media/ffmpeg.ts Outdated
Comment thread apps/sim/lib/copilot/tools/server/media/file-paths.ts
@j15z
j15z force-pushed the feat/media-upload-path-validation branch from 6bccb71 to 9c234ad Compare July 12, 2026 02:28
@j15z
j15z requested a review from a team as a code owner July 12, 2026 02:28
@j15z
j15z changed the base branch from staging to dev July 12, 2026 02:28
@j15z

j15z commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

@j15z

j15z commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7c321ca. Configure here.

@j15z
j15z requested a review from Sg312 July 12, 2026 02:49
@Sg312
Sg312 force-pushed the dev branch 4 times, most recently from 477ab00 to caa454a Compare July 17, 2026 18:17
j15z added 3 commits July 22, 2026 17:24
Allow media tools to consume chat-scoped uploads directly while keeping outputs under files/. Fail malformed or unresolved declarations before provider work and regenerate the Mothership-derived tool schemas.
Resolve uploads through the current chat, enforce workspace ownership, and reuse the existing URL or buffered sandbox mount path so function_execute and run_code can process uploaded files directly.
@j15z
j15z force-pushed the feat/media-upload-path-validation branch from 81891df to 3bf10de Compare July 23, 2026 00:28
@j15z
j15z changed the base branch from dev to staging July 23, 2026 00:28
Regenerate the Sim catalog and runtime schemas from the finalized Mothership contract so canonical upload support and bounded media file declarations stay aligned across repositories.
@j15z
j15z force-pushed the feat/media-upload-path-validation branch from 3bf10de to bb60a56 Compare July 23, 2026 00:41

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

There are 5 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bb60a56. Configure here.

Comment thread apps/sim/lib/copilot/tools/handlers/function-execute.ts
Comment thread apps/sim/lib/copilot/tools/server/media/file-paths.ts
- Reject chat uploads that belong to another workspace
- Add regression coverage for media upload ownership
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