Repository navigation
📊 feat: Feed a Side Chat's Usage to Its Composer's Gauge - #18488
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: f63edcfdc6
ℹ️ 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 (final == null) { | ||
| /** No reply is on its way in what was just read, so no estimate of one is kept. */ | ||
| usageHandlers.resetLive({ conversation: { conversationId: id } }); |
There was a problem hiding this comment.
Clear side-chat usage on terminal paths without a final frame
When a turn sent from the side composer receives a terminal error frame after streaming output or token usage, this reset is never reached: createEventApplier only flushes message writes for errors, and useFollowChat's conclude() does not call onSettled for an owned turn without a final frame. The newly connected writers therefore leave the active response, live counters, and pending usage populated. useTokenUsage continues adding that pending usage to totals, and the next turn inherits it because neither bindResponse nor contextHandler clears pending usage. Wire terminal failure cleanup separately from history settlement, with a regression test covering an error after usage has arrived.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid, fixed in 8c883b3.
A turn sent from the side composer that ends with no final frame (an error frame, or a stop before the server kept anything of it) now drops what was counted for its reply: useFollowChat's conclude() calls usage.resetLive on that path, which toResumableUsage maps to the same resetLive main chat's session runs on its error frame (core/resumable/failure.ts). A turn that ends on its final frame is still settled by finalizeUsage alone.
Test: driven.spec.tsx › "drops what was counted for a reply that fails, and keeps it for one that ends" runs the real usage writers against a store, sends a turn, folds a token_usage frame, then an error frame, and reads the pending usage and the active response back. Without the call it fails with the 40 output tokens and one folded event still pending; with it, both are cleared, and a following turn that ends on its final frame never triggers the reset.
|
Codex Review: Didn't find any major issues. Keep them coming! 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
The gauge in a side chat's composer does not count a reply while it is written. It keeps the count it had when the turn was sent and jumps when the reply ends.
Two things were missing. One is main chat's too and is fixed in #18487: the gauge lost track of the reply as soon as its row was renamed. The other is the side chat's own: nothing handed the usage frames of a conversation driven through a core
Chatto the writers the gauge reads. The event applier already calls those writers at the points main chat's stream session does (the context reading as a reply starts, the output arriving, the totals at its end, a resumed run's snapshot); the app's side chat host passed it none.This change passes it main chat's own writers, so the side composer's gauge counts a reply as it arrives, the same way and from the same frames.
Stacked on #18469 and depends on #18487, whose commit is included here until it merges into
dev. Without #18487 the side gauge would keep the right state and still show it frozen, as main chat's does today.How it works
toResumableUsageis the mapping from the usage writers to the shape a stream's applier calls, which main chat's stream session built inline. It now lives besideuseUsageHandlerin@librechat/chatand both use it, so the two cannot drift.The live estimate and the usage counted for a reply are cleared (
resetLive) where main chat clears them, on the paths that end without a final frame: when the side chat reads its stored rows and no reply is on its way, and when a turn sent from it fails or is stopped before the server kept anything of it. Without the second, a failed reply's count would be added to the conversation's next one.Type of change
Testing
In a real browser on the mock e2e lane: send a slow reply in a side chat and read the gauge at chunk 20 and chunk 100 of 160, with the Stop control still on screen for both. With #18487 but without this change the two readings are equal (
Expected: > 43,Received: 43); with it the second is higher.An earlier scenario for this checked the gauge's breakdown after a turn. It passed with and without the change, because that breakdown is rebuilt from what the messages store, so I replaced it with the one above.
Tested environments/configuration:
Automated tests:
packages/chat:npx jest(250 suites, 4029 tests),tsc --noEmit.packages/chat:driven.spec.tsx› "drops what was counted for a reply that fails, and keeps it for one that ends" (real usage writers; fails without the reset with the failed reply's tokens still pending).client: new case insrc/Providers/__tests__/SideChatHostContext.spec.tsx(a context reading on the side conversation's stream lands in that conversation's usage state);npx jest src/hooks/SSE src/Providers(30 suites, 719 tests).@scenario:side-chat-composer-gauge-follows-the-reply; the composer spec (11 scenarios) andgauge-follows-reply.spec.tspass together.