{"record":{"id":"c1a24695a15e7069","repo":"can1357/oh-my-pi","slug":"nothing-to-compact-session-too-small","errorCode":null,"errorMessage":"Nothing to compact (session too small)","messagePattern":"Nothing to compact \\(session too small\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"packages/coding-agent/src/session/session-maintenance.ts","lineNumber":819,"sourceCode":"\t\t\t\t\t: undefined,\n\t\t\t);\n\t\t\tif (requireProviderRemote && compactionCandidates.length === 0) {\n\t\t\t\tthis.#host.emitNotice(\n\t\t\t\t\t\"warning\",\n\t\t\t\t\t`remote compaction is unavailable for ${activeModel.id}; trying the next preferred method`,\n\t\t\t\t\t\"compaction\",\n\t\t\t\t);\n\t\t\t\treturn await this.compact(customInstructions, options, selectedMethodIndex + 1, compactionAbortController);\n\t\t\t}\n\t\t\tconst pathEntries = this.#host.sessionManager.getBranch();\n\t\t\tconst preparation = prepareCompaction(pathEntries, effectiveSettings, activeModel, this.#tokenizer);\n\t\t\tif (!preparation) {\n\t\t\t\t// Check why we can't compact\n\t\t\t\tconst lastEntry = pathEntries[pathEntries.length - 1];\n\t\t\t\tif (lastEntry?.type === \"compaction\") {\n\t\t\t\t\tthrow new Error(\"Already compacted\");\n\t\t\t\t}\n\t\t\t\tthrow new Error(\"Nothing to compact (session too small)\");\n\t\t\t}\n\n\t\t\tlet hookCompaction: CompactionResult | undefined;\n\t\t\tlet fromExtension = false;\n\t\t\tlet preserveData: Record<string, unknown> | undefined;\n\n\t\t\tif (this.#host.extensionRunner?.hasHandlers(\"session_before_compact\")) {\n\t\t\t\tconst result = (await this.#host.extensionRunner.emit({\n\t\t\t\t\ttype: \"session_before_compact\",\n\t\t\t\t\tpreparation,\n\t\t\t\t\tbranchEntries: pathEntries,\n\t\t\t\t\tcustomInstructions,\n\t\t\t\t\tsignal: compactionAbortController.signal,\n\t\t\t\t})) as SessionBeforeCompactResult | undefined;\n\n\t\t\t\tif (result?.cancel) {\n\t\t\t\t\tthrow new CompactionCancelledError();\n\t\t\t\t}","sourceCodeStart":801,"sourceCodeEnd":837,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/session/session-maintenance.ts#L801-L837","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Keep chatting — compaction is only needed once the session approaches context limits.","Only invoke compaction programmatically when estimated token usage exceeds your configured threshold.","If compaction should trigger earlier, lower the compaction threshold settings (contextThreshold/tokens) in the compaction settings group."],"exampleFix":"// before\nawait session.compact(); // unconditional\n// after\nif (session.getTokenUsage().total > thresholdTokens) await session.compact();","handlingStrategy":"validation","validationCode":"const usage = session.getTokenUsage();\nconst threshold = settings.getGroup(\"compaction\").contextTokens ?? defaultThreshold;\nif (usage.total < threshold) return; // nothing to compact yet","typeGuard":null,"tryCatchPattern":"try {\n  await session.compact();\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"Nothing to compact\")) return; // session below threshold\n  throw err;\n}","preventionTips":["Gate compaction on token usage exceeding the configured threshold.","Align automation triggers with the compaction settings thresholds.","Treat this as an expected signal in scripts, not an exception path."],"tags":["compaction","threshold","no-op"],"backgroundTag":"nothing-to-compact","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}