2.4. Wait for worker tasks that belong to the run
A session ends when its top-level action returns. It cannot discover detached tasks or decide whether they belong to the workload. Await every worker whose events should be present before leaving the profiled action.
A worker thread has its own nesting stack. To retain the logical relationship with the caller, capture the active parent index and install it in the worker:
let some parent ← currentSpanIndex
| throw <| IO.userError "expected an active parent span"
let task ← IO.asTask do
withParentIndex parent do
span "worker.decode" decode
let _ ← task.get
The trace stores the worker's parent_index, so Perfetto can relate the decode operation to the
calling span. The analyzer does not subtract cross-thread children from a parent's self time.
Threads may overlap, and subtracting one thread's elapsed interval from another would turn a
causal link into a false exclusive-time calculation.