Skip to content

Dispose TensorFlow sessions before test process cleanup - #7747

Merged
svick merged 4 commits into
dotnet:mainfrom
svick:fix/7730-tensorflow-test-cleanup
Oct 15, 2026
Merged

svick merged 4 commits into
dotnet:mainfrom
svick:fix/7730-tensorflow-test-cleanup

Conversation

@svick

@svick svick commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #7730

Summary

  • Dispose the legacy view chain created by ShowSchemaCommand, from the final transform back to its source.
  • Explicitly dispose TensorFlow models and transformers owned by TensorFlow tests.

Why

The TensorFlow.NET Session finalizer can crash during test-process shutdown if it runs after TensorFlow.NET has disposed its global thread-local state. The showschema command constructed a TensorFlow-backed legacy pipeline but did not release its transforms when the command completed.

ShowSchemaCommand owns the pipeline returned by CreateAndSaveLoader, so it now materializes that pipeline's view chain and deterministically disposes every disposable view in downstream-to-source order.

svick and others added 2 commits September 30, 2026 16:59
Dispose test-owned TensorFlow models and finalize the command-line pipeline before TensorFlow.NET global teardown.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Dispose each view created by ShowSchemaCommand from the end of the legacy pipeline back to its source, avoiding TensorFlow session finalization after global teardown.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

Legacy row-to-row views still hide undisposed TensorFlow transformers and sessions.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Ensures TensorFlow sessions are released before test-process shutdown.

Changes:

  • Adds explicit model and transformer disposal in TensorFlow tests.
  • Disposes legacy showschema view chains downstream-to-source.
File Description
TensorflowTests.cs Disposes TensorFlow models.
TensorFlowEstimatorTests.cs Disposes fitted transformers and models.
ShowSchemaCommand.cs Adds legacy pipeline cleanup.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Unwrap RowToRowMapperTransform views when cleaning up ShowSchema pipelines and dispose the independently loaded TensorFlow transformer in the legacy save/load test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@svick
svick requested a balanced review from Copilot October 1, 2026 16:49

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

🟢 Approval recommended

Resource ownership and disposal ordering are handled correctly across the changed paths.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.34884% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.00%. Comparing base (e1e858a) to head (1d013b5).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
...ft.ML.TensorFlow.Tests/TensorFlowEstimatorTests.cs 85.71% 0 Missing and 2 partials ⚠️
test/Microsoft.ML.Tests/EvaluateTests.cs 94.44% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7747      +/-   ##
==========================================
+ Coverage   69.89%   70.00%   +0.10%     
==========================================
  Files        1487     1419      -68     
  Lines      276294   272832    -3462     
  Branches    28294    27584     -710     
==========================================
- Hits       193127   190993    -2134     
+ Misses      75677    73651    -2026     
- Partials     7490     8188     +698     
Flag Coverage Δ
Debug 70.00% <95.34%> (+0.10%) ⬆️
production 64.18% <100.00%> (+0.10%) ⬆️
test 89.72% <93.33%> (-0.12%) ⬇️

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

Files with missing lines Coverage Δ
...rc/Microsoft.ML.Data/Commands/ShowSchemaCommand.cs 81.37% <100.00%> (+2.13%) ⬆️
...t/Microsoft.ML.TensorFlow.Tests/TensorflowTests.cs 91.84% <100.00%> (-0.05%) ⬇️
...ft.ML.TensorFlow.Tests/TensorFlowEstimatorTests.cs 97.64% <85.71%> (-0.89%) ⬇️
test/Microsoft.ML.Tests/EvaluateTests.cs 97.05% <94.44%> (-2.95%) ⬇️

... and 454 files with indirect coverage changes

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

@svick
svick marked this pull request as ready for review October 9, 2026 14:35
Skip parent-transformer disposal when a legacy row mapper explicitly reports that GetTransformer is unsupported, and cover the full ShowSchema command behavior with an evaluator transform.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@svick
svick requested review from matouskozak and a balanced review from Copilot October 14, 2026 16:29

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

No blocking defects were identified; direct disposal assertions would strengthen regression coverage.

1 open finding

🧠 Review effort: Balanced

@matouskozak matouskozak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

svick added a commit that referenced this pull request Oct 15, 2026
## Summary
Enable .NET dumps, JSON crash reports, and dump-generation diagnostic
logging in the Unix Helix runner when HELIX_DUMP_FOLDER is set. Document
where to find the artifacts.

## Motivation
While validating #7747, [build
1629902](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1629902)
failed with an unrelated crash: the main `Microsoft.ML.Tests` process
exited with SIGSEGV (139) on macOS x64 Debug. The main test process
crashed while tests were still running, rather than during shutdown.

The console log ended just after an image-creation test started, but
several tests were running concurrently. Helix uploaded no dump or crash
report, despite the shell printing "core dumped", so there was no
crashing-thread stack or process state to identify the faulting code.
The available evidence was insufficient to determine the cause or
establish whether the crash was related to the PR.

Enabling capture preserves evidence from future crashes instead of
relying on the last test logged or waiting for a local reproduction. The
JSON report provides thread stacks that can be inspected without a
matching-OS debugger; the dump allows deeper analysis of memory,
modules, and thread state with the matching runtime and native binaries.
Writing them to Helix's dump directory makes them available as work-item
artifacts, and diagnostic logging helps explain any capture failure.

## Actual CI validation
[Build
1632277](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1632277)
ran a temporary fatal native-memory-access probe on macOS x64 in both
Debug and Release. Both processes exited with SIGSEGV (139), and both
Helix work items uploaded a dump and readable JSON crash report. The
reports identify the crashing thread and include
DumpCaptureProbeTests.CaptureSegmentationFault plus native frames.

- [Debug crash
report](https://helixr1107v0xdeko0k025g8.blob.core.windows.net/dotnet-machinelearning-refs-pull-7780-merge-2b02312c4c2a4317bf/Microsoft.ML.Tests/1/coredump.68046.1791823117.dmp.crashreport.json?helixlogtype=result)
- [Release crash
report](https://helixr1107v0xdeko0k025g8.blob.core.windows.net/dotnet-machinelearning-refs-pull-7780-merge-efff89a63ce5409f86/Microsoft.ML.Tests/1/coredump.15665.1791822990.dmp.crashreport.json?helixlogtype=result)

The probe and temporary test filtering were removed in a follow-up
commit. The final diff contains only the runner configuration and
documentation.

---------

Copilot-Session: 7f213f15-6239-4a5b-b50e-de711637d646
@svick
svick merged commit 47eecc6 into dotnet:main Oct 15, 2026
25 of 27 checks passed
@svick
svick deleted the fix/7730-tensorflow-test-cleanup branch October 15, 2026 15:12
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.

CI race: Tensorflow.BaseSession finalizer accessing a disposed ThreadLocal during test process cleanup

3 participants