TypeScript
fix(claude): show automatic compaction while it runs (#15631)
mariafc21184afbb8
diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.tsindex cf327f13b30..f9fccc8a394 100644--- a/apps/mobile/src/lib/threadActivity.test.ts+++ b/apps/mobile/src/lib/threadActivity.test.ts@@ -1740,9 +1740,14 @@ describe("retained v2 feed presentation", () => {expect(afterPresentation[1]).toBe(beforePresentation[1]);});- it.each(["running", "completed", "interrupted"] as const)(- "uses the compaction row as the live activity only while %s",- (status) => {+ it.each([+ { status: "running", summary: "Compacting context" },+ { status: "completed", summary: "Context compacted 899K → 19K tokens" },+ { status: "failed", summary: "Context compaction failed" },+ { status: "interrupted", summary: "Context compaction stopped" },+ ] as const)(+ "uses the compaction row as the live activity only while $status",+ ({ status, summary }) => {const compact = projected({...base("compacted", "2026-06-20T00:00:02.000Z", 1),@@ -1769,16 +1774,7 @@ describe("retained v2 feed presentation", () => {);expect(rows.some((row) => row.type === "thinking")).toBe(status !== "running");expect(rows.find((row) => row.type === "activity-group")).toMatchObject({- activities: [- {- summary:- status === "running"- ? "Compacting context"- : status === "completed"- ? "Context compacted 899K → 19K tokens"- : "Context compacted",- },- ],+ activities: [{ summary }],});},);diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.tsindex f99b071bf36..bb2be14282e 100644--- a/apps/mobile/src/state/use-thread-composer-state.ts+++ b/apps/mobile/src/state/use-thread-composer-state.ts@@ -334,6 +334,14 @@ export function useThreadComposerState() {if (queuedCompact) return true;const activeRunId = selectedThreadRuntime?.activeRunId;if (!activeRunId || !threadRuntimeIsActive(selectedThreadRuntime)) return false;+ if (+ selectedThreadVisibleTurnItems.some(+ ({ item }) =>+ item.runId === activeRunId && item.type === "compaction" && item.status === "running",+ )+ ) {+ return true;+ }const compactMessage = selectedThreadVisibleTurnItems.findLast(({ item }) =>item.runId === activeRunId &&@@ -346,7 +354,10 @@ export function useThreadComposerState() {({ item }) =>item.runId === activeRunId &&item.type === "compaction" &&- (item.status === "completed" || item.status === "failed"),+ (item.status === "completed" ||+ item.status === "failed" ||+ item.status === "interrupted" ||+ item.status === "cancelled"),);})();// A compacting turn cannot take steering input, so follow-ups queue meanwhile.diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsindex 2d2c787f936..d9bf5007f7e 100644--- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts+++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts@@ -3705,6 +3705,13 @@ describe("ClaudeAdapterV2 background wake turns", () => {}),]: []),+ claudeSdkFrame({+ type: "system",+ subtype: "status",+ status: "compacting",+ uuid: "00000000-0000-4000-8000-000000000610",+ session_id: WAKE_NATIVE_SESSION,+ }),claudeSdkFrame({type: "system",subtype: "status",@@ -3716,10 +3723,44 @@ describe("ClaudeAdapterV2 background wake turns", () => {uuid: "00000000-0000-4000-8000-000000000612",session_id: WAKE_NATIVE_SESSION,}),- compact ? claudeSdkFrame({ ...result, local_command: "compact" }) : result,+ claudeSdkFrame({+ type: "system",+ subtype: "informational",+ content: "Compaction finished; turn continues.",+ level: "warning",+ uuid: "00000000-0000-4000-8000-000000000614",+ session_id: WAKE_NATIVE_SESSION,+ }),]);+ yield* Queue.take(harness.systemNoticeReceipts);+ const updates = harness.events.flatMap((event) =>+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"+ ? [event.turnItem]+ : [],+ );+ assert.lengthOf(updates, 2);+ const [running, settled] = updates;+ assert.equal(running?.status, "running");+ assert.equal(settled?.status, compaction === "success" ? "completed" : "failed");+ assert.equal(settled?.id, running?.id);+ assert.equal(settled?.ordinal, running?.ordinal);+ assert.deepEqual(settled?.startedAt, running?.startedAt);+ assert.isNotNull(settled?.completedAt);+ assert.isEmpty(harness.terminalEvents());+ yield* Queue.offer(+ harness.sdkMessages,+ compact ? claudeSdkFrame({ ...result, local_command: "compact" }) : result,+ );const terminal = yield* Queue.take(harness.terminalReceipts);+ assert.deepEqual(+ harness.events.flatMap((event) =>+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"+ ? [event.turnItem]+ : [],+ ),+ updates,+ );assert.equal(terminal.status, status);if (terminal.status !== "failed") return;assert.equal(terminal.failure.class, "usage_limit");@@ -4443,6 +4484,307 @@ describe("ClaudeAdapterV2 background wake turns", () => {),);+ it.effect("shows automatic compaction before its boundary and completes the same item", () =>+ Effect.gen(function* () {+ const harness = yield* makeWakeHarness;+ const observeCompactions = Effect.fnUntraced(function* (uuid: string) {+ // A later notice receipt confirms the event subscriber consumed preceding updates.+ yield* Queue.offer(+ harness.sdkMessages,+ claudeSdkFrame({+ type: "system",+ subtype: "informational",+ content: "Context checkpoint",+ level: "warning",+ session_id: WAKE_NATIVE_SESSION,+ uuid,+ }),+ );+ yield* Queue.take(harness.systemNoticeReceipts);+ return harness.events.flatMap((event) =>+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"+ ? [event.turnItem]+ : [],+ );+ });+ yield* harness.runtime.startTurn(+ makeClaudeTestTurnInput({+ threadId: harness.threadId,+ providerThread: harness.providerThread,+ now: yield* DateTime.now,+ attemptId: RunAttemptId.make("claude-auto-compact-attempt"),+ text: "Continue working.",+ attachments: [],+ }),+ );+ for (const index of [1, 2]) {+ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "status",+ status: "compacting",+ uuid: `00000000-0000-4000-8000-00000000021${index}`,+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ }+ const beforeBoundary = yield* observeCompactions("00000000-0000-4000-8000-000000000215");+ assert.lengthOf(beforeBoundary, 1);+ const running = beforeBoundary[0]!;+ assert.equal(running.status, "running");+ assert.isNull(running.completedAt);+ assert.isNotNull(running.startedAt);++ yield* TestClock.adjust(1_000);+ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "status",+ status: null,+ compact_result: "success",+ uuid: "00000000-0000-4000-8000-000000000222",+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ const reported = yield* observeCompactions("00000000-0000-4000-8000-000000000223");+ assert.lengthOf(reported, 2);+ assert.equal(reported[1]?.id, running.id);+ assert.equal(reported[1]?.status, "completed");+ assert.isUndefined(reported[1]?.afterTokenCount);+ assert.isEmpty(harness.terminalEvents());+ yield* TestClock.adjust(1_000);+ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "compact_boundary",+ compact_metadata: { trigger: "auto", pre_tokens: 1500, post_tokens: 400 },+ uuid: "00000000-0000-4000-8000-000000000213",+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ const afterBoundary = yield* observeCompactions("00000000-0000-4000-8000-000000000216");+ assert.lengthOf(afterBoundary, 3);+ const completed = afterBoundary[2]!;+ assert.equal(completed.status, "completed");+ assert.equal(completed.id, running.id);+ assert.equal(completed.ordinal, running.ordinal);+ assert.deepEqual(completed.startedAt, running.startedAt);+ assert.equal(completed.beforeTokenCount, 1500);+ assert.equal(completed.afterTokenCount, 400);+ assert.deepEqual(completed.completedAt, reported[1]?.completedAt);++ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "compact_boundary",+ compact_metadata: { trigger: "manual", pre_tokens: 2000, post_tokens: 500 },+ uuid: "00000000-0000-4000-8000-000000000217",+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "status",+ status: "compacting",+ uuid: "00000000-0000-4000-8000-000000000218",+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ const nextCompactions = yield* observeCompactions("00000000-0000-4000-8000-000000000219");+ assert.lengthOf(nextCompactions, 5);+ const boundaryOnly = nextCompactions[3]!;+ const nextRunning = nextCompactions[4]!;+ assert.equal(boundaryOnly.status, "completed");+ assert.notEqual(boundaryOnly.id, completed.id);+ assert.isAbove(boundaryOnly.ordinal, completed.ordinal);+ assert.equal(boundaryOnly.beforeTokenCount, 2000);+ assert.equal(boundaryOnly.afterTokenCount, 500);+ assert.equal(nextRunning.status, "running");+ assert.notEqual(nextRunning.id, boundaryOnly.id);+ assert.isAbove(nextRunning.ordinal, boundaryOnly.ordinal);++ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "status",+ status: null,+ permissionMode: "default",+ uuid: "00000000-0000-4000-8000-000000000233",+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ assert.deepEqual(+ yield* observeCompactions("00000000-0000-4000-8000-000000000234"),+ nextCompactions,+ );++ let retryRunning = nextRunning;+ for (const [index, outcome] of [+ { compact_result: "failed", compact_error: "Temporary compaction failure." },+ {},+ ].entries()) {+ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "status",+ status: null,+ ...outcome,+ uuid: `00000000-0000-4000-8000-00000000024${index}`,+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ const stopped = yield* observeCompactions(`00000000-0000-4000-8000-00000000025${index}`);+ assert.lengthOf(stopped, 6 + index * 2);+ const settled = stopped.at(-1)!;+ assert.equal(settled.id, retryRunning.id);+ assert.equal(settled.ordinal, retryRunning.ordinal);+ assert.deepEqual(settled.startedAt, retryRunning.startedAt);+ assert.equal(+ settled.status,+ outcome.compact_result === "failed" ? "failed" : "interrupted",+ );+ assert.equal(+ settled.title,+ outcome.compact_result === "failed"+ ? "Context compaction failed"+ : "Context compaction stopped",+ );+ assert.isNotNull(settled.completedAt);+ assert.isEmpty(harness.terminalEvents());++ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "status",+ status: "compacting",+ uuid: `00000000-0000-4000-8000-00000000026${index}`,+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ const retried = yield* observeCompactions(`00000000-0000-4000-8000-00000000027${index}`);+ assert.lengthOf(retried, stopped.length + 1);+ retryRunning = retried.at(-1)!;+ assert.equal(retryRunning.status, "running");+ assert.notEqual(retryRunning.id, settled.id);+ assert.isAbove(retryRunning.ordinal, settled.ordinal);+ }++ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "compact_boundary",+ compact_metadata: { trigger: "auto", pre_tokens: 3000, post_tokens: 600 },+ uuid: "00000000-0000-4000-8000-000000000220",+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ const allCompactions = yield* observeCompactions("00000000-0000-4000-8000-000000000221");+ assert.lengthOf(allCompactions, 10);+ assert.equal(allCompactions[9]?.id, retryRunning.id);+ assert.equal(allCompactions[9]?.ordinal, retryRunning.ordinal);+ assert.equal(allCompactions[9]?.status, "completed");+ assert.equal(allCompactions[9]?.beforeTokenCount, 3000);+ assert.equal(allCompactions[9]?.afterTokenCount, 600);++ yield* Queue.offer(+ harness.sdkMessages,+ makeResultFrame({+ uuid: "00000000-0000-4000-8000-000000000214",+ result: "Work complete.",+ }),+ );+ yield* Queue.take(harness.terminalReceipts);+ assert.deepEqual(+ harness.events.flatMap((event) =>+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"+ ? [event.turnItem]+ : [],+ ),+ allCompactions,+ );+ }).pipe(+ Effect.scoped,+ Effect.provide(+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),+ ),+ ),+ );++ it.effect.each([+ { outcome: "result", turnStatus: "completed", itemStatus: "failed" },+ { outcome: "interrupt", turnStatus: "interrupted", itemStatus: "interrupted" },+ { outcome: "query_exit", turnStatus: "failed", itemStatus: "failed" },+ ] as const)(+ "settles unfinished compaction before the $outcome terminal receipt",+ ({ outcome, turnStatus, itemStatus }) =>+ Effect.gen(function* () {+ const harness = yield* makeWakeHarnessWithOptions({+ close: (sdkMessages) => Queue.shutdown(sdkMessages),+ });+ const attemptId = RunAttemptId.make(`claude-compact-${outcome}`);+ yield* harness.runtime.startTurn(+ makeClaudeTestTurnInput({+ threadId: harness.threadId,+ providerThread: harness.providerThread,+ now: yield* DateTime.now,+ attemptId,+ text: "Continue.",+ attachments: [],+ }),+ );+ yield* harness.offerAndWait(+ claudeSdkFrame({+ type: "system",+ subtype: "status",+ status: "compacting",+ uuid: "00000000-0000-4000-8000-000000000221",+ session_id: WAKE_NATIVE_SESSION,+ }),+ );+ if (outcome === "query_exit") {+ yield* Queue.shutdown(harness.sdkMessages);+ } else if (outcome === "interrupt") {+ const idAllocator = yield* IdAllocator.IdAllocatorV2;+ yield* harness.runtime.interruptTurn({+ providerThread: harness.providerThread,+ providerTurnId: idAllocator.derive.providerTurn({+ driver: ClaudeAdapterV2.CLAUDE_PROVIDER,+ nativeTurnId: `turn:${attemptId}`,+ }),+ });+ } else {+ yield* Queue.offer(+ harness.sdkMessages,+ makeResultFrame({+ uuid: "00000000-0000-4000-8000-000000000222",+ result: "Stopped before the boundary.",+ }),+ );+ }+ const terminal = yield* Queue.take(harness.terminalReceipts);+ assert.equal(terminal.status, turnStatus);+ const updates = harness.events.flatMap((event) =>+ event.type === "turn_item.updated" && event.turnItem.type === "compaction"+ ? [event.turnItem]+ : [],+ );+ assert.lengthOf(updates, 2);+ const [running, settled] = updates;+ assert.equal(running?.status, "running");+ assert.equal(settled?.status, itemStatus);+ assert.equal(settled?.id, running?.id);+ assert.equal(settled?.ordinal, running?.ordinal);+ assert.deepEqual(settled?.startedAt, running?.startedAt);+ assert.isNotNull(settled?.completedAt);+ }).pipe(+ Effect.scoped,+ Effect.provide(+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),+ ),+ ),+ );+it.effect("titles Claude reads, searches, and skills on tool completion", () =>Effect.gen(function* () {const harness = yield* makeWakeHarness;diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsindex f00bd90b7af..992215dd35f 100644--- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts+++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts@@ -3044,6 +3044,8 @@ interface ActiveClaudeTurnContext {// compaction makes the usage stale (null) without forgetting the request.streamUsage: { readonly messageId: string; usage: ClaudeMessageUsage | null } | null;readonly toolCalls: Map<string, ActiveClaudeToolCall>;+ // A successful status can precede the boundary that supplies its token counts.+ compaction: Extract<OrchestrationV2TurnItem, { type: "compaction" }> | null;readonly ignoredTaskIds: Set<string>;readonly announcedUsageLimits: Set<string>;authenticationFailureMessage: string | undefined;@@ -6050,6 +6052,23 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (readonly result?: SDKResultMessage;}) {yield* reasoningDeltas.flushTurn(input.context.nativeTurnId);+ if (input.context.compaction?.status === "running") {+ yield* emitProviderEvent({+ type: "turn_item.updated",+ driver: CLAUDE_PROVIDER,+ turnItem: {+ ...input.context.compaction,+ status: input.status === "completed" ? "failed" : input.status,+ title:+ input.status === "completed" || input.status === "failed"+ ? "Context compaction failed"+ : "Context compaction stopped",+ completedAt: input.completedAt,+ updatedAt: input.completedAt,+ },+ });+ }+ input.context.compaction = null;if (input.status !== "completed") {const liveQuery = yield* Ref.get(queryContext);for (const [taskId, subagent] of yield* Ref.get(sessionSubagentsByTaskId)) {@@ -7119,16 +7138,86 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (if (message.type === "system" &&message.subtype === "status" &&- message.compact_result !== undefined+ (message.compact_result !== undefined ||+ (message.status === null && message.permissionMode === undefined))) {- context.compactionFailure =- message.compact_result === "failed" ? { message: message.compact_error } : null;+ if (message.compact_result !== undefined) {+ context.compactionFailure =+ message.compact_result === "failed" ? { message: message.compact_error } : null;+ }+ if (context.compaction?.status === "running") {+ const now = yield* DateTime.now;+ context.compaction = {+ ...context.compaction,+ status:+ message.compact_result === "success"+ ? "completed"+ : message.compact_result === "failed"+ ? "failed"+ : "interrupted",+ title:+ message.compact_result === "success"+ ? "Context compacted"+ : message.compact_result === "failed"+ ? "Context compaction failed"+ : "Context compaction stopped",+ completedAt: now,+ updatedAt: now,+ };+ yield* emitProviderEvent({+ type: "turn_item.updated",+ driver: CLAUDE_PROVIDER,+ turnItem: context.compaction,+ });+ if (message.compact_result !== "success") context.compaction = null;+ }}- if (message.type === "system" && message.subtype === "compact_boundary") {- if (context.streamUsage !== null) context.streamUsage.usage = null;+ if (+ message.type === "system" &&+ (message.subtype === "compact_boundary" ||+ (message.subtype === "status" && message.status === "compacting"))+ ) {+ if (message.subtype === "status" && context.compaction?.status === "running") return;const now = yield* DateTime.now;const nativeItemId = message.uuid;+ const compaction =+ (message.subtype === "compact_boundary" ? context.compaction : null) ??+ ({+ id: idAllocator.derive.turnItemFromProviderItem({+ driver: CLAUDE_PROVIDER,+ nativeItemId,+ }),+ threadId: context.input.threadId,+ runId: context.input.runId,+ nodeId: context.input.rootNodeId,+ providerThreadId: context.input.providerThread.id,+ providerTurnId: context.providerTurnId,+ nativeItemRef: {+ driver: CLAUDE_PROVIDER,+ nativeId: nativeItemId,+ strength: "strong",+ },+ parentItemId: null,+ ordinal: yield* resolveItemOrdinal(context, nativeItemId),+ type: "compaction",+ driver: CLAUDE_PROVIDER,+ status: "running",+ title: "Compacting context",+ startedAt: now,+ completedAt: null,+ updatedAt: now,+ } satisfies OrchestrationV2TurnItem);+ if (message.subtype === "status") {+ context.compaction = compaction;+ yield* emitProviderEvent({+ type: "turn_item.updated",+ driver: CLAUDE_PROVIDER,+ turnItem: compaction,+ });+ return;+ }+ if (context.streamUsage !== null) context.streamUsage.usage = null;const postTokens = message.compact_metadata.post_tokens;const afterTokenCount =typeof postTokens === "number" && Number.isFinite(postTokens) && postTokens > 0@@ -7165,28 +7254,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (type: "turn_item.updated",driver: CLAUDE_PROVIDER,turnItem: {- id: idAllocator.derive.turnItemFromProviderItem({- driver: CLAUDE_PROVIDER,- nativeItemId,- }),- threadId: context.input.threadId,- runId: context.input.runId,- nodeId: context.input.rootNodeId,- providerThreadId: context.input.providerThread.id,- providerTurnId: context.providerTurnId,- nativeItemRef: {- driver: CLAUDE_PROVIDER,- nativeId: nativeItemId,- strength: "strong",- },- parentItemId: null,- ordinal: yield* resolveItemOrdinal(context, nativeItemId),- type: "compaction",- driver: CLAUDE_PROVIDER,+ ...compaction,status: "completed",title: "Context compacted",- startedAt: now,- completedAt: now,+ completedAt: compaction.completedAt ?? now,updatedAt: now,...(message.compact_metadata.pre_tokens === undefined? {}@@ -7194,6 +7265,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (...(afterTokenCount === undefined ? {} : { afterTokenCount }),},});+ context.compaction = null;return;}@@ -8727,6 +8799,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (},streamUsage: null,toolCalls: new Map(),+ compaction: null,ignoredTaskIds: new Set(),announcedUsageLimits: new Set(),authenticationFailureMessage: undefined,diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 5096063c74d..879d66d7712 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -2518,12 +2518,21 @@ export default function ChatView(props: ChatViewProps) {({ item }) =>item.type === "compaction" &&item.runId === activeActivityRun?.runId &&- item.status === "completed",+ (item.status === "completed" ||+ item.status === "failed" ||+ item.status === "interrupted" ||+ item.status === "cancelled"),+ );+ const compactionRunning = serverVisibleTurnItems.some(+ ({ item }) =>+ item.type === "compaction" &&+ item.runId !== null &&+ item.runId === activeRuntime?.activeRunId &&+ item.status === "running",);const isCompacting =(isSendBusy || phase === "connecting" || phase === "running") &&- compactRequestIsActive &&- !compactionSettled;+ (compactionRunning || (compactRequestIsActive && !compactionSettled));const isWorking =phase === "running" ||isSendBusy ||diff --git a/packages/client-runtime/src/work-log/presentation.ts b/packages/client-runtime/src/work-log/presentation.tsindex b3cfcc9779b..de0fd994084 100644--- a/packages/client-runtime/src/work-log/presentation.ts+++ b/packages/client-runtime/src/work-log/presentation.ts@@ -67,6 +67,9 @@ export function contextCompactionTokenCounts(}export function contextCompactionLabel(item: CompactionLabelItem): string {+ if (item.status === "failed") return "Context compaction failed";+ if (item.status === "cancelled" || item.status === "interrupted")+ return "Context compaction stopped";if (item.status === "running") return "Compacting context";const tokens = contextCompactionTokenCounts(item);return tokens