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

[Security Assistant] Abort signal fix #203041

Merged
merged 6 commits into from
Dec 5, 2024

Conversation

stephmilovic
Copy link
Contributor

@stephmilovic stephmilovic commented Dec 5, 2024

Summary

I noticed that abortSignal was not being properly piped through for any of the connector types. I suspect this happened when we made the switch to be fully LangChain. It is most evident with OpenAI, as the stream never finishes (handleStreamEnd not called) so the message does not get persisted, resulting in the following misbehavior:

bad1.mov

In Bedrock and Gemini we had the handleStreamEnd behavior correctly handling abort signal. However, we did not pass through the signal in the chat model. On top of that, for some reason Bedrock gets the abort signal off of the invoke config and we were not providing signal there. I made changes to pass the signal to the connector, and to pass the signal through the invoke config for Bedrock.

Impact

OpenAI

OpenAI had the biggest impact. Below is a screen capture of the problematic steps above, now behaving as expected. The stream runs slightly longer on the server, so when the UI updates it has a little extra text than when the stream originally finished.

good1a.mov

Bedrock

Bedrock behaves differently in that when you end the stream, it still gives you the complete output. So although the signal is now included in the connector request, there is not a UI implication. It behaves the same way as before: The stream will stop in the UI, but when you reload the conversation the full response will be there.

Gemini

The stream is so fast in Gemini, I can't actually successfully press "Stop generating" so it seems there is no user impact. However, I ensured that the signal is now included in the connector request.

@stephmilovic stephmilovic added release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. backport:prev-major Backport to (8.x, 8.17, 8.16) the previous major branch and other branches in development Team:Security Generative AI Security Generative AI labels Dec 5, 2024
@stephmilovic stephmilovic requested review from a team as code owners December 5, 2024 00:21
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@@ -160,10 +160,7 @@ export const streamGraph = async ({
finalMessage += msg.content;
}
} else if (event.event === 'on_llm_end' && !didEnd) {
const generations = event.data.output?.generations[0];
if (generations && generations[0]?.generationInfo.finish_reason === 'stop') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this condition prevented aborted generations from being persisted in the conversation

@pgayvallet pgayvallet removed request for a team December 5, 2024 11:41
Copy link
Member

@KDKHD KDKHD left a comment

Choose a reason for hiding this comment

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

Looks good to me (aside from failing CI). I tested locally but maybe another review from someone with more context would be good.

@stephmilovic stephmilovic enabled auto-merge (squash) December 5, 2024 20:06
@stephmilovic stephmilovic merged commit b3b2c17 into elastic:main Dec 5, 2024
8 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.15, 8.16, 8.17, 8.x

https://github.com/elastic/kibana/actions/runs/12188345046

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 5, 2024
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 5, 2024
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 5, 2024
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.15 Backport failed because of merge conflicts
8.16
8.17
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 203041

Questions ?

Please refer to the Backport tool documentation

@stephmilovic stephmilovic removed the backport:prev-major Backport to (8.x, 8.17, 8.16) the previous major branch and other branches in development label Dec 5, 2024
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Dec 5, 2024
@stephmilovic stephmilovic added backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) and removed backport:skip This commit does not require backporting labels Dec 5, 2024
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12189308563

@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12189308566

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 5, 2024
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 5, 2024
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Dec 6, 2024
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Assistant] Abort signal fix
(#203041)](#203041)

<!--- 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":"2024-12-05T21:27:29Z","message":"[Security
Assistant] Abort signal fix
(#203041)","sha":"b3b2c1745ac846b377d8e234526aa965196e4de9","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:
SecuritySolution","backport:prev-major","Team:Security Generative
AI"],"title":"[Security Assistant] Abort signal
fix","number":203041,"url":"https://github.com/elastic/kibana/pull/203041","mergeCommit":{"message":"[Security
Assistant] Abort signal fix
(#203041)","sha":"b3b2c1745ac846b377d8e234526aa965196e4de9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203041","number":203041,"mergeCommit":{"message":"[Security
Assistant] Abort signal fix
(#203041)","sha":"b3b2c1745ac846b377d8e234526aa965196e4de9"}}]}]
BACKPORT-->

Co-authored-by: Steph Milovic <[email protected]>
markov00 pushed a commit to markov00/kibana that referenced this pull request Dec 7, 2024
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 9, 2024
Samiul-TheSoccerFan pushed a commit to Samiul-TheSoccerFan/kibana that referenced this pull request Dec 10, 2024
mykolaharmash pushed a commit to mykolaharmash/kibana that referenced this pull request Dec 11, 2024
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:Security Generative AI Security Generative AI Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants