Skip to content

📮 feat: Send a Turn Through the Chat Class's Generation Transport - #18411

Merged
danny-avila merged 2 commits into
devfrom
danny-avila/chat-driving-path
Nov 18, 2026
Merged

danny-avila merged 2 commits into
devfrom
danny-avila/chat-driving-path

Conversation

@danny-avila

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

Copy link
Copy Markdown
Collaborator

Summary

A Chat in @librechat/chat can follow a generation over LibreChat's routes but cannot start one. createGenerationTransport reattaches to a running generation; its sendMessages only passed through to a function the app might supply, and nothing supplies one, so chat.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. A Chat built 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 Chat yet.

How it works

chat.sendMessage(input)
  prepareRequest        host builds the body and the turn to show meanwhile
  transport.sendMessages
    start({ server, payload })          # the app's POST, auth refresh included
      settled   → { status: 'settled' }                the server had already run this turn
      replaced  → { status: 'replaced' }               a newer generation took its place
      streamId  → open /chat/stream/:id                resume=true only if the server says it
                                                       folded the start into a running generation
        → { status: 'stream', stream }                 also when the stream will not open:
                                                       named, and already dropped
  applyEvent(created | step | … | final)  # createEventApplier, with the turn's shape from #18401

The start response is read with the predicates main chat's startGeneration uses (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. The Chat already 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 next resumeStream reads 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 of createPayload in the data provider so both derive it one way.

start and the existing sendMessages override are both optional; without either the transport still only follows.

Type of change

  • Feature
  • Tests / tooling / CI

Testing

Tested environments/configuration:

Unit level, with a real Chat in the end-to-end case. Not exercised against a running server: nothing in the app passes start to 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; settled and replaced reported 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.
  • Same file, through a real Chat: a turn whose stream 404s before opening ends as a disconnect, and the next resumeStream finds 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 previous settled result.
  • apply.spec.ts: a real Chat sends a turn through the real transport, shows the prepared turn, and applies created, steps and final to the same two rows main chat ends with.
  • Three pieces were removed in turn (the resume flag, the control-word check, the retry); each fails a test.
  • 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

createPayload builds 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; startGeneration itself 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.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head a4d8fea.

@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-18T14:00:30.013357Z a1f7f8b 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: 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 };

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 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 👍 / 👎.

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 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.
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head a1f7f8b.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a1f7f8be45

ℹ️ 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
danny-avila marked this pull request as ready for review November 18, 2026 14:02
@danny-avila
danny-avila added this pull request to stack #18414 November 18, 2026 14:03
@danny-avila
danny-avila merged commit 7a8e656 into dev Nov 18, 2026
69 of 70 checks passed
@danny-avila
danny-avila deleted the danny-avila/chat-driving-path branch November 18, 2026 14:22
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