{"record":{"id":"1298a5c3cfec73c2","repo":"sigoden/aichat","slug":"no-need-to-compress-since-there-are-no-messages-in","errorCode":null,"errorMessage":"No need to compress since there are no messages in the session","messagePattern":"No need to compress since there are no messages in the session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/config/mod.rs","lineNumber":1262,"sourceCode":"        print!(\n            \"\\n📢 {}\\n\",\n            color.italic().paint(\"Compressing the session.\"),\n        );\n        tokio::spawn(async move {\n            if let Err(err) = Config::compress_session(&config).await {\n                warn!(\"Failed to compress the session: {err}\");\n            }\n            if let Some(session) = config.write().session.as_mut() {\n                session.set_compressing(false);\n            }\n        });\n    }\n\n    pub async fn compress_session(config: &GlobalConfig) -> Result<()> {\n        match config.read().session.as_ref() {\n            Some(session) => {\n                if !session.has_user_messages() {\n                    bail!(\"No need to compress since there are no messages in the session\")\n                }\n            }\n            None => bail!(\"No session\"),\n        }\n\n        let prompt = config\n            .read()\n            .summarize_prompt\n            .clone()\n            .unwrap_or_else(|| SUMMARIZE_PROMPT.into());\n        let input = Input::from_str(config, &prompt, None);\n        let summary = input.fetch_chat_text().await?;\n        let summary_prompt = config\n            .read()\n            .summary_prompt\n            .clone()\n            .unwrap_or_else(|| SUMMARY_PROMPT.into());\n        if let Some(session) = config.write().session.as_mut() {","sourceCodeStart":1244,"sourceCodeEnd":1280,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L1244-L1280","documentation":"GlobalConfig::compress_session (src/config/mod.rs:1262) refuses to compress when an active session exists but contains no user messages. Compression summarizes conversation history; with an empty session there is nothing to summarize, so it bails with 'No need to compress since there are no messages in the session'.","triggerScenarios":"Running `.compress` (compress_session) right after starting a fresh session; running compress after clearing all messages; compressing a loaded session file that has only system/assistant messages.","commonSituations":"User wants to shrink context at the start of a session out of habit; automation that compresses on a timer even when nothing new was said; resuming an old session that was previously fully compressed/cleared.","solutions":["Send at least one message before compressing","Skip compression when the session is empty (check has_user_messages() first)","Exit the empty session and start fresh instead of compressing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if let Some(session) = config.read().session.as_ref() {\n    if !session.has_user_messages() {\n        eprintln!(\"nothing to compress\");\n        return Ok(());\n    }\n}","typeGuard":null,"tryCatchPattern":"match compress_session(&config).await {\n    Err(e) if e.to_string().starts_with(\"No need to compress\") => { /* skip silently */ }\n    other => other?,\n}","preventionTips":["Only enable `.compress` after the first user message","Skip timer-based compression when has_user_messages() is false","Inform users why compression was skipped"],"tags":["session","compression","empty"],"backgroundTag":"invalid-state-transition","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}