Skip to content

Commit ddc52a4

Browse files
committed
fix(knowledge): re-verify connectorId in updateDocument's atomic write
Greptile P1: updateDocument's content-update/resurrect write only checked document.id and archivedAt, never connectorId — despite connectorId being a parameter — so a document a concurrent "delete connector, keep documents" request already detached could still be matched, resurrected, and overwritten with connector-sourced content after the connector was deleted. Adds the same connectorId ownership check already used by the reconciliation transaction and hardDeleteDocuments in this PR.
1 parent 73e767e commit ddc52a4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

apps/sim/lib/knowledge/connectors/sync-engine.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,17 @@ async function updateDocument(
15411541
// on deletedAt IS NULL, rejects the row and leaves stale content active.
15421542
deletedAt: null,
15431543
})
1544-
.where(and(eq(document.id, existingDocId), isNull(document.archivedAt)))
1544+
.where(
1545+
and(
1546+
eq(document.id, existingDocId),
1547+
// A concurrent "delete connector, keep documents" request can null out
1548+
// connectorId between this sync's liveness check and this write. Without
1549+
// this check, that now-standalone document would still match on id alone
1550+
// and get overwritten with connector-sourced content post-detachment.
1551+
eq(document.connectorId, connectorId),
1552+
isNull(document.archivedAt)
1553+
)
1554+
)
15451555
.returning({ id: document.id })
15461556
.then((rows) => {
15471557
if (rows.length === 0) {

0 commit comments

Comments
 (0)