Skip to main content

Side threads

A side thread lets you dig into a passage of an assistant answer without cluttering the main conversation. Select text in an answer, click Approfondisci in un thread ("Explore in a thread") and keep chatting in a panel next to the main chat. The first section (User flow) is for end users; the rest describes the API, storage and implementation for developers.

A side thread is not temporary: it is a regular conversation with its own id, history, STM window, MCP session and stream. It can be reopened from the parent (underline, chip, sidebar) or as a full page at /c/{threadId}.

Naming

In the code, "thread" already means a conversation (ThreadSidebar, useConversationThreads). The new concept is called side thread (sideThread, side-thread). The user-facing label is "Thread".

User flow​

  • Selection: valid only when it sits inside the prose of one assistant message (no code blocks, user bubbles, buttons, cross-message ranges). Quotes over 2000 characters are truncated and a hint is shown.
  • Lazy creation: the panel opens as a draft; the conversation is created on the first send, so abandoned drafts leave nothing behind. Selecting a passage that already has a thread reopens it.
  • Parallel streaming: the thread has its own engine (useSideThreadChat), so it can stream while the parent streams. Closing the panel does not stop the run, and reopening reconnects with getChatStreamReconnect.
  • Thread turns always use agent_mode: "normal" (no plan / deep research). Profile, model, reasoning effort, thinking and runtime tunings come from the parent.

Where threads appear​

SurfaceBehaviour
Parent feedThe passage is marked with the CSS Custom Highlight API (no DOM mutation): a soft brand wash plus a solid underline, stronger on hover and for the thread open in the panel. Clicking it opens the thread.
Message actionsA chip with the thread count under the source answer. It always works, even when the passage cannot be located (regenerated or edited answer).
Dock panelNew dock tab "thread": quote (click to scroll to and flash the passage), title, switcher between the conversation's threads, "open as chat", messages, compact composer. Full-screen sheet on mobile.
SidebarThreads are hidden from the main list and nested under their parent (chevron + count, lazily loaded). The parent of the open thread expands automatically.
Full page /c/{threadId}Breadcrumb "Thread from parent" with the quote; the back link /c/{parent}?thread={id} reopens the thread in the panel.
Admin UI /conversationsThreads are nested under their parent (collapsible, with tree connectors and the quote). Filters keep a matching thread's parent as dimmed context; sorting uses the latest activity of the whole family. The reader shows "Thread from parent" (opens the parent at the source message) and thread chips under each source answer.

Data model​

A side thread is a Conversation with three extra columns (migration w5x6y7z025_side_threads, also patched by bootstrap._patch_sqlite_columns):

ColumnMeaning
parent_conversation_idParent conversation id (indexed, no FK). One level only: threads cannot be nested.
parent_message_idId of the source assistant message.
anchor_json{quote, prefix, suffix} — a TextQuoteSelector-style anchor (prefix/suffix ~32 chars) used to find the passage again in the rendered markdown.

API​

All endpoints use the usual chat-ui auth (Authorization: Bearer <chat token>; X-AION-User-Id only counts in open mode). Threads of a conversation owned by another user answer 404.

  • GET /chat-ui/conversations — excludes threads by default (include_threads=1 to include them); every summary carries thread_count.
  • GET /chat-ui/conversations/{id}/threads — non-archived threads of a conversation.
  • POST /chat-ui/conversations/{id}/threads — body {parent_message_id, quote, prefix, suffix}. Returns created: false when a thread with the same message and quote exists. 404 if the parent or message is not the caller's, 409 if the parent is itself a thread. Parent uploads are synced into the thread workspace.
  • GET /chat-ui/conversations/{id} — also returns parent_conversation_id, parent_message_id, parent_title, anchor.
  • DELETE /chat-ui/conversations/{id} — archives the child threads too and releases their MCP sessions.
  • POST /v1/chat/stream — now rejects (404) an existing session_id owned by another user.

Agent context​

build_turn_context adds the layer side_thread_context (src/runtime/turn/side_thread_context.py) on every turn of a thread. It contains:

  • the parent title;
  • up to 4 parent messages before the source answer (≈2400 chars);
  • the source answer, clipped to ≈6000 chars around the quote;
  • the highlighted passage, with an instruction to answer in the parent's context.

The layer is recomputed each turn, never persisted and not passed to LTM extraction.

Frontend map​

FileRole
lib/side-thread/anchor.tsAnchor from a DOM range, and range from an anchor (best prefix/suffix match).
lib/side-thread/use-text-selection-anchor.tsTracks a valid prose selection in the feed.
components/chat/side-thread/SelectionThreadPopover.tsxFloating action (above on desktop, below on touch).
lib/side-thread/use-side-thread-highlights.tsPaints ::highlight(side-thread*), hit-tests clicks, revealThread.
lib/side-thread/use-side-thread-chat.tsIndependent streaming engine for one thread (draft → create on first send).
components/dock/SideThreadPanel.tsxPresentational panel (the dock renders twice, desktop and mobile, so the engine lives in ChatWorkspace).

Without the Custom Highlight API, the underline is not painted; the chip, the sidebar and the panel keep working.