Skip to content

New Conversation always creates empty session even when current session is empty #1171

@nesquena-hermes

Description

@nesquena-hermes

Summary

Clicking "New Conversation" (or pressing Cmd+K) always creates a new empty session, even when the current session has zero messages. Clicking it rapidly 5 times adds 5 empty sessions to the list. The 60-second cleanup window means they accumulate visibly, and users who frequently use Cmd+K end up with a cluttered session list.

Steps to reproduce

  1. Open the WebUI — a new empty session is created (normal)
  2. Without sending any message, click "New Conversation" in the sidebar header
  3. Another empty session appears in the list
  4. Click it 5 more times → 5 empty "Untitled" sessions pile up
  5. They eventually disappear after ~60 seconds, but during that window (and before) the list is cluttered

Root cause — confirmed in code

static/boot.js:385 — the btnNewChat onclick handler:

$('btnNewChat').onclick = async () => {
  await newSession();
  await renderSessionList();
  closeMobileSidebar();
  $('msg').focus();
};

static/boot.js:517–519 — Cmd+K shortcut:

if((e.metaKey||e.ctrlKey) && e.key==='k'){
  if(!S.busy){ await newSession(); await renderSessionList(); ... }
}

Neither handler checks whether the current session already has zero messages. newSession() unconditionally calls POST /api/session/new, creating and persisting a fresh session every time.

api/models.py:563–567 — the 60-second cleanup filter:

result = [s for s in result if not (
    s.get('title', 'Untitled') == 'Untitled'
    and s.get('message_count', 0) == 0
    and (_now - s.get('updated_at', _now)) > 60
)]

Empty sessions are hidden from the sidebar after 60 seconds, but during the window they're fully visible. And the session files still exist on disk even after they're hidden — the filter is UI-only.

Expected behavior

If the current session is empty (0 messages sent), clicking "New Conversation" or pressing Cmd+K should focus the composer of the existing empty session rather than creating another one.

Proposed fix

Add a guard in both btnNewChat and the Cmd+K handler:

$('btnNewChat').onclick = async () => {
  // If current session is already empty, just focus the composer
  if (S.session && (S.session.message_count || 0) === 0) {
    $('msg').focus();
    return;
  }
  await newSession();
  await renderSessionList();
  closeMobileSidebar();
  $('msg').focus();
};

Same guard for the Cmd+K path. Optionally also clean up orphaned zero-message sessions on server restart or add a "cleanup" call after session creation so old orphan files don't accumulate on disk.

Impact

Low-medium — annoying UX noise, not data-destructive. Users who use Cmd+K habitually as a "go to chat" shortcut hit this constantly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions