🌊 Add task service and client to manage background tasks#245725
Merged
miltonhultgren merged 10 commits intoelastic:mainfrom Dec 16, 2025
Merged
🌊 Add task service and client to manage background tasks#245725miltonhultgren merged 10 commits intoelastic:mainfrom
miltonhultgren merged 10 commits intoelastic:mainfrom
Conversation
klacabane
reviewed
Dec 10, 2025
klacabane
reviewed
Dec 10, 2025
x-pack/platform/plugins/shared/streams/server/lib/tasks/storage.ts
Outdated
Show resolved
Hide resolved
klacabane
reviewed
Dec 10, 2025
ruflin
reviewed
Dec 11, 2025
x-pack/platform/plugins/shared/streams/server/lib/tasks/storage.ts
Outdated
Show resolved
Hide resolved
ruflin
reviewed
Dec 11, 2025
ruflin
reviewed
Dec 11, 2025
x-pack/platform/plugins/shared/streams/server/lib/tasks/task_client.ts
Outdated
Show resolved
Hide resolved
klacabane
reviewed
Dec 11, 2025
klacabane
reviewed
Dec 11, 2025
x-pack/platform/plugins/shared/streams/server/lib/tasks/task_client.ts
Outdated
Show resolved
Hide resolved
Contributor
💚 Build Succeeded
Metrics [docs]
History
|
miltonhultgren
added a commit
that referenced
this pull request
Jan 7, 2026
### Summary
This PR:
- Adds a task called `streams_feature_identification` via the newly
added task service which calls the existing `identifyFeatures` function
and stores the result on the task document
- Updates the `POST /internal/streams/{name}/features/_identify` route
to schedule this task and check for the results
- Adds the `FeatureIdentificationControl` component which manages all of
the API interaction around Feature identification
- Moves related telemetry reporting to the server
- Adds a way to type and store parameters on the task document
- Adds a way to cancel tasks (wrap your run function in
`cancellableTask`)
- Adds another task state (`acknowledged`) to mark that the user has
taken action on the result of the task
- Adds a hook to poll for task updates for in progress tasks (and tasks
being cancelled)
https://github.com/user-attachments/assets/7c667112-e0a1-426d-a958-55cf4f2e26bb
https://github.com/user-attachments/assets/61e2c079-53dd-4318-8075-fdce466de35d
### Route changes and flags
The feature identification route now serves two roles:
- Managing the task
- Reporting the status of the task
The route accepts three flags: `schedule`, `cancel` and `acknowledge`
that all have a side effect.
`schedule` tries to schedule the task with task manager (and is a
`no-op` if the task is already running), this fails if the task is in
the `being_cancelled` state.
`cancel` moves the task document to `being_cancelled` state so that
`cancellableTask` can engage the abort controller to stop on going work.
`acknowledge` moves a `complete` task to the `acknowledged` state,
indicating that the user has reviewed the results of this task and taken
some follow up action, so it's safe to schedule this task again with
losing results (this is not enforced)
The route reports the following statuses:
`'not_started' | 'in_progress' | 'stale' | 'being_canceled' | 'canceled'
| 'failed' | 'completed' | 'acknowledged'`
Most of them are the state of the task, but `stale` is a special route
status that indicates that no updates were made to the task document for
a while.
The `failed` result includes an error message while `completed` and
`acknowledged` include the payload found on `task.task.payload`.
### Task document schema
Follow up to #245725
The stored documents have the following shape:
```typescript
{
id: string;
type: string;
status: TaskStatus;
stream: string;
space: string;
created_at: string;
task: {
params: TaskParams;
payload?: any // Only for completed and acknowledged tasks
error?: string // Only for failed tasks
};
}
```
All fields except `task` are indexed, and we store things under `task`
to avoid indexing them because of
#245974
The tasks are stored in `.kibana_streams_tasks`
### To do
- Fix failing tests
- Add test for `cancellableTask`
- Manually test for robustness
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Shahzad <shahzad31comp@gmail.com>
Co-authored-by: Mykola Harmash <mykola.harmash@gmail.com>
devamanv
pushed a commit
to devamanv/kibana
that referenced
this pull request
Jan 12, 2026
### Summary
This PR:
- Adds a task called `streams_feature_identification` via the newly
added task service which calls the existing `identifyFeatures` function
and stores the result on the task document
- Updates the `POST /internal/streams/{name}/features/_identify` route
to schedule this task and check for the results
- Adds the `FeatureIdentificationControl` component which manages all of
the API interaction around Feature identification
- Moves related telemetry reporting to the server
- Adds a way to type and store parameters on the task document
- Adds a way to cancel tasks (wrap your run function in
`cancellableTask`)
- Adds another task state (`acknowledged`) to mark that the user has
taken action on the result of the task
- Adds a hook to poll for task updates for in progress tasks (and tasks
being cancelled)
https://github.com/user-attachments/assets/7c667112-e0a1-426d-a958-55cf4f2e26bb
https://github.com/user-attachments/assets/61e2c079-53dd-4318-8075-fdce466de35d
### Route changes and flags
The feature identification route now serves two roles:
- Managing the task
- Reporting the status of the task
The route accepts three flags: `schedule`, `cancel` and `acknowledge`
that all have a side effect.
`schedule` tries to schedule the task with task manager (and is a
`no-op` if the task is already running), this fails if the task is in
the `being_cancelled` state.
`cancel` moves the task document to `being_cancelled` state so that
`cancellableTask` can engage the abort controller to stop on going work.
`acknowledge` moves a `complete` task to the `acknowledged` state,
indicating that the user has reviewed the results of this task and taken
some follow up action, so it's safe to schedule this task again with
losing results (this is not enforced)
The route reports the following statuses:
`'not_started' | 'in_progress' | 'stale' | 'being_canceled' | 'canceled'
| 'failed' | 'completed' | 'acknowledged'`
Most of them are the state of the task, but `stale` is a special route
status that indicates that no updates were made to the task document for
a while.
The `failed` result includes an error message while `completed` and
`acknowledged` include the payload found on `task.task.payload`.
### Task document schema
Follow up to elastic#245725
The stored documents have the following shape:
```typescript
{
id: string;
type: string;
status: TaskStatus;
stream: string;
space: string;
created_at: string;
task: {
params: TaskParams;
payload?: any // Only for completed and acknowledged tasks
error?: string // Only for failed tasks
};
}
```
All fields except `task` are indexed, and we store things under `task`
to avoid indexing them because of
elastic#245974
The tasks are stored in `.kibana_streams_tasks`
### To do
- Fix failing tests
- Add test for `cancellableTask`
- Manually test for robustness
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Shahzad <shahzad31comp@gmail.com>
Co-authored-by: Mykola Harmash <mykola.harmash@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a way to manage the status and results of background tasks within the Streams plugin.
Via the
TaskServicewe can get aTaskClientthat has the following API:get(id): Returns the status and result of a taskschedule({ task, params, request }): Schedules a task of the specified type with thetaskManageras a single run task and writes a task document to an internal index to track the status and resultupdate(task): Update the stored task document, this should be called by the task run functionThe
TaskServicealso has a methodregisterTaskswhich takes a context object that is used to create the task definitions and registers them. Through the context, we are able to pass things likegetScopedClientsso that a background task can have access to this as well.schedulerequires aKibanaRequestto be passed,taskManageruses this request to create an API key for the task to run with and creates a fakeKibanaRequestthat we can use to pass togetScopedClients.Within the task runner, we can get access to the
taskClientalso viagetScopedClients.See usage here