Compaction: count only completed auto-compactions (#24056)

* Compaction: count only completed auto-compactions

* Compaction: count only non-retry completions

* Changelog: note completed-only compaction counting

* Agents/Compaction: guard optional compaction increment
This commit is contained in:
Tak Hoffman
2026-02-22 20:16:45 -06:00
committed by GitHub
parent 05691be511
commit 457835b104
3 changed files with 19 additions and 1 deletions

View File

@@ -5,7 +5,6 @@ import type { EmbeddedPiSubscribeContext } from "./pi-embedded-subscribe.handler
export function handleAutoCompactionStart(ctx: EmbeddedPiSubscribeContext) {
ctx.state.compactionInFlight = true;
ctx.incrementCompactionCount();
ctx.ensureCompactionPromise();
ctx.log.debug(`embedded run compaction start: runId=${ctx.params.runId}`);
emitAgentEvent({
@@ -40,6 +39,9 @@ export function handleAutoCompactionEnd(
) {
ctx.state.compactionInFlight = false;
const willRetry = Boolean(evt.willRetry);
if (!willRetry) {
ctx.incrementCompactionCount?.();
}
if (willRetry) {
ctx.noteCompactionRetry();
ctx.resetForCompactionRetry();

View File

@@ -30,6 +30,21 @@ describe("subscribeEmbeddedPiSession", () => {
expect(resolved).toBe(true);
});
it("does not count compaction until end event", async () => {
const { emit, subscription } = createSubscribedSessionHarness({
runId: "run-compaction-count",
});
emit({ type: "auto_compaction_start" });
expect(subscription.getCompactionCount()).toBe(0);
emit({ type: "auto_compaction_end", willRetry: true });
expect(subscription.getCompactionCount()).toBe(0);
emit({ type: "auto_compaction_end", willRetry: false });
expect(subscription.getCompactionCount()).toBe(1);
});
it("emits compaction events on the agent event bus", async () => {
const { emit } = createSubscribedSessionHarness({
runId: "run-compaction",