can1357/oh-my-pi · error

Compaction failed: no available model

Error message

Compaction failed: no available model

What it means

Thrown by session compaction when the model selection loop exhausts every candidate model without producing a compaction result. Each candidate can fail (API error, rate limit, no provider configured), and lastError is rethrown if one exists; this generic error only appears when there were zero successful candidates AND no captured underlying error. It signals the session could not summarize its history, so compaction is aborted.

Source

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

								delayMs,
								retryAfterMs,
								error: message,
								model: `${candidate.provider}/${candidate.id}`,
							});
							await scheduler.wait(delayMs, { signal: autoCompactionSignal });
						}
					}

					if (compactResult) {
						break;
					}
				}

				if (!compactResult) {
					if (lastError) {
						throw lastError;
					}
					throw new Error("Compaction failed: no available model");
				}

				summary = compactResult.summary;
				shortSummary = compactResult.shortSummary;
				firstKeptEntryId = compactResult.firstKeptEntryId;
				tokensBefore = compactResult.tokensBefore;
				details = compactResult.details;
				preserveData = mergeLlmCompactionPreserveData(compactionPrep.preserveData, compactResult.preserveData);
			}

			return await this.#commitAutoCompactionResult({
				summary,
				shortSummary,
				firstKeptEntryId,
				tokensBefore,
				details,
				preserveData,
				fromExtension,

View on GitHub (pinned to 9690622007)

Solutions

  1. Configure at least one working model provider (API keys, base URL) so compaction has a candidate model.
  2. Check logs/session config for why the candidate model list was empty and widen the model selection filter.
  3. Retry compaction later if providers were transiently unavailable; if a provider error occurred it would surface as lastError instead.
  4. Reduce context growth (trim session history) so compaction can be deferred until a model is available.

Example fix

// before: compaction runs with no provider configured -> no available model
await agent.compact();
// after: ensure a model is resolvable before compacting
if (!session.hasAvailableModel()) {
  await session.setProvider({ apiKey: process.env.OPENAI_API_KEY });
}
await agent.compact();
Defensive patterns

Strategy: try-catch

Validate before calling

if (!process.env.OPENAI_API_KEY && !process.env.ANTHROPIC_API_KEY) {
  throw new Error("Configure a model provider before compaction");
}

Type guard

null

Try / catch

try {
  await maintenance.compact();
} catch (err) {
  if (err.message.includes("no available model")) {
    // configure/retry a provider, or defer compaction
    logger.warn("Compaction skipped: no model available", { err });
  } else throw err;
}

Prevention

When it happens

Trigger: Calling the compaction path in SessionMaintenance (packages/coding-agent/src/session/session-maintenance.ts:3625) when the compact result is undefined after trying all available models and no intermediate error was recorded (e.g. the candidate model list was empty, or candidates were skipped silently without setting lastError).

Common situations: No API keys / providers configured for any compaction-capable model; model filter excludes all models; provider registry returns an empty candidate list; all candidates fail before producing a summary so lastError stays unset.

Related errors


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