From 97a472c5f853945f539c5fdb3239ca0f1812829c Mon Sep 17 00:00:00 2001 From: "glm-5.1" Date: Tue, 21 Apr 2026 11:47:34 +0000 Subject: [PATCH] Fix memory_compact deadlock: return immediately, fire summarize via setTimeout The tool was awaiting ctx.client.session.summarize() but compaction can't start until the tool returns control. Now returns right away and schedules the summarize call via setTimeout(0). --- src/tools.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/tools.ts b/src/tools.ts index fa68e45..f8fd4af 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -382,16 +382,13 @@ export const createTools = ( if (!providerID || !modelID) return "Cannot determine model for compaction. Please ensure the session has at least one message."; - try { - await ctx.client.session.summarize({ - path: { id: context.sessionID }, - body: { providerID, modelID }, - }); - const contextNote = info ? ` (was at ${info.percentage}%)` : ""; - return `Compaction triggered successfully${contextNote}. The session will be summarized and you'll continue with freed context space.`; - } catch (err) { - return `Failed to trigger compaction: ${err instanceof Error ? err.message : String(err)}`; - } + const contextNote = info ? ` (was at ${info.percentage}%)` : ""; + setTimeout(() => { + ctx.client.session + .summarize({ path: { id: context.sessionID }, body: { providerID, modelID } }) + .catch(() => {}); + }, 0); + return `Compaction triggered${contextNote}. The session will be summarized shortly and you'll continue with freed context space.`; }, }), });