From 5995effa3248ba3ade10efc93288f2bc2f7e67fb Mon Sep 17 00:00:00 2001 From: Sreeram Sreedhar Date: Mon, 20 Apr 2026 17:34:15 -0700 Subject: [PATCH] bug fix --- .../src/convex-component/src/component/mutations.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/tools/src/convex-component/src/component/mutations.ts b/packages/tools/src/convex-component/src/component/mutations.ts index 046dc80d..66c104be 100644 --- a/packages/tools/src/convex-component/src/component/mutations.ts +++ b/packages/tools/src/convex-component/src/component/mutations.ts @@ -194,12 +194,16 @@ export const updateChatSession = internalMutation({ memoriesRetrieved: v.array(v.string()), }, handler: async (ctx, args) => { + const MAX_MESSAGES = 500 if (args.sessionId) { // Update existing session const session = await ctx.db.get(args.sessionId) if (session) { + const messages = [...session.messages, args.newMessage].slice( + -MAX_MESSAGES, + ) await ctx.db.patch(args.sessionId, { - messages: [...session.messages, args.newMessage], + messages, memoriesRetrieved: [ ...new Set([ ...session.memoriesRetrieved, @@ -240,13 +244,16 @@ export const trackChatMessage = mutation({ memoriesRetrieved: v.array(v.string()), }, handler: async (ctx, args) => { - // Inline the logic instead of calling another mutation + const MAX_MESSAGES = 500 if (args.sessionId) { // Update existing session const session = await ctx.db.get(args.sessionId) if (session) { + const messages = [...session.messages, args.newMessage].slice( + -MAX_MESSAGES, + ) await ctx.db.patch(args.sessionId, { - messages: [...session.messages, args.newMessage], + messages, memoriesRetrieved: [ ...new Set([ ...session.memoriesRetrieved,