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

@@ -34,6 +34,7 @@ Docs: https://docs.openclaw.ai
### Fixes
- Agents/Compaction: count auto-compactions only after a non-retry `auto_compaction_end`, keeping session `compactionCount` aligned to completed compactions.
- Security/CLI: redact sensitive values in `openclaw config get` output before printing config paths, preventing credential leakage to terminal output/history. (#13683) Thanks @SleuthCo.
- Install/Discord Voice: make `@discordjs/opus` an optional dependency so `openclaw` install/update no longer hard-fails when native Opus builds fail, while keeping `opusscript` as the runtime fallback decoder for Discord voice flows. (#23737, #23733, #23703) Thanks @jeadland, @Sheetaa, and @Breakyman.
- Docker/Setup: precreate `$OPENCLAW_CONFIG_DIR/identity` during `docker-setup.sh` so CLI commands that need device identity (for example `devices list`) avoid `EACCES ... /home/node/.openclaw/identity` failures on restrictive bind mounts. (#23948) Thanks @ackson-beep.

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",