Skip to content

fix(openrouter): deduplicate repeated finish metadata#38552

Merged
Mason Daugherty (mdrxy) merged 1 commit into
masterfrom
mdrxy/openrouter/duplicate-generation-info
Jun 29, 2026
Merged

fix(openrouter): deduplicate repeated finish metadata#38552
Mason Daugherty (mdrxy) merged 1 commit into
masterfrom
mdrxy/openrouter/duplicate-generation-info

Conversation

@mdrxy

@mdrxy Mason Daugherty (mdrxy) commented Jun 29, 2026

Copy link
Copy Markdown
Member

Closes #38226


OpenRouter can emit more than one terminal streaming chunk for a single response. Before this change, LangChain treated each terminal chunk as independent final metadata, so repeated string fields could be merged into corrupted values like stopstop.

This updates ChatOpenRouter streaming so repeated terminal chunks are interpreted as parts of the same response ending. Usage metadata is still captured, later chunks can fill in terminal details that were missing from earlier chunks, and already-seen terminal fields are not duplicated.

The regression coverage exercises sync and async generation with duplicate finish chunks, including the case where usage and additional terminal metadata arrive on the later chunk.

@github-actions github-actions Bot added fix For PRs that implement a fix integration PR made that is related to a provider partner package integration internal openrouter `langchain-openrouter` package issues & PRs size: M 200-499 LOC labels Jun 29, 2026

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Open SWE Review: No issues found

Open SWE reviewed this PR and found no potential bugs to report.

Open in WebView Open SWE trace

@mdrxy Mason Daugherty (mdrxy) merged commit 7725cce into master Jun 29, 2026
32 checks passed
@mdrxy Mason Daugherty (mdrxy) deleted the mdrxy/openrouter/duplicate-generation-info branch June 29, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix For PRs that implement a fix integration PR made that is related to a provider partner package integration internal openrouter `langchain-openrouter` package issues & PRs size: M 200-499 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChatOpenRouter writes generation_info twice causing double strings as values

1 participant