As per [this comment](https://github.com/elastic/elasticsearch/pull/93375#discussion_r1093607808) the changes in #90977 may leak the thread context of the last-completing task into the response to the list-tasks API. We need to address this before these changes are released, which is planned for 8.7.0.
server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TransportListTasksAction.java
actionFilters,
            ListTasksRequest::new,
            ListTasksResponse::new,
            TaskInfo::from,
            ThreadPool.Names.MANAGEMENT
        );
    }
    @Override
    protected ListTasksResponse newResponse(
        ListTasksRequest request,
        List<TaskInfo> tasks,
        List<TaskOperationFailure> taskOperationFailures,
        List<FailedNodeException> failedNodeExceptions
    ) {
        return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions);
    }
    @Override
    protected void taskOperation(Task actionTask, ListTasksRequest request, Task task, ActionListener<TaskInfo> listener) {
        listener.onResponse(task.taskInfo(clusterService.localNode().getId(), request.getDetailed()));
    }
    @Override
    protected void processTasks(ListTasksRequest request, Consumer<Task> operation, ActionListener<Void> nodeOperation) {
        if (request.getWaitForCompletion()) {
            final ListenableActionFuture<Void> future = new ListenableActionFuture<>();
            final Set<Task> removedTasks = Sets.newConcurrentHashSet();
            final Set<Task> matchedTasks = Sets.newConcurrentHashSet();
            final RefCounted removalRefs = AbstractRefCounted.of(() -> {
                matchedTasks.removeAll(removedTasks);
                removedTasks.clear();
                if (matchedTasks.isEmpty()) {