-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[AI Assistant] Fix OpenAI, error race condition bug #205665
Conversation
Pinging @elastic/security-solution (Team: SecuritySolution) |
// if generation is null, an error occurred - do nothing and let error handling complete the stream | ||
generation != null && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is the actual bug fix, the rest is cleanup to match the same syntax we're using for Bedrock/Gemini
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally. Looks good!
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]
|
Starting backport for target branches: 8.x |
(cherry picked from commit 2c70e86)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…205767) # Backport This will backport the following commits from `main` to `8.x`: - [[AI Assistant] Fix OpenAI, error race condition bug (#205665)](#205665) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Steph Milovic","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-07T15:12:20Z","message":"[AI Assistant] Fix OpenAI, error race condition bug (#205665)","sha":"2c70e8651e52966f7c47bedfcd898eeb23bc0b1e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team: SecuritySolution","backport:prev-minor","Team:Security Generative AI","v8.18.0"],"title":"[AI Assistant] Fix OpenAI, error race condition bug","number":205665,"url":"https://github.com/elastic/kibana/pull/205665","mergeCommit":{"message":"[AI Assistant] Fix OpenAI, error race condition bug (#205665)","sha":"2c70e8651e52966f7c47bedfcd898eeb23bc0b1e"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205665","number":205665,"mergeCommit":{"message":"[AI Assistant] Fix OpenAI, error race condition bug (#205665)","sha":"2c70e8651e52966f7c47bedfcd898eeb23bc0b1e"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Steph Milovic <[email protected]>
Summary
Fixes a race condition that caused generic errors to show some of the time in OpenAI. The actual fix is adding a condition to the
on_llm_end
event that does not callhandleStreamEnd
ifgenerations
is undefined. This should only happen when there is an error. The error is caught inpost_actions_connector_execute.ts
and reported tohandleStreamEnd
.I changed the stream style to async iterator to match what we are doing in Bedrock/Gemini. This doesn't have to do with the fix, but makes the code a bit more readable.
To test
401 Incorrect API key provided
. You should NOT see an error likeResponse from LLM API is empty or undefined
Deleted files
I deleted some files I discovered are no longer in use. This is also unrelated to the bug fix