Repository navigation
Description
Summary
When MTP renders a failed-test stack trace, hide internal MTP/MSTest plumbing frames so the user (and any LLM agent reading the output) only sees frames that come from their own code or the dependencies they care about.
Motivation
The current TerminalTestReporter.Formatting.cs:FormatStackTrace simply line-splits exception.StackTrace and prints every frame. Every failure dumps frames like:
at Microsoft.Testing.Platform.Hosts.CommonTestHost.ExecuteRequestAsync(...)
at Microsoft.Testing.Platform.MSTest.MSTestBridgedTestFramework.ExecuteRequestAsync(...)
at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTestRunner.RunSingleTest(...)
…
These frames have zero diagnostic value when the user is debugging their own test — the relevant frames are the user's TestMethod, the assertion site, and the production code under test. MSTest's Assert.* helpers are already annotated with [StackTraceHidden], so those frames are already invisible; the remaining noise is the MTP/adapter plumbing chain.
For LLM consumers this matters most: each hidden frame is ~80-120 tokens that is pure noise. A typical failed test today emits 8-15 frames where only 2-4 are user-relevant.
Proposed design
Add a frame-filter at the rendering layer (not in ExceptionFlattener):
- In
TerminalTestReporter.Formatting.cs:FormatStackTrace, before callingAppendStackFrame, run each parsed frame through a predicate that returnsfalsefor frames whose declaring type matches one of the known internal namespaces. - Internal namespace prefixes to hide:
Microsoft.Testing.Platform.(excludingMicrosoft.Testing.Platform.Extensions.*— extension authors' own code? TBD)Microsoft.Testing.Extensions.(TrxReport, HtmlReport, etc. — plumbing only)Microsoft.VisualStudio.TestPlatform.MSTestAdapter.(VSTest adapter plumbing)- Possibly
Microsoft.VisualStudio.TestTools.UnitTesting.for any non-[StackTraceHidden]member.
- Collapse contiguous hidden frames into a single
...skipped N frames in Microsoft.Testing.Platform.* ...line so the user can tell something was hidden (and so the line count still indicates real depth). - Apply at the rendering layer only.
ExceptionFlattener.FlatException.StackTracecontinues to carry the raw string so TRX/HTML/AzDO/JSON-report consumers receive untouched data.
Configuration
- Default-on when
LLMEnvironmentDetector.IsLLMEnvironment()returnstrue. - Default-off otherwise (preserves today's human-mode transcript exactly).
- Add a new option
--stack-trace <filtered|full>(or--full-stack-traceflag) so humans can opt in to filtering and LLM-mode agents can opt out for debugging extensions. - For v1 we may skip the flag entirely and only flip on LLM mode, to avoid help/info-acceptance and XLF churn — see umbrella [RFC] Agent/LLM-efficient test output for Microsoft.Testing.Platform #8824 for the trade-off.
Risks / open questions
- Could hide a relevant frame if a user has derived from an MTP type and is debugging their own override. Mitigation: opt-out flag + only hide frames whose declaring type's namespace starts with one of the known prefixes; user-derived classes will live in user namespaces and so will not be filtered.
- AOT mode may have different frame visibility (some frames stripped, others present only as
__Thunk__). Filter should be defensive: if regex parse fails for a frame, print it unfiltered.
Acceptance criteria
- A failing test in LLM mode shows only user-code frames (plus a collapsed
...N skipped frames...marker). - Same failing test in human mode shows today's full trace.
- TRX / HTML reports for the same run still contain the full unfiltered trace.
- Unit tests cover: pure-user frames pass through, pure-internal trace collapses to one line, mixed trace shows user frames + collapse markers, malformed lines are passed through unchanged.
References
- Umbrella: [RFC] Agent/LLM-efficient test output for Microsoft.Testing.Platform #8824
- File:
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.Formatting.cs(FormatStackTrace,AppendStackFrame) - File:
src/Platform/Microsoft.Testing.Platform/Helpers/LLMEnvironmentDetector.cs
Activity
Youssef1313 commentedon Jun 5, 2026
Why not use StackTraceHidden instead of trying to alter stack trace manually. I don't think it's a good idea to try to manually mess up with stack traces.
Evangelink commentedon Jul 1, 2026
After #8854 (which annotated the MTP host + MSTest adapter execution plumbing with
[StackTraceHidden], per Youssef Fahmy (@Youssef1313)'s suggestion), I re-measured a real failing-test transcript to see what noise actually remains. My conclusion is that we should close this as won't-do — the declarative[StackTraceHidden]approach already delivered the win, and the leftover frames are standard .NET behavior we shouldn't manipulate.Post-#8854 transcript (4 failing tests: sync assert, sync throw-from-helper, async assert, async throw-from-helper)
Why the original motivation is now obsolete
The three example frames this issue was filed to remove —
CommonTestHost.ExecuteRequestAsync,MSTestBridgedTestFramework.ExecuteRequestAsync,UnitTestRunner.RunSingleTest— no longer appear at all. The whole MTP-host + adapter plumbing chain is gone thanks to[StackTraceHidden]. The "8–15 frames, only 2–4 user-relevant" claim is outdated: failures are now 2–5 frames with only 1–2 non-user frames each. Async user frames also unwind cleanly (noMoveNext/closure spam) thanks to modern .NET stack-trace demystification.Why we should NOT add a rendering-layer filter for what's left
The residual frames are not MTP noise — they're .NET's own default stack-trace surface:
System.RuntimeMethodHandle.InvokeMethod+System.Reflection.MethodBaseInvoker.InvokeWithNoArgs— the standard frames any reflection-based invoker shows (xUnit, NUnit, ASP.NET model binding, etc.). They're a familiar "reached via reflection" signal, not confusing noise.TestMethodInfo.ExecuteInternalAsyncleaking despite the type being[StackTraceHidden]— the documented runtime limitation for[StackTraceHidden]on async methods. If the runtime tightens that, the frame disappears for free; a rendering filter would just be papering over it.A rendering-layer deny-list would be guesswork about a frame's meaning. It can't tell "MTP invoked the test reflectively" from "the user's own code called
MethodInfo.Invokeand that reflection call is the bug" — so filteringRuntimeMethodHandlerisks eating a genuinely relevant user frame. It also reintroduces exactly the fragility we avoided by choosing[StackTraceHidden]: localization, AOT, obfuscation, and a permanent terminal-vs-report divergence to maintain. Keeping the terminal faithful to .NET's default trace is a feature, not a gap.Recommendation
Close as won't-do; #8854 is the delivered solution. The one genuinely separate observation is that the async frame can carry an absolute build-machine path (from the shipped PDBs) — that's a deterministic-build / source-path config topic, not a stack-rendering concern, and can be filed separately if we think it's worth pursuing.