{"record":{"id":"685bfb3144111197","repo":"sigoden/aichat","slug":"no-chat-history","errorCode":null,"errorMessage":"No chat history","messagePattern":"No chat history","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/mod.rs","lineNumber":1329,"sourceCode":"        tokio::spawn(async move {\n            if let Err(err) = Config::autoname_session(&config).await {\n                warn!(\"Failed to autonaming the session: {err}\");\n            }\n            if let Some(session) = config.write().session.as_mut() {\n                session.set_autonaming(false);\n            }\n        });\n    }\n\n    pub async fn autoname_session(config: &GlobalConfig) -> Result<()> {\n        let text = match config\n            .read()\n            .session\n            .as_ref()\n            .and_then(|v| v.chat_history_for_autonaming())\n        {\n            Some(v) => v,\n            None => bail!(\"No chat history\"),\n        };\n        let role = config.read().retrieve_role(CREATE_TITLE_ROLE)?;\n        let input = Input::from_str(config, &text, Some(role));\n        let text = input.fetch_chat_text().await?;\n        if let Some(session) = config.write().session.as_mut() {\n            session.set_autoname(&text);\n        }\n        Ok(())\n    }\n\n    pub async fn use_rag(\n        config: &GlobalConfig,\n        rag: Option<&str>,\n        abort_signal: AbortSignal,\n    ) -> Result<()> {\n        if config.read().agent.is_some() {\n            bail!(\"Cannot perform this operation because you are using a agent\")\n        }","sourceCodeStart":1311,"sourceCodeEnd":1347,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L1311-L1347","documentation":"Raised in the session auto-naming path (src/config/mod.rs:1329) when there is no chat history to derive a session title from. The code pulls session.chat_history_for_autonaming() and bails with 'No chat history' on None. Auto-naming needs at least some exchanged messages to feed the CREATE_TITLE_ROLE prompt.","triggerScenarios":"Calling the autoname/set-session-title routine before any user/assistant exchange has happened; calling it on a session whose messages were cleared; invoking autonaming on a freshly loaded empty session file.","commonSituations":"Automation that names sessions immediately after creation; resuming a cleared session and trying to rename it automatically; a title-generation command run before the first prompt.","solutions":["Exchange at least one message before auto-naming the session","Set the session name explicitly (e.g. `.name <title>` or session.set_autoname) instead of deriving it","Guard on chat_history_for_autonaming() being Some before invoking"],"exampleFix":"// before\nconfig.write().session.as_ref().and_then(|s| s.chat_history_for_autonaming()).map(|_| autoname(&config));\n// after\nif let Some(history) = config.read().session.as_ref().and_then(|s| s.chat_history_for_autonaming()) {\n    if !history.is_empty() {\n        autoname(&config).await?;\n    }\n}","handlingStrategy":"validation","validationCode":"fn can_autoname(cfg: &GlobalConfig) -> bool {\n    cfg.read().session.as_ref()\n        .and_then(|s| s.chat_history_for_autonaming())\n        .map_or(false, |h| !h.is_empty())\n}","typeGuard":null,"tryCatchPattern":"match autoname_session(&config).await {\n    Err(e) if e.to_string() == \"No chat history\" => { /* fall back to manual name */ }\n    other => other?,\n}","preventionTips":["Trigger auto-naming only after the first completed exchange","Provide a manual name fallback for empty sessions","Retry auto-naming lazily after each message until it succeeds"],"tags":["session","naming","history"],"backgroundTag":"empty-result-set","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"}