Repository navigation
Keep the hosted flow off the stack of every scan - #2234
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
Conversation
`scan_project` awaited the hosted flow in line, so the flow's future, which embeds the whole hosted engine, lay in the poll frame of a scan in every mode, an agent scan too. The deepest in-process test, `in_process_gem_multi_platform::rollback_all_over_broad_manifest_succeeds`, needs about 2,013,000 of the 2,097,152 bytes of a test thread on macOS, and Windows has less room: a change that made one struct of the hosted flow 64 bytes larger overflowed that test's stack there. The flow is now built by a constructor that is not async, the way the vendored flows of a scan already are, so a scan holds one pointer to it. That test needs about 49 KB less stack: it passes with a stack of 1,966,080 bytes and overflows at 1,949,696, where before it passed at 2,002,944 and overflowed at 1,998,848 (`RUST_MIN_STACK`, which this machine rounds to 16 KiB). What a scan does is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The wrapper of the last commit repeated the thirteen parameters of the hosted flow. The crate already has a helper that builds a future on a frame of its own and returns the pointer (`boxed`, used by the crawl): it is now visible to the crate and never inlined, since inlined it would put the future back into its caller's frame, and a scan uses it instead of a wrapper of its own. Two more futures of a scan were temporaries of a frame on the same chain: `run_scan` wrote `Box::pin(scan_project(..))` in line, and the hosted flow awaited its inner flow in line where the other two callers of that flow already go through `boxed_run_redirect_selected`. Both are built off the frame now. The deepest in-process test passes with a stack of 1,933,312 bytes and overflows at 1,916,928 (`RUST_MIN_STACK`, 16 KiB steps); with the last commit alone it needed 1,966,080, and on main 2,002,944. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryLow Risk Overview
The Reviewed by Cursor Bugbot for commit 32d5506. Configure here. |
A scan needs about 80 KB less stack, which gives the Windows test job room that main does not have today.
Why
scan_projectawaited the hosted flow in line. The flow's future embeds the whole hosted engine, so its size lay in the poll frame of a scan in every mode, an agent scan too.The deepest in-process test,
in_process_gem_multi_platform::rollback_all_over_broad_manifest_succeeds, needs about 2,013,000 of the 2,097,152 bytes a test thread has (macOS arm64, debug build). Windows has less room: on another open pull request a change that made one struct of the hosted flow 64 bytes larger, held three times in the flow, overflowed that test's stack in thetest (windows-latest, 2)job (STATUS_STACK_OVERFLOW), while main and the other branches passed it. So main is within a few hundred bytes of failing that job, and the next change to the hosted flow, or two that land together, can tip it.What changes
Three futures on a scan's chain are now built on a frame that is gone before anything is polled, so their caller holds one pointer:
scan_project;run_scanbuilt with aBox::pin(..)written in line (that makes the future a temporary of the caller's frame first);run_redirectawaited in line where the other two callers already go throughboxed_run_redirect_selected.The first two use the helper the crate already has for this (
boxedinecosystem_dispatch.rs), now visible to the crate and marked#[inline(never)]. Three files, +36 −28 against main. What a scan does is unchanged.Measured
The smallest stack on which that test passes, with
RUST_MIN_STACK(this machine rounds it to 16 KiB), macOS arm64, debug:Main's row is from the investigation on the other pull request; the second row was measured on this branch.
Code review
No correctness finding; six about how far the change goes, all read from the code.
#[inline(never)]; the thirteen-parameter wrapper of the first commit is gone in favour of the crate's one helper; the comments say what the code does.boxed_*constructors into calls of the helper, and marking them#[inline(never)]. They are used by other commands and are not what this change is about.How it was checked
rustfmt --checkon the three files;cargo clippy --locked --workspace --all-features -- -D warnings.cli(120),in_process_gem_multi_platform(9),in_process_redirect(138),in_process_redirect_pnpm(55),in_process_rollback_hosted(41),in_process_vendor(157): all pass.test (windows-latest, 2).🤖 Generated with Claude Code