mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 03:44:31 +00:00
fix: preserve assistant usage snapshots during compaction cleanup
This commit is contained in:
@@ -2,6 +2,7 @@ import type { AgentEvent } from "@mariozechner/pi-agent-core";
|
||||
import { emitAgentEvent } from "../infra/agent-events.js";
|
||||
import { getGlobalHookRunner } from "../plugins/hook-runner-global.js";
|
||||
import type { EmbeddedPiSubscribeContext } from "./pi-embedded-subscribe.handlers.types.js";
|
||||
import { makeZeroUsageSnapshot } from "./usage.js";
|
||||
|
||||
export function handleAutoCompactionStart(ctx: EmbeddedPiSubscribeContext) {
|
||||
ctx.state.compactionInFlight = true;
|
||||
@@ -96,9 +97,8 @@ function clearStaleAssistantUsageOnSessionMessages(ctx: EmbeddedPiSubscribeConte
|
||||
if (candidate.role !== "assistant") {
|
||||
continue;
|
||||
}
|
||||
if (!("usage" in candidate)) {
|
||||
continue;
|
||||
}
|
||||
delete (candidate as { usage?: unknown }).usage;
|
||||
// pi-coding-agent expects assistant usage to exist when computing context usage.
|
||||
// Reset stale snapshots to zeros instead of deleting the field.
|
||||
candidate.usage = makeZeroUsageSnapshot();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user