Add PPL query cancellation via Discover cancel button#11593
Add PPL query cancellation via Discover cancel button#11593mengweieric merged 5 commits intoopensearch-project:mainfrom
Conversation
Enable cancellation of in-flight PPL queries from the Discover UI cancel button by leveraging the OpenSearch task framework. - Generate a client-side UUID (queryId) for each synchronous PPL query - Pass queryId through the full request pipeline to OpenSearch PPL API - Add POST /api/enhancements/ppl/cancel server route that lists PPL tasks via _tasks API, matches by queryId in task description, and cancels all matching tasks - Wire the existing Discover abort flow to call the cancel route on abort - Cancel all matching tasks (data + histogram queries share the same queryId) Depends on opensearch-project/sql#5254 for backend task registration. Signed-off-by: Kai Huang <ahkcs@amazon.com>
❌ Invalid Changelog HeadingThe '## Changelog' heading in your PR description is either missing or malformed. Please make sure that your PR description includes a '## Changelog' heading with proper spelling, capitalization, spacing, and Markdown syntax. |
❌ Invalid Changelog HeadingThe '## Changelog' heading in your PR description is either missing or malformed. Please make sure that your PR description includes a '## Changelog' heading with proper spelling, capitalization, spacing, and Markdown syntax. |
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit 0216993.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
|
Failed to generate code suggestions for PR |
❌ Invalid Changelog HeadingThe '## Changelog' heading in your PR description is either missing or malformed. Please make sure that your PR description includes a '## Changelog' heading with proper spelling, capitalization, spacing, and Markdown syntax. |
1 similar comment
❌ Invalid Changelog HeadingThe '## Changelog' heading in your PR description is either missing or malformed. Please make sure that your PR description includes a '## Changelog' heading with proper spelling, capitalization, spacing, and Markdown syntax. |
❌ Invalid Prefix For Manual Changeset CreationInvalid description prefix. Found "feat". Only "skip" entry option is permitted for manual commit of changeset files. If you were trying to skip the changelog entry, please use the "skip" entry option in the ##Changelog section of your PR description. |
|
Failed to generate code suggestions for PR |
| } else if (context.body?.queryId) { | ||
| // Cancel synchronous PPL query via task cancellation | ||
| try { | ||
| await http.fetch({ |
There was a problem hiding this comment.
is it better to not await this request? since frontend can't do much if cancel failed, it's job is to notify backend to cancel query, and it can move on. no need to block here in case PPL cancel API is stuck
There was a problem hiding this comment.
Good call — updated to fire-and-forget. The cancel request now uses a .catch() chain instead of await, so the AbortError propagates immediately and the UI isn't blocked
| method: 'GET', | ||
| path: '/_tasks', | ||
| querystring: { | ||
| actions: '*ppl*', |
There was a problem hiding this comment.
can it be PPL * or something more specific, like searching for queryId?
There was a problem hiding this comment.
The _tasks API doesn't support filtering by description or queryId — it only supports taskId, actions and parentTaskId. The queryId is embedded in the task description string (e.g. PPL [queryId=]: ...), so we have to list PPL tasks with detailed=true and match client-side. This is the only approach available without a backend change to expose a cancel-by-queryId endpoint.
Remove await from the cancel HTTP call so the AbortError propagates immediately. The cancel is a best-effort notification to the backend and should not block the frontend from moving on. Signed-off-by: Kai Huang <ahkcs@amazon.com>
|
Failed to generate code suggestions for PR |
Use 'cluster:admin/opensearch/ppl' instead of '*ppl*' to avoid matching unrelated tasks. The _tasks API does not support filtering by description or queryId, so client-side matching remains necessary. Signed-off-by: Kai Huang <ahkcs@amazon.com>
|
Failed to generate code suggestions for PR |
The exact action name is less resilient to future changes. The wildcard is sufficient since we still match by queryId in the task description. Signed-off-by: Kai Huang <ahkcs@amazon.com>
|
Failed to generate code suggestions for PR |
✅ All unit and integration tests passing
|
|
General question:
Should the API return 4xx error code instead of 500? as this is not the backend error at all. |
Good call. I will open a follow-up PR on the backend side to change the classification of |
|
opensearch-project/sql#5273 Updated error message: |
|
CI failure seems to be unrelated to our changes — this is an Explore app UI issue (autocomplete widget visibility) Example: https://github.com/opensearch-project/OpenSearch-Dashboards/actions/runs/23563713788/job/68611665458 |
494ecc7
into
opensearch-project:main
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11593 +/- ##
===========================================
- Coverage 61.58% 0 -61.59%
===========================================
Files 4995 0 -4995
Lines 137542 0 -137542
Branches 23901 0 -23901
===========================================
- Hits 84707 0 -84707
+ Misses 46692 0 -46692
+ Partials 6143 0 -6143
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
queryId) for each synchronous PPL query and pass it through the full request pipeline to the OpenSearch/_plugins/_pplendpointPOST /api/enhancements/ppl/cancelserver route that queries/_tasks?actions=*ppl*&detailed=true, matches tasks byqueryIdin the task description, and cancels all matching tasks via/_tasks/{taskId}/_cancelqueryId, and both are cancelled independently when the user clicks cancelBackend dependency
Depends on opensearch-project/sql#5254 (merged) which registers PPL queries as
CancellableTaskwith the OpenSearch task framework.Files changed
common/constants.tsPPL_CANCELAPI pathcommon/types.tsqueryIdtoEnhancedFetchContextcommon/utils.tsqueryIdin request body; call cancel route on abortpublic/search/ppl_search_interceptor.tsserver/routes/index.tsqueryIdin route schema; register cancel routeserver/routes/ppl_cancel.tsserver/routes/ppl_cancel.test.tsserver/utils/facet.tsqueryIdto OpenSearch PPL APIChangelog
E2E verification logs
Cancel both data + histogram queries (double join)
OSD server log — both tasks found and cancelled:
OpenSearch backend log — both queries throw
TaskCancelledExceptionfrom cooperativeisCancelled()check inmoveNext():OSD receives error responses confirming cancellation:
{ "error": { "reason": "Error occurred in OpenSearch engine: The task is cancelled.", "type": "TaskCancelledException" }, "status": 500 }Test plan
TaskCancelledExceptionfrom cooperativeisCancelled()polling inmoveNext()queryIdfield name, task description format, task action wildcard)