Skip to content

Commit 055cb47

Browse files
committed
fix deleted kb article bug
1 parent 69300db commit 055cb47

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

apps/sim/lib/workspaces/fork/copy/copy-resources.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ export async function copyForkResourceContainers(
159159
.where(
160160
and(
161161
inArray(mcpServers.id, selection.mcpServers),
162-
eq(mcpServers.workspaceId, sourceWorkspaceId)
162+
eq(mcpServers.workspaceId, sourceWorkspaceId),
163+
isNull(mcpServers.deletedAt)
163164
)
164165
)
165166
// `generateMcpServerId` is deterministic on (workspace, url), so two selected
@@ -319,10 +320,16 @@ export async function copyForkResourceContent(params: {
319320
try {
320321
let afterDocId: string | null = null
321322
for (;;) {
323+
// Only copy LIVE documents - exclude soft-deleted and archived rows, matching
324+
// how the rest of the KB system treats them as gone (chunks/tags/search filter
325+
// both). A fork must not resurrect documents removed from the source base.
326+
const liveDocs = and(
327+
eq(document.knowledgeBaseId, kb.sourceId),
328+
isNull(document.deletedAt),
329+
isNull(document.archivedAt)
330+
)
322331
const where: SQL<unknown> | undefined =
323-
afterDocId === null
324-
? eq(document.knowledgeBaseId, kb.sourceId)
325-
: and(eq(document.knowledgeBaseId, kb.sourceId), gt(document.id, afterDocId))
332+
afterDocId === null ? liveDocs : and(liveDocs, gt(document.id, afterDocId))
326333
const docs = await db
327334
.select()
328335
.from(document)
@@ -332,9 +339,14 @@ export async function copyForkResourceContent(params: {
332339
if (docs.length === 0) break
333340
for (const doc of docs) {
334341
const childDocId = generateId()
335-
await db
336-
.insert(document)
337-
.values({ ...doc, id: childDocId, knowledgeBaseId: kb.childId, connectorId: null })
342+
await db.insert(document).values({
343+
...doc,
344+
id: childDocId,
345+
knowledgeBaseId: kb.childId,
346+
connectorId: null,
347+
deletedAt: null,
348+
archivedAt: null,
349+
})
338350
await copyDocumentEmbeddings(doc.id, childDocId, kb.childId)
339351
}
340352
afterDocId = docs[docs.length - 1].id

0 commit comments

Comments
 (0)