Skip to content

Processing: smaller stack frames, so tests run at the default stack (no RUST_MIN_STACK) - #296

Merged
ndbroadbent merged 1 commit into
mainfrom
stack-frames
Dec 5, 2026
Merged

ndbroadbent merged 1 commit into
mainfrom
stack-frames

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

#279 added .cargo/config.toml [env] RUST_MIN_STACK = "4194304" because the deepest app tests overflowed Rust's 2 MB test-thread stack. This PR removes it: every app test binary now passes at the default stack.

Why the stack was deep

In a debug build, every temporary in an async fn's poll gets its own stack slot. That includes a future the function boxes straight away: Box::pin(step(..)) builds the future on the caller's stack before moving it to the heap. So an async fn that awaits many things gets a frame as big as all of them together.

Tests run queued jobs and event listeners inline (a sync queue). A build is processed inside the request that finalized it, and builds are processed inside each other: the merge commit builds finished wakes, and a previous build that adopt_on_branch or reruns::adopt finalizes. So these frames stack up once per nested run.

I measured the frames from the test binary's disassembly (each function's stack allocation). I also took a backtrace at the overflow, with each frame's size, from a temporary SIGSEGV handler on an alternate stack. The probes aren't in this PR.

Poll frame (debug) main This PR
processing::process 299 KB ~2 KB, plus one step's frame at a time: confirm 52 KB, find_bases 36 KB, fill_in 36 KB, warnings_of 57 KB
processing::run 136 KB ~1.5 KB, plus one step's frame at a time: charge_before_run 75 KB (runs before any nested work), after_run ~2 KB
http::api::builds::finalize (handler body) 135 KB 91 KB

What changed (behaviour unchanged)

  • process is now a short list of steps, each its own async fn. Same order, same queries, same early returns.
    • prepare: bundle readiness, the config item, reruns::follow, waits_for_previous.
    • confirm: uploads and renders.
    • find_bases.
    • compare_all.
    • fill_in: carry forward, the branch's unreviewed carry and keep_rejections, sourced groups, removed rows, merged approvals. It returns the UnreviewedCarry.
    • warnings_of.
    • settle: the concluding transaction. It gets hold: true when the previous build was unfinished, or when merge.hold is set.
  • run is split the same way:
    • charge_before_run.
    • The adopt_on_branch / reruns::start step.
    • process_exclusively: the lock and the one retry.
    • after_run.
  • domain::boxed(|| step(..)) is Box::pin(make()) with the future built in its own frame, so the caller's frame holds only a pointer. It's used for:
    • those steps;
    • exclusive → exclusive_with;
    • the conclusion's charge_locked, conclude and baselines::record (calls only: conclude itself is untouched);
    • carry-forward's compare;
    • finalize's finalize_shard, reruns::adopt and dispatches.
  • Doc comments on domain::boxed, process and run explain why, so nobody inlines the steps again.
  • .cargo/config.toml: the [env] RUST_MIN_STACK block and its comment are removed. The wasm target section stays.

Measurements

The smallest RUST_MIN_STACK each test passes at, found by bisecting in 16 KB steps on main (ff782a8) and on this branch. These are the 20 deepest tests on main.

Test main This PR
baselines::a_merge_commit_build_waits_for_the_pull_requests_head_build 2080 KB 1520 KB
reruns::a_skipped_build_finalizes_and_follows_the_branchs_unfinished_build 2066 KB 1576 KB
project_deletion::the_purge_removes_its_rows_and_objects_keeps_shared_blobs_and_usage 2052 KB 1576 KB
processing::a_stored_config_that_no_longer_validates_fails_the_build_and_names_the_field 2024 KB 1548 KB
pr_comment_images::a_changed_page_shows_its_changes_boxed_and_a_closeup 2010 KB 1534 KB
processing::a_build_pays_for_the_base_it_drew_again 1982 KB 1576 KB
reruns::a_skipped_build_behind_a_superseded_build_follows_what_superseded_it 1968 KB 1492 KB
gallery::a_new_project_publishes_nothing_until_its_gallery_is_turned_on 1968 KB 1492 KB
reruns::a_second_run_that_sent_the_same_snapshots_follows_the_first 1940 KB 1450 KB
reruns::a_follower_of_a_build_superseded_later_follows_the_superseding_build 1926 KB 1464 KB
reruns::an_empty_rerun_waits_for_the_review_of_the_build_that_covers_it 1912 KB 1450 KB
processing::a_build_that_runs_out_part_way_stops_between_batches_and_free_owes_nothing 1912 KB 1436 KB
gallery::wide_screenshots_get_a_640_px_webp_thumbnail_that_follows_approvals 1912 KB 1520 KB
project_deletion::a_deleted_project_is_hidden_everywhere_and_its_token_and_uploads_are_refused 1898 KB 1492 KB
processing::builds_compare_with_their_baselines_and_read_unchanged_groups_from_the_build_that_holds_them 1898 KB 1422 KB
baselines::inherited_changes_are_found_from_the_pull_requests_second_build_on 1898 KB 1422 KB
baselines::a_squash_merged_pull_requests_approvals_reach_the_default_branch_at_the_merge 1898 KB 1422 KB
baselines::a_pull_request_on_an_unreviewed_main_build_marks_the_inherited_changes 1898 KB 1422 KB
baselines::a_pending_build_on_the_branch_is_never_the_base 1898 KB 1422 KB
retention::retention_keeps_the_builds_a_kept_build_reads_groups_from 1884 KB 1394 KB
  • At 1.5 MB: 113 of the app binary's 452 tests overflowed on main; 4 do on this branch.
  • Headroom: the deepest test needs 1576 KB, about 470 KB (23%) under the 2 MB default. The whole --test app binary passes with RUST_MIN_STACK=1703936 (1664 KB).
  • What's left on the deepest paths is mostly outside processing: the HTTP middleware (~350 KB), each queued job's dispatch layers (~180 KB per nested job), sqlx's connection acquire (~170 KB), and the test bodies themselves (up to ~210 KB).

Checks

  • cargo test -p visualci-app passes with no RUST_MIN_STACK set: the lib's unit tests (69), app (452), live, live_limits, mcp_hosts, proxies, sentry and shutdown.
  • cargo clippy --all-targets -- -D warnings and cargo fmt --check pass.
  • No changelog entry: this is internal test work.

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…no RUST_MIN_STACK)

A debug build gives every temporary of an async fn its own slot in its poll's stack frame, a future it
boxes at once included: `process` was one ~270 KB frame and `run` ~130 KB. Tests run queued jobs inline
(a sync queue), so builds are processed inside the request that finalized them and inside each other,
and the deepest tests needed up to 2080 KB, past the test threads' 2 MB.

- `process` is now steps of their own (prepare, confirm, find_bases, compare_all, fill_in, warnings_of,
  settle), and `run` too (charge_before_run, process_exclusively, after_run).
- `domain::boxed(|| step(..))` builds a step's future in a frame of its own, so the caller's frame holds
  a pointer. Used for those steps, `exclusive`, the conclusion's calls, carry-forward's compare, and
  finalize's dispatches and adopt.
- .cargo/config.toml's `[env] RUST_MIN_STACK` is gone.

The deepest test now needs 1576 KB; the whole suite passes at 1664 KB.
@visualci-com

visualci-com Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #1432 · 578 unchanged · no changes

This PR vs base: 26 changed since #1362, across 2 builds

docspring/visualci · journeys · build #1429 · 6 removed, 53 unchanged · approved by visualci coordinator agent (MCP) for Nathan Broadbent

Not #296's change: the six removals are main's own (stale numbered journey names, approved on main's build #1428).

This PR vs base: 53 added, 47 removed since #1357, across 2 builds

Removed: journeys/sign-in-redirects-at-once-and-lists-after/03-finding-repositories, journeys/sign-in-redirects-at-once-and-lists-after/04-picker-refreshing, journeys/sign-in-redirects-at-once-and-lists-after/05-site, journeys/sign-in-redirects-at-once-and-lists-after/06-setup-listing-failed, journeys/sign-in-redirects-at-once-and-lists-after/07-picker-listing-failed, journeys/sign-in-redirects-at-once-and-lists-after/08-not-found

Updated as builds change. Agents can review with VisualCI's MCP tools.

@ndbroadbent
ndbroadbent merged commit d6b38a3 into main Dec 5, 2026
17 checks passed
@ndbroadbent
ndbroadbent deleted the stack-frames branch December 5, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant