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] Fix error handling on new chat #195507

Merged
merged 5 commits into from
Oct 14, 2024

Conversation

stephmilovic
Copy link
Contributor

@stephmilovic stephmilovic commented Oct 8, 2024

Summary

Resolves #191025

Fixes a bug in Security Assistant where the user's message disappears when a New chat is started with a bad connector.

Since the connector is bad and the first LLM call is to create the title, the error was thrown, the chain ended, and handleLllmResponse was called with the error message to save as an assistant message. Because the chain exited early, the title was not created, and the user's message was not persisted. By handling the error on the chat title and titling the conversation, the chain continues, saves the user's message, hits the LLM error again when it tries to send the conversation message, and handleLllmResponse is called with the error message.

Previous behavior

  1. Create new conversation
  2. Have invalid connector selected
  3. Send a message with the invalid connector selected
  4. Notice the following behaviors:
    a. Title is "New chat"
    b. User's message disappears
    c. Assistant error message persists
    Screenshot 2024-08-21 at 1 26 31 PM

New behavior

  1. Create new conversation
  2. Have invalid connector selected
  3. Send a message with the invalid connector selected
  4. Notice the following behaviors:
    a. Title is "Error name else error message, shortened to 60 characters"
    b. User's message persists
    c. Assistant error message persists
    Screenshot 2024-10-08 at 2 11 01 PM

Cypress test

There was a cypress test that led me to discover this bug in the first place that I am now unskipping. I've got a successful Flakey Test Runner build to show you!

@stephmilovic stephmilovic added release_note:skip Skip the PR/issue when compiling release notes v9.0.0 Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Team:Security Generative AI Security Generative AI v8.16.0 labels Oct 8, 2024
@stephmilovic stephmilovic requested a review from a team as a code owner October 8, 2024 21:07
@elasticmachine
Copy link
Contributor

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

`${LLM_TYPE}: ${actionResult?.message} - ${actionResult?.serviceMessage}`
);
if (actionResult?.serviceMessage) {
error.name = actionResult?.serviceMessage;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

generateChatTitle will first look for error.name and if not fall back to error.message, in order to deliver a terse title. Therefore I'm putting the serviceMessage (comes from LLM directly) on error.name in each of these chat models.

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🎉 All tests passed! - kibana-flaky-test-suite-runner#7111

[✅] Security Solution AI Assistant - Cypress: 50/50 tests passed.
[✅] [Serverless] Security Solution AI Assistant - Cypress: 50/50 tests passed.

see run history

@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@andrew-goldstein andrew-goldstein left a comment

Choose a reason for hiding this comment

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

Thanks for this fix @stephmilovic!
✅ Desk tested locally with OpenAI, Bedrock, and Gemini connectors, with new and valid -> invalid conversations
LGTM 🚀

@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

@stephmilovic stephmilovic enabled auto-merge (squash) October 14, 2024 19:46
@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

@stephmilovic stephmilovic merged commit a15940d into elastic:main Oct 14, 2024
38 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

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

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 14, 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 Oct 14, 2024
…196215)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Assistant] Fix error handling on new chat
(#195507)](#195507)

<!--- 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-10-14T22:10:43Z","message":"[Security
Assistant] Fix error handling on new chat
(#195507)","sha":"a15940d9b939dbf29f74dbde28a2a543b8849cc1","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:
SecuritySolution","backport:prev-minor","Team:Security Generative
AI","v8.16.0"],"title":"[Security Assistant] Fix error handling on new
chat","number":195507,"url":"https://github.com/elastic/kibana/pull/195507","mergeCommit":{"message":"[Security
Assistant] Fix error handling on new chat
(#195507)","sha":"a15940d9b939dbf29f74dbde28a2a543b8849cc1"}},"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/195507","number":195507,"mergeCommit":{"message":"[Security
Assistant] Fix error handling on new chat
(#195507)","sha":"a15940d9b939dbf29f74dbde28a2a543b8849cc1"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Steph Milovic <[email protected]>
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.16.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution] New chat error conversation state
4 participants