feat(knowledge): multipart knowledge document uploads - #6244
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview The shared multipart layer gains a Completion is idempotent (upload id = document id): retries return the bound document; The workspace knowledge upload hook switches to Reviewed by Cursor Bugbot for commit 09c27a4. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThe PR adds multipart knowledge-document uploads to the public and session-authenticated APIs, migrates the knowledge upload UI to the session flow, and hardens token scoping and idempotent completion.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the prior billing-ordering, retry-idempotency, and storage-cleanup findings are addressed by bound-document-first finalization, admission-only usage enforcement, non-destructive failure handling, and delayed orphan cleanup.
|
| Filename | Overview |
|---|---|
| apps/sim/app/api/v2/knowledge/[id]/documents/uploads/utils.ts | Centralizes knowledge upload creation, ownership binding, abort protection, and idempotent finalization; the latest cleanup-race fix retains uploaded state for safe retries. |
| apps/sim/lib/uploads/multipart-session/service.ts | Extends the shared multipart service with knowledge-document scoping, key validation, quota checks, and purpose-bound ownership verification. |
| apps/sim/app/workspace/[workspaceId]/knowledge/hooks/use-knowledge-upload.ts | Replaces legacy presigned and proxied upload paths with the shared multipart session client. |
| apps/sim/lib/knowledge/orchestration/documents.ts | Adds deterministic document binding and retry convergence around upload-backed knowledge-document creation. |
| apps/sim/background/cleanup-soft-deletes.ts | Extends delayed orphan-binding cleanup to cover abandoned multipart knowledge uploads while excluding keys referenced by documents. |
| apps/docs/openapi-v2-knowledge.json | Documents the multipart knowledge-document upload lifecycle, request contracts, and response schemas. |
Sequence Diagram
sequenceDiagram
participant Client
participant API as Knowledge Upload API
participant Store as Object Storage
participant DB as Ownership and Document DB
participant Queue as Processing Queue
Client->>API: Create upload session
API->>Store: Initiate multipart upload
API->>DB: Record KB ownership binding
API-->>Client: Signed upload token
Client->>API: Request part URLs
API-->>Client: Signed part URLs
Client->>Store: Upload parts
Client->>API: Complete upload
API->>Store: Assemble and verify object
API->>DB: Look up deterministic document ID
alt Document already bound
DB-->>API: Existing document
else First completion
API->>DB: Create pending document
API->>Queue: Queue document processing
end
API-->>Client: Completed upload and document
Reviews (5): Last reviewed commit: "fix(uploads): prevent multipart cleanup ..." | Re-trigger Greptile
|
@cursor review |
|
@cursor review |
|
@cursor review |
|
@cursor review |
There was a problem hiding this comment.
✅ 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 09c27a4. Configure here.
Summary
knowledge_documentpurpose: knowledge-base storage keys, KB-scoped quota checks, and a 100MB cap inMAX_KNOWLEDGE_DOCUMENT_FILE_SIZEknowledgeBaseIdandpurposeinto the signed upload token, and reject any token whose purpose doesn't match its storage context or key prefix.getOwnedUploadSessionnow requirespurpose, so a workspace-file or table-import token can't be replayed against a knowledge endpointfinalizeKnowledgeDocumentUploadbetween both complete routes. A retry is answered from the bound document before any work that can fail independently of the upload, and cleanup is gated on the upload still being unbound — uploaded bytes are never deleted out from under a live document rowType of Change
Testing
bun run lint— cleantype-checkreports only errors that are pre-existing onimprovement/v2-endpoints(providers/*,workspace-file-manager.ts,contracts/v2/credentials.ts) — the clean base worktree at the same commit reports the identical set. Same for the 7 failures intrack-chat-upload.test.tsChecklist