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(core): Fix race condition in AI tool invocation with multiple items from the parent #12169

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

netroy
Copy link
Member

@netroy netroy commented Dec 11, 2024

Summary

When an AI agent has multiple items, it can invoke a tool once for each of those items, but that can happen concurrently.
When we increment the runIndex in the finally block, this can lead to each item executing with the same runIndex, since the tool handling function is async.
By moving runIndex++ to where the context is created, we can now guarantee unique runIndex for each tool invocation.

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@netroy netroy requested a review from OlegIvaniv December 11, 2024 17:11
@netroy netroy added the release/backport Changes that need to be backported to older releases. label Dec 11, 2024
@netroy netroy force-pushed the fix-AI-tools-invocation-race-consition branch from 5639d3a to 43c59bc Compare December 11, 2024 17:37
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/core/src/CreateNodeAsTool.ts 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

✅ All Cypress E2E specs passed

Copy link

cypress bot commented Dec 11, 2024

n8n    Run #8299

Run Properties:  status check passed Passed #8299  •  git commit 43c59bc707: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 netroy 🗃️ e2e/*
Project n8n
Branch Review fix-AI-tools-invocation-race-consition
Run status status check passed Passed #8299
Run duration 04m 35s
Commit git commit 43c59bc707: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 netroy 🗃️ e2e/*
Committer कारतोफ्फेलस्क्रिप्ट™
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 480
View all changes introduced in this branch ↗︎

@netroy netroy merged commit dce0c58 into master Dec 11, 2024
37 checks passed
@netroy netroy deleted the fix-AI-tools-invocation-race-consition branch December 11, 2024 18:06
ivov pushed a commit that referenced this pull request Dec 12, 2024
@github-actions github-actions bot mentioned this pull request Dec 12, 2024
tomi pushed a commit that referenced this pull request Dec 12, 2024
@github-actions github-actions bot mentioned this pull request Dec 12, 2024
@janober
Copy link
Member

janober commented Dec 12, 2024

Got released with n8n@1.72.1

@github-actions github-actions bot mentioned this pull request Dec 19, 2024
riascho pushed a commit that referenced this pull request Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/backport Changes that need to be backported to older releases. Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants