Skip to content

[flaky-ci] Isolate JavaSideActivation GREF leak check - #12716

Merged
simonrozsival merged 5 commits into
mainfrom
simonrozsival-javasideactivation-leak-test
Sep 10, 2026
Merged

simonrozsival merged 5 commits into
mainfrom
simonrozsival-javasideactivation-leak-test

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

  • mark the process-wide JavaSideActivation GREF check as an explicit JniReferenceLeak test
  • run that category in a dedicated JcwGen instrumentation process, separate from the ordinary 38-test suite
  • warm and measure 100 Java-side activations while requiring no positive net GREF growth
  • run destructive peer cleanup only before the measured baseline, then use GC/finalizer synchronization before the final count
  • add a retained-global-reference control proving the assertion detects a real leak

Why

BindingTests.JavaSideActivation compared the process-global JNI GREF count around one activation in a shared device-test process. It failed in builds 1577025, 1578128, 1581740, and 1583153 with deltas of +1, +6, +3, and +4; every failure ended at 101 GREFs from a different lower baseline. The affected jobs passed when rerun, which points to one-time or ambient shared-process reference creation rather than a stable per-call leak.

This now follows the isolation strategy from #12709. Both PRs use the JniReferenceLeak category, [Explicit] default exclusion, a fresh instrumentation process, 100 warmup and measured operations, and a retained-GREF control. This PR needs a separate JcwGen invocation because its Java-side activation fixture and generated binding types exist only in the JcwGen test application.

Isolation removes the need for the previous +10 tolerance. The focused lane allows no positive net GREF growth, while 100 measured activations preserve a strong signal for the known TypeManager.Activate regression that leaked three GREFs per activation.

Validation

  • isolated Release JniReferenceLeak category on API 35 emulator: 2 passed, 0 failed, 0 skipped
  • repeated isolated category: 10/10 runs passed
  • ordinary Release JcwGen suite: 38 passed, 0 failed, 2 explicit leak checks skipped
  • package-test YAML parsed successfully
  • git diff --check

Tracks #12704

Addresses #12031

Warm and amplify the Java-side activation path so process-wide GREF noise does not cause exact-count flakes while per-call leaks remain strongly detectable.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival added the flaky-ci Intermittent CI failures and work to improve CI reliability label Sep 8, 2026
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12716

@github-actions github-actions Bot 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.

⚠️ Needs Changes

Findings: 0 errors, 1 warning, 0 suggestions.

The repeated activation strategy preserves the peer-identity and constructor assertions while making a per-call leak much easier to distinguish from ambient process drift. However, the new cleanup helper introduces a final collection without a corresponding managed-finalizer wait, so the sampled GREF count can still include peers awaiting finalization; I left the required ordering fix inline.

CI build #1586961 is red because MSBuild Emulator Tests macOS > Tests > MSBuild+Emulator 7 reached the 180-minute cap. This appears unrelated to this change: Xamarin.Android.JcwGen-Tests is assigned to Package Tests, and both Package Tests APK lanes passed.

Generated by Android PR Reviewer for #12716 · gpt56 · 141.8 AIC · ⌖ 5.5 AIC · ⊞ 27.7K
Comment /review to run again

Comment thread tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs Outdated
Ensure the legacy Android value manager's CollectPeers GC completes finalization before sampling the process-wide GREF count.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • azcliprod.blob.core.windows.net

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "azcliprod.blob.core.windows.net"

See Network Configuration for more information.

Generated by Android PR Reviewer for #12716

@github-actions github-actions Bot 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.

⚠️ Needs Changes — 0 errors, 0 warnings, 1 suggestion.

The revised test preserves the activation/identity coverage and now waits for finalization after CollectPeers(). I left one non-blocking suggestion to reduce redundant warm-up work.

CI is currently red: the Linux Build, macOS Build, and Windows Build & Smoke Test checks failed in Azure DevOps build 1587821. Detailed failure logs require Azure DevOps authentication that was unavailable in this review run, so those failures could not be classified as PR-related or infrastructure-related.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • azcliprod.blob.core.windows.net

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "azcliprod.blob.core.windows.net"

See Network Configuration for more information.

Generated by Android PR Reviewer for #12716 · gpt56 · 121.9 AIC · ⌖ 8.9 AIC · ⊞ 25.7K
Comment /review to run again

Comment thread tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs Outdated
simonrozsival and others added 3 commits September 9, 2026 11:09
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Run the process-wide GREF assertion in a dedicated category-filtered instrumentation process, matching the isolation strategy in #12709. Require no positive net growth after amplification and retain a control that proves the helper detects live global references.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival changed the title [flaky-ci] Stabilize JavaSideActivation GREF leak check [flaky-ci] Isolate JavaSideActivation GREF leak check Sep 10, 2026
@simonrozsival
simonrozsival marked this pull request as ready for review September 10, 2026 10:27
Copilot AI lite review requested due to automatic review settings September 10, 2026 10:27

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.

Copilot review overview

🟡 Changes recommended

The updated leak-check helper should synchronize JNI GC bridge processing before sampling GlobalReferenceCount, and there’s also a new formatting inconsistency that should be corrected.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 Medium severity · 1 Low severity

New issues introduced by this change (2)
Severity Finding
Medium severity tests/​CodeGen-Binding/​Xamarin.Android.JcwGen-Tests/​BindingTests.cs⚠️ warning: CollectGarbage() only waits for managed finalizers; on CoreCLR/NativeAOT the JNI GC…
Low severity tests/​CodeGen-Binding/​Xamarin.Android.JcwGen-Tests/​BindingTests.cs — ❌ error: This line uses JavaCast&lt;ConstructorTest&gt;() without the repo-standard space before (,…
What changed in this PR

This PR quarantines the BindingTests.JavaSideActivation process-wide JNI global-reference (GREF) leak assertion into an explicit JniReferenceLeak category and adds a dedicated CI lane that runs only those leak checks in a fresh JcwGen instrumentation process to eliminate shared-process noise.

Changes:

  • Adds IncludeCategories plumbing (MSBuild → runtimeconfig → AppContext) so the JcwGen instrumentation runner can filter tests by category.
  • Reworks JavaSideActivation into an explicit, amplified (100-iteration) “no sustained positive GREF growth” leak check, plus a retained-GREF control test.
  • Adds a dedicated apk-instrumentation CI invocation to run only JniReferenceLeak-categorized JcwGen tests.
File Description
tests/​CodeGen-Binding/​Xamarin.Android.JcwGen-Tests/​Xamarin.Android.JcwGen-Tests.csproj Emits IncludeCategories into runtimeconfig via RuntimeHostConfigurationOption.
tests/​CodeGen-Binding/​Xamarin.Android.JcwGen-Tests/​TestInstrumentation.cs Reads IncludeCategories from AppContext and exposes it to the test runner for category filtering.
tests/​CodeGen-Binding/​Xamarin.Android.JcwGen-Tests/​BindingTests.cs Converts the flaky single-snapshot check into an explicit, amplified leak test with a retained-reference control.
build-tools/​automation/​yaml-templates/​stage-package-tests.yaml Adds a dedicated CI lane to run only the JcwGen JniReferenceLeak category in an isolated process.

Comment thread tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs
Comment thread tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs
@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Sep 10, 2026
@simonrozsival
simonrozsival enabled auto-merge (squash) September 10, 2026 13:37
@simonrozsival
simonrozsival merged commit 5986770 into main Sep 10, 2026
45 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-javasideactivation-leak-test branch September 10, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flaky-ci Intermittent CI failures and work to improve CI reliability ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants