fix(agents): rename auto_compaction_start/end to compaction_start/end

This commit is contained in:
wu.duozhen@xydigit.com
2026-04-16 22:45:00 +08:00
committed by Josh Lehman
parent 020a49de41
commit 8181b6de60
9 changed files with 38 additions and 38 deletions

View File

@@ -225,7 +225,7 @@ Events handled include:
- `tool_execution_start` / `tool_execution_update` / `tool_execution_end`
- `turn_start` / `turn_end`
- `agent_start` / `agent_end`
- `auto_compaction_start` / `auto_compaction_end`
- `compaction_start` / `compaction_end`
### 4. Prompting

View File

@@ -13,7 +13,7 @@ import {
waitForCompactionCount,
} from "./pi-embedded-subscribe.compaction-test-helpers.js";
import {
handleAutoCompactionEnd,
handleCompactionEnd,
reconcileSessionStoreCompactionCountAfterSuccess,
} from "./pi-embedded-subscribe.handlers.compaction.js";
import type { EmbeddedPiSubscribeContext } from "./pi-embedded-subscribe.handlers.types.js";
@@ -112,7 +112,7 @@ describe("reconcileSessionStoreCompactionCountAfterSuccess", () => {
});
});
describe("handleAutoCompactionEnd", () => {
describe("handleCompactionEnd", () => {
it("reconciles the session store after a successful compaction end event", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-compaction-handler-"));
const storePath = path.join(tmp, "sessions.json");
@@ -129,8 +129,8 @@ describe("handleAutoCompactionEnd", () => {
initialCount: 1,
});
handleAutoCompactionEnd(ctx, {
type: "auto_compaction_end",
handleCompactionEnd(ctx, {
type: "compaction_end",
result: { kept: 12 },
willRetry: false,
aborted: false,

View File

@@ -4,7 +4,7 @@ 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) {
export function handleCompactionStart(ctx: EmbeddedPiSubscribeContext) {
ctx.state.compactionInFlight = true;
ctx.state.livenessState = "paused";
ctx.ensureCompactionPromise();
@@ -39,7 +39,7 @@ export function handleAutoCompactionStart(ctx: EmbeddedPiSubscribeContext) {
}
}
export function handleAutoCompactionEnd(
export function handleCompactionEnd(
ctx: EmbeddedPiSubscribeContext,
evt: AgentEvent & { willRetry?: unknown; result?: unknown; aborted?: unknown },
) {

View File

@@ -16,8 +16,8 @@ import { isPromiseLike } from "./pi-embedded-subscribe.promise.js";
import { isAssistantMessage } from "./pi-embedded-utils.js";
export {
handleAutoCompactionEnd,
handleAutoCompactionStart,
handleCompactionEnd,
handleCompactionStart,
} from "./pi-embedded-subscribe.handlers.compaction.js";
export function handleAgentStart(ctx: EmbeddedPiSubscribeContext) {

View File

@@ -1,8 +1,8 @@
import {
handleAgentEnd,
handleAgentStart,
handleAutoCompactionEnd,
handleAutoCompactionStart,
handleCompactionEnd,
handleCompactionStart,
} from "./pi-embedded-subscribe.handlers.lifecycle.js";
import {
handleMessageEnd,
@@ -113,14 +113,14 @@ export function createEmbeddedPiSessionEventHandler(ctx: EmbeddedPiSubscribeCont
handleAgentStart(ctx);
});
return;
case "auto_compaction_start":
case "compaction_start":
scheduleEvent(evt, () => {
handleAutoCompactionStart(ctx);
handleCompactionStart(ctx);
});
return;
case "auto_compaction_end":
case "compaction_end":
scheduleEvent(evt, () => {
handleAutoCompactionEnd(ctx, evt as never);
handleCompactionEnd(ctx, evt as never);
});
return;
case "agent_end":

View File

@@ -58,7 +58,7 @@ describe("subscribeEmbeddedPiSession", () => {
for (const listener of listeners) {
listener({
type: "auto_compaction_end",
type: "compaction_end",
willRetry: true,
});
}
@@ -96,7 +96,7 @@ describe("subscribeEmbeddedPiSession", () => {
});
for (const listener of listeners) {
listener({ type: "auto_compaction_start" });
listener({ type: "compaction_start" });
}
expect(subscription.isCompacting()).toBe(true);
@@ -110,7 +110,7 @@ describe("subscribeEmbeddedPiSession", () => {
expect(resolved).toBe(false);
for (const listener of listeners) {
listener({ type: "auto_compaction_end", willRetry: false });
listener({ type: "compaction_end", willRetry: false });
}
await waitPromise;
@@ -147,7 +147,7 @@ describe("subscribeEmbeddedPiSession", () => {
});
for (const listener of listeners) {
listener({ type: "auto_compaction_end", willRetry: false });
listener({ type: "compaction_end", willRetry: false });
}
const usage = (session.messages?.[0] as { usage?: unknown } | undefined)?.usage;

View File

@@ -602,7 +602,7 @@ describe("subscribeEmbeddedPiSession", () => {
isError: false,
result: { ok: true },
});
emit({ type: "auto_compaction_end", willRetry: true, result: { summary: "compacted" } });
emit({ type: "compaction_end", willRetry: true, result: { summary: "compacted" } });
emit({ type: "agent_end" });
expect(subscription.getReplayState()).toEqual({
@@ -638,7 +638,7 @@ describe("subscribeEmbeddedPiSession", () => {
isError: false,
result: { details: { status: "ok" } },
});
emit({ type: "auto_compaction_end", willRetry: true, result: { summary: "compacted" } });
emit({ type: "compaction_end", willRetry: true, result: { summary: "compacted" } });
emit({ type: "agent_end" });
const payloads = extractAgentEventPayloads(onAgentEvent.mock.calls);

View File

@@ -8,8 +8,8 @@ describe("subscribeEmbeddedPiSession", () => {
runId: "run-3",
});
emit({ type: "auto_compaction_end", willRetry: true });
emit({ type: "auto_compaction_end", willRetry: true });
emit({ type: "compaction_end", willRetry: true });
emit({ type: "compaction_end", willRetry: true });
let resolved = false;
const waitPromise = subscription.waitForCompactionRetry().then(() => {
@@ -35,15 +35,15 @@ describe("subscribeEmbeddedPiSession", () => {
runId: "run-compaction-count",
});
emit({ type: "auto_compaction_start" });
emit({ type: "compaction_start" });
expect(subscription.getCompactionCount()).toBe(0);
// willRetry with result — counter IS incremented (overflow compaction succeeded)
emit({ type: "auto_compaction_end", willRetry: true, result: { summary: "s" } });
emit({ type: "compaction_end", willRetry: true, result: { summary: "s" } });
expect(subscription.getCompactionCount()).toBe(1);
// willRetry=false with result — counter incremented again
emit({ type: "auto_compaction_end", willRetry: false, result: { summary: "s2" } });
emit({ type: "compaction_end", willRetry: false, result: { summary: "s2" } });
expect(subscription.getCompactionCount()).toBe(2);
});
@@ -53,10 +53,10 @@ describe("subscribeEmbeddedPiSession", () => {
});
// No result (e.g. aborted or cancelled) — counter stays at 0
emit({ type: "auto_compaction_end", willRetry: false, result: undefined });
emit({ type: "compaction_end", willRetry: false, result: undefined });
expect(subscription.getCompactionCount()).toBe(0);
emit({ type: "auto_compaction_end", willRetry: false, aborted: true });
emit({ type: "compaction_end", willRetry: false, aborted: true });
expect(subscription.getCompactionCount()).toBe(0);
});
@@ -79,9 +79,9 @@ describe("subscribeEmbeddedPiSession", () => {
});
});
emit({ type: "auto_compaction_start" });
emit({ type: "auto_compaction_end", willRetry: true });
emit({ type: "auto_compaction_end", willRetry: false });
emit({ type: "compaction_start" });
emit({ type: "compaction_end", willRetry: true });
emit({ type: "compaction_end", willRetry: false });
stop();
@@ -99,7 +99,7 @@ describe("subscribeEmbeddedPiSession", () => {
sessionExtras: { isCompacting: true, abortCompaction },
});
emit({ type: "auto_compaction_start" });
emit({ type: "compaction_start" });
const waitPromise = subscription.waitForCompactionRetry();
subscription.unsubscribe();

View File

@@ -22,8 +22,8 @@ vi.mock("../infra/agent-events.js", () => ({
}));
import {
handleAutoCompactionEnd,
handleAutoCompactionStart,
handleCompactionEnd,
handleCompactionStart,
} from "../agents/pi-embedded-subscribe.handlers.compaction.js";
describe("compaction hook wiring", () => {
@@ -111,16 +111,16 @@ describe("compaction hook wiring", () => {
aborted?: boolean;
},
) {
handleAutoCompactionEnd(
handleCompactionEnd(
ctx as never,
{
type: "auto_compaction_end",
type: "compaction_end",
...event,
} as never,
);
}
it("calls runBeforeCompaction in handleAutoCompactionStart", () => {
it("calls runBeforeCompaction in handleCompactionStart", () => {
hookMocks.runner.hasHooks.mockReturnValue(true);
const ctx = {
@@ -136,7 +136,7 @@ describe("compaction hook wiring", () => {
ensureCompactionPromise: vi.fn(),
};
handleAutoCompactionStart(ctx as never);
handleCompactionStart(ctx as never);
expect(hookMocks.runner.runBeforeCompaction).toHaveBeenCalledTimes(1);
expectCompactionEvent({