Skip to content

Fix TerminalLogger node status restoration after MSBuild task yields - #12820

Merged
JanProvaznik merged 9 commits into
dotnet:mainfrom
JanProvaznik:tl-node-null
Nov 25, 2025
Merged

JanProvaznik merged 9 commits into
dotnet:mainfrom
JanProvaznik:tl-node-null

Conversation

@JanProvaznik

Copy link
Copy Markdown
Member

Fixes #12819

Context

This PR addresses the root cause of TerminalNodeStatus becoming null unexpectedly during builds. This was identified as the underlying cause for issues where test summaries were missing because the logger couldn't attribute events to an active node (discussed in [related PR/Issue]).

When the <MSBuild> task runs, the node yields. TerminalLogger correctly cleared the status on yield but failed to restore it upon resume.

Changes Made

  • Implemented TaskFinished handler in TerminalLogger.cs.
  • Added logic to detect when the MSBuild task finishes.
  • Restores the TerminalNodeStatus using the preserved TerminalProjectInfo (ProjectFile, TargetFramework, etc.) and the CurrentTarget.
  • Restarts the stopwatch for the project to accurately track the resumed duration.

Testing

  • Unit Test: Added DisplayNodesRestoresStatusAfterMSBuildTaskYields to TerminalLogger_Tests.cs. This test simulates the TaskStarted("MSBuild") -> TaskFinished("MSBuild") sequence and asserts that DisplayNodes() renders the project status correctly after the task finishes.
  • Manual Verification: Verified using a multi-process reproduction project where worker nodes yield to leaf projects. Confirmed that worker nodes reappear in the terminal status bar after the leaf projects complete.

Notes

This ensures that long-running tasks occurring after an MSBuild task call are correctly visualized in the terminal, and that any logic depending on _nodes[index] being non-null works as expected.

Copilot AI review requested due to automatic review settings November 24, 2025 10:39

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.

Pull request overview

This PR fixes an issue where TerminalLogger failed to restore node status after the MSBuild task yields during multi-process builds. The fix ensures that when a node resumes after yielding (when the MSBuild task finishes), the terminal display correctly shows the project's current target and timing information.

Key Changes:

  • Added CurrentTarget property to track the currently executing target in TerminalProjectInfo
  • Implemented TaskFinished event handler to detect when the MSBuild task completes and restore the node status
  • Added comprehensive unit test with snapshot verification to validate the yield/resume behavior

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/Build/Logging/TerminalLogger/TerminalProjectInfo.cs Added CurrentTarget property to store the name of the currently executing target
src/Build/Logging/TerminalLogger/TerminalLogger.cs Subscribed to TaskFinished event, set CurrentTarget in TargetStarted, and implemented restoration logic in TaskFinished handler
src/Build.UnitTests/TerminalLogger_Tests.cs Added test that simulates MSBuild task yield/resume sequence and verifies node status restoration
src/Build.UnitTests/Snapshots/TerminalLogger_Tests.DisplayNodesRestoresStatusAfterMSBuildTaskYields.Windows.verified.txt Snapshot verification file showing expected terminal output during yield/resume cycle

@JanProvaznik JanProvaznik self-assigned this Nov 24, 2025

@baronfel baronfel 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.

Added some test infra to make multi-node logger testing easier

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.

TerminalLogger node status is lost after MSBuild task yields and resumes

4 participants