Skip to content

🧭 feat: Queue and Steer a Reply From a Side Chat - #18491

Draft
danny-avila wants to merge 3 commits into
danny-avila/side-chat-composerfrom
danny-avila/side-chat-queue
Draft

danny-avila wants to merge 3 commits into
danny-avila/side-chat-composerfrom
danny-avila/side-chat-queue

Conversation

@danny-avila

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

Copy link
Copy Markdown
Collaborator

Summary

In a conversation open beside the chat, the composer could not do anything to a reply in flight except stop it. Typing while the side chat's reply streamed and pressing Enter did nothing useful: main chat's during-run actions (queue a follow-up, steer the reply, interrupt it) were switched off for every pane but the main one, because only main chat's stream session publishes what those actions need.

This turns them on for a side chat, with the same behavior as main chat:

  • A message queued behind the reply (Ctrl/Cmd+Enter, or Enter when queueing is the default) waits in the side composer's queue and is sent as the conversation's next turn when the reply ends.
  • A steer is shown waiting at the end of the side chat's list, joins the reply where the run takes it (a tool boundary), and becomes the next message when the reply ends without having taken it.
  • An interrupt (Alt+Enter, or "Interrupt now" on a queued row) cuts the reply where it is and continues it with the reader's words.
  • Stop leaves what was queued for the reader to send ("Send now"), as it does in main chat, including a stop that lands just before completion and ends the run on a reply marked unfinished.
  • In a saved agent's conversation the queue is kept by the server, which starts the queued turn itself when the reply ends. The side chat now follows that turn; before, it would have sat on "Starting as the next turn" until the panel was reopened. The same wiring makes a side chat follow a run started from another tab.

All of it is the side conversation's own: the chat on screen gains no turn, row or chip. While a side chat's reply runs the sidebar now lists the conversation under Running, as it does for main chat's.

Stacked on #18469, which gave the side chat main chat's composer.

A run that ends without its reply is handled as main chat's session handles it, through the same functions:

  • A control frame that only says the run is over settles the reader's steers against the stored rows once they are read, not against the frame: a steer the run took is not sent again as a new turn. The run counts as completed only when the server says so and the rows were read.
  • A stop that could not be saved takes back the leave "interrupt and send" had given the queue.
  • A queued turn whose start the server refuses goes back in the queue in its place; one another generation got ahead of goes back behind that generation, which is then followed, and leaves nothing in the list.
  • A turn that replays a steer the server had parked is not sent once the reader has dealt with that steer, and the steer is put back if the turn ended without the server keeping it.
  • A steer left waiting by a run that ended while the side chat was closed is settled when the conversation is opened again.

Not covered here. A reply that ends while its side chat is closed leaves a client-held queue in place for a manual send when the conversation is next opened; main chat's recovery for a run that ended while away is not run by a side chat. A stream that is gone for good (a 404, or the reconnect ceiling) ends a side chat's run as an error, so its queue waits for a manual send, where main chat reads the run's terminal status to decide. Both are read from the code, not exercised. @ mentions and model choice stay off in a side chat, as in #18469.

How it works

Main chat's stream session publishes three things the composer's during-run machinery reads: the generation in flight (what a steer or stop addresses), each run's end (what lets the queue go), and the settlement of the reader's steers at the run's terminal frame. A side chat runs on a core Chat followed by useFollowChat, which published none of them. Now it does, into the same atoms, so useSteering, useQueueDrain, the queue rail and the pending-steer row work unchanged.

useFollowChat                          packages/chat/src/react/follow.ts
  note(stream)        -> onGeneration({ createdAt, protocolVersion })
  runEnded(finished)  -> onRunEnd({ outcome, generationCreatedAt, responseMessageId })
                         after the list holds what the run left, and not for a dropped stream
  attach()               exposed: look for a run this chat did not start

  conclude / attach / open
    control frame, or nothing running -> read rows, then settleStoredSteers(...)
    start refused                     -> restoreRefusedStart(...) or back behind the winner
    replayed steer not kept           -> restoreReleasedSource(...)

createEventApplier                     packages/chat/src/core/apply.ts
  final with the reply -> settleFinalSteers(...)   shared with main chat's session
  final, control frame -> nothing: the stored rows decide
  error (server's)     -> convertLocalToQueued(claimParked)
  abort                -> convertLocalToQueued(failed only)

SideChatPanel                          packages/chat/src/components/side/panel.tsx
  onGeneration        -> activeGenerationCreatedAtByConvoId / ...ProtocolVersionByConvoId
  onRunEnd            -> runEndByIndex(SIDE_CHAT_PANE), after disarming interrupt-and-send
                         when the stop could not be saved

DrivenThread                           packages/chat/src/components/pane/Driven.tsx
  useQueueDrain(index, id, contract.ask)   mounted where the app hosts the steer hooks
  pending steers and the revealed queued turn drawn at the end of the list

app side chat host                     client/src/Providers/SideChatHostContext.tsx
  beside.steers = useResumableSteers(useSteerState())
  generation named -> addActiveJob; run ended -> removeActiveJob
  useOwedSuccessor(...) -> followed.attach() when the server announces a run

What main chat's session did inline for steers and the queue at a run's end is now four functions in core/resumable/steers.ts, each called by the session handler it came from and by the side chat's path, so both leave a steer or a queued turn the same way:

Function Came from Also called by
settleFinalSteers handleFinal (frames.ts) the event applier, at a final frame with the reply
settleStoredSteers reconcileGenerationLifecycle (reconcile.ts) useFollowChat, after reading the stored rows
restoreRefusedStart startGeneration (launch.ts) useFollowChat, when a start is refused
restoreReleasedSource failure.ts, launch.ts useFollowChat, after a replayed steer's turn ended unkept

clearMatchingDrainAfterAbort moved the same way, from the app's pane into core/steer/drain.ts.

The gate that kept during-run actions to the main pane is now a statement the chat makes: ChatContract.steers (the driven contract sets it), which the composer passes to useSteering as duringRun. Main chat's pane still qualifies by being the pane with the stream session.

For a run the server starts, the side chat's host uses the hook main chat uses, useOwedSuccessor, over the receipts of the reader's queued turns and the list of running generations. It looks (one status read; one read of the stored rows when nothing is found) once when the receipts change while a run is owed, and once per fetch of the list while the list names the conversation. A turn that waits before the server takes it is not looked for on every poll.

Requests added. During a side chat's reply: none. When a run ends on a control frame, or a side chat follows a run to an end that carried no reply: one status read, to settle steers. When a side chat opens: none (the status it already reads is reused). When a reply ends with a queued turn the server owns: one status read, plus one read of the conversation's messages if the server has not started the turn yet; then the active-job list is polled every 5 s while the turn is owed, as it is for main chat. When the list names a side conversation that is not being followed: one status read per list fetch until it attaches. Latency was not measured.

Type of change

  • Feature

Testing

In a real browser on the mock e2e lane, six scenarios in e2e/specs/mock/scenarios/side-chat-steering.spec.ts, each run against builds with one part of the change removed:

Scenario Fails without
side-chat-queued-message-follows-the-reply steers on the driven contract (no during-run control in the side composer)
side-chat-steer-joins-the-reply steers; the pending-steer row in a driven thread
side-chat-steer-not-taken-follows-the-reply steers; settleFinalSteers in the applier (the steer is accepted, then never sent); the pending-steer row
side-chat-interrupt-continues-the-reply steers
side-chat-stop-keeps-the-queue steers
side-chat-server-queued-turn-is-followed the host's look for announced runs (Expected: 6 turns, Received: 5: the queued turn stays on "Starting as the next turn")

A unit test caught a defect the browser did not: with a queued turn the server had not yet taken, the host looked for it again every time a look ended, in a tight loop of status reads. The mock lane takes the turn within milliseconds, so the loop was short there. SideChatHostContext.spec.tsx now pins one look per change.

Tested environments/configuration:

  • Chromium via Playwright, mock e2e lane (in-memory MongoDB, fake model), desktop 1440×900. Mock Provider A for queue, unapplied steer, interrupt and stop; Mock Provider C with the E2E Memory MCP server for a steer taken at a tool boundary; a saved agent for the server-owned queue.
  • Not exercised in a browser: a stream that drops and is attached to again during a steer, and a run started from another tab.

Automated tests:

  • packages/chat: npx jest (250 suites, 4060 tests), tsc --noEmit.
    • core/__tests__/apply.spec.ts: steers at a final frame, at a server-written error, at a local close, and none moved for a dropped stream.
    • react/chat/__tests__/driven.spec.tsx: the generation and run-end reports (completed, failed, taken back, stopped on an unfinished reply, dropped then reattached, a run it did not start, and nothing said after the chat is let go of).
    • react/chat/__tests__/driven.spec.tsx, "the reader's steers and queue when a run ends without its reply": control frames, a stop that could not be saved, a settled start, refused starts, a turn another generation got ahead of, replayed steers, and steers left waiting when the conversation opens.
    • core/__tests__/steers.spec.ts: the three shared functions that had no test of their own.
    • components/side/__tests__/panel.spec.tsx: the panel names the running generation and the queue goes out when the run ends; a stopped run keeps the queue; no queue is sent where the app hosts no steer hooks.
  • client: tsc --noEmit; npx jest src/Providers src/hooks/SSE src/hooks/Chat src/components/Chat/Input (82 of 83 suites pass; hooks/Chat/__tests__/target.spec.tsx needs a server on :3080 locally and is not touched here).
    • Providers/__tests__/SideChatHostContext.spec.tsx: a steer the reply never took is queued before the run is said to have ended; a run the server starts is followed; the list is kept in step; one look per change.
    • hooks/Chat/__tests__/useSteering.spec.tsx: the during-run gate for a pane other than main chat's.
  • Each new jest case was run with its part of the change removed and failed.
  • The composer spec (10 scenarios), main chat's queued-reveal.spec.ts and main chat's steering.spec.ts (15 scenarios, whose handlers now call the shared functions) pass alongside the new ones: 32 scenarios in one run.

side-chat-steer-queue

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review dda8286

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-19T05:29:33.500515Z 9fa61ac 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.

@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: dda8286ae3

ℹ️ 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 thread packages/chat/src/react/follow.ts Outdated
Comment on lines +393 to +397
let outcome: FollowedRunEnd['outcome'] = 'completed';
if (finished.isError === true) {
outcome = 'error';
} else if (finished.isAbort === true || withdrawn) {
outcome = 'aborted';

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 Treat unfinished replies as aborted before publishing run end

When a side-chat run stops just before completion, the final frame can contain responseMessage.unfinished: true without aborted or terminalStatus (see the final-event construction in api/server/controllers/agents/request.js). Chat.getFinalOutcome() classifies that frame as complete, so checking only finished.isAbort publishes a completed run end here. The newly mounted queue drain can then automatically send locally queued follow-ups despite the Stop, rather than leaving them for manual submission. Main chat explicitly handles this case in core/resumable/frames.ts; preserve the same unfinished-reply check for side-chat run ends.

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 f22862e.

runEnded in useFollowChat now says aborted when the reply the run ended on is marked unfinished, alongside the chat's own abort and a turn taken back. It is the check main chat's session makes in core/resumable/frames.ts (data.aborted === true || data.responseMessage?.unfinished === true), applied where the side chat publishes its run end, so the core Chat's own classification of the frame is unchanged for everything else that reads it.

Tests, both failing without the check and passing with it:

  • driven.spec.tsx › "says a turn was stopped when its final frame only marks the reply unfinished": a final frame with responseMessage.unfinished: true and no aborted reports { outcome: 'aborted', generationCreatedAt: 3000, responseMessageId: 'response-2' }.
  • panel.spec.tsx › "keeps the queue when the run ends on a reply marked unfinished, with no word of an abort": with a message queued, that frame leaves the queue as it was and sends nothing.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review f22862e

@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: f22862ed10

ℹ️ 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 +753 to +755
const ending = steerTarget(event.data.conversation?.conversationId);
if (init.steers != null && ending != null) {
settleFinalSteers(init.steers, ending, event.data, init.protocol?.());

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 Reconcile persisted steer parts before sweeping lifecycle finals

When a reconnect misses a steer's application and receives a reconcile: true / terminal_payload_missing final, that control frame deliberately contains no responseMessage. Calling settleFinalSteers here nevertheless sweeps local pending steers into the queue before the follower reloads persisted history. An already-applied steer consequently becomes a spurious queued recovery attempt, and the subsequent history read does not undo that conversion. Main chat's reconcileGenerationLifecycle first reads authoritative messages and excludes their applied steer IDs; lifecycle finals need equivalent reconciliation rather than ordinary-final settlement.

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 9fa61ac.

The event applier no longer settles steers on a frame that only says the run is over (reconcile: true): no reply in it says which steers the run took. useFollowChat settles them after it has read the stored rows, through settleStoredSteers, which is the block main chat's reconcileGenerationLifecycle ran, moved to core/resumable/steers.ts and called by both: applied ids from the stored rows and the run's last status, promoted steers adopted, parked ones restored, and only then the chips still left swept, excluding the reconciled ids. Nothing is swept when the rows could not be read, or while the status says another generation is already running.

The same settlement now runs when a side chat opens on a conversation with nothing running, so a steer left waiting by a run that ended while the panel was closed is not shown as waiting forever.

Tests (each fails without its part): apply.spec.ts › "settles no steers on a frame that only says the run is over…"; driven.spec.tsx › "settles steers against the rows it reads, not against a frame that carries none", "sweeps nothing after such a frame while another generation is already running", "settles steers left waiting by a run that ended while the conversation was not open", "settles nothing from stored rows while a generation is running, or after one that ended on its reply"; steers.spec.ts › settleStoredSteers.

Comment on lines +404 to +408
host.current.onRunEnd?.({
outcome,
generationCreatedAt: known?.createdAt,
responseMessageId: finished.message?.messageId,
});

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 Disarm interrupt-and-send when abort persistence fails

If “interrupt & send” receives an abort_persistence_failed reconciliation frame, Chat exposes that reason through finished.reconcileReason, but this callback publishes an aborted run end without clearing the armed drain override. The newly mounted useQueueDrain explicitly drains aborted/error outcomes while that override is armed, so it automatically submits the follow-up even though the interrupted reply's persistence is unknown. Main chat handles this exact case by clearing the override in reconcileGenerationLifecycle; preserve the reason through the side-chat run-end path and disarm it before publishing.

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 9fa61ac.

FollowedRunEnd carries the frame's reconcileReason, and the panel takes back the interrupt-and-send override armed for that exact generation (clearMatchingDrainAfterAbort, moved from the app's pane into core/steer/drain.ts and used by both) before it publishes the run end when the reason is abort_persistence_failed.

Reading this path by what main chat publishes, the outcome itself was also wrong for runs that end with no payload, so runEnded now says what main chat's session says: a control frame is completed only when the server says complete and the stored rows were read (error if they were not), otherwise aborted; a start the server answers as already settled is aborted, not a completion of this turn.

Tests (each fails without its part): driven.spec.tsx › "says a run whose stop could not be saved was stopped, and why", "says a start the server answered as already settled was not a completed run"; panel.spec.tsx › "takes back the leave to send on a stopped run when the stop could not be saved" (armed override, queued message, the frame: the override is cleared and nothing is sent).

ask,
}: Pick<DrivenThreadProps, 'id' | 'index'> & { ask: ChatContract['ask'] }): null {
const revealQueuedTurn = useQueuedTurnReveal(id, index);
useQueueDrain(index, id, ask, revealQueuedTurn);

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 Restore dequeued side-chat turns on predecessor conflicts

If another tab starts a generation before a locally queued side-chat follow-up is admitted, the follow-up's predecessor fence can return HTTP 409 GENERATION_PREDECESSOR_MISMATCH. This drain has already removed the queue item once ask synchronously accepts it, but the side chat's createGenerationTransport treats the response as a rejected start and useFollowChat.conclude only builds a transient failed turn; neither restores submission.queuedMessageOrigin. The queued message therefore disappears from the queue without running and is lost from the transcript on reload. Main chat explicitly restores the exact row in core/resumable/launch.ts and reconciles the winning generation; provide that recovery for this sender before enabling its drain.

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 9fa61ac.

A start the server refuses now leaves a queued turn where main chat leaves it:

  • 409 GENERATION_PREDECESSOR_MISMATCH: the row goes back with the winner's generationCreatedAt as its new fence, nothing of the turn stays in the list (no message, no failure row, and the words are not also handed back to the composer), no run end is published (that would send it again at once), and the generation that won is followed to its end.
  • Any other 4xx: restoreRefusedStart, which is main chat's own block from core/resumable/launch.ts moved to core/resumable/steers.ts and called by both: a recovery the server rejected as such is barred first, then the row goes back. The refusal still shows as the turn's reply and the run end is error, so nothing queued is sent on its account.
  • A transport failure or 5xx: nothing is put back, as in main chat, since the turn may have started.

While in this path I added the rest of what main chat does for a turn that replays a parked steer, so it is not left as a caveat: the turn is not sent when the reader has already dealt with that steer (isRecoveryHeld), and after a start that may have run or an error the stream reported, the status is read and the steer is put back if the server let go of it again (restoreReleasedSource, shared with failure.ts and launch.ts).

Tests (each fails without its part): driven.spec.tsx › "puts a turn back in the queue when the server refuses its start, and not when it may have started", "leaves nothing of a turn another generation got ahead of, and follows that generation", and the three cases under "for a turn that replays a steer the server had parked"; steers.spec.ts › restoreRefusedStart, restoreReleasedSource.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review 9fa61ac

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 9fa61aca36

ℹ️ 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".

This branch has not been deployed

No deployments
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