can1357/oh-my-pi · info

Nothing to compact (session too small)

Error message

Nothing to compact (session too small)

What it means

Thrown when `prepareCompaction` returns null because the session is not compactable: the branch has no compaction entry at its tip but the message history is too small to justify compaction under the effective settings (thresholds/token minimums). Compaction is a no-op below the size threshold, so the library surfaces why instead of silently doing nothing.

Source

Thrown at packages/coding-agent/src/session/session-maintenance.ts:819

					: undefined,
			);
			if (requireProviderRemote && compactionCandidates.length === 0) {
				this.#host.emitNotice(
					"warning",
					`remote compaction is unavailable for ${activeModel.id}; trying the next preferred method`,
					"compaction",
				);
				return await this.compact(customInstructions, options, selectedMethodIndex + 1, compactionAbortController);
			}
			const pathEntries = this.#host.sessionManager.getBranch();
			const preparation = prepareCompaction(pathEntries, effectiveSettings, activeModel, this.#tokenizer);
			if (!preparation) {
				// Check why we can't compact
				const lastEntry = pathEntries[pathEntries.length - 1];
				if (lastEntry?.type === "compaction") {
					throw new Error("Already compacted");
				}
				throw new Error("Nothing to compact (session too small)");
			}

			let hookCompaction: CompactionResult | undefined;
			let fromExtension = false;
			let preserveData: Record<string, unknown> | undefined;

			if (this.#host.extensionRunner?.hasHandlers("session_before_compact")) {
				const result = (await this.#host.extensionRunner.emit({
					type: "session_before_compact",
					preparation,
					branchEntries: pathEntries,
					customInstructions,
					signal: compactionAbortController.signal,
				})) as SessionBeforeCompactResult | undefined;

				if (result?.cancel) {
					throw new CompactionCancelledError();
				}

View on GitHub (pinned to 9690622007)

Solutions

  1. Keep chatting — compaction is only needed once the session approaches context limits.
  2. Only invoke compaction programmatically when estimated token usage exceeds your configured threshold.
  3. If compaction should trigger earlier, lower the compaction threshold settings (contextThreshold/tokens) in the compaction settings group.

Example fix

// before
await session.compact(); // unconditional
// after
if (session.getTokenUsage().total > thresholdTokens) await session.compact();
Defensive patterns

Strategy: validation

Validate before calling

const usage = session.getTokenUsage();
const threshold = settings.getGroup("compaction").contextTokens ?? defaultThreshold;
if (usage.total < threshold) return; // nothing to compact yet

Try / catch

try {
  await session.compact();
} catch (err) {
  if (err instanceof Error && err.message.startsWith("Nothing to compact")) return; // session below threshold
  throw err;
}

Prevention

When it happens

Trigger: Calling manual compaction on a short/new session whose token count is under `compaction` settings thresholds; running `/compact` right after starting a conversation; automated maintenance jobs that compact regardless of session size.

Common situations: Users running /compact out of habit on fresh sessions; scripts compacting every turn; lowered threshold settings from a copied config making even modest sessions 'too small' is impossible — but raised thresholds after a settings migration can make previously compactable sessions too small.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/c1a24695a15e7069. Report an issue: GitHub.