Skip to content

feat: conversations keep answering in the background, with a list to switch between them - #198

Merged
bencode merged 2 commits into
mainfrom
feat/background-conversations
Oct 23, 2026
Merged

bencode merged 2 commits into
mainfrom
feat/background-conversations

Conversation

@bencode

@bencode bencode commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Several conversations can now run at once. Switching away from a conversation no longer stops its reply; it keeps answering in the background. Clicking the conversation's name at the top of the assistant panel opens a list of recent conversations to switch between. The interaction was settled with a clickable prototype (option A).

Behavior

  • Switching: switching never aborts a reply. The conversation you leave keeps answering, and any messages queued for it go with it.
  • The list: clicking the name opens it. It stays open, so you can switch back and forth, until you click the name again. Collapsed, the header looks exactly as before. The list is closed by default and remembers whether it was open.
    • It shows the 10 most recently used conversations. The open conversation and any that are answering are always included; older ones are under All history.
    • While the list is open, its order stays fixed, so rows don't move as you click. Closing and reopening it re-sorts by recent use.
    • It takes at most half the panel's height and scrolls inside itself.
  • Status: a conversation that is answering shows a spinner. One that finished in the background and hasn't been looked at yet shows a dot, which clears when you switch to it. The collapsed header shows how many conversations are answering.
  • Unchanged: the conversation number is still its own copy button, and the header's +, History and Close buttons are as before. There is no limit on how many conversations run at once. Reloading the page still aborts any reply in progress, as before.

Implementation

Commit 1: multiple conversations in the controller (no UI). The controller used to treat "one store, one runtime" as the open conversation. It now separates two levels:

  • Per session (Session): its own store (conversation, draft, messages, phase), runtime (agent, run state) and draft queue.
  • Controller level (ConversationState): which conversation is open, the background activity marks (activity), the model configuration and history.

The SessionCtx type ties these together. The run, draft, compaction, title and settings modules now each operate on a single session. In memory the controller keeps only the open conversation plus those answering; when a background reply finishes, that conversation is marked unread and released. navigation.ts switches in this order: save the draft, activate the target, release the previous session. The open session is therefore always in memory. A conversation still in memory is taken and activated synchronously, so a reply finishing at that moment cannot release it first.

controller.store is now a view store: controller state plus the open session's state, kept in sync by subscription. Field names are unchanged, so the hook and the existing tests need no changes.

Commit 2: list UI.

  • recent-conversations.ts: pure functions. recentConversations picks the rows; keepOrder holds the order fixed while the list is open.
  • session-list.tsx: the list.
  • session-list-preference.ts: remembers open/closed, following pdf-reading-preferences.
  • In the header, the title becomes a toggle button.
  • Tutorial updated: the Conversations section of the assistant chapter, and a What's new entry.

Verification

  • pnpm check passes on both commits. On commit 1, no existing test changed: switching, /clear, queueing and stop tests all pass.
  • New tests:
    • recent-conversations.test.ts: limiting to 10; keeping older conversations that are open or answering; an unsaved conversation going on top; holding the order.
    • An integration test: send in A and hold the reply, then + to create B and write a draft. The list shows A with a spinner; when the reply is released, A shows a dot; switching to A shows the full reply and clears the dot; switching back to B, the draft is still there.
  • End-to-end on brain2 (agent-browser, local server):
    • A ran a long task: search, read four notes, summarize. B was asked something in the meantime. The header showed "2 answering".
    • A finished in the background: the spinner turned into a dot, and the model named it in the background too. Switching back to A showed the full summary, with no "Generation stopped".
    • While the list was open, repeated switching didn't change the order. Closing and reopening re-sorted it by recent use.
    • Drafts follow their own conversation when switching.
    • After a reload, the list's open state, the open conversation and its draft were all restored. All history opens the history view.
    • Found and fixed during e2e: the list's text was larger than the header's, now set to 13px.
  • Not run end-to-end: more than 10 conversations (covered by the unit test), and a background reply failing so that its queued messages go back to its draft (that path exists in code but is not covered by any test).
  • Self-reviewed twice, once for behavior and once for code quality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant