Skip to content

fix(rallocator): keep stack-grouped allocations on a single call site - #748

Merged
Zac Walker (ZacWalk) merged 1 commit into
mainfrom
fix/rallocator-stack-test-unrolling
Sep 11, 2026
Merged

Zac Walker (ZacWalk) merged 1 commit into
mainfrom
fix/rallocator-stack-test-unrolling

Conversation

@ZacWalk

Copy link
Copy Markdown
Member

Root cause

OxidizerGitHub.PublishEachCommit is red on main. The Cargo test step fails in the release profile on both Linux and Windows (dev passes), with one failing test out of ~7,700:

FAIL rallocator::telemetry snapshot_encodes_allocations_by_stack
assertion `left == right` failed
  left: 1
 right: 4

The last green and the first red run used the same toolchain (1.97.1-ms-20260901.3), so this is a code regression, not a tooling migration:

Build Commit Result
20260910.1 70bd5aa (#744) succeeded
20260910.2 8624f90 (#733) first failing build
20260910.3 03e3dfe (#722) failed, unrelated to the triggering commit

snapshot_encodes_allocations_by_stack allocates in a loop with a compile-time trip count and asserts that all four samples share one call stack. Call stacks are recorded as raw return addresses in capture_platform_stack, and the release profile fully unrolls that loop, so each sample allocates from its own call site. Instrumenting the test confirms all four allocations are recorded, but their stacks differ in exactly one frame - the return address inside the test function, stepping by a fixed instruction offset per iteration:

stack = [140702813012151, 140702812954602, 140702813025904, ...]
stack = [140702813012151, 140702812954684, 140702813025904, ...]
stack = [140702813012151, 140702812954766, 140702813025904, ...]
stack = [140702813012151, 140702812954848, 140702813025904, ...]

The grouping filter therefore matches 1 event instead of 4. The allocations are not elided, they are split across four stack buckets. #733 reworked the allocation path and changed inlining enough to tip this loop into being unrolled; the test has never been protected against release codegen. This is the same class of fragility as #666 (fix(rallocator): preserve allocation effects in release tests), where LLVM elided unprotected test allocations.

Fix

Route every sample through a single #[inline(never)] helper and make the loop bound opaque, so all samples allocate from one instruction and record one shared call stack. black_box alone would not fix this, since the allocations do occur - the call site itself has to stay singular.

Validation

Against the exact CI toolchain (ms-prod-1.97@llvm, 1.97.1-ms-20260901.3):

  • cargo test --release --all-features -p rallocator --test telemetry - fails on main before the change, 19/19 pass after it
  • cargo test --all-features -p rallocator --test telemetry (dev profile) - 19/19 pass
  • cargo clippy --release --all-features -p rallocator --all-targets -- -D warnings - clean
  • cargo +nightly-2026-05-30 fmt -p rallocator -- --check - clean
  • just anvil-spellcheck - clean

Also reproduced and verified on 1.96.1; the failure does not reproduce on 1.95.0.

Bug: https://o365exchange.visualstudio.com/O365%20Core/_workitems/edit/7866558
Failing build: https://dev.azure.com/O365Exchange/O365%20Core/_build/results?buildId=40955158&view=results
First failing build: https://dev.azure.com/O365Exchange/O365%20Core/_build/results?buildId=40907883&view=results

The release profile fully unrolls the constant-trip-count loop in
`snapshot_encodes_allocations_by_stack`, so each sample allocated from
its own call site and recorded its own return address. Call stacks are
captured as raw return addresses, so the four samples landed in four
stack buckets and the grouping assertion saw 1 allocation instead of 4.

Route every sample through a single `#[inline(never)]` helper and make
the loop bound opaque, so all samples allocate from one instruction and
share one recorded call stack.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 11, 2026 10:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The release test is hardened and no unresolved issues remain.

Pull request overview

Fixes release-profile telemetry test flakiness by keeping stack-grouped allocations at one call site.

Changes:

  • Adds a non-inlined allocation helper.
  • Makes the loop bound opaque.
  • Derives the expected count from the sample constant.
File summaries
File Description
crates/rallocator/tests/telemetry.rs Stabilizes stack-grouped allocation testing in optimized builds.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (704eba8) to head (fae3e5f).

Additional details and impacted files
@@          Coverage Diff           @@
##            main     #748   +/-   ##
======================================
  Coverage   99.9%   100.0%           
======================================
  Files        634      634           
  Lines      84746    84746           
======================================
+ Hits       84744    84746    +2     
+ Misses         2        0    -2     
Flag Coverage Δ
linux 78.6% <ø> (?)
linux-arm 78.6% <ø> (?)
windows 78.2% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ZacWalk
Zac Walker (ZacWalk) enabled auto-merge (squash) September 11, 2026 11:34
@ZacWalk
Zac Walker (ZacWalk) merged commit 369796e into main Sep 11, 2026
60 checks passed
@ZacWalk
Zac Walker (ZacWalk) deleted the fix/rallocator-stack-test-unrolling branch September 11, 2026 11:51
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.

4 participants