Skip to content

fix(mcp): check tracing state before stopping in browser_stop_tracing#41040

Open
SebTardif wants to merge 1 commit into
microsoft:mainfrom
SebTardif:fix/tracing-stop-check-before-stop
Open

fix(mcp): check tracing state before stopping in browser_stop_tracing#41040
SebTardif wants to merge 1 commit into
microsoft:mainfrom
SebTardif:fix/tracing-stop-check-before-stop

Conversation

@SebTardif
Copy link
Copy Markdown
Contributor

browser_stop_tracing calls browserContext.tracing.stop() unconditionally before checking the traceLegendSymbol guard. When tracing was started via config (saveTrace: true) rather than via the browser_start_tracing tool, the symbol is not set. The tool kills the config-initiated trace recording, then throws "Tracing is not started." The destructive side effect fires before the guard check.

Fix

Move the traceLegendSymbol check before tracing.stop() so the guard is evaluated first and the active trace is preserved on the error path.

Trigger scenario

  1. User starts MCP server with saveTrace = true in config
  2. Config-initiated tracing starts in context.ts:329-335 (no traceLegendSymbol set)
  3. MCP client calls browser_stop_tracing
  4. Before fix: tracing.stop() kills the config trace, then the symbol check throws "Tracing is not started"
  5. After fix: symbol check throws "Tracing is not started" immediately; config trace continues recording

The config-initiated trace has its own cleanup via the disposable registered at context.ts:336-340, so the tool should not interfere with it.

Test

Added a test that starts with saveTrace: true, calls browser_stop_tracing (expects error), then verifies the config trace is still active by confirming browser_start_tracing fails with "Tracing has been already started."

Bug introduced in #39646 (2026-03-12).

browser_stop_tracing called tracing.stop() unconditionally before
checking the traceLegendSymbol. If tracing was started via config
(saveTrace: true) rather than via browser_start_tracing, the tool
killed the config-initiated trace, then threw 'Tracing is not
started'. The destructive side effect happened before the guard.

Move the traceLegendSymbol check before tracing.stop() so the
guard is evaluated first and the active trace is preserved on the
error path.

Bug introduced in microsoft#39646 (2026-03-12).

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@github-actions
Copy link
Copy Markdown
Contributor

Test results for "MCP"

7220 passed, 1113 skipped


Merge workflow run.

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.

2 participants