Repository navigation
📮 feat: Send a Turn Through the Chat Class's Generation Transport - #18411
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: a4d8fea66f
ℹ️ 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".
| }); | ||
| if (stream == null) { | ||
| /** The generation was over before its stream could be opened; its result is stored. */ | ||
| return { status: 'settled', conversationId: conversationId ?? request.chatId }; |
There was a problem hiding this comment.
Preserve protocol metadata when settling an unavailable stream
When a generation finishes before its stream opens and the attachment returns 404 or 409, this branch returns settled without generationProtocolVersion. However, Chat explicitly rejects every settled result whose protocol version is not 2 (packages/chat/src/core/chat.ts:2144–2146), so even a successfully negotiated v2 turn enters the error state instead of settling and triggering normal reconciliation. Preserve the negotiated protocol metadata and handle legacy outcomes consistently with the caller's contract. The new transport-only test asserts the incomplete result but does not exercise its consumption by Chat.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid, fixed in a1f7f8b. The transport no longer answers for the turn here at all: only the server's own settled/replaced is reported as such. A stream that will not open (404, 409, a closed wire, or a cancelled open) comes back as a named stream that dropped before its first frame. The Chat ends the turn as a disconnect, and the next resumeStream reads the status route and attaches to what is running or settles, under either protocol. It also fixes a stop that landed while the stream was opening, which had no generation to address. Covered through a real Chat in generation.spec.ts ("finds what became of a turn that was over before its stream opened", "stops the generation a start began when the stop lands before its stream opens"); both fail with the previous result.
A start the server took but whose stream did not open came back as a settled turn with no negotiated protocol, which the Chat refuses, and a stop that landed while the stream was opening had no generation to address. It is now a named stream that dropped before its first frame: the Chat stops it by name, or asks again and settles on what it finds.
|
Codex Review: Didn't find any major issues. Nice work! 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
A
Chatin@librechat/chatcan follow a generation over LibreChat's routes but cannot start one.createGenerationTransportreattaches to a running generation; itssendMessagesonly passed through to a function the app might supply, and nothing supplies one, sochat.sendMessage()on a real conversation was refused as view-only.This gives the transport the send. Handed the app's own way of posting a turn (
start, the call main chat's stream session already makes), it posts the turn to its endpoint's route, reads what the server did with it, and opens the stream of the generation it started. AChatbuilt on it can now take a turn end to end: prepare, post, stream, settle.Third of the steps toward a chat a reader can open and drive beside the main one, after #18398 and #18401. No user-facing change: nothing constructs a driving
Chatyet.How it works
The start response is read with the predicates main chat's
startGenerationuses (core/resumable/start.ts), and the post is retried on the same terms: a dropped connection a few times, a server that is still starting for as long as it says to wait within the readiness window. A v2-only control word from a server that did not negotiate v2 is refused rather than read as a stream, as it is there. Only the server's own answer settles or replaces a turn. A generation whose stream will not open (it was over already, a newer one took its place, the wire closed, or the caller cancelled) says nothing about how the turn ended, so the transport reports it as a stream that dropped before its first frame, carrying the generation's stream id and epoch. TheChatalready knows what to do with that: a stop addresses the generation by name, and otherwise the turn ends as a disconnect, and the host's nextresumeStreamreads the status route and either attaches to what is running or settles the turn for the host to read back, which is what main chat does on a 404.The route comes from
generationServer(endpoint), lifted out ofcreatePayloadin the data provider so both derive it one way.startand the existingsendMessagesoverride are both optional; without either the transport still only follows.Type of change
Testing
Tested environments/configuration:
Unit level, with a real
Chatin the end-to-end case. Not exercised against a running server: nothing in the app passesstartto this transport yet.Automated tests:
packages/chat/src/core/__tests__/generation.spec.ts, new "sending a turn" (7): the post's route and stripped body, and a live (not replayed) stream; a folded start replayed;settledandreplacedreported without opening a stream; a response naming no stream, or an unnegotiated control word, refused; a stream that will not open (404, 409, closed wire) reported as a named stream with no frames; a retry after a dropped connection and none after a refusal; a turn with no endpoint refused before any post.Chat: a turn whose stream 404s before opening ends as a disconnect, and the nextresumeStreamfinds nothing running and settles it; a stop that lands while the stream is opening reaches the server with the generation's stream id and epoch. Both, and the transport case above, fail with the previoussettledresult.apply.spec.ts: a realChatsends a turn through the real transport, shows the prepared turn, and appliescreated, steps andfinalto the same two rows main chat ends with.packages/chat:npx jest src/core(1729 tests),npx tsc --noEmit;packages/data-provider:npx jest specs(1316 tests),npx tsc --noEmit.npm run static-checks -- --against origin/dev.Risk / compatibility
createPayloadbuilds the same route through the new helper. The transport's new option is unused by the app, so following behaves as it did.The retry loop restates main chat's start policy with the shared predicates and constants;
startGenerationitself is not changed here and still owns the pane-specific handling around it (queued-turn restore, error cards). Folding the two onto one loop is a follow-up.