Skip to content

Auto-refresh session title using the existing summarization cycle in TokenAwareSummarizingMemory #536

Description

@haiphucnguyen

Summary

Session titles are currently generated once from the first user message and never updated, even as the conversation evolves significantly. This ticket wires a title refresh into the existing TokenAwareSummarizingMemory summarization cycle so the title stays meaningful over long, topic-drifting conversations — with no additional AI calls.

Motivation

A conversation that starts as "How do I center a div?" and evolves into a deep Kotlin coroutines debugging session still shows the original title in the sidebar. This makes it hard for users to find past conversations and gives no signal that the session has changed direction.

Proposed approach

Piggyback on the existing summarizeAndPrune() cycle in TokenAwareSummarizingMemory. When a new SessionConversationSummary is produced, derive a refreshed title from the summary data already available — no extra AI call needed.

Title derivation logic (in priority order):

  1. Use recentContext (first sentence, truncated to ~60 chars) if it's meaningfully different from the current title
  2. Fall back to mainTopics.take(2).joinToString(" · ") if recentContext is blank
  3. If neither yields anything useful, keep the existing title unchanged

Change detection — only update if:

  • The new candidate title differs from the current title by more than a trivial threshold (e.g. Levenshtein distance > 20% of current title length), to avoid flickering on minor rewordings
  • The session has at least MIN_MESSAGES_FOR_TITLE_REFRESH messages (e.g. 10) so very short sessions are not affected

Implementation

  1. TokenAwareSummarizingMemory — after mergeWithExistingSummary() produces a new summary, invoke an optional onTitleSuggested: ((String) -> Unit)? callback with the derived title candidate. Caller decides whether to apply it.

  2. SessionManager (or wherever TokenAwareSummarizingMemory is constructed) — wire onTitleSuggested to call chatSessionService.updateSessionTitle(sessionId, newTitle) when the candidate passes the change-detection check.

  3. ChatState / ChatViewModel — emit the updated title so ChatView reflects it live in the header without a full reload.

  4. Guard — skip title refresh if:

    • The user has manually renamed the session (track a userHasRenamedSession flag on the session)
    • The session has fewer than MIN_MESSAGES_FOR_TITLE_REFRESH messages
    • Summarization is running in fallback (basic) mode — basic summaries are not rich enough for a reliable title

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions