fix: propagate AbortSignal to executeAsReasoningAgent for task cancellation#262811
Merged
flash1293 merged 3 commits intoelastic:mainfrom Apr 14, 2026
Merged
Conversation
…lation - Add optional `abortSignal` to `ReasoningPromptOptions` so callers can pass a cancellation signal to the reasoning agent loop - Check `abortSignal.aborted` at the start of each reasoning step and in `callTools`, throwing 'Request was aborted' when cancelled - Forward `abortSignal` to `inferenceClient.prompt()` calls via the existing options spread (signal flows through to HTTP requests) - Fix `cancellableTask` to abort the signal BEFORE resolving the cancellation promise, so running tasks can detect it immediately rather than only after the Promise.race completes - Pass `runContext.abortController.signal` as `abortSignal` in memory_generation, memory_consolidation, conversation_scraper, and via MemoryUpdateContext for memory_update/discovery_completed_trigger - Add signal.aborted check at loop boundaries outside the reasoning agent (e.g., per-stream loop in memory_generation) - Add unit tests for abort signal behavior in executeAsReasoningAgent Fixes elastic#262800
067c599 to
d6dd3b8
Compare
Contributor
|
Pinging @elastic/obs-onboarding-team (Team:obs-onboarding) |
pgayvallet
approved these changes
Apr 14, 2026
Contributor
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]
History
|
mbondyra
added a commit
to mbondyra/kibana
that referenced
this pull request
Apr 14, 2026
* commit '11ed3645c5ededae2a6e29f2a79b31f52208b441': (157 commits) remove sync register uiAction methods (elastic#254590) [performance] Apply minimal auth to the search route (elastic#257497) [ES|QL] Reports correctly the controls server side errors (elastic#263020) [SecuritySolution][Navigation] Enable classic nav updates (elastic#262358) [Inference] Use pretty name and logo on feature settings page (elastic#262531) [Security Solution] fix AT-AB cypress test (elastic#262991) [SigEvents] Seed sigevents env script (elastic#261172) Adjust conditions for validating no refetch for expanded row (elastic#262978) [Agent Builder] update copy for the announcement modal (elastic#263034) [Search] Hide index management links for users without privileges (elastic#262627) Simplify OAS schema for GET `/api/spaces/space` query params (elastic#260831) Fix fleet output OAS regressions: SSL type explosion and Kafka union wrappers (elastic#260842) [Dashboards in chat] fix agent confusing the axes in a horizontal chat (elastic#263064) [One Workflow] Add alert state checkbox UI for workflow connector (elastic#259770) [One Workflow] Deprecate legacy Cases step types in workflow authoring (elastic#262070) skip failing test suite (elastic#248090) fix flaky test: MonitorDetails filter apply button not enabled (elastic#260788) fix: propagate AbortSignal to executeAsReasoningAgent for task cancellation (elastic#262811) [Security Solution][Alert KPI] Fix white space bug in alert KPIs (elastic#260803) [Streams] Move helpers and format_size_unit to utils folder (elastic#262550) ... # Conflicts: # x-pack/platform/plugins/shared/dashboard_agent/public/attachment_types/canvas_integration/dashboard_canvas_content.test.tsx # x-pack/platform/plugins/shared/dashboard_agent/public/attachment_types/canvas_integration/dashboard_canvas_content.tsx # x-pack/platform/plugins/shared/dashboard_agent/public/attachment_types/canvas_integration/use_register_canvas_action_buttons.ts # x-pack/platform/plugins/shared/dashboard_agent/public/attachment_types/index.test.tsx # x-pack/platform/plugins/shared/dashboard_agent/public/attachment_types/index.tsx
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
Fixes #262800
Tasks that use
executeAsReasoningAgentfrom@kbn/inference-prompt-utilscould not properly respond to Task Manager cancellation because the reasoning agent did not accept anAbortSignal. This PR adds cancellation support throughout the chain.Changes
1.
executeAsReasoningAgentnow accepts an optionalabortSignal(kbn-inference-prompt-utils)abortSignal?: AbortSignaltoReasoningPromptOptions'Request was aborted'callToolsbefore invoking tool callbacks, returning an error result if abortedinferenceClient.prompt(), so in-progress HTTP requests are also cancelled2.
cancellableTasknow aborts the signal before resolving the cancellation promise (cancellable_task.ts)runContext.abortController.abort()was called only in the.finally()block — after thePromise.racewas already decidedTaskStatus.BeingCanceledis detected in the polling loop, before resolving the promise.finally()block still handles the case whererun()exits early on its own (scenario 2 from the original comment), callingabort()only if the signal hasn't already been aborted3. Affected tasks now pass
abortSignal: runContext.abortController.signalmemory_generation— passes signal toexecuteAsReasoningAgentand checkssignal.abortedat per-stream loop boundarymemory_consolidation— passes signal toexecuteAsReasoningAgentconversation_scraper— passes signal toexecuteAsReasoningAgentmemory_update→discovery_completed_trigger— signal propagated via newabortSignalfield onMemoryUpdateContext, with loop boundary check in the trigger4. Tests
executeAsReasoningAgentabort signal behaviorHow cancellation now works
Before this fix:
BeingCanceledcancellableTaskpolling detects it, resolves cancellation promise.finally()— too late for the running task to act on itexecuteAsReasoningAgentcontinue running all reasoning stepsAfter this fix:
BeingCanceledcancellableTaskpolling detects it, aborts the signal immediately, then resolves cancellation promiseexecuteAsReasoningAgentdetectssignal.abortedat the next reasoning step and throwsinferenceClient.prompt()calls also receive the signal and can abort HTTP requestscatchblocks in each task detect'Request was aborted'and returngetDeleteTaskRunResult()How to test
executeAsReasoningAgent(e.g., memory consolidation, conversation scraper)node scripts/jest x-pack/platform/packages/shared/kbn-inference-prompt-utils/src/flows/reasoning/execute_as_reasoning_agent.test.ts