:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): stop a follow-up message from aborting a running compaction (#89067)
Alessandro Pogliaghieb7d8b9435ae
diff --git a/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts b/products/desktop/packages/agent/src/adapters/claude/claude-agent.tsindex 605718dc3e04..c264a0c77caa 100644--- a/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts+++ b/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts@@ -597,7 +597,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {this.session.activeTurn !== null || this.session.turnQueue.length > 0;const isSteer = isSteerMeta(params._meta);- if (hasInFlightTurns && isSteer) {+ if (hasInFlightTurns && isSteer && !this.session.compacting) {// Fold into the running turn (promptToClaude tagged it priority:"now");// the benign end_turn is ignored by clients, which key off _meta.steer.const owner =@@ -754,13 +754,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {cache_read_input_tokens: 0,cache_creation_input_tokens: 0,};- // Tracks whether we're inside a compaction. The SDK emits the terminal- // `status` (compact_result success/failed) twice for a single failed- // compaction, and the two messages are indistinguishable, so we report the- // outcome only while a compaction is in progress, then clear this. A fresh- // `compacting` status sets it again, so every distinct compaction (e.g.- // repeated auto-compactions in a long turn) is still shown.- let compactionInProgress = false;let stopReason: PromptResponse["stopReason"] = "end_turn";// Read live: model switches reset session.lastContextWindowSize.@@ -831,7 +824,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {cache_read_input_tokens: 0,cache_creation_input_tokens: 0,};- compactionInProgress = false;+ session.compacting = false;stopReason = "end_turn";// sessionResources is intentionally NOT reset — the products list// accumulates across the whole session and is deduped, not per-turn.@@ -1047,18 +1040,18 @@ export class ClaudeAcpAgent extends BaseAcpAgent {// The SDK signals manual `/compact` completion with a status// message carrying `compact_result`, not the `compact_boundary`// message (which only fires when there's content to compact).- // Gate the user-facing outcome on `compactionInProgress` to+ // Gate the user-facing outcome on `session.compacting` to// dedupe the duplicate terminal status the SDK emits for failed// compactions.if (message.status === "compacting") {- compactionInProgress = true;+ session.compacting = true;// Fall through to handleSystemMessage so the COMPACTING// extNotification still fires.} else if (message.compact_result === "success" &&- compactionInProgress+ session.compacting) {- compactionInProgress = false;+ session.compacting = false;await this.client.sessionUpdate({sessionId,update: {@@ -1083,9 +1076,9 @@ export class ClaudeAcpAgent extends BaseAcpAgent {break;} else if (message.compact_result === "failed" &&- compactionInProgress+ session.compacting) {- compactionInProgress = false;+ session.compacting = false;// A failed compaction never emits a `compact_boundary`, so emit a// structured failure status: the renderer clears the "Compacting…"// spinner and reports the outcome as its own status row (a separatordiff --git a/products/desktop/packages/agent/src/adapters/claude/claude-agent.turn-queue.test.ts b/products/desktop/packages/agent/src/adapters/claude/claude-agent.turn-queue.test.tsindex 9760a7ddcf0f..bd7e60c2dc50 100644--- a/products/desktop/packages/agent/src/adapters/claude/claude-agent.turn-queue.test.ts+++ b/products/desktop/packages/agent/src/adapters/claude/claude-agent.turn-queue.test.ts@@ -159,6 +159,38 @@ describe("ClaudeAcpAgent turn queue input dispatch", () => {await expect(second).rejects.toThrow(/session has ended/);});+ it("never hands a steer to the SDK while a compaction is running", async () => {+ const sessionId = "s-steer-compacting";+ const harness = installHarness(sessionId);+ const first = harness.agent.prompt({+ sessionId,+ prompt: [{ type: "text", text: "first" }],+ });+ await tick();+ echoTurn(harness.query, sessionOf(harness.agent).turnQueue[0].promptUuid);+ await tick();+ harness.query._mockHelpers.sendMessage({+ type: "system",+ subtype: "status",+ status: "compacting",+ } as unknown as SDKMessage);+ await tick();++ const steer = harness.agent.prompt({+ sessionId,+ prompt: [{ type: "text", text: "change direction" }],+ _meta: { steer: true },+ });++ await expect(steer).resolves.toMatchObject({ _meta: { steer: false } });+ expect(harness.pushed).toHaveLength(1);++ harness.query._mockHelpers.sendMessage(createSuccessResult());+ await tick();+ harness.query._mockHelpers.complete();+ await expect(first).resolves.toBeDefined();+ });+it("never hands a prompt cancelled while queued to the SDK", async () => {const sessionId = "s-cancel-queued";const { agent, query, pushed, first, second } =diff --git a/products/desktop/packages/agent/src/adapters/claude/types.ts b/products/desktop/packages/agent/src/adapters/claude/types.tsindex 0b36ec468fe1..676300fff8fb 100644--- a/products/desktop/packages/agent/src/adapters/claude/types.ts+++ b/products/desktop/packages/agent/src/adapters/claude/types.ts@@ -126,6 +126,13 @@ export type Session = BaseSession & {* cancel and the other swap path refuse during it, and a second swap is* rejected — the swap must never be raced. */querySwap?: Promise<void>;+ /** Tracks whether we're inside a compaction. The SDK emits the terminal+ * `status` (compact_result success/failed) twice for a single failed+ * compaction, and the two messages are indistinguishable, so we report the+ * outcome only while a compaction is in progress, then clear this. A fresh+ * `compacting` status sets it again, so every distinct compaction (e.g.+ * repeated auto-compactions in a long turn) is still shown. */+ compacting?: boolean;cancelController?: AbortController;forceCancelTimer?: ReturnType<typeof setTimeout>;emitRawSDKMessages: boolean | SDKMessageFilter[];