diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ee24be3329..5832e21775f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/agents/pi-embedded-subscribe.handlers.compaction.ts b/src/agents/pi-embedded-subscribe.handlers.compaction.ts index f28e47d1a9d..a9dda4110e0 100644 --- a/src/agents/pi-embedded-subscribe.handlers.compaction.ts +++ b/src/agents/pi-embedded-subscribe.handlers.compaction.ts @@ -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(); diff --git a/src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.waits-multiple-compaction-retries-before-resolving.test.ts b/src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.waits-multiple-compaction-retries-before-resolving.test.ts index bab3d4e3dfe..334839730f6 100644 --- a/src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.waits-multiple-compaction-retries-before-resolving.test.ts +++ b/src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.waits-multiple-compaction-retries-before-resolving.test.ts @@ -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",