earendil-works/pi · error · Error

Compaction cancelled

Error message

Compaction cancelled

What it means

Thrown when a session_before_compact extension handler returned cancel: true, so manual compaction is aborted by explicit request rather than by a failure. It is a control-flow signal surfaced as an error.

Solutions

  1. Adjust or disable the extension that cancels compaction
  2. Retry compaction if the cancellation was conditional (e.g. token threshold) and conditions changed
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/coding-agent/src/core/agent-session.ts:1904 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/e12022351825d521. Report an issue: GitHub.

Appendix: source

Thrown at packages/coding-agent/src/core/agent-session.ts:1904

				}
				throw new Error("Nothing to compact (session too small)");
			}

			let extensionCompaction: CompactionResult | undefined;

			if (this._extensionRunner.hasHandlers("session_before_compact")) {
				const result = (await this._extensionRunner.emit({
					type: "session_before_compact",
					preparation,
					branchEntries: pathEntries,
					customInstructions,
					reason: "manual",
					willRetry: false,
					signal: this._compactionAbortController.signal,
				})) as SessionBeforeCompactResult | undefined;

				if (result?.cancel) {
					throw new Error("Compaction cancelled");
				}

				if (result?.compaction) {
					extensionCompaction = result.compaction;
					fromExtension = true;
				}
			}

			let summary: string;
			let firstKeptEntryId: string;
			let tokensBefore: number;
			let usage: Usage | undefined;
			let details: unknown;

			if (extensionCompaction) {
				// Extension provided compaction content
				summary = extensionCompaction.summary;
				firstKeptEntryId = extensionCompaction.firstKeptEntryId;

View on GitHub (pinned to 4af9d21d3b)