Skip to content

[9.3] [Security GenAI] Use stable IDs for Security AI Prompt saved object filenames (#265301)#265823

Merged
kibanamachine merged 2 commits intoelastic:9.3from
kibanamachine:backport/9.3/pr-265301
Apr 30, 2026
Merged

[9.3] [Security GenAI] Use stable IDs for Security AI Prompt saved object filenames (#265301)#265823
kibanamachine merged 2 commits intoelastic:9.3from
kibanamachine:backport/9.3/pr-265301

Conversation

@kibanamachine
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 9.3:

Questions ?

Please refer to the Backport tool documentation

…ilenames (elastic#265301)

## Summary

Resolves elastic#237178.

The `generate_security_ai_prompts_script.ts` script previously generated
saved object filenames using a random UUID on every invocation (e.g.
`security_ai_prompts-022f0559-929f-4b06-ad08-571fc9b768ca.json`). This
made PR reviews noisy and required a `rm ./*.json` step when copying
files into the integration package.

This PR replaces `uuidv4()` with a deterministic `generateStableId`
function that builds the ID from `promptGroupId`, `promptId`, and
optionally `provider` and `model` — all lowercased. Example stable
filename:

```
security_ai_prompts-aiassistant-systemprompt-openai.json
```

### Changes

- **Script**: replaced `uuidv4()` with `generateStableId(prompt)` that
derives a stable, lowercase ID from the prompt's identifying fields.
Removed `uuid` import.
- **Tests**: added 13 Jest unit tests for `generateStableId`,
`generateSavedObject`, and `generateSavedObjects`.
- **README**: removed the `rm ./*.json` step from the developer update
flow — with stable filenames, `cp` overwrites files in place without
needing to clear them first.

### Migration note

The first time the script runs after this change, the integration repo
(`elastic/integrations`) will still contain the old UUID-named files. A
one-time `rm ./*.json` followed by `cp` in that repo is needed to fully
replace them with stable-named files. After that, the `rm` step is no
longer required.

## Test plan

- [x] `node scripts/jest
x-pack/solutions/security/plugins/elastic_assistant/scripts/generate_security_ai_prompts_script.test.ts`
— 13 tests pass
- [x] `node scripts/check_changes.ts` — lint and pre-commit checks pass
- [x] Run `yarn generate-security-ai-prompts` in
`x-pack/solutions/security/plugins/elastic_assistant` and confirm output
filenames are stable across multiple invocations

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 6f23495)
@kibanamachine kibanamachine added the backport This PR is a backport of another PR label Apr 27, 2026
@kibanamachine kibanamachine enabled auto-merge (squash) April 27, 2026 15:33
@KDKHD
Copy link
Copy Markdown
Member

KDKHD commented Apr 30, 2026

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor Author

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @KDKHD

@kibanamachine kibanamachine merged commit fda40ab into elastic:9.3 Apr 30, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants