sigoden/aichat · error

No chat history

Error message

No chat history

What it means

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.

Solutions

  1. Exchange at least one message before auto-naming the session
  2. Set the session name explicitly (e.g. `.name <title>` or session.set_autoname) instead of deriving it
  3. Guard on chat_history_for_autonaming() being Some before invoking

Example fix

// before
config.write().session.as_ref().and_then(|s| s.chat_history_for_autonaming()).map(|_| autoname(&config));
// after
if let Some(history) = config.read().session.as_ref().and_then(|s| s.chat_history_for_autonaming()) {
    if !history.is_empty() {
        autoname(&config).await?;
    }
}
Defensive patterns

Strategy: validation

Validate before calling

fn can_autoname(cfg: &GlobalConfig) -> bool {
    cfg.read().session.as_ref()
        .and_then(|s| s.chat_history_for_autonaming())
        .map_or(false, |h| !h.is_empty())
}

Try / catch

match autoname_session(&config).await {
    Err(e) if e.to_string() == "No chat history" => { /* fall back to manual name */ }
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09). Data as JSON: /api/errors/685bfb3144111197. Report an issue: GitHub.

Appendix: source

Thrown at src/config/mod.rs:1329

        tokio::spawn(async move {
            if let Err(err) = Config::autoname_session(&config).await {
                warn!("Failed to autonaming the session: {err}");
            }
            if let Some(session) = config.write().session.as_mut() {
                session.set_autonaming(false);
            }
        });
    }

    pub async fn autoname_session(config: &GlobalConfig) -> Result<()> {
        let text = match config
            .read()
            .session
            .as_ref()
            .and_then(|v| v.chat_history_for_autonaming())
        {
            Some(v) => v,
            None => bail!("No chat history"),
        };
        let role = config.read().retrieve_role(CREATE_TITLE_ROLE)?;
        let input = Input::from_str(config, &text, Some(role));
        let text = input.fetch_chat_text().await?;
        if let Some(session) = config.write().session.as_mut() {
            session.set_autoname(&text);
        }
        Ok(())
    }

    pub async fn use_rag(
        config: &GlobalConfig,
        rag: Option<&str>,
        abort_signal: AbortSignal,
    ) -> Result<()> {
        if config.read().agent.is_some() {
            bail!("Cannot perform this operation because you are using a agent")
        }

View on GitHub (pinned to 82976d349a)