Expand description
Fresh-task stack relief for deep async construction chains.
At opt-level=0 LLVM performs no stack-slot coloring, so the poll function
of a large async fn reserves a separate stack slot for every local in
every branch. Deep construction chains (session runtime registration,
agent build, mob machine commands) therefore carry enormous poll frames,
and awaiting them inline stacks those frames beneath the caller’s own
poll chain — e.g. an agent’s run loop → tool dispatch → mob spawn →
child-session registration. That sum is what overflowed the 2 MiB
production worker-stack budget asserted by
tools_full_with_explicit_auth_binding_can_spawn_within_production_stack_budget.
relieve_caller_stack moves such a chain onto its own tokio task, so
its frames start near the top of a fresh task poll rather than on top of
the caller’s. It takes a future-maker rather than a future because
tokio::spawn moves its argument by value: a large future would
otherwise transit the caller’s stack (and the spawn call’s frame) at its
full size. The maker closure is small (its captures), and the future it
makes is materialized and boxed on the fresh task’s stack instead.
Functions§
- relieve_
caller_ stack - Runs the future produced by
make_futureon its own tokio task and awaits its completion, aborting the task if the caller is dropped first.