Skip to content

[Entity Store] Reset state error after successful task run#263087

Merged
orouz merged 3 commits intoelastic:mainfrom
orouz:entity_store_err_so
Apr 19, 2026
Merged

[Entity Store] Reset state error after successful task run#263087
orouz merged 3 commits intoelastic:mainfrom
orouz:entity_store_err_so

Conversation

@orouz
Copy link
Copy Markdown
Contributor

@orouz orouz commented Apr 14, 2026

closes #261551

we were setting the error to undefined but applying it using mergeAttributes: true which meant existing fields will not be set to undefined

added an updateWith(current => ...) method which lets the caller update the state object manually with mergeAttributes: false

@orouz orouz changed the title ignore abort error [Entity Store] Return early when error is aborted task Apr 14, 2026
@orouz orouz force-pushed the entity_store_err_so branch 2 times, most recently from 75c6123 to 2bb9a8b Compare April 15, 2026 12:43
@orouz orouz marked this pull request as ready for review April 15, 2026 12:48
@orouz orouz requested a review from a team as a code owner April 15, 2026 12:48
Comment on lines +729 to +733
if (isRequestAbortedError(error)) {
this.logger.warn(`Logs extraction was aborted for entity type ${type}`);
return { success: false, error };
}

Copy link
Copy Markdown
Member

@romulets romulets Apr 15, 2026

Choose a reason for hiding this comment

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

This depends I believe. If it's a requested aborted and we have processed 0 pages, this warrants be called an error.

If one or more pages have been processed, we can ignore.

But I believe the issue should not be treated like this. I think we should clear the error if a successful run has happened. The timeout is the easy one to solve.

But what if there is a cluster upgrade and elasticsearch is unavailable for one or two iterations? Then we are able to resume on the third iteration and the error never gets cleaned.

I believe the best solution is: clear the error SO once we have successful run

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe the best solution is: clear the error SO once we have successful run

I tend to agree. In addition, I would persist also aborted requests and clear them after a successful run of the Kibana task.

@orouz orouz force-pushed the entity_store_err_so branch from f19cd5d to 7dac6af Compare April 16, 2026 08:11
@orouz orouz added backport:version Backport to applied version labels Entity Store (Next) Team:Core Analysis Security Solution v9.4.0 labels Apr 16, 2026
@orouz orouz requested review from romulets and uri-weisman April 16, 2026 08:13
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Apr 16, 2026

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] affected Scout: [ security / entity_store ] plugin / local-stateful-classic - Entity Store Logs Extraction with pagination (entity pages + maxLogsPerPage) - Should extract host with entity pagination (docsLimit 5, wide log slices)
  • [job] [logs] affected Scout: [ security / entity_store ] plugin / local-stateful-classic - Entity Store stop/start API tests - Should stop and start the extract entity task after install
  • [job] [logs] Jest Tests #11 / SelectedFilters should render properly
  • [job] [logs] Jest Tests #11 / SelectedFilters should render properly

Metrics [docs]

✅ unchanged

History

@orouz orouz added the release_note:skip Skip the PR/issue when compiling release notes label Apr 19, 2026
@orouz orouz changed the title [Entity Store] Return early when error is aborted task [Entity Store] Reset state error after successful task run Apr 19, 2026
Copy link
Copy Markdown
Contributor

@uri-weisman uri-weisman left a comment

Choose a reason for hiding this comment

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

Approved, even though we have a minor race condition.
Let's handle it in a follow-up PR.

Comment on lines +83 to +86
const current = await this.findOrThrow(entityType);
const updated = updater(current);
const id = this.getSavedObjectId(entityType);
const { attributes } = await this.soClient.update<EngineDescriptor>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have a potential race condition here, any concurrent change to the SO between findOrThrow() and update() can be lost (a call to the entity store management api updates the SO).
I consider it as minor, but something we should be aware of.
The right way to overcome this race would be by optimistic concurrency, adding the SO version to the update call, a conflict will be thrown in case there were an additional update between our read-write operation.

Example:

  public async get(
    id: string,
    spaceId?: string
  ): Promise<{ id: string; attributes: RuleSavedObjectAttributes; version?: string }> {
    const namespace = spaceIdToNamespace(this.spaces, spaceId);
    const doc = await this.client.get<RuleSavedObjectAttributes>(
      RULE_SAVED_OBJECT_TYPE,
      id,
      namespace ? { namespace } : undefined
    );
    return { id: doc.id, attributes: doc.attributes, version: doc.version };
  }
  public async update({
    id,
    attrs,
    version,
  }: {
    id: string;
    attrs: RuleSavedObjectAttributes;
    version?: string;
  }): Promise<void> {
    await this.client.update<RuleSavedObjectAttributes>(RULE_SAVED_OBJECT_TYPE, id, attrs, {
      ...(version ? { version } : {}),
      mergeAttributes: false,
    });
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is the same for our regular update not just the newly added updateWith

doc.version seems like a nice addition we should add anyway, even if this specifically is hardly an issue

@orouz orouz merged commit b2a9396 into elastic:main Apr 19, 2026
19 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 9.4

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

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
9.4

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 Apr 19, 2026
…3087) (#264284)

# Backport

This will backport the following commits from `main` to `9.4`:
- [[Entity Store] Reset state error after successful task run
(#263087)](#263087)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT
[{"author":{"name":"orouz","email":"or.ouziel@elastic.co"},"sourceCommit":{"committedDate":"2026-04-19T11:35:34Z","message":"[Entity
Store] Reset state error after successful task run
(#263087)","sha":"b2a93965a2fe962dc6a625ee3a69a762e39bca5e","branchLabelMapping":{"^v9.5.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","Entity
Store (Next)","Team:Core Analysis","v9.4.0","v9.5.0"],"title":"[Entity
Store] Reset state error after successful task
run","number":263087,"url":"https://github.com/elastic/kibana/pull/263087","mergeCommit":{"message":"[Entity
Store] Reset state error after successful task run
(#263087)","sha":"b2a93965a2fe962dc6a625ee3a69a762e39bca5e"}},"sourceBranch":"main","suggestedTargetBranches":["9.4"],"targetPullRequestStates":[{"branch":"9.4","label":"v9.4.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.5.0","branchLabelMappingKey":"^v9.5.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/263087","number":263087,"mergeCommit":{"message":"[Entity
Store] Reset state error after successful task run
(#263087)","sha":"b2a93965a2fe962dc6a625ee3a69a762e39bca5e"}}]}]
BACKPORT-->

Co-authored-by: orouz <or.ouziel@elastic.co>
kapral18 added a commit to kapral18/kibana that referenced this pull request Apr 19, 2026
* main: (114 commits)
  Fix observability_ai_assistant_tool_call EBT error when connector is an inference endpoint (elastic#263334)
  init on install (elastic#263732)
  [One Workflow] fail-fast TaskRecovery for interrupted runs (elastic#261275)
  [Entity Store] Reset state error after successful task run (elastic#263087)
  [api-docs] 2026-04-19 Daily api_docs build (elastic#264280)
  [UII] Fix integration card row height calculation (elastic#264212)
  [scout] migrate FTR logstash api tests (elastic#262953)
  [StorageIndexAdapter] Set auto_expand_replicas to fix yellow health on single-node ES clusters (elastic#263096)
  [api-docs] 2026-04-18 Daily api_docs build (elastic#264260)
  [Scout] Update test config manifests (elastic#264257)
  [Security Solution][Detection Engine] enables AI rule creation feature flag (elastic#264036)
  [dashboards as code] only validate id on PUT route when creating new dashboard (elastic#264161)
  chore(NA): bump version to 9.5.0 (elastic#262165)
  skip failing test suite (elastic#263649)
  skip failing test suite (elastic#264236)
  [Discover] Convert remaining Enzyme tests to RTL (elastic#259676)
  auto-implement: Labels in model endpoints table of the model details flyout look misaligned (elastic#263770)
  [ci] Promote ES docker image after verification (elastic#263890)
  [Observability:Onboarding] Remove suppress global announcements that was breaking ensemble tests (elastic#264169)
  [Cases][AttachmentV2] Migrate persistable state part 2 - ML and AIOps charts (elastic#262597)
  ...
orouz added a commit to orouz/kibana that referenced this pull request Apr 21, 2026
orouz added a commit to orouz/kibana that referenced this pull request Apr 23, 2026
orouz added a commit to orouz/kibana that referenced this pull request Apr 23, 2026
orouz added a commit to orouz/kibana that referenced this pull request Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Entity Store (Next) release_note:skip Skip the PR/issue when compiling release notes Team:Core Analysis Security Solution v9.4.0 v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Entity Store] Errors are never cleaned and always propagated to the UI

6 participants