{"record":{"id":"f6498bcfc1d209f9","repo":"can1357/oh-my-pi","slug":"no-model-selected","errorCode":null,"errorMessage":"No model selected","messagePattern":"No model selected","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/session/session-maintenance.ts","lineNumber":754,"sourceCode":"\t\tlet methodAttempted = false;\n\t\tconst compactionAbortController = retryController ?? new AbortController();\n\t\tconst manualCompactionCleanup = ownsCompactionController ? Promise.withResolvers<void>() : undefined;\n\t\tif (ownsCompactionController) {\n\t\t\tthis.#compactionAbortController = compactionAbortController;\n\t\t\tthis.#manualCompactionCleanup = manualCompactionCleanup?.promise;\n\t\t}\n\t\t// A manual pass supersedes any background speculation; running both would\n\t\t// double-bill the summarizer and race the commit.\n\t\tthis.cancelSpeculation();\n\n\t\ttry {\n\t\t\tif (ownsCompactionController) {\n\t\t\t\tthis.#host.disconnectFromAgent();\n\t\t\t\tawait this.#host.abort({ goalReason: \"internal\", preserveCompaction: true });\n\t\t\t}\n\t\t\tconst activeModel = this.#model;\n\t\t\tif (!activeModel) {\n\t\t\t\tthrow new Error(\"No model selected\");\n\t\t\t}\n\n\t\t\tconst compactionSettings = this.#host.settings.getGroup(\"compaction\");\n\t\t\tmethods = resolveCompactionMethodOrder(compactMode?.overrides.methodOrder ?? compactionSettings.methodOrder);\n\t\t\tconst explicitSnapcompact = compactMode?.name === \"snapcompact\";\n\t\t\tlet selectedMethod: CompactionMethod | undefined;\n\t\t\tfor (let index = methodOffset; index < methods.length; index++) {\n\t\t\t\tconst method = methods[index];\n\t\t\t\tif (method === \"remote\") {\n\t\t\t\t\tif (canUseRemoteCompaction(activeModel, resolveMethodSettings(compactionSettings, method))) {\n\t\t\t\t\t\tselectedMethod = method;\n\t\t\t\t\t\tselectedMethodIndex = index;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (method === \"snapcompact\") {\n\t\t\t\t\tif (","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/session/session-maintenance.ts#L736-L772","documentation":"Thrown when manual compaction starts but `this.#model` is unset, meaning no model has been selected for the session. Compaction needs an active model to resolve candidates, settings, and (for soft/snapcompact) to run. The library refuses to proceed with a null model rather than guessing one.","triggerScenarios":"Invoking compaction (manual `/compact` or API compaction call) on a session where `SessionMaintenance.#model` is still null — e.g. compaction before a model was ever set, or after the model was cleared without selecting a replacement.","commonSituations":"Running `/compact` in a fresh session before `/model` was used; SDK/embedding usage that calls compact() without first calling the model-selection API; automated flows where model selection failed earlier and the error was swallowed.","solutions":["Select a model first (e.g. `/model <provider/id>` in the CLI or the session's model-set API), then retry compaction.","In SDK code, assert a model is set before calling compaction.","Check earlier logs for a failed model-selection/provider-auth step that left the session without a model."],"exampleFix":"// before\nawait session.compact(); // throws if no model\n// after\nif (!session.getModel()) await session.setModel(\"anthropic/claude-sonnet-4\");\nawait session.compact();","handlingStrategy":"validation","validationCode":"if (!session.getModel()) {\n  throw new Error(\"Select a model before compacting\");\n}","typeGuard":"function hasModel(s: { getModel(): unknown | null }): boolean {\n  return s.getModel() != null;\n}","tryCatchPattern":"try {\n  await session.compact();\n} catch (err) {\n  if (err instanceof Error && err.message === \"No model selected\") {\n    await session.setModel(defaultModelId);\n    await session.compact();\n    return;\n  }\n  throw err;\n}","preventionTips":["Always set a model at session startup before any maintenance operations.","In SDK scripts, assert model presence before compaction calls.","Don't swallow errors from model-selection APIs — a silent failure surfaces later here."],"tags":["compaction","model-selection","state"],"backgroundTag":"no-model-selected","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}