Skip to content

Commit 92b6812

Browse files
committed
fix(workspace-source): count a finished replacement among the documents keeping their chunks
1 parent b8af837 commit 92b6812

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎apps/sim/lib/workspace-source/application/kinds/knowledge/diff.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ export async function diffKnowledgeBase(input: {
363363
...changes.finishes.map((finish) => finish.replaces.id),
364364
...changes.deletes.map((doc) => doc.id),
365365
])
366-
const keepingChunks = [...byName.values()].filter((doc) => !reindexed.has(doc.id)).length
366+
// A finished replacement is already stored and indexed, so it keeps its chunks too.
367+
const keepingChunks =
368+
[...byName.values()].filter((doc) => !reindexed.has(doc.id)).length + changes.finishes.length
367369
changes.diagnostics.push(
368370
...indexingFindings(key, changes.uploads, chunkingChanged, keepingChunks)
369371
)

‎apps/sim/lib/workspace-source/application/knowledge.integration.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,38 @@ describe('knowledge bases as workspace source', () => {
10481048
}
10491049
)
10501050

1051+
check(
1052+
'a chunking change counts the replacement a stopped replace left among the documents keeping their chunks',
1053+
async () => {
1054+
const { workspaceId, read, dir } = await setUp()
1055+
const edited = withDoc(dir, REFUNDS, '# Refunds\nWithin 60 days.\n')
1056+
const failing = vi
1057+
.spyOn(deleteKnowledgeDocument, 'execute')
1058+
.mockRejectedValueOnce(new Error('storage unavailable'))
1059+
.mockRejectedValueOnce(new Error('storage unavailable'))
1060+
const first = await apply(workspaceId, edited, { base: read.base }).finally(() =>
1061+
failing.mockRestore()
1062+
)
1063+
expect(first.failed).toMatchObject({ key: 'policies' })
1064+
1065+
const planned = await apply(
1066+
workspaceId,
1067+
{
1068+
...edited,
1069+
files: {
1070+
...edited.files,
1071+
[POLICIES_FILE]: declaration('Policies', '\n chunking: { maxSize: 512 },'),
1072+
},
1073+
},
1074+
{ base: first.base, dryRun: true, carry: 'none' }
1075+
)
1076+
1077+
// The finished replacement and shipping.txt keep their chunks; the replaced refunds.md goes.
1078+
const chunking = planned.diagnostics.find((finding) => finding.code === 'I_KB_CHUNKING')
1079+
expect(chunking?.message).toContain('2 stored document(s) keep their chunks')
1080+
}
1081+
)
1082+
10511083
check('a create that fails partway is adopted and finished by the next apply', async () => {
10521084
const workspaceId = await newWorkspace()
10531085
const failing = failUpload(2)

0 commit comments

Comments
 (0)