Skip to content

fix(sdk-react): clear stale stream values after joinStream history refresh#2010

Closed
pawel-twardziak wants to merge 3 commits intolangchain-ai:mainfrom
pawel-twardziak:fix/sdk-joinstream-clear-stale-values-1969
Closed

fix(sdk-react): clear stale stream values after joinStream history refresh#2010
pawel-twardziak wants to merge 3 commits intolangchain-ai:mainfrom
pawel-twardziak:fix/sdk-joinstream-clear-stale-values-1969

Conversation

@pawel-twardziak
Copy link
Contributor

Summary

This PR fixes a stale state issue in useStream/useStreamLGP after joinStream completes.

When joinStream succeeds and history is refetched, the hook could keep showing stale local stream
values if no final values event was applied.
This change clears local stream state after a successful history refresh so the hook falls back to the
latest /history values.

What Changed

  • Updated libs/sdk/src/react/stream.lgp.tsx to reset local stream state (return null) after
    history.mutate(threadId) returns a latest head.
  • Added a regression test in libs/sdk-validation/src/tests/stream.test.tsx covering:
    • stale local values after submit
    • joinStream path where no final values event is delivered
    • expected fallback to refreshed history values

Issue Fixed

Fixes a bug where joinStream could leave UI state stale (e.g. generating: true, outdated messages) even
after history was successfully refreshed.

Relevant Context

This is most visible in slow/interrupted stream flows where joinStream returns but no terminal values
event updates local stream state.

Testing

  • Added integration-style regression test: joinStream clears stale values when history is refetched.

Fix #1969

…fresh

Reset local stream state after join completion so hook values fall back to fresh /history data.
Add a regression test for the stale-values case when joinStream refetches history but no final values event is applied.

Fix langchain-ai#1969
@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2026

⚠️ No Changeset found

Latest commit: c9555bf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@christian-bromann

Thank you for raising the PR, we are currently working on new SDK packages to integrate in different frontend frameworks, see #2001. I will incorporate your PR in there manually.

@pawel-twardziak
Copy link
Contributor Author

Hi Christian Bromann (@christian-bromann) thanks for that info, I forgot for a moment about that PR

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.

joinStream's onSuccess doesn't clear stream values, causing stale state after reconnect

2 participants