{"record":{"id":"70e2c51974ff8c36","repo":"can1357/oh-my-pi","slug":"compaction-failed-no-available-model","errorCode":null,"errorMessage":"Compaction failed: no available model","messagePattern":"Compaction failed: no available model","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/session/session-maintenance.ts","lineNumber":3625,"sourceCode":"\t\t\t\t\t\t\t\tdelayMs,\n\t\t\t\t\t\t\t\tretryAfterMs,\n\t\t\t\t\t\t\t\terror: message,\n\t\t\t\t\t\t\t\tmodel: `${candidate.provider}/${candidate.id}`,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tawait scheduler.wait(delayMs, { signal: autoCompactionSignal });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (compactResult) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!compactResult) {\n\t\t\t\t\tif (lastError) {\n\t\t\t\t\t\tthrow lastError;\n\t\t\t\t\t}\n\t\t\t\t\tthrow new Error(\"Compaction failed: no available model\");\n\t\t\t\t}\n\n\t\t\t\tsummary = compactResult.summary;\n\t\t\t\tshortSummary = compactResult.shortSummary;\n\t\t\t\tfirstKeptEntryId = compactResult.firstKeptEntryId;\n\t\t\t\ttokensBefore = compactResult.tokensBefore;\n\t\t\t\tdetails = compactResult.details;\n\t\t\t\tpreserveData = mergeLlmCompactionPreserveData(compactionPrep.preserveData, compactResult.preserveData);\n\t\t\t}\n\n\t\t\treturn await this.#commitAutoCompactionResult({\n\t\t\t\tsummary,\n\t\t\t\tshortSummary,\n\t\t\t\tfirstKeptEntryId,\n\t\t\t\ttokensBefore,\n\t\t\t\tdetails,\n\t\t\t\tpreserveData,\n\t\t\t\tfromExtension,","sourceCodeStart":3607,"sourceCodeEnd":3643,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/session/session-maintenance.ts#L3607-L3643","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Configure at least one working model provider (API keys, base URL) so compaction has a candidate model.","Check logs/session config for why the candidate model list was empty and widen the model selection filter.","Retry compaction later if providers were transiently unavailable; if a provider error occurred it would surface as lastError instead.","Reduce context growth (trim session history) so compaction can be deferred until a model is available."],"exampleFix":"// before: compaction runs with no provider configured -> no available model\nawait agent.compact();\n// after: ensure a model is resolvable before compacting\nif (!session.hasAvailableModel()) {\n  await session.setProvider({ apiKey: process.env.OPENAI_API_KEY });\n}\nawait agent.compact();","handlingStrategy":"try-catch","validationCode":"if (!process.env.OPENAI_API_KEY && !process.env.ANTHROPIC_API_KEY) {\n  throw new Error(\"Configure a model provider before compaction\");\n}","typeGuard":"null","tryCatchPattern":"try {\n  await maintenance.compact();\n} catch (err) {\n  if (err.message.includes(\"no available model\")) {\n    // configure/retry a provider, or defer compaction\n    logger.warn(\"Compaction skipped: no model available\", { err });\n  } else throw err;\n}","preventionTips":["Configure at least one provider/API key before long-running sessions that will need compaction.","Monitor context size and compact while a model is known-good.","Log candidate model failures so you see why the list ended up empty."],"tags":["compaction","model-selection","session"],"backgroundTag":"no-available-model","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}