diff --git a/packages/data-schemas/src/methods/chatProject.spec.ts b/packages/data-schemas/src/methods/chatProject.spec.ts index ca60fd0a7b..53f283a5a0 100644 --- a/packages/data-schemas/src/methods/chatProject.spec.ts +++ b/packages/data-schemas/src/methods/chatProject.spec.ts @@ -313,13 +313,17 @@ describe('ChatProject methods', () => { ]); await SharedLink.create({ conversationId: 'convo-1', user, shareId: uuidv4() }); - await methods.assignConversationToProject( + const result = await methods.assignConversationToProject( user, 'convo-1', project._id!.toString(), ephemeralConfig, ); + expect(result?.conversation.isTemporary).toBe(true); + expect(result?.conversation.expiredAt).toBeInstanceOf(Date); + expect(result?.conversation.chatProjectId).toBe(project._id!.toString()); + const conversation = await Conversation.findOne({ user, conversationId: 'convo-1', diff --git a/packages/data-schemas/src/methods/chatProject.ts b/packages/data-schemas/src/methods/chatProject.ts index cb7dd7fb35..45772512d7 100644 --- a/packages/data-schemas/src/methods/chatProject.ts +++ b/packages/data-schemas/src/methods/chatProject.ts @@ -486,6 +486,16 @@ export function createChatProjectMethods(mongoose: typeof import('mongoose')): C } const previousProjectId = conversation.chatProjectId ?? null; + + /** + * Convert the touched conversation to the forced (ephemeral) window before capturing the + * updated document. The caller returns this object straight to the client, which writes it + * into the active conversation and the React Query cache, so it must already carry the + * isTemporary/expiredAt fields rather than a stale pre-conversion snapshot. A no-op outside + * forced retention. + */ + await forceConversationRetention(user, conversationId, interfaceConfig); + const update = normalizedProjectId == null ? { $unset: { chatProjectId: '' } } @@ -500,8 +510,6 @@ export function createChatProjectMethods(mongoose: typeof import('mongoose')): C return null; } - await forceConversationRetention(user, conversationId, interfaceConfig); - const projectIds = new Set( [previousProjectId, normalizedProjectId].filter((id): id is string => Boolean(id)), );