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: clean up two explicit errors handled elsewhere #138

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

Conversation

adamrturman
Copy link
Collaborator

Summary

Removes two explicit error checks

Copy link

netlify bot commented Jan 15, 2025

Deploy Preview for hardfunai canceled.

Name Link
🔨 Latest commit a69b7ee
🔍 Latest deploy log https://app.netlify.com/sites/hardfunai/deploys/6787ffeb83fced0008c02509

Comment on lines -161 to -165
// Errors can be thrown when recursive call is cancelled
if (errorMessage.includes('JSON')) {
errorMessage = 'You clicked cancel - please try again';
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No longer an error after introducing JSON streaming parser.

Copy link
Member

Choose a reason for hiding this comment

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

Nice cleanup

Comment on lines -65 to -73
const lastMessage = messages[messages.length - 1];
const lastMessageRole = lastMessage.role;

// if a user has initiated a wallet-based tool call, but not confirmed or denied it
// we don't want to add more messages to the history
const userRequestInProgress =
messages.length > 1 && lastMessageRole === 'user';

if (isRequesting || userRequestInProgress) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We now early return from the streaming store if we get into a bad state and don't call the .write() method which triggered the error when a user entered more messages after starting a tx, but never completing that tool call in metamask.

if (!streamParser) {
return;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

the reason for the write error in the streaming store is because:

  1. model generates a single tool call which gets added to the toolCallStream store the index for the tool call is 0
  2. the tool call stream store parses the streaming json for the tool call and removes the underlying parser once the tool call stream is finished from the model.
  3. another tool call is made but it's scoped to a different request, however the problem is that the index of the new tool call corresponds with the old tool call which had it's parser removed, so when the new tool call json args are being streamed this is when the errors gets thrown. The problem here is that the old tool call from the previous request is not removed/resolved yet, and there's no way for us to know that this reffers to a different request all together since all we get is an index for each tool call request from the model. and those indices are scoped per request. so the problem here is that we shouldn't allow users to submit more requests until the previous tool call is resolved/removed in some way.

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.

3 participants