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

Bug sc 62423 fred service error missing toolcallid or #4

Merged

Conversation

hoangvvo
Copy link
Collaborator

@hoangvvo hoangvvo commented Nov 9, 2024

What does this PR do?

Fix https://fireflies.sentry.io/issues/6052582757/?referrer=slack&notification_uuid=e1c886ce-dfea-4803-a716-8305fe4f218e&alert_rule_id=15510789&alert_type=issue

Type of change

This pull request is a

  • Feature
  • Bugfix
  • Enhancement

Which introduces

  • Breaking changes
  • Non-breaking changes

How should this be manually tested?

xxx

What are the requirements to deploy to production?

Any background context you want to provide beyond Shortcut?

xxx

Screenshots (if appropriate)

Without this fix:
image

With this fix:
image

all tests pass:
Uploading image.png…

Loom Video (if appropriate)

xxx

Any Security implications

xxx

Summary by CodeRabbit

  • New Features

    • Updated version of the @firefliesai/llm-sdk module to 0.1.6.
  • Bug Fixes

    • Refined logic for matching tool calls, improving accuracy in processing multiple tool calls.
  • Tests

    • Added a new test case for handling multiple tool calls with the same name.
    • Enhanced existing test case for user registration with more detailed attributes.

Copy link

coderabbitai bot commented Nov 9, 2024

Walkthrough

The changes in this pull request involve updates to the package.json file for the @firefliesai/llm-sdk module, specifically a version increment from 0.1.5 to 0.1.6. Additionally, there are modifications to the ContentDeltaAccumulator class in stream.utils.ts, where the logic for matching tool calls has been simplified by removing the toolName matching condition. Lastly, the test-language-model.ts file has been enhanced with a new test case for handling multiple tool calls of the same name and an updated test case for user registration.

Changes

File Change Summary
javascript/package.json Updated version from 0.1.5 to 0.1.6. No other changes made.
javascript/src/utils/stream.utils.ts Modified guessDeltaIndex function to remove toolName matching condition, simplifying tool call logic.
javascript/test/test-language-model.ts Added new test case for parallel tool calls with the same name; updated existing user registration test case.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Tool
    participant System

    User->>System: Request multiple tool calls (same name)
    System->>Tool: Process tool call 1
    Tool-->>System: Return result for tool call 1
    System->>Tool: Process tool call 2
    Tool-->>System: Return result for tool call 2
    System-->>User: Return results for all tool calls
Loading

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hoangvvo hoangvvo requested review from greguintow and a team November 9, 2024 03:06
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
javascript/src/utils/stream.utils.ts (1)

Line range hint 158-169: Consider documenting the tool call handling strategy.

The change to always return false for tool calls represents an important architectural decision in how tool calls are processed. Consider adding a code comment explaining this design choice to help future maintainers understand why tool calls are handled differently from text and audio parts.

 } else {
   // we won't be able to reliably match tool calls
   // because there can be multiple tool calls with the same tool name
+  // Each tool call needs a unique index to prevent conflicts and ensure
+  // proper accumulation of arguments and IDs
   return false;
 }
javascript/test/test-language-model.ts (1)

522-564: LGTM with a suggestion: Add assertion for unique toolCallIds.

The test case effectively verifies handling of parallel tool calls with the same name but different arguments. This is crucial for the bug fix related to missing toolCallId.

Consider adding an assertion to verify that the toolCallIds are unique:

   t.assert.equal(!!weatherCall1, true);
   t.assert.equal(!!weatherCall2, true);
+  t.assert.notEqual(weatherCall1?.toolCallId, weatherCall2?.toolCallId, 
+    "Tool calls should have unique toolCallIds");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 94720c0 and 14f7748.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • javascript/package.json (1 hunks)
  • javascript/src/utils/stream.utils.ts (1 hunks)
  • javascript/test/test-language-model.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • javascript/package.json
🔇 Additional comments (3)
javascript/src/utils/stream.utils.ts (2)

167-167: LGTM! Safer handling of tool call indices.

The change to return false for tool calls is a good safety improvement. It prevents potential overwrites that could occur when multiple tool calls share the same name, ensuring each tool call gets a unique index.


Line range hint 102-109: Verify error handling for tool calls.

The error handling for missing toolCallId or toolName is well-implemented. Let's verify that this validation is sufficient for catching the reported bug.

✅ Verification successful

Let me analyze the validation of toolCallId and toolName across the codebase:

  1. In stream.utils.ts, there's strict validation in computeContent() that throws an error if either field is missing.
  2. The schema in schemas.gen.ts enforces both fields as required for tool calls and tool results.
  3. The merging logic in stream.utils.ts correctly handles both fields during delta merging.
  4. All language model adapters (OpenAI, Mistral, Google, Cohere, Anthropic) properly map these fields.

The error handling for tool calls is robust and correctly implemented. The validation in computeContent() ensures that both toolCallId and toolName are present before processing, which effectively prevents the reported bug. The schema validation and consistent handling across all adapters provide additional safeguards.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other places where toolCallId or toolName might be used without validation
rg -g '*.ts' -g '*.js' 'toolCallId|toolName' -C 3

Length of output: 29713

javascript/test/test-language-model.ts (1)

387-387: LGTM: Comprehensive test input covering all schema requirements.

The test input provides good coverage of the complex schema by including all required fields with properly formatted data.

Copy link

@greguintow greguintow left a comment

Choose a reason for hiding this comment

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

Left a non blocking comment

@@ -164,10 +164,7 @@ export function guessDeltaIndex(
} else {

Choose a reason for hiding this comment

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

This else technically becomes unnecessary in this case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i will make that change on the hoangvvo/llm-sdk and include on next release

@hoangvvo hoangvvo merged commit cf24deb into main Nov 9, 2024
2 checks passed
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.

2 participants