Skip to content

🪟 feat: Continue a Subagent's Thread as a Chat Beside the Conversation - #18417

Merged
danny-avila merged 2 commits into
devfrom
danny-avila/side-chat-surface
Nov 18, 2026
Merged

danny-avila merged 2 commits into
devfrom
danny-avila/side-chat-surface

Conversation

@danny-avila

@danny-avila danny-avila commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When a subagent has finished, its panel offers "Continue in a new chat": the child's thread is forked into a conversation of the reader's own. Until now that navigated the page to the new conversation, leaving the one the child ran under, with the reader's words dropped into the new chat's composer to be sent again.

The continuation now opens where the child's activity was, beside the conversation. It is a side chat: the forked conversation drawn by main chat's message list, with a composer, driven through a core Chat (#18413). The words the reader wrote to get there are sent as its next turn, the reply streams in, and further turns, reruns, edits and stops work from the panel. A control in its header moves it into the main chat's place.

side chat

This is the surface the earlier steps were for (#18398 side frames, #18401 turn shape, #18411 transport send, #18413 driving contract), and the first place the app starts a generation through the Chat class. Stacked on #18413.

Behavior change: "Continue in a new chat" no longer leaves the parent conversation. interface.sideChat: false restores the navigation (default true).

How it works

SubagentThreadPanel   continue → fork (unchanged)
  onSuccess → navigation.openBeside(conversation, text)      # absent when sideChat is off → navigates as before
     sideChatAtom = { conversation, text }

Presentation          side panel slot: artifacts ?? child activity ?? side chat
  <SideChatPanel chat onClose onHandedTextTaken>
     host.useChat(conversation)            useFollowChat over createGenerationTransport({ wire, getStatus, start, abort })
     pane conversation ← chat.conversation (SIDE_CHAT_PANE = 3; main 0, added 1, child thread 2)
     <DrivenThread>                        useDrivenContract → main chat's list (ContractThread)
        <Composer>                         ask({ text }) · Stop while a generation runs
     chat.text → ask once, when the conversation has loaded and the pane holds it
     the draft lives in the panel: handed to the main composer on "Open as the main chat",
     and refilled with the words of a turn stopped before the server kept it
  <ParentSubagentsProvider conversationId=side>   children its agent dispatches are its own
  rows' host: no comparison model (useGetAddedConvo), no queued turn, no seen-marking
packages/chat
  react/side/state.ts        sideChatAtom, SIDE_CHAT_PANE
  react/side/host.tsx        SideChatHost: useChat, useOpenConversation, useSheetLayout, useClearsFooter
  components/side/panel.tsx  SideChatPanel (lazy, via loadSideChatPanel)
  components/pane/Driven.tsx DrivenThread; Followed.tsx now shares ContractThread with it
client
  Providers/SideChatHostContext.tsx   the app's host: the transport main chat uses, with start and abort
  components/Chat/Presentation.tsx    mounts it; closes it when the conversation changes or another panel opens

The panel reuses what the child-activity panel uses: the same shell and header, the shared Composer from @librechat/client, the reader's Enter-to-send preference and rebound submit shortcut, the sheet layout on narrow screens.

Type of change

  • Feature
  • Tests / tooling / CI

Testing

Tested environments/configuration:

Chromium on the mock e2e lane (in-memory Mongo, fake model), from this branch's own server: the new scenario below, and the capture above is from that run.

Automated tests:

  • e2e/specs/mock/subagent-activity.spec.ts, new @scenario:subagent-continue-opens-side-chat: a parent dispatches two children; the first one's panel is continued with a typed follow-up; the side chat opens with the URL unchanged, shows the child's history and the follow-up, and the reply arrives; exactly one generation is started, for the forked conversation; a second turn is sent from the side chat's composer; "Open as the main chat" navigates to it with both turns stored.
  • packages/chat/src/components/side/__tests__/panel.spec.tsx (10), over the real useFollowChat, useDrivenContract and useTurns: loading then the stored rows under the title; a typed turn's posted body and rows, then Stop reaching the transport; a settled reply and the next turn answering it; handed-over words sent once; a failed load with Retry; open-as-main and close; unsent words handed to the main composer; the words of a turn the server never kept back in the field; no comparison model handed to its rows.
  • packages/chat/src/components/subagents/__tests__/panel.spec.tsx (2): the continuation is handed beside with its words, and without navigating; with no words.
  • client/src/Providers/__tests__/SubagentsHostContext.spec.tsx: openBeside is offered only with side chats on, and sets the side chat.
  • client/src/components/Chat/Presentation.test.tsx (2): the side chat mounts with child activity read for its own conversation and gives way to a child's panel; it closes when the main conversation changes.
  • client/.../Content/__tests__/AskUserQuestionCollapse.test.tsx: outside the main pane a live question stays in its card.
  • client/src/Providers/__tests__/SideChatHostContext.spec.tsx (3), over the app's real host and a wire the test drives: the conversation read as a list; a streamed attachment reaching the app's file list; a stop reaching the app's abort with the conversation, stream and epoch.
  • packages/data-schemas/src/app/interface.spec.ts (2): the flag reaches clients, and defaults on.
  • packages/chat npx jest (3989), npx tsc --noEmit; packages/data-provider config specs + tsc; packages/data-schemas app specs + tsc; the client suites above and tsc filtered to the touched files; npm run static-checks -- --against origin/dev.

Risk / compatibility

Followed.tsx changes by extraction (ContractThread). With interface.sideChat: false, or before the deployment's config has answered, the panel navigates as it did.

Pauses work in a side chat: a tool approval and an ask-user question are both answered from their card there, the answer is posted for the side conversation, and the rest of the reply arrives in the side chat. An earlier version of this description listed that as unsupported; that was read from the code, not observed, and a browser run showed otherwise. The follow-up PR adds the two scenarios.

Known gaps, not handled here:

  • Opening a child agent's activity from inside the side chat takes the panel slot and closes the side chat.
  • The side chat's composer is text only: no attachments, tools menu, model picker or queue/steer while a generation runs (the field sends once the turn is over).
  • Usage and title frames are not yet wired to the side pane (useFollowChat({ beside })), so a new conversation's generated title shows after it is reopened. Streamed attachments are wired, through the app's own handler.
  • A side chat can only be opened from a subagent's continuation; there is no entry point for an arbitrary or a new conversation.
  • No render benchmark: main chat's rows are not changed.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head 5c6b0e8.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T16:33:38.838288Z ce4c149 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danny-avila
danny-avila added this pull request to stack #18414 November 18, 2026 14:41
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head 5baccc5 (rebased onto #18413's new head; no change of its own).

@danny-avila
danny-avila force-pushed the danny-avila/side-chat-surface branch from 5c6b0e8 to 5baccc5 Compare November 18, 2026 14:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5baccc559f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const contract = useDrivenContract({ id, followed, index });
return (
<>
<ContractThread contract={contract} messages={followed.messages} slots={slots} />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Isolate side-chat reruns from the main chat's comparison target

When the main chat has an added comparison model, regenerating a response in the side chat also sends that comparison target. ContractThread inherits the app's useGetAddedConvo, which reads pane 1; both useMessageActions and useMessageHelpers pass its result to regenerate, and createPayload includes it as addedConvo. The backend's processAddedConvo consequently runs the main chat's comparison agent against the side conversation, producing unexpected additional responses and model usage. Override this host member with a null-returning getter for the independent side chat.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 0d401e7. The thread's messages host now answers useGetAddedConvo with nothing, beside the other members it already points away from main chat, so a rerun or edit here sends no comparison target. Test: "keeps a rerun in the side chat to its own conversation" (fails without the override).

Comment on lines +169 to +171
const openAsMain = useCallback(() => {
openConversation(pane.conversation ?? opened);
onClose();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Transfer the unsent draft when opening the side chat as main

If the reader types a follow-up in the side composer and then clicks “Open as the main chat,” their text is silently discarded. The composer keeps its draft only in local value state, while this handler transfers only the conversation and immediately closes the panel; the main composer therefore cannot recover the draft. This also loses handed-over continuation text that ask refused and left in the field. Hand the current draft to the destination composer before unmounting the side panel.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 0d401e7. The panel now holds the draft (so it outlives the composer) and hands it to the destination with handOffComposerText before the conversation opens as the main chat, the same hand-off the continuation used to make. Tests: "takes the unsent words along when the conversation moves to the main chat" and "hands nothing along when nothing was written". The same lifted state takes back the words of a turn stopped before the server kept it (onWithdrawn, from #18413).

Comment on lines +199 to +203
<DrivenThread id={conversationId} index={SIDE_CHAT_PANE} followed={followed}>
{(contract) => (
<SideChatComposer
contract={contract}
conversationId={conversationId}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Disable question handoff until the side composer can answer

When a side-chat agent pauses for ask_user_question, its message card still offers “Move to composer” through the app's AskUserQuestion adapter and useAskAnswerMode. Clicking it marks the question expanded, causing Question.tsx to replace the interactive card with an invisible placeholder, but SideChatComposer renders neither the answer popover nor its submit/collapse controls. The question therefore becomes unanswerable in the side panel. With Save Drafts disabled, that same handoff also writes the answer text into the enclosing main chat's form, because the side panel inherits its ChatFormProvider. Supply a side-scoped answer-mode integration, or withhold the move-to-composer action on this surface.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 0d401e7 by withholding the hand-off: the app's ask card offers "Answer from the message box" only in the main pane (ChatContext.index 0), so in any other pane the question stays in its card and nothing is written to main chat's form. Test in AskUserQuestionCollapse.test.tsx. This does not make pauses work in a side chat: answering resumes the generation through the app's resume route, and the side chat is not told to follow it yet. That is now listed under known gaps in the description rather than patched here.

Comment on lines +168 to +172
<SideChatHostProvider host={appSideChatHost}>
<Suspense fallback={null}>
<SideChatPanel
key={sideChat.conversation.conversationId}
chat={sideChat}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope subagent discovery to the side conversation

If the continued agent dispatches event-spawned subagents during a side-chat turn, their activity group never appears. This panel inherits the outer ParentSubagentsProvider, which is keyed to the main conversation, and neither SideChatPanel nor ContractThread supplies a replacement. EventSubagentActivityGroup reads that provider's byMessageId rather than fetching by its conversationId prop, so the side response's message IDs have no matching children and the component returns null. Detached tool-call previews likewise refresh the main conversation's index through useDetachedStatus. Wrap the side thread in a provider keyed to its own conversation and generation state so its child activity can be discovered and inspected.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 0d401e7. Presentation wraps the side chat in a ParentSubagentsProvider keyed to the side conversation, enabled for an agent conversation and fed the side pane's submitting flag. Test: "shows a side chat beside the conversation, with child activity read for its own conversation" (fails with the main conversation's id). Opening one of those children takes the panel slot, which closes the side chat; noted under known gaps.

@danny-avila
danny-avila force-pushed the danny-avila/side-chat-surface branch from 5baccc5 to 0d401e7 Compare November 18, 2026 15:04
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head 0d401e7.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d401e7f72

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

slots,
children,
}: DrivenThreadProps): ReactElement {
const contract = useDrivenContract({ id, followed, index });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Isolate the side chat's turn services from the comparison pane

When the main chat's comparison target is not ready, the side composer silently refuses otherwise valid turns. This contract inherits appChatHost.useTurnServices, whose client/src/hooks/Chat/services.ts reads the main chat's addedConversation and requires isTargetReady(queryClient, addedConversation) before allowing any submission. It also includes that comparison agent in the side chat's code-workspace and approval derivations, so an unavailable workspace belonging only to the comparison agent can block the side conversation. Clearing useGetAddedConvo in the messages host fixes the rerun payload, but does not isolate these submission checks. Supply turn services that omit the main comparison conversation for this independent pane.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 37e45f4. useTurnServices now takes the comparison conversation only for main chat's own panes (0 and 1); any other pane gets none, so its readiness check, code workspace and approval derivations are the side conversation's alone. Test in services.readCodeInputs.spec.tsx: with an unloaded comparison agent, pane 0 refuses and is handed the comparison, pane 3 submits and is handed nothing (fails without the scoping).

const openConversation = host.useOpenConversation();
const { handOffComposerText } = useChatSurface();
const conversationId = chat.conversation.conversationId ?? '';
const [draft, setDraft] = useState('');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the side draft across responsive layout changes

If the reader types a follow-up and then resizes the window or rotates a device across the side-panel breakpoint, their unsent text disappears. client/src/components/SidePanel/SidePanelGroup.tsx renders the panel inside ArtifactsPanel on wide screens and in a separate fixed container on narrow screens, so crossing that breakpoint unmounts and remounts SideChatPanel. This local state consequently resets to an empty string even though sideChatAtom still holds the same open conversation. Keep the draft in a conversation-keyed owner that survives that responsive remount, or preserve the panel's mounted identity when moving between layouts.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 37e45f4. The draft lives in sideChatDraftFamily(conversationId), an in-memory atom outside the panel, so the remount across the breakpoint keeps it (and nothing unsent is written to storage). Test: "keeps the unsent words when the layout draws the panel again" unmounts and mounts the panel (fails with the draft in panel state).

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head 37e45f4. Also fixes the two CI failures at 0d401e7: ChatSettings.spec.tsx asserted the config object without the new flag, and the new e2e scenario compared full URLs across the app's own removal of the agent_id query (it now compares the path; 3/3 locally with --repeat-each).

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 37e45f46be

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head 1ce2724. Rebased onto #18413's rebased head (which is now on dev with #18424). Squashed to one commit. Hand-resolved: e2e/specs/mock/subagent-activity.spec.ts (both new scenarios kept whole) and components/pane/Followed.tsx, where the shared ContractThread now takes the followed chat so the earlier-messages control from #18424 is drawn for a followed and a driven thread alike.

@danny-avila
danny-avila force-pushed the danny-avila/side-chat-surface branch from 37e45f4 to 1ce2724 Compare November 18, 2026 16:15

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ce2724e0c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +42 to +44
endpoint,
enabled: id !== '',
onWithdrawn: options?.onWithdrawn,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Connect the side stream's attachment handler

When a side-chat agent emits attachment events, such as web-search sources or generated-file metadata, this call supplies no beside.onAttachment handler. createEventApplier in packages/chat/src/core/apply.ts forwards these events only to that callback; it does not merge them into messages. Consequently, the side thread's useAttachments receives no streamed attachments, so attachment-backed output remains unavailable until the generation finishes and messages reload. The app's file, memory, and preview caches also miss the updates performed by client/src/hooks/SSE/useAttachmentHandler.ts. Pass that handler through beside so side-chat tool results receive the same attachment processing as main-chat results.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 3a822a8. The side chat's host passes the app's useAttachmentHandler to useFollowChat as beside.onAttachment, so a streamed attachment lands on the rows through the same live-attachments store the driven contract reads, and in the file, memory and preview caches. New SideChatHostContext.spec.tsx drives a real stream through the app's host: an attachment frame after created shows up in the app's file list (fails without the wiring). Usage and title frames are still not wired here; that stays under known gaps.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head 3a822a8.

Base automatically changed from danny-avila/chat-prepare-turn to dev November 18, 2026 16:30
What a tool hands back while a side chat's generation runs (search
sources, a generated file) reached no handler, so it was missing from
the rows and from the app's file, memory and preview caches. The side
chat's stream now uses the app's attachment handler.
@danny-avila
danny-avila force-pushed the danny-avila/side-chat-surface branch from 3a822a8 to ce4c149 Compare November 18, 2026 16:30
@danny-avila
danny-avila marked this pull request as ready for review November 18, 2026 16:30
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head ce4c149. The same tree as 3a822a8, rebased onto dev by the stack after #18413 merged.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: ce4c1494b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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