Repository navigation
🛟 fix: Handle Gemini Heartbeats and Upstream Cancellation - #701
Conversation
|
Review head: |
|
Review head: |
|
Review head: |
|
Review head: |
|
Verified head: Independent review: complete, no findings. Previous ledger: P1 smoothed-stream cleanup fixed in Local: 397 Google/smoothing/protection regressions and 211 tracing tests passed. TypeScript, scoped lint/import order, CJS/ESM build and HTTP smoke, circular dependencies and dependency audit passed. CI: all 13 validation jobs passed; the body-edit-only workflow was skipped. The independent reviewer inspected frozen source and did not run dependency-based tests. Live Gemini/gateway tests were not run locally. No publication or LibreChat dependency update. Fork provenance and upstream reference are in the description. |
|
@codex review the latest head, final review |
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. |
|
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
Google reasoning streams can freeze on SSE keepalives. Stop also leaves the archived SDK's upstream request and aggregate-response branch running.
Reconcile the current LangChainJS GenerateContentApiHandler HTTP/SSE flow with LibreChat's custom Google class:
eventsource-parser, without an SDK compatibility shim or handwritten SSE grammar.Deliberate differences from upstream: malformed/truncated JSON and provider errors fail rather than becoming empty chunks; stream exit cancels the reader and request. No gateway-specific
[DONE]handling or broader LangChain migration.Related to LibreChat-AI/LibreChat#18153.
Verification
Real local HTTP regressions cover heartbeats, fragmented UTF-8/CRLF, abort before headers and during idle streaming, early exit with smoothing on/off, protected budget rejection, cache/event paths and exact signed replay/metadata. Existing Google, smoothing and protection boundary tests remain.
Also checked: TypeScript, scoped lint/imports, package build, CJS/ESM public API smoke, circular dependencies, dependency audit and tracing regressions.
Not included: live Gemini/gateway verification, package publication or LibreChat's dependency update.
Fork Provenance
The fork began with custom header forwarding in June 2025. That alone no longer justifies a fork: current LangChain Google classes accept custom headers.
Current upstream
ChatGooglealready handles headers, thinking tokens and native thought signatures. Those capabilities are not unique fork requirements; LibreChat's persisted replay format, event metadata and caller contracts still need reconciliation. The old publiccompletionWithRetryinputs/helpers remain compatibility obligations while inheriting the old class.This PR follows upstream's HTTP/SSE approach. Its strict malformed/provider-error handling and explicit reader/request cancellation are deliberate, covered differences, not a new Gemini feature surface.