Skip to content

[FEATURE] Support task cancellation for long-running PPL queries. #4887

Closed

Description

@Swiddis

Is your feature request related to a problem?
Followup to #4857, #4886 -- if a query has a very long timeout and is unexpectedly taking longer than expected, we should be able to cancel queries via the _tasks/_cancel API.

What solution would you like?
For the most part cancellation should already be supported fundamentally by #4857, we just need to integrate with the actual task endpoint and let that interrupt the query thread. We may also need to support canceling whatever background IO is running during that process (but I think this will self-interrupt anyway, since the socket will get closed & OpenSearch detects that).

What alternatives have you considered?
N/A

Do you have any additional context?
N/A

Activity

  1. added
    enhancement
    on Dec 1, 2025
  2. added
    PPL
    on Feb 26, 2026
  3. anasalkouz commented on Feb 26, 2026

    @anasalkouz
    Member

    This should also be connected to the Discover page cancel button

  4. assigned and unassigned on Feb 26, 2026
  5. Swiddis commented on Mar 2, 2026

    @Swiddis
    CollaboratorAuthor

    That can be a frontend feature after we have backend support

  6. ahkcs commented on Mar 2, 2026

    @ahkcs
    Collaborator

    I've been looking into this and started putting together a design doc for the backend cancel API. A few things I noticed while exploring:

    • The thread interruption infra from Support timeouts for Calcite queries #4857 does most of the heavy lifting already — cancel is basically triggering that same interrupt externally instead of via timeout.
    • For the Discover cancel button use case (@anasalkouz), we'd need an additional client-provided query ID in the request body, so the frontend can reference which query to cancel on a separate connection.
    • For the endpoint, I was thinking POST /_plugins/_query/{queryId}/_cancel — following the same _cancel convention as OpenSearch core's _tasks API.
  7. Swiddis commented on Mar 2, 2026

    @Swiddis
    CollaboratorAuthor

    Do we need a custom endpoint? Queries are already tasks that show up in the core _tasks list, but they're not registered. We should just hook directly to core's task cancellation service. I don't think we want to try and implement our own task ID routing infrastructure (suppose you try to cancel a query ID from another node?).

    For the most part this should be doable by extending TransportPPLQueryRequest to extend TaskAwareRequest and override createTask. Will need a task type that supports cancellation (PPLQueryTask?) and some light infra to ensure the task knows which thread to interrupt when onCancelled is called. Can just use the regular query UUID that we pass around for the task ID.

  8. sunil9977 commented on Mar 5, 2026

    @sunil9977
    Contributor

    Please let me know if I can take this up.

  9. ahkcs commented on Mar 16, 2026

    @ahkcs
    Collaborator

    Can just use the regular query UUID that we pass around for the task ID.

    The query ID is mainly for Discover cancel button use case, when the client-side sends a query, the server won't respond until the query finishes, so we need the query ID to be generated on the client-side, otherwise the client would have no way to learn which query to cancel when using query cancellation API. I think we can just use client-side UUID for this

  10. Swiddis commented on Mar 16, 2026

    @Swiddis
    CollaboratorAuthor

    That should be fine, just register the task with that ID (assuming some interface exists for it). How does it exist with existing query cancellation flows? If the task API doesn't support some sort of ID registration then that means no OSD cancellation is supported for regular OS operations.

  11. Swiddis commented on Mar 16, 2026

    @Swiddis
    CollaboratorAuthor
  12. ahkcs commented on Mar 16, 2026

    @ahkcs
    Collaborator

    Yes, I think we can override createTask on TransportPPLQueryRequest to return a PPLQueryTask extends CancellableTask, with the client-provided UUID in the task description via getDescription(). Cancellation uses the native _tasks/_cancel API — no new endpoint needed on the SQL plugin side. On the OSD side, a new server route takes the queryId from the browser, resolves it to a task ID via _tasks list, and calls _cancel.

  13. moved this from Not Started to Done in PPL Trackeron Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLenhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions