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
future.onResponse(null);
                }
            });
            final AtomicBoolean collectionComplete = new AtomicBoolean();
            final RemovedTaskListener removedTaskListener = task -> {
                if (collectionComplete.get() == false && removalRefs.tryIncRef()) {
                    removedTasks.add(task);
                    removalRefs.decRef();
                } else {
                    matchedTasks.remove(task);
                    if (matchedTasks.isEmpty()) {
                        future.onResponse(null);
                    }
                }
            };
            taskManager.registerRemovedTaskListener(removedTaskListener);
            final ActionListener<Void> allMatchedTasksRemovedListener = ActionListener.runBefore(
                nodeOperation,
                () -> taskManager.unregisterRemovedTaskListener(removedTaskListener)
            );
            try {
                processTasks(request, task -> {
                    if (task.getAction().startsWith(ListTasksAction.NAME) == false) {
                        
                        
                        matchedTasks.add(task);
                    }
                    operation.accept(task);
                });
            } catch (Exception e) {