thread.isLoading remains `true` even after stream completion due to delayed `history` fetch

:bug: Bug Report: isLoading remains true even after stream completion due to delayed history fetch

:pushpin: Context

We are using stream.submit() from the LangGraph SDK to stream messages with streamMode: ["custom"]. During the streaming process, stream.isLoading is set to true — which is expected. However, it remains true even after streaming completes. This introduces unnecessary UI blocking and delays the feedback to the user.

Code snippet:

stream.submit(
  {
    messages: [...toolMessages, ...messages],
    userId: user!.id,
    currentBrandContextId: selectedBrandId,
  },
  {
    streamMode: ["custom"],
    optimisticValues: (prev) => ({
      ...prev,
      messages: [...(prev.messages ?? []), ...toolMessages, ...messages],
    }),
  }
);

Expected Behavior
Once the streaming of response chunks is finished — i.e., the for await (const chunk of stream) equivalent is complete — we expect isLoading to be set to false.

Actual Behavior
What seems to be happening is:

stream.submit() starts the stream.

Streaming completes (we receive the final chunk).

Then, the SDK internally triggers a history fetch request (likely via refetch() or a similar method).

isLoading remains true until this secondary history call also completes.

As a result, the UI is blocked even after the streaming has concluded, leading to a delayed perception of responsiveness.

Why this matters
For most UI implementations, isLoading is interpreted as “stream in progress”.

Fetching history can be slower and shouldn’t block the streaming UX.

From a user’s perspective, the spinner or loading indicator persists longer than expected, creating confusion or perceived slowness.

3 Likes

Facing the same issue, can someones tell how to solve this with OSS version. @nithin

@nithin any help on this?

Hi Dhanush,

Thank you so much for bringing this to our attention and for your help so far. I also saw your bug report here. Would you be able to share your full graph implementation so we can take a deeper look and try to triage this issue?

Hi Liam,

I don’t believe this is related to the graph implementation. Even with a minimal graph setup, including your own examples, the issue still occurs.

As the number of thread messages and the context grow, the SDK’s history fetch API call becomes increasingly slow. The time taken seems to scale exponentially with the length of the message list.

Additionally, I wanted to check if the streamMode option in the SDK is necessary in this context. Could you help clarify its relevance here?

@liam-langchain Any update?

@liam-langchain Please let us know if there are any updates regarding this.

@liam-langchain Are you working on this, still not addressed.