Skip to content

Commit 30745dc

Browse files
committed
fix(knowledge): stabilize skipped connector documents
1 parent adbb9b6 commit 30745dc

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,23 @@ describe('classifyExternalDoc', () => {
515515
).toEqual({ type: 'update', existingId: 'doc-1' })
516516
})
517517

518+
it('uses the same skip replacement rule after deferred hydration', async () => {
519+
const { shouldReplaceExistingWithSkippedDocument } = await import(
520+
'@/lib/knowledge/connectors/sync-engine'
521+
)
522+
523+
expect(shouldReplaceExistingWithSkippedDocument({ storageKey: null }, {})).toBe(true)
524+
expect(shouldReplaceExistingWithSkippedDocument({ storageKey: 'kb/indexed.txt' }, {})).toBe(
525+
false
526+
)
527+
expect(
528+
shouldReplaceExistingWithSkippedDocument(
529+
{ storageKey: 'kb/indexed.txt' },
530+
{ skippedExistingDisposition: 'replace' }
531+
)
532+
).toBe(true)
533+
})
534+
518535
it('replaces stale indexed content for an authoritative skip', async () => {
519536
const { classifyExternalDoc } = await import('@/lib/knowledge/connectors/sync-engine')
520537

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ type DocClassification =
454454
| { type: 'unchanged' }
455455
| { type: 'drop' }
456456

457+
export function shouldReplaceExistingWithSkippedDocument(
458+
existing: { storageKey?: string | null },
459+
skipped: Pick<ExternalDocument, 'skippedExistingDisposition'>
460+
): boolean {
461+
return existing.storageKey === null || skipped.skippedExistingDisposition === 'replace'
462+
}
463+
457464
/**
458465
* Decides what a listed external document becomes during reconciliation.
459466
*
@@ -487,7 +494,7 @@ export function classifyExternalDoc(
487494
): DocClassification {
488495
if (extDoc.skippedReason) {
489496
if (!existing) return { type: 'skip' }
490-
return existing.storageKey === null || extDoc.skippedExistingDisposition === 'replace'
497+
return shouldReplaceExistingWithSkippedDocument(existing, extDoc)
491498
? { type: 'skip', existingId: existing.id }
492499
: { type: 'unchanged' }
493500
}
@@ -2377,7 +2384,8 @@ export async function executeSync(
23772384
extDoc: mergeHydratedSkippedDocument(op.extDoc, fullDoc),
23782385
})
23792386
} else if (op.type === 'update') {
2380-
if (fullDoc.skippedExistingDisposition === 'replace') {
2387+
const existing = priorByExternalId.get(op.extDoc.externalId)
2388+
if (existing && shouldReplaceExistingWithSkippedDocument(existing, fullDoc)) {
23812389
skipOps.push({
23822390
type: 'skip',
23832391
existingId: op.existingId,

0 commit comments

Comments
 (0)