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:
17
src/tools.ts
17
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 {
|
const contextNote = info ? ` (was at ${info.percentage}%)` : "";
|
||||||
await ctx.client.session.summarize({
|
setTimeout(() => {
|
||||||
path: { id: context.sessionID },
|
ctx.client.session
|
||||||
body: { providerID, modelID },
|
.summarize({ path: { id: context.sessionID }, body: { providerID, modelID } })
|
||||||
});
|
.catch(() => {});
|
||||||
const contextNote = info ? ` (was at ${info.percentage}%)` : "";
|
}, 0);
|
||||||
return `Compaction triggered successfully${contextNote}. The session will be summarized and you'll continue with freed context space.`;
|
return `Compaction triggered${contextNote}. The session will be summarized shortly and you'll continue with freed context space.`;
|
||||||
} catch (err) {
|
|
||||||
return `Failed to trigger compaction: ${err instanceof Error ? err.message : String(err)}`;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user