Skip to content

๐Ÿ๏ธ feat: Apply Stream Metadata Through Shared Chat Handlers - #18398

Merged
danny-avila merged 1 commit into
devfrom
danny-avila/chat-side-frames-host
Nov 18, 2026
Merged

danny-avila merged 1 commit into
devfrom
danny-avila/chat-side-frames-host

Conversation

@danny-avila

Copy link
Copy Markdown
Collaborator

Summary

A stream changes two kinds of state: the message list, and state kept beside it (token usage, the conversation's title, attachments a tool produced, the composer's steer chips). createEventApplier, the reducer that lets a Chat in @librechat/chat apply a stream the way main chat does, covered only the first. Frames of the second kind reached a Chat's consumer as raw events through onEvent, and a chat that joined a run late got nothing for them at all: a resume snapshot carries the run's usage so far, its title and its still-queued steers as fields, not as events, and only main chat's stream session read those fields.

This gives the applier the second kind. It takes the handlers main chat's own stream session uses for that state and calls each one for the frames, live or carried by a snapshot, that main chat calls it for. A Chat handed main chat's handlers keeps the state main chat keeps, in main chat's own stores, without a parallel copy.

First of the steps that turn a followed conversation into a chat a reader can open and drive beside the main one. No user-facing change: nothing passes these handlers yet.

Related to #18190, #18195.

How it works

The handler interfaces already exist in the package core, where main chat's resumable session is defined (ResumableUsage, ResumableEvents, ResumableSteers in core/resumable/host.ts). The applier's init takes them as optional fields.

frame                          handler called                                   main chat's call site
created                        usage.bindResponse(turn)                         frames.ts
step (message/reasoning ฮ”)     usage.tapStream(ฮ”, turn)                         frames.ts
context_usage | token_usage    usage.contextHandler | usageHandler(data, turn)  frames.ts
attachment                     onAttachment({ data, submission: turn })         frames.ts
title                          onTitle(frame)                                   frames.ts
steer_updated                  steers.update(event)                             frames.ts
steer_applied                  steers.resolve(...) at once; markLiveApplied     patches.ts
                               when its part is drawn
final                          usage.finalizeUsage(frame, turn)                 frames.ts
sync (snapshot)                usage.bindResponse, backfillUsage(collected),    sync.ts
                               contextHandler(contextUsage), seedLiveFromContent,
                               steers.seed(pendingSteers) + settleApplied,
                               onTitle(titleEvent), then replayEvents and
                               pendingEvents routed as above

Two rules carried over from main chat. A steer's chip is settled the moment the server says the steer was taken, before its part can be drawn, because a chip left pending meanwhile could be sent again. And an empty pendingSteers list is still seeded, because it is what clears a chip whose steer was applied while the chat was away.

A frame that needs its turn (an attachment, a usage event) and arrives before a frame has named the turn is held and applied once one does, the way early step events already are.

useFollowChat takes the same handlers as beside and forwards each frame to the caller's current ones.

Type of change

  • Feature
  • Tests / tooling / CI

Testing

Tested environments/configuration:

Unit level. Not exercised in a browser: a background subagent's stream carries only step events and applied steers, so the one consumer of the applier today receives none of these frames.

Automated tests:

  • packages/chat/src/core/__tests__/apply.spec.ts, new "state beside the message list" (6 cases): each live frame reaches the handler main chat gives it, bound to the turn, in order; a snapshot rebuilds usage, context, the live estimate, chips and title, then applies the usage and attachment events it carries; an empty snapshot list still seeds the chips; a steer chip is settled before its part is drawn and marked when it is; frames that need a turn are held until one is named; with no handlers the messages are applied as before.
  • follow.spec.tsx (1 new): the hook forwards an attachment to the caller's handler, and to the newer handler after a rerender.
  • Four pieces of the change were removed in turn (snapshot usage, chip seeding, replay of snapshot-carried frames, settling a chip before its part is drawn); each fails a test.
  • packages/chat: npx jest (3924 tests), npx tsc --noEmit. npm run static-checks -- --against origin/dev.

Risk / compatibility

Every field is optional and absent everywhere today, so the applier behaves as it did. The steer chips are seeded without the generation's timestamp and protocol version, which main chat passes from its stream subscription and the applier is not given; both are optional there.

@danny-avila
danny-avila added this pull request to stack #18403 November 18, 2026 12:00
@lia-by-librechat lia-by-librechat Bot changed the title ๐Ÿงพ feat: Apply a Stream's Usage, Attachments, Title and Steer Chips in the Chat Event Applier ๐Ÿ๏ธ feat: Apply Stream Metadata Through Shared Chat Handlers Nov 18, 2026
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head 43d4a19.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 43d4a19b59

โ„น๏ธ 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".

@chatgpt-codex-connector

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-18T12:37:25.768349Z 43d4a19 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 marked this pull request as ready for review November 18, 2026 12:51
@danny-avila
danny-avila merged commit 83bd676 into dev Nov 18, 2026
64 of 65 checks passed
@danny-avila
danny-avila deleted the danny-avila/chat-side-frames-host branch November 18, 2026 12:51
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