Skip to content

Commit 746229c

Browse files
fix: preserve existing matched posts when running AI Match
The mergeMatches function was incorrectly dropping existing pending matches that weren't in new AI results. Since AI matching only evaluates queued posts (not already-evaluated ones), there's no overlap between existing and new matches - they should simply be combined. Removed the status !== 'pending' condition so all existing matched posts are preserved regardless of their status.
1 parent 7c8f65d commit 746229c

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/background/matcher.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,10 @@ export function mergeMatches(
266266
}
267267
}
268268

269-
// Add any existing matches not in new results that haven't been acted on
269+
// Add all remaining existing matches (not in new results)
270+
// These should be preserved since they were already evaluated and matched
270271
for (const existing of existingMap.values()) {
271-
if (existing.status !== 'pending') {
272-
merged.push(existing);
273-
}
272+
merged.push(existing);
274273
}
275274

276275
// Sort by score descending

tests/background/matcher.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('Matcher', () => {
217217
expect(merged[0].score).toBe(0.8); // Score should be updated
218218
});
219219

220-
it('should add new matches not in existing', () => {
220+
it('should add new matches while keeping existing matches', () => {
221221
const existing = [
222222
createTestMatch({
223223
post: createTestPost({ id: 'post-1' }),
@@ -232,28 +232,35 @@ describe('Matcher', () => {
232232

233233
const merged = mergeMatches(existing, newMatches);
234234

235-
expect(merged.length).toBe(1); // Only new matches by default
235+
expect(merged.length).toBe(2); // Both existing and new matches should be kept
236+
expect(merged.some((m) => m.post.id === 'post-1')).toBe(true);
236237
expect(merged.some((m) => m.post.id === 'post-2')).toBe(true);
237238
});
238239

239-
it('should keep non-pending existing matches', () => {
240+
it('should keep existing matches regardless of status', () => {
240241
const existing = [
241242
createTestMatch({
242243
post: createTestPost({ id: 'post-1' }),
244+
status: 'pending',
245+
}),
246+
createTestMatch({
247+
post: createTestPost({ id: 'post-2' }),
243248
status: 'replied',
244249
}),
245250
];
246251

247252
const newMatches = [
248253
createTestMatch({
249-
post: createTestPost({ id: 'post-2' }),
254+
post: createTestPost({ id: 'post-3' }),
250255
}),
251256
];
252257

253258
const merged = mergeMatches(existing, newMatches);
254259

260+
expect(merged.length).toBe(3);
255261
expect(merged.some((m) => m.post.id === 'post-1')).toBe(true);
256262
expect(merged.some((m) => m.post.id === 'post-2')).toBe(true);
263+
expect(merged.some((m) => m.post.id === 'post-3')).toBe(true);
257264
});
258265

259266
it('should respect maxMatchedPosts limit', () => {

0 commit comments

Comments
 (0)