You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/sim/lib/knowledge/connectors/deletion.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,12 @@
2
2
3
3
All existing UI, API, and Copilot callers still enter `knowledge.connectors.delete` through its authorized application use case. Roles, scope checks, response shapes, audit attribution, and the workspace-only option to retain documents are unchanged.
4
4
5
-
When documents are removed, a transaction locks the canonical knowledge base and connector, counts the attached documents, marks the connector deleted, invalidates both sync leases, disables scheduling, and inserts one `knowledge.connector.cleanup` outbox event. Failure rolls back both the deletion and the event. Returned deletion counts describe documents logically removed from Sim; physical deletion follows asynchronously. The keep-documents path still performs its storage quota check and detachment atomically.
5
+
When documents are removed, a transaction locks the canonical knowledge base and connector, counts the attached documents, marks the connector deleted, invalidates both sync leases, disables scheduling, and inserts one `knowledge.connector.cleanup` outbox event. Failure rolls back both the deletion and the event. Returned deletion counts describe documents logically removed from Sim; physical deletion follows asynchronously.
6
6
7
7
The shared document access predicate excludes deleted connectors, including public and workspace access and internal indexing reads. Ingestion also checks connector liveness before claiming or committing document processing. Existing source-write leases reject late sync writes. Documents keep their connector reference until physical deletion, so they cannot become standalone readable or billable documents during cleanup. Restoring a knowledge base does not restore a directly deleted connector.
8
8
9
+
When documents are kept, the same transaction admits their storage against the payer's quota, sets the connector's `detached_at` instead of `deleted_at`, invalidates both sync leases, disables scheduling, and inserts one `knowledge.connector.detach` outbox event. The request writes no document: releasing a document nulls its `connector_id`, and the projection trigger then rewrites every enabled chunk of it in both search projections, each a fresh index entry, so an in-request release timed out on any sizeable source. A detached connector fails `connectorIsLive()`, so it cannot be synced, managed, or listed, while document visibility checks only `archived_at` and `deleted_at`, so its documents stay readable throughout. The detach worker releases at most 250 projection rows per table of the next 100 documents per transaction and flips those documents, resurrecting live tombstones and zeroing legacy skipped sizes, once none of their rows still names the connector; the trigger then has nothing to rewrite. Each flipped page is billed in its own transaction, so a document is billable exactly when it no longer names a connector. When no document remains, the worker drains the connector's history and member rows and deletes it.
10
+
9
11
The existing outbox worker runs cleanup, with 48 failure attempts and bounded continuations that do not consume that retry budget. Each transaction removes at most 1,000 chunks, 250 documents, or 1,000 sync-history/member rows. A run does at most four batches and yields after its time budget. Transactions use lock and statement timeouts. The worker verifies the connector's deletion timestamp, locks documents against late indexing commits, and commits storage cleanup intents before deleting those documents. It resolves storage ownership from the currently locked knowledge base. Already committed batches survive worker restarts. Failures remain retryable; exhausted events remain as dead letters while the source stays inaccessible.
10
12
11
13
After document and connector cleanup, credential grant revocation and unused-tag cleanup are retried as needed. Tag cleanup checks for existence rather than counting the entire remaining corpus. No provider credentials or document contents enter the connector cleanup payload.
0 commit comments