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).
This commit is contained in:
15
src/tools.ts
15
src/tools.ts
@@ -382,16 +382,13 @@ export const createTools = (
|
|||||||
if (!providerID || !modelID)
|
if (!providerID || !modelID)
|
||||||
return "Cannot determine model for compaction. Please ensure the session has at least one message.";
|
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}%)` : "";
|
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.`;
|
setTimeout(() => {
|
||||||
} catch (err) {
|
ctx.client.session
|
||||||
return `Failed to trigger compaction: ${err instanceof Error ? err.message : String(err)}`;
|
.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.`;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user