﻿# Dask nested submission: secede frees a slot, not the parent's memory

Use Dask secede, rejoin or worker_client to avoid nested thread-pool starvation while accounting for the parent thread and retained application state.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/dask-secede-nested-execution/
Language: en

Every Dask worker thread runs a parent that submits child tasks and waits for them. The children are ready, but no normal execution slot remains. Adding more parents can reproduce the same condition at a larger scale. The application needs to expose its waiting state to the worker's scheduling machinery.

## Draw the occupied-slot cycle

Record parent tasks, the children they submit and where each parent waits. The [nested task guide](https://distributed.dask.org/en/stable/task-launch.html) warns that get_client alone does not communicate that a parent is free to let other tasks execute. If all slots contain waiting parents, children can starve. The [runner boundary guide](/journal/fg2-kedro-runner-process-boundary-state-ownership/) explains process and thread differences, but this case concerns capacity inside an already selected worker execution model.

## Separate connection from secession

Obtaining a Client inside a worker gives access to submission; it does not by itself release the current thread's slot. The guide describes secede and rejoin around waiting, as well as worker_client as a context-manager alternative. Name which pattern the application uses and preserve exception paths. A call placed only after a blocking gather cannot free the slot soon enough to resolve the dependency that gather is already waiting for.

## Understand what remains alive

The [API reference](https://distributed.dask.org/en/stable/api.html) says secede opens a scheduling slot and a new thread can execute another task. It does not destroy the waiting parent stack or release its objects. Bound how many parents can wait with large decoded data or client state. The [memory granularity guide](/journal/fg2-dask-cuda-spill-task-buffer-granularity/) explains why some task intermediates remain outside ordinary completed-result eviction. Escaping thread-pool starvation can therefore reveal memory pressure that the blocked configuration had temporarily hidden.

## Rejoin before returning to heavy computation

The API documents rejoin as waiting until an executor slot becomes available. Define the intended boundary between waiting for children and doing further CPU work. Review cleanup if a child errors, a timeout occurs or the surrounding function exits unexpectedly. The worker_client context manager is documented to manage cleanup on the worker. Do not claim that arbitrary application locks, external connections or accelerator allocations are automatically released by entering that context.

## Exercise saturation and failure together

Use a disposable fixture where parents occupy the available normal slots and submit distinguishable children. Compare the unmodified wait path with the chosen documented pattern. Record child start, parent wait, rejoin and final outputs. Include a child exception and verify the parent does not leave a persistent unintended scheduling state. Acceptance demonstrates progress and a bounded population of retained parents; it does not claim a measured speedup or unlimited safe recursive task creation.

## Consider a simpler graph boundary

When possible, return a small description of newly discovered work and let a coordinator submit the next stage. The nested guide also describes gathering limited metadata rather than entire large values. This can avoid holding heavyweight parent state, but its extra coordination must be evaluated for the actual workload. The supported result is a reviewed nested execution protocol, not proof that secession solves resource constraints, external lock cycles or every form of distributed deadlock.
