fix(ai): resolve contacts across all history

Use the all-history contacts snapshot when translating stable contact references into cross-chat scopes, so older source sessions are not silently excluded from historical analysis.
This commit is contained in:
digua committed 2026-08-22 07:43:31 +08:00
1 parent 831861a993
commit 812440c565
2 files changed
+39 -1

No files matched your search

@@ -239,6 +239,41 @@ test('entity resolution uses contact keys and resolves per-session member ids wi
}
})
test('entity resolution uses the all-history contact snapshot so older source sessions remain searchable', () => {
const { env } = createFixture()
try {
const contactsService: Pick<ContactsService, 'getContactDetail'> = {
getContactDetail: (_key, options) =>
detail(
contact({
key: 'test:alice',
platformId: 'alice',
displayName: 'Alice',
sourceSessions:
options?.timeRangePreset === 'all'
? [
{ id: 'private-alice', name: 'Alice private', platform: 'test', type: 'private' },
{ id: 'group-work', name: 'Work group', platform: 'test', type: 'group' },
]
: [{ id: 'group-work', name: 'Work group', platform: 'test', type: 'group' }],
})
),
}
const service = createCrossChatAnalysisService({ adapter: env.adapter, contactsService })
const result = service.resolveEntities([{ type: 'contact', contactKey: 'test:alice', displayName: 'Alice' }])
assert.deepEqual(
result.contacts[0]?.sessions.map((session) => session.sessionId),
['private-alice', 'group-work']
)
assert.equal(result.coverage.candidateSessions, 2)
assert.equal(result.coverage.resolvedSessions, 2)
} finally {
env.cleanup()
}
})
test('scoped search filters by resolved member ids and keeps compound evidence identity', async () => {
const { env, contactsService } = createFixture()
try {
@@ -83,7 +83,10 @@ class DefaultCrossChatAnalysisService implements CrossChatAnalysisService {
continue
}
const detail = this.deps.contactsService.getContactDetail(ref.contactKey, { acceptStale: true })
const detail = this.deps.contactsService.getContactDetail(ref.contactKey, {
acceptStale: true,
timeRangePreset: 'all',
})
const contact = detail.contact
if (!contact) {
contacts.push({