Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should trigger request again when throttle is not undefined #5528

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

coverlv
Copy link

@coverlv coverlv commented Apr 3, 2025

when experimental_throttle is set, occasionally useChat() will not trigger request again, because the messageRef.current is not the newest messages.

reproduction:

const { append } = useChat({
  maxSteps: 5,
  experimental_throttle: 100
});

Root cause:

// Keep the latest messages in a ref.
const messagesRef = useRef<UIMessage[]>(messages || []);
useEffect(() => {
  messagesRef.current = messages || [];
}, [messages]);

// ...

onUpdate({ message, data, replaceLastMessage }) {
   // has latency here
  throttledMutate(
    newMessages,
    false,
  );
});

const messages = messagesRef.current;
if (
  shouldResubmitMessages({
    originalMaxToolInvocationStep: maxStep,
    originalMessageCount: messageCount,
    maxSteps,
    messages,
  })
)// return false;

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.

1 participant