Conversation
* chore(deps): bump mermaid to 11.15.0 for GHSA-ghcm-xqfw-q4vr * chore(deps): override transitive mermaid to 11.15.0
…4610) * File block v4 * Support files in agent block * Clean up attachments * Fix start.files * Fix * Fix
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds file attachment support to the agent block (upload or reference files that are attached to the last user message and hydrated with base64 for each provider), introduces a new
Confidence Score: 4/5The core attachment pipeline is well-structured and the provider-specific formatting is comprehensive; the main rough edges are in size validation and error messaging rather than broken data paths. The size check in prepareProviderAttachments compares raw file size against a 10 MB threshold, but base64 encoding inflates the actual payload by ~33%, so files between ~7.5 MB and 10 MB pass the guard and then silently fail during hydration with a generic error. The memory sanitizer also strips function_call and tool_calls as a side effect of only whitelisting three fields. apps/sim/providers/attachments.ts (size validation logic) and apps/sim/executor/handlers/agent/memory.ts (sanitizeMessageForStorage field preservation) Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as Agent Block UI
participant AH as AgentBlockHandler
participant MEM as Memory
participant HYDRATE as user-file-base64.server
participant PROV as LLM Provider
UI->>AH: execute(inputs, files)
AH->>AH: buildMessages()
AH->>AH: attachFilesToLastUserMessage(messages, files)
note over AH: normalizeFileInput to processFilesToUserFiles sets message.files = UserFile[]
AH->>AH: hydrateMessageFilesForProvider(messages, providerId)
AH->>HYDRATE: hydrateUserFilesWithBase64(userFiles, maxBytes 10MB)
HYDRATE-->>AH: UserFile[] with base64
AH->>AH: missingFile check throws if base64 absent
AH->>PROV: providerRequest with hydrated messages
note over PROV: buildOpenAIMessageContent or buildAnthropicMessageContent or buildGeminiMessageParts
PROV-->>AH: response
AH->>MEM: appendMessage sanitized files stripped
note over MEM: sanitizeMessageForStorage keeps role content executionId only
Reviews (1): Last reviewed commit: "improvement(agent, file-block): files in..." | Re-trigger Greptile |
| return messages.slice(-limit) | ||
| } | ||
|
|
||
| private sanitizeMessageForStorage(message: Message): Message { | ||
| return { | ||
| role: message.role, | ||
| content: message.content, | ||
| ...(message.executionId && { executionId: message.executionId }), | ||
| } |
There was a problem hiding this comment.
sanitizeMessageForStorage silently drops function_call and tool_calls
The sanitizer rebuilds the message from scratch, keeping only role, content, and executionId. Any assistant messages that carry non-null string content alongside function_call or tool_calls will lose those fields on the next load. An LLM that re-reads its own history from memory will see gaps it cannot reconcile, which can cause follow-on API errors on providers that require a tool-use/tool-result pair to be contiguous. If the intent is strictly to strip files, prefer an explicit files omission rather than a full reconstruction that silently discards other fields.
| if (Number.isFinite(file.size) && file.size > maxBytes) { | ||
| const sizeMB = (file.size / (1024 * 1024)).toFixed(2) | ||
| const maxMB = (maxBytes / (1024 * 1024)).toFixed(0) | ||
| throw new Error( | ||
| `File "${file.name}" (${sizeMB}MB) exceeds the ${maxMB}MB agent attachment limit for provider "${providerId}"` | ||
| ) | ||
| } |
There was a problem hiding this comment.
Size check uses raw file size, not base64 size — files 7.5–10 MB will silently pass this guard then fail during hydration
Base64 encoding inflates size by ~33%, so a 9 MB raw file produces ~12 MB of base64 which exceeds maxBytes = 10 MB. hydrateUserFilesWithBase64 strips the base64 in that case, the missingFile check later throws a generic "could not be read" error, and users never learn that file size was the actual cause. Changing the threshold to maxBytes * 0.75 would make the validation match what hydration actually allows.
| if (Number.isFinite(file.size) && file.size > maxBytes) { | |
| const sizeMB = (file.size / (1024 * 1024)).toFixed(2) | |
| const maxMB = (maxBytes / (1024 * 1024)).toFixed(0) | |
| throw new Error( | |
| `File "${file.name}" (${sizeMB}MB) exceeds the ${maxMB}MB agent attachment limit for provider "${providerId}"` | |
| ) | |
| } | |
| // Base64 encoding inflates size by ~33%; use 75% of maxBytes as the raw-size gate. | |
| const rawSizeLimit = maxBytes * 0.75 | |
| if (Number.isFinite(file.size) && file.size > rawSizeLimit) { | |
| const sizeMB = (file.size / (1024 * 1024)).toFixed(2) | |
| const maxMB = (rawSizeLimit / (1024 * 1024)).toFixed(0) | |
| throw new Error( | |
| `File "${file.name}" (${sizeMB}MB) exceeds the ~${maxMB}MB agent attachment limit for provider "${providerId}" (base64 encoding adds ~33% overhead)` | |
| ) | |
| } |
| ): Promise<Message[] | undefined> { | ||
| if (!messages?.some((message) => message.files?.length)) { | ||
| return messages | ||
| } | ||
|
|
||
| if (!supportsFileAttachments(providerId)) { | ||
| throw new Error(`File attachments are not supported for provider "${providerId}"`) | ||
| } | ||
|
|
||
| const requestId = ctx.executionId || ctx.workflowId || 'agent-files' | ||
| const nextMessages = [...messages] | ||
|
|
||
| for (let messageIndex = 0; messageIndex < messages.length; messageIndex++) { | ||
| const message = messages[messageIndex] | ||
| const normalizedFiles = normalizeFileInput(message.files) | ||
| if (!normalizedFiles || normalizedFiles.length === 0) { | ||
| continue | ||
| } | ||
|
|
||
| const userFiles = processFilesToUserFiles( | ||
| normalizedFiles as RawFileInput[], | ||
| requestId, | ||
| logger | ||
| ) | ||
| if (userFiles.length === 0) { | ||
| throw new Error('Files must include at least one valid file object') | ||
| } | ||
|
|
||
| const hydratedFiles = await hydrateUserFilesWithBase64(userFiles, { | ||
| requestId, | ||
| workspaceId: ctx.workspaceId, | ||
| workflowId: ctx.workflowId, | ||
| executionId: ctx.executionId, | ||
| largeValueExecutionIds: ctx.largeValueExecutionIds, | ||
| allowLargeValueWorkflowScope: ctx.allowLargeValueWorkflowScope, | ||
| userId: ctx.userId, | ||
| logger, | ||
| maxBytes: getProviderAttachmentMaxBytes(providerId), | ||
| }) | ||
|
|
||
| const missingFile = hydratedFiles.find((file) => !file.base64) | ||
| if (missingFile) { | ||
| throw new Error( | ||
| `File "${missingFile.name}" could not be read for provider "${providerId}". Make sure the file is still accessible and under the provider attachment size limit.` | ||
| ) | ||
| } | ||
|
|
||
| nextMessages[messageIndex] = { | ||
| ...message, | ||
| files: hydratedFiles, | ||
| } | ||
| } | ||
|
|
||
| return nextMessages | ||
| } | ||
|
|
||
| private extractValidMessages(messages?: Message[]): Message[] { |
There was a problem hiding this comment.
Files are processed twice — once in
attachFilesToLastUserMessage, again in hydrateMessageFilesForProvider
attachFilesToLastUserMessage already calls processFilesToUserFiles and stores the resulting UserFile[] on the message. hydrateMessageFilesForProvider then runs normalizeFileInput + processFilesToUserFiles on the same already-normalized UserFile[] before hydrating. Because convertToUserFile short-circuits on isCompleteUserFile, the double pass is harmless, but the redundant work (plus the cast as RawFileInput[]) obscures intent. hydrateMessageFilesForProvider can work directly with message.files since they are already UserFile[].
| const missingFile = hydratedFiles.find((file) => !file.base64) | ||
| if (missingFile) { | ||
| throw new Error( | ||
| `File "${missingFile.name}" could not be read for provider "${providerId}". Make sure the file is still accessible and under the provider attachment size limit.` | ||
| ) | ||
| } |
There was a problem hiding this comment.
missingFile error message says "still accessible" when the real cause is almost always size
When hydrateUserFilesWithBase64 strips base64 from a file because it exceeds maxBytes, the error says "Make sure the file is still accessible and under the provider attachment size limit." The "still accessible" language misleads users into thinking the file was deleted or permission-denied; the likeliest failure at this stage is that the file is too large.
| const missingFile = hydratedFiles.find((file) => !file.base64) | |
| if (missingFile) { | |
| throw new Error( | |
| `File "${missingFile.name}" could not be read for provider "${providerId}". Make sure the file is still accessible and under the provider attachment size limit.` | |
| ) | |
| } | |
| const missingFile = hydratedFiles.find((file) => !file.base64) | |
| if (missingFile) { | |
| throw new Error( | |
| `File "${missingFile.name}" could not be read for provider "${providerId}". The file may exceed the attachment size limit or may no longer be accessible.` | |
| ) | |
| } |
* v0.6.29: login improvements, posthog telemetry (#4026) * feat(posthog): Add tracking on mothership abort (#4023) Co-authored-by: Theodore Li <theo@sim.ai> * fix(login): fix captcha headers for manual login (#4025) * fix(signup): fix turnstile key loading * fix(login): fix captcha header passing * Catch user already exists, remove login form captcha * feat(files): folders + vfs update * address comments * address comments * cleanup unnused code * address comments * perf improvements * address next set * cycle detect * error handling * path improvements * cleanup, best practices * react query best practices: targeted invalidation, optimistic updates, key factory hierarchy - Add workspaceLists(workspaceId) intermediate key level to both workspaceFilesKeys and workspaceFileFolderKeys so invalidation targets only the affected workspace instead of all workspaces - Replace all lists() invalidation calls with workspaceLists(workspaceId) across every mutation (upload, rename, delete, restore, update content, folder mutations) - Add optimistic updates to useRenameWorkspaceFile and useUpdateWorkspaceFileFolder with onMutate snapshot, onError rollback, onSettled reconciliation - Move storage key into the content() factory as optional param so query keys are always built through the factory (useWorkspaceFileContent, useWorkspaceFileBinary) - Fix AnimatePresence wrapping in FilesActionBar so exit animation fires on deselect - Fix ResourceColGroup to use percentage weights instead of pixel widths to prevent horizontal scroll on narrow viewports * add shift-click range selection and selection-aware context menu for files - Extend SelectableConfig.onSelectRow with optional shiftKey param; DataRow captures shiftKey before onCheckedChange fires via a ref so the Radix Checkbox interaction chain stays intact - Implement shift-click range selection in files.tsx using lastSelectedIndexRef; tracks last-selected index in visibleRowIds to compute the range - Reset lastSelectedIndexRef on deselect and select-all - Add selectedCount prop to FileRowContextMenu; hide Open and Rename when multiple items are selected, show "Delete N items" / "Download N items" labels in multi-select mode * add Move submenu to file context menu and fix shift-click anchor update - Add nested Move submenu to FileRowContextMenu using DropdownMenuSub/SubTrigger/SubContent; shows available folders filtered by selection, converts '__root__' -> null for moving to the root level - Add handleContextMenuMove in files.tsx that calls moveItems.mutateAsync directly (no modal) and clears selection on success - Fix shift-click range selection: update lastSelectedIndexRef after range select so chained shift-clicks extend from the new anchor point correctly * fix move submenu: use folder names with tree-ordered indentation instead of stale paths - Compute folder depth from parentId chain client-side (avoids stale server-computed path field) - Tree-order folders so parents appear before their children, sorted by sortOrder then name - Show folder.name instead of folder.path so optimistic renames are reflected immediately - Indent each folder by depth * 12px in the submenu so po/shit renders as 'shit' indented under 'po' - MoveOption gains optional depth field; contextMenuMoveOptions is a separate memo from moveFolderOptions (modal keeps its existing path-label behavior) * fix shift-click anchor drift and remove dead stopPropagation constant - Remove dead stopPropagation const in resource.tsx (replaced by handleSelectRowClick) - Reset lastSelectedIndexRef when visibleRowIds changes so search/filter/folder navigation doesn't leave a stale anchor that produces wrong ranges on the next shift-click - Update lastSelectedIndexRef in handleRowContextMenu when right-clicking resets selection to a single item, so the anchor matches the newly-selected row - Add visibleRowIds to handleRowContextMenu deps (now reads it to compute anchor index) - Remove moveItems.mutateAsync from handleContextMenuMove deps per project convention (.mutateAsync is stable in TanStack v5) * complete workspace files feature: audit logs, posthog events, folder restore, empty state, keyboard shortcuts, storage indicator, breadcrumb rename - Audit + PostHog: wire file_renamed, file_deleted, file_moved, file_bulk_deleted, folder_created, folder_renamed, folder_deleted, folder_moved events to all file/folder API routes - Add AuditAction.FOLDER_UPDATED, FILE_MOVED, FOLDER_MOVED to audit types - Folder restore: server function, contract, API route (POST /files/folders/[folderId]/restore), hook (useRestoreWorkspaceFileFolder), Recently Deleted integration with new File Folders tab - Empty state: contextual emptyMessage passed to <Resource> based on search/filters/folder context - Keyboard shortcuts: Delete/Backspace deletes selection, Escape deselects, Cmd+A selects all (list view only, input-aware guard) - Storage indicator: useStorageInfo drives compact "used / limit" display in file list header via leadingActions - Breadcrumb rename: current folder breadcrumb gains Rename dropdown + inline editing via breadcrumbRename (useInlineRename) - Resource: thread leadingActions prop from ResourceProps to ResourceHeader * cleanup: accessibility, emcn design tokens, react best practices across workspace UI - Add sr-only ModalDescription to dialogs/modals for accessibility - Replace hardcoded colors and z-indices with design token CSS variables - Apply emcn design review fixes across tables, knowledge, logs, settings, workflows * fix audit and posthog: FOLDER_RESTORED action on restore, fire folder_moved event separately from file_moved * sidebar: add Files section with nested folder tree; polish move UX and cleanup - Files section in sidebar shows folder/file tree with expand/collapse, matching Workflows section structure; collapsed sidebar shows flyout menu - Move action bar now uses nested DropdownMenuSub tree instead of flat modal - Context menu and action bar share renderMoveOption from move-options.tsx - FolderInput added to emcn icons barrel; all FolderInput imports migrated - Drag ghost uses CSS vars (--border, --shadow-medium, --z-toast) - Selection pruning converted from useEffect to render-time comparison - Keyboard listener stabilized with handleBulkDeleteRef pattern - toError() used consistently in restore and move route handlers * remove Files section from sidebar * restore Files nav item in sidebar workspace section * fix infinite re-render on files page - revert selection pruning to useEffect * add filefolder resource type for ingesting workspace file folders * export filefolder tree types; add toast feedback for file/folder mutations * regenerate migration as 0208 after rebase onto staging * add workspaceFileFolder to schema mock * add FILE_MOVED, FOLDER_MOVED, FOLDER_UPDATED to audit mock * add filefolder ChatContext kind and wire through schema and resolver * add filefolder to AgentContextType * add filefolder to chat context kind registry; fix resolver to use workspaceFiles table * add .deepsec to gitignore * cleanup: effect, emcn tokens, mutation error handling - Replace selection-pruning useEffect with inline state adjustment during render - Fix drag overlay using invalid --accent HSL token → --brand-secondary; z-50 → z-[var(--z-dropdown)] - Move static inline styles on context menu trigger div to className - Add missing onError toast to useUpdateWorkspaceFileFolder, useRestoreWorkspaceFileFolder, useRestoreWorkspaceFile * lint * fix: remove duplicate handleCopilotStopGeneration from rebase * feat(copilot): folder-aware file context in WORKSPACE.md * feat(copilot): add move operation to file manage API * fix(files): make targetFolder optional in move file contract * perf(files): parallelize buffer fetches, fix N+1 folder queries, stabilize drag useMemo - download route: fan out all fetchWorkspaceFileBuffer calls with Promise.all before zip assembly so 100 files resolve in one round-trip instead of sequentially - getWorkspaceFileFolder: replace per-ancestor SELECTs with a single workspace-wide folder load + buildWorkspaceFileFolderPathMap, making depth irrelevant to query count - ensureWorkspaceFileFolderPath: pre-load all workspace folders in one SELECT before the segment loop; resolve existing segments from an in-memory map; only hit the DB to CREATE missing segments; conflict retry path preserved and also updates the map - files.tsx rowDragDropConfig: move activeDropTargetId into a ref so the useMemo does not recompute on every drag-over event * fix(files): remove files/ path stripping, fix stale path in optimistic update - splitWorkspaceFilePath: remove the unconditional .replace(/^files\//, '') that clobbered paths for files inside a folder literally named "files" - useUpdateWorkspaceFileFolder: when a name update is in flight, recompute the path field for the renamed folder (replace last segment) and propagate the new prefix to all descendant folders so breadcrumbs stay correct during the optimistic window * fix(files): revert broken ref opt, clean 409 on restore, null parentId on orphaned restore - files.tsx: revert the activeDropTargetId ref optimization — the ref doesn't trigger re-renders so the drop-target highlight never updated during drag; activeDropTargetId is back in state and in the rowDragDropConfig deps - restore/route.ts: catch Postgres 23505 unique-constraint violation and return a clean 409 instead of leaking the raw error as 400 - restoreWorkspaceFileFolder: check if the parent folder is still archived before restoring; if it is, restore to root (parentId: null) so the folder is never orphaned under an archived parent * feat(search): show folder path for files in cmd-k modal, strip extraneous comments - FileItem interface with folderPath?: string[] added to search modal utils - MemoizedFileItem component renders folder breadcrumb identically to MemoizedWorkflowItem — truncated path segments on the right with / separators - FilesGroup rewritten as a dedicated memo component (was createIconGroup factory) so it accepts FileItem[] and includes folderPath segments in the search value - searchModalFiles in sidebar splits f.folderPath string into string[] segments - search-modal.tsx typed to FileItem and includes folderPath in filterAndSort - Remove self-explanatory "Phase 1" section label from download route - Remove redundant TSDoc on the unique index in db schema * fix(workspace-files): audit fixes — transaction, status codes, contract refinements, guards * fix(vfs): pass folderPath separately so buildWorkspaceMd groups files correctly * fix(types): narrow unknown fileInput with Record cast after object guard * fix(routes): replace instanceof Error with toError() across new workspace file routes * improvement(files): cleanup pass — remove unnecessary useCallbacks, consolidate emcn icon imports - Remove useCallback from 5 drag-event handlers in DataRow (passed to native <tr> elements, no observer) - Remove stable useCallback fns from 3 useMemo deps arrays in files.tsx (editingId/editValue remain) - Merge all @/components/emcn/icons subpath imports into barrel (files.tsx, action-bar, file-row-context-menu) * fix(files): apply activeSort to folders, reject drop onto current parent folder - visibleFolders now respects activeSort column (name/updated/created) and direction so folder ordering stays consistent with file ordering - isInvalidDropTarget now returns true when all dragged items are already direct children of the target folder, preventing a no-op move mutation * fix breadcrumb * add new tools to rename, create, delete folders * move more ui actions into orchestration dir * address comments * fix params * fix tests * address comments * improve error codes * address comments * address more nits * fix mcp server error code --------- Co-authored-by: Theodore Li <theodoreqili@gmail.com> Co-authored-by: waleed <walif6@gmail.com>
PR SummaryMedium Risk Overview Adds workspace file/folder management APIs: folder CRUD/restore, bulk archive, move, and a ZIP download endpoint with file-count/size limits; existing file upload/presigned/register flows now accept an optional Refactors a broad set of mutation routes (credentials, folders, workflows, schedules/jobs, tables/knowledge/workflow restores, MCP server/tool CRUD, workspace API keys, workspace file rename/delete/restore, v1 file delete) to delegate to Reviewed by Cursor Bugbot for commit c9118e7. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c9118e7. Configure here.
|
|
||
| const executionId = generateId() | ||
| const executionId = | ||
| isClientSession && requestedExecutionId ? requestedExecutionId : generateId() |
There was a problem hiding this comment.
Client-supplied execution ID lacks validation constraints
Medium Severity
The new code allows client sessions to supply an arbitrary executionId via requestedExecutionId, validated only as z.string().optional() with no format, length, or uniqueness constraints. Since execution IDs are used as database keys and storage paths throughout the system, a malicious or buggy client could inject an ID that collides with an existing execution, contains path-traversal characters, or is excessively long. Previously, executionId was always server-generated via generateId().
Reviewed by Cursor Bugbot for commit c9118e7. Configure here.
| options: FileMetadataInsertOptions | ||
| ): Promise<FileMetadataRecord> { | ||
| const { key, userId, workspaceId, context, originalName, contentType, size, id } = options | ||
| const { key, userId, workspaceId, context, originalName, contentType, size, folderId, id } = |
| options: FileMetadataInsertOptions | ||
| ): Promise<FileMetadataRecord> { | ||
| const { key, userId, workspaceId, context, originalName, contentType, size, id } = options | ||
| const { key, userId, workspaceId, context, originalName, contentType, size, folderId, id } = |
…ove impersonation banner (#4617) - Guard completeWithError against overwriting a cancelled execution status — cancel route writes cancelled to DB optimistically, but a block error racing the 500ms Redis check could finalize with failed before the engine detects cancellation - Add tests covering the guard: cancelled DB status skips the write, non-cancelled proceeds normally, DB failure falls through to cost-only fallback, and subsequent attempts are deduped after guard marks session complete - Move ImpersonationBanner from workspace root into components/ folder
* fix(files): fixed resource spacing on files directories pages * fix(build): align turbo schema version Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>


Uh oh!
There was an error while loading. Please reload this page.