Improve diagnostic logging across MTP crash and IPC paths#8584
Merged
Conversation
Surgical improvements to internal logging across high-risk crash/diagnostic paths in Microsoft.Testing.Platform. No public API changes. - UnhandledExceptionHandler/ServerTestHost: pattern-match e.ExceptionObject as Exception and pass the typed exception via structured logging instead of stringifying it into the message; route exception into FailFast. - NamedPipeClient: write a stderr diagnostic naming the pipe before silent _environment.Exit on IPC EOF (best-effort, wrapped in try/catch). - NamedPipeServer: log Debug on graceful client disconnect; log Error with pipe name, WasConnected and LoopTaskStatus before throwing on Dispose/DisposeAsync timeout. - JsonConfigurationProvider: add null-safe LogDebugAsync/LogErrorAsync helpers; log swallowed Path.GetFullPath failure, missing default config file, and wrap parser invocation with Error log including file path. - ConfigurationManager: wrap Trace-level full-config dump in try/catch so I/O failures cannot break configuration loading. - TestHostControllersTestHost: log Debug when PID lookup InvalidOperationException is swallowed; log Warning on non-graceful exit with OS exit code, IPC-reported exit code, TestHostCompletedRequest flag, PID and CancellationRequested. - TestHostTestFrameworkInvoker: log Debug session UID; log Warning/Error from session results with phase (CreateTestSession/CloseTestSession) and session UID. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves internal diagnostics across Microsoft.Testing.Platform crash, IPC, configuration, and test-host session paths without changing public API.
Changes:
- Routes typed exceptions into logger exception parameters for unhandled exception paths.
- Adds diagnostic logging for IPC disconnects, non-graceful test-host exits, config parse/load failures, and session warnings/failures.
- Makes trace-level configuration file dumping best-effort so diagnostic I/O failures do not break configuration loading.
Show a summary per file
| File | Description |
|---|---|
src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs |
Logs session UID and mirrors session warning/failure results to diagnostic logs. |
src/Platform/Microsoft.Testing.Platform/IPC/NamedPipeServer.cs |
Logs graceful client disconnects and dispose timeout diagnostics. |
src/Platform/Microsoft.Testing.Platform/IPC/NamedPipeClient.cs |
Emits a stderr diagnostic before exiting on IPC EOF. |
src/Platform/Microsoft.Testing.Platform/Hosts/TestHostControllersTestHost.cs |
Adds debug/warning details for PID lookup failures and non-graceful test-host exits. |
src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs |
Passes unhandled exceptions through logger exception parameters while preserving output-device text. |
src/Platform/Microsoft.Testing.Platform/Helpers/UnhandledExceptionHandler.cs |
Separates console text from structured log text and passes typed exceptions to logging/FailFast. |
src/Platform/Microsoft.Testing.Platform/Configurations/JsonConfigurationProvider.cs |
Adds null-safe debug/error logging for path resolution, missing default config, and parse failures. |
src/Platform/Microsoft.Testing.Platform/Configurations/ConfigurationManager.cs |
Wraps trace config dump in best-effort logging. |
Copilot's findings
- Files reviewed: 8/8 changed files
- Comments generated: 0
- TestHostControllersTestHost: drop redundant _testHostPID.HasValue ternary; the value is guaranteed by the Unreachable guard a few lines above. - NamedPipeClient: replace bare catch with typed/filtered catch for the expected non-fatal exceptions from Console.Error.WriteLineAsync. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Evangelink
commented
May 26, 2026
Evangelink
commented
May 26, 2026
Addresses PR feedback: each diagnostic field on its own line is easier to read in log files than a single comma-separated line. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
nohwnd
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Surgical improvements to internal logging across high-risk crash and diagnostic paths in
Microsoft.Testing.Platform. The goal is to make it noticeably easier to diagnose problems and crashes from logs alone, without changing any public API.Changes
Helpers/UnhandledExceptionHandler.cse.ExceptionObject is Exception, route the typed exception throughLog(LogLevel.Critical, msg, ex, Formatter)(structured sinks now get the object, not just a stringified message), and pass it intoFailFast(msg, ex). Console output kept full-fidelity for backward-compat with acceptance tests.Hosts/ServerTestHost.csOnCurrentDomainUnhandledException/OnTaskSchedulerUnobservedTaskException.IPC/NamedPipeClient.cs_environment.Exit(GenericFailure)with zero diagnostic output. Now writes a clearConsole.Error.WriteLineAsyncdiagnostic naming the pipe and the most likely cause before exiting. Wrapped in try/catch so logging failures cannot shadow the original issue.[Embedded]type cannot take anILoggerwithout breakingMTP_MSBUILD_TASKSsource-embedded compilation, so stderr is the pragmatic compromise.IPC/NamedPipeServer.csreturn). Error log with pipe name,WasConnectedandLoopTaskStatusbefore throwing onDispose/DisposeAsynctimeout.Configurations/JsonConfigurationProvider.csLogDebugAsync/LogErrorAsynchelpers. Logs: previously swallowedPath.GetFullPathfailure; missing default config file (was silent return);JsonConfigurationFileParser.Parsefailures with file path before rethrowing.Configurations/ConfigurationManager.csHosts/TestHostControllersTestHost.csInvalidOperationExceptionis swallowed. Warning log on non-graceful exit including OS exit code, IPC-reported exit code (or<not received>), whetherTestHostCompletedRequestwas received, PID, andCancellationRequested.Requests/TestHostTestFrameworkInvoker.csCreateTestSession/CloseTestSession) and session UID.Deliberately out of scope
Microsoft.Testing.Extensions.HotReloadhas zero logging today — sizable instrumentation effort, deferred.ServerMode/JsonRpc/TcpMessageHandler.cs/MessageHandlerFactory.cs— connection loss, malformed headers and deserialization failures not logged. Substantial server-mode surface change, deferred.NamedPipeClientcannot accept anILoggerwithout breaking the[Embedded]/MTP_MSBUILD_TASKSsource-embedded constraint.Validation
.\build.cmd -projects Microsoft.Testing.Platform.csproj— green fornet8.0,net9.0,netstandard2.0.dotnet test Microsoft.Testing.Platform.UnitTests --filter "FullyQualifiedName~Configuration|FullyQualifiedName~UnhandledException|FullyQualifiedName~NamedPipe|FullyQualifiedName~ServerTestHost|FullyQualifiedName~TestHostControllers|FullyQualifiedName~TestHostTestFrameworkInvoker"— 75/75 pass.dotnet test Microsoft.Testing.Extensions.UnitTests— 334 pass, 4 skipped (platform-specific).UnhandledExceptionPolicyTests.cs) only assert message prefixes; verified the new structure still matches.Notes
.resxchanges — MTP log messages are not localized.