mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 06:24:34 +00:00
fix(agents): harden compaction and reset safety
Co-authored-by: jaden-clovervnd <91520439+jaden-clovervnd@users.noreply.github.com> Co-authored-by: Sid <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: Marcus Widing <245375637+widingmarcus-cyber@users.noreply.github.com>
This commit is contained in:
@@ -52,6 +52,7 @@ export function handleAutoCompactionEnd(
|
||||
ctx.log.debug(`embedded run compaction retry: runId=${ctx.params.runId}`);
|
||||
} else {
|
||||
ctx.maybeResolveCompactionWait();
|
||||
clearStaleAssistantUsageOnSessionMessages(ctx);
|
||||
}
|
||||
emitAgentEvent({
|
||||
runId: ctx.params.runId,
|
||||
@@ -81,3 +82,23 @@ export function handleAutoCompactionEnd(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearStaleAssistantUsageOnSessionMessages(ctx: EmbeddedPiSubscribeContext): void {
|
||||
const messages = ctx.params.session.messages;
|
||||
if (!Array.isArray(messages)) {
|
||||
return;
|
||||
}
|
||||
for (const message of messages) {
|
||||
if (!message || typeof message !== "object") {
|
||||
continue;
|
||||
}
|
||||
const candidate = message as { role?: unknown; usage?: unknown };
|
||||
if (candidate.role !== "assistant") {
|
||||
continue;
|
||||
}
|
||||
if (!("usage" in candidate)) {
|
||||
continue;
|
||||
}
|
||||
delete (candidate as { usage?: unknown }).usage;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user