Skip to content

Generation page: switching sessions via the sidebar leaves the previous session's composer draft behind #106

Description

Capability or area

generation-ui — Generation page, session panel + composer (imagent-ui/app/components/GenerationChat.tsx)

Problem

Clicking a different session in the sidebar does not clear the composer.
A draft typed into one session stays in the composer after switching to a
completely different session, and can be sent into the wrong session if
the user does not notice.

createSession already clears the composer correctly:

// GenerationChat.tsx ~line 389
function createSession() {
  const reusableSession = sessions.find((session) => session.messages.length === 0);
  if (reusableSession) {
    setActiveSessionId(reusableSession.id);
    setPrompt("");
    clearInputImage();
    setSidebarCollapsed(false);
    return;
  }
  // ...same pattern for the brand-new-session branch
}

But the two sidebar session-switch handlers only update the active id:

// GenerationChat.tsx ~line 764 (collapsed rail) and ~line 783 (full list)
onClick={() => {
  if (sessions.length) {
    setActiveSessionId(session.id);
  }
}}

Reproducible on main (04c818a):

  1. Send a prompt in session A so it has content, then create session B.
  2. Type a draft into Bs composer (do not send it).
  3. Click session A in the sidebar.
  4. The transcript correctly switches to A, but the composer still shows
    Bs draft, sitting right above an enabled Send button — sending now
    would deliver Bs draft into A.

Proposed change

Inside the approved Generation UI files only
(app/components/GenerationChat.tsx):

  • Add a small switchSession(sessionId) helper (mirroring what
    createSession already does) that resets the composer (setPrompt(""),
    clearInputImage()) whenever the active session actually changes, and
    call it from both sidebar click handlers instead of calling
    setActiveSessionId directly.
  • No-op if the clicked session is already active, so an in-progress draft
    is not wiped by re-clicking the current session.

No visual/layout changes — state-management fix only.

Expected agent impact

None — Generation page UI only; no agent, runtime, or benchmark behavior
changes. Switching sessions no longer risks delivering a draft (or an
attached image) into the wrong conversation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions