Repository navigation
🧭 feat: Queue and Steer a Reply From a Side Chat - #18491
danny-avila wants to merge 3 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| let outcome: FollowedRunEnd['outcome'] = 'completed'; | ||
| if (finished.isError === true) { | ||
| outcome = 'error'; | ||
| } else if (finished.isAbort === true || withdrawn) { | ||
| outcome = 'aborted'; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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 withresponseMessage.unfinished: trueand noabortedreports{ 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.
There was a problem hiding this comment.
💡 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".
| const ending = steerTarget(event.data.conversation?.conversationId); | ||
| if (init.steers != null && ending != null) { | ||
| settleFinalSteers(init.steers, ending, event.data, init.protocol?.()); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| host.current.onRunEnd?.({ | ||
| outcome, | ||
| generationCreatedAt: known?.createdAt, | ||
| responseMessageId: finished.message?.messageId, | ||
| }); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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'sgenerationCreatedAtas 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 fromcore/resumable/launch.tsmoved tocore/resumable/steers.tsand 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 iserror, 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.
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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:
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:
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
Chatfollowed byuseFollowChat, which published none of them. Now it does, into the same atoms, souseSteering,useQueueDrain, the queue rail and the pending-steer row work unchanged.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:settleFinalSteershandleFinal(frames.ts)settleStoredSteersreconcileGenerationLifecycle(reconcile.ts)useFollowChat, after reading the stored rowsrestoreRefusedStartstartGeneration(launch.ts)useFollowChat, when a start is refusedrestoreReleasedSourcefailure.ts,launch.tsuseFollowChat, after a replayed steer's turn ended unkeptclearMatchingDrainAfterAbortmoved the same way, from the app's pane intocore/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 touseSteeringasduringRun. 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
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:side-chat-queued-message-follows-the-replysteerson the driven contract (no during-run control in the side composer)side-chat-steer-joins-the-replysteers; the pending-steer row in a driven threadside-chat-steer-not-taken-follows-the-replysteers;settleFinalSteersin the applier (the steer is accepted, then never sent); the pending-steer rowside-chat-interrupt-continues-the-replysteersside-chat-stop-keeps-the-queuesteersside-chat-server-queued-turn-is-followedExpected: 6turns,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.tsxnow pins one look per change.Tested environments/configuration:
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.tsxneeds 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.queued-reveal.spec.tsand main chat'ssteering.spec.ts(15 scenarios, whose handlers now call the shared functions) pass alongside the new ones: 32 scenarios in one run.