fix(knowledge): give users choice to keep or delete documents when removing connector#3825
Conversation
PR SummaryMedium Risk Overview The workspace UI updates the removal modal to reflect this behavior and adds a checkbox to optionally delete all synced documents, wiring the flag through the Written by Cursor Bugbot for commit a2959f5. Configure here. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR fixes a misleading connector-removal modal that previously claimed "documents will remain" while actually hard-deleting them. It adds an opt-in checkbox ("Also delete all synced documents", unchecked by default) to the UI, threads Key changes:
Confidence Score: 5/5Safe to merge — the core logic is correct, the FK migration is well-formed, and the only finding is a stale test name with missing coverage for the deletion branch. All remaining findings are P2. The prior dangling-FK concern was fully addressed by switching to ON DELETE SET NULL. The UI/API/hook changes are straightforward and correctly implement the described behaviour. The only gap is that the ?deleteDocuments=true code path lacks a dedicated test and the existing test's name is now a misnomer — neither blocks correct production behaviour. apps/sim/app/api/knowledge/[id]/connectors/[connectorId]/route.test.ts — test name is stale and ?deleteDocuments=true path is untested. Important Files Changed
Sequence DiagramsequenceDiagram
actor User
participant UI as ConnectorsSection
participant Hook as useDeleteConnector
participant API as DELETE /connectors/:id
participant DB as PostgreSQL
User->>UI: Click "Remove Connector"
UI->>User: Show modal (checkbox unchecked)
User->>UI: (Optionally) Check "Also delete all synced documents"
User->>UI: Click "Remove"
UI->>Hook: deleteConnector({ knowledgeBaseId, connectorId, deleteDocuments })
alt deleteDocuments = false (default)
Hook->>API: DELETE /connectors/:id
API->>DB: BEGIN TRANSACTION
API->>DB: SELECT docs (active only)
API->>DB: DELETE FROM knowledge_connector WHERE id = :connectorId
DB-->>DB: ON DELETE SET NULL → document.connectorId = NULL
API->>DB: COMMIT
API-->>Hook: { success: true }
else deleteDocuments = true
Hook->>API: DELETE /connectors/:id?deleteDocuments=true
API->>DB: BEGIN TRANSACTION
API->>DB: SELECT docs (active only)
API->>DB: DELETE FROM embedding WHERE documentId IN (docs)
API->>DB: DELETE FROM document WHERE id IN (docs)
API->>DB: DELETE FROM knowledge_connector WHERE id = :connectorId
API->>DB: COMMIT
API->>API: deleteDocumentStorageFiles(deletedDocs)
API->>API: cleanupUnusedTagDefinitions(knowledgeBaseId)
API-->>Hook: { success: true }
end
Hook-->>UI: onSuccess → closeDeleteModal()
Reviews (2): Last reviewed commit: "fix(knowledge): fix connector delete tes..." | Re-trigger Greptile |
apps/sim/app/api/knowledge/[id]/connectors/[connectorId]/route.ts
Outdated
Show resolved
Hide resolved
apps/sim/app/api/knowledge/[id]/connectors/[connectorId]/route.ts
Outdated
Show resolved
Hide resolved
…ension validator - Extract `isAlphanumericExtension` helper to deduplicate regex across parser-extension.ts and validation.ts - Extract `closeDeleteModal` callback to eliminate 4x scattered state resets - Add archivedAt/deletedAt filters to UPDATE query in keep-docs delete path - Parallelize storage file cleanup and tag definition cleanup with Promise.all - Deduplicate URL construction in delete connector hook Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nsion Use SUPPORTED_DOCUMENT_EXTENSIONS and isSupportedExtension from validation.ts instead of maintaining a separate identical list. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The cascade behavior meant deleting a connector would always delete its documents, contradicting the "keep documents" option. With set null, the database automatically nullifies connectorId when a connector is removed, and we only need explicit deletion when the user opts in. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
abbc17e to
ee5cc5b
Compare
Use `new URL(request.url).searchParams` instead of `request.nextUrl.searchParams` for compatibility with test mocks. Add missing `connectorType` to test fixture. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@cursor review |
|
@greptile |
Summary
connectorIdforeign key?deleteDocuments=truequery param on DELETE endpointType of Change
Testing
Tested manually
Checklist