Skip to content

fix(tracing): mkdir tracesDir before live .stacks writes#40730

Open
Skn0tt wants to merge 1 commit intomicrosoft:mainfrom
Skn0tt:fix-mcp-tracing-stacks-race
Open

fix(tracing): mkdir tracesDir before live .stacks writes#40730
Skn0tt wants to merge 1 commit intomicrosoft:mainfrom
Skn0tt:fix-mcp-tracing-stacks-race

Conversation

@Skn0tt
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt commented May 8, 2026

Fixes a race in live tracing.

localUtils.tracingStarted returns a stacksId at <tracesDir>/<traceName>.stacks, and addStackToTracingNoReply writes to that file directly. The recorder’s Tracing enqueues a recursive mkdir of <tracesDir>/resources through its own SerializedFS queue — separate from the per-session writer chain in localUtils, so there’s no happens-before guarantee between them.

When the SerializedFS worker hasn’t drained the mkdir yet and a stack write fires (live mode + an action like page.goto), the write fails with ENOENT.

Surfaces as a flake on mcp-windows-latest-firefox via tests/mcp/tracing.spec.ts:54 (browser_stop_tracing returns result: undefined because tracing.stop bubbled the ENOENT).

Fix: precreate path.dirname(traceStacksFile) in tracingStarted, so the contract is self-contained for any caller.

https://mspwblobreport.z1.web.core.windows.net/run-25561393525-1-d8c56b0253640b9f180ee09093c38892d31661d7/index.html#?testId=39a796cef0e6f5869c06-d52e545eb08e8dd5c09c7

`localUtils.tracingStarted` returns a stacksId pointing at
`<tracesDir>/<traceName>.stacks`, and `addStackToTracingNoReply` writes
to that file directly via `fs.writeFile`. The trace recorder enqueues a
recursive mkdir of `<tracesDir>/resources` through its own `SerializedFS`
queue, but the two queues have no happens-before relationship — so when
live tracing fires a stack write before the recorder's mkdir drains, the
write fails with ENOENT.

Surfaces as a flake on slower shards (observed on
mcp-windows-latest-firefox via tests/mcp/tracing.spec.ts:54).

Make the contract self-contained by precreating the directory in
tracingStarted before any caller can write to it.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Test results for "MCP"

9 failed
❌ [firefox] › mcp/annotate.spec.ts:173 › user-initiated annotate downloads zip with feedback.md @mcp-ubuntu-latest-firefox
❌ [firefox] › mcp/cli-devtools.spec.ts:217 › video-start-stop @mcp-windows-latest-firefox
❌ [firefox] › mcp/cli-devtools.spec.ts:231 › video-chapter @mcp-windows-latest-firefox
❌ [msedge] › mcp/annotate.spec.ts:137 › should abort MCP annotation when last screenshot is removed @mcp-windows-latest-msedge
❌ [msedge] › mcp/annotate.spec.ts:273 › should enter annotate mode on fresh dashboard.tsx mount with -s --annotate @mcp-windows-latest-msedge
❌ [msedge] › mcp/annotate.spec.ts:330 › should annotate when context has no fixed viewport @mcp-windows-latest-msedge
❌ [msedge] › mcp/annotate.spec.ts:367 › should cancel browser_annotate when the MCP request is aborted @mcp-windows-latest-msedge
❌ [msedge] › mcp/annotate.spec.ts:398 › should cancel browser_annotate when the MCP client disconnects @mcp-windows-latest-msedge
❌ [webkit] › mcp/launch.spec.ts:101 › isolated context @mcp-windows-latest-webkit

7022 passed, 1068 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Test results for "tests 1"

4 flaky ⚠️ [chromium-library] › library/video.spec.ts:647 › screencast › should capture full viewport `@ubuntu-22.04-chromium-tip-of-tree`
⚠️ [chromium-library] › library/video.spec.ts:682 › screencast › should capture full viewport on hidpi `@ubuntu-22.04-chromium-tip-of-tree`
⚠️ [chromium-library] › library/video.spec.ts:719 › screencast › should work with video+trace `@chromium-ubuntu-22.04-arm-node20`
⚠️ [firefox-library] › library/inspector/cli-codegen-3.spec.ts:224 › cli codegen › should generate frame locators (4) `@firefox-ubuntu-22.04-node20`

41692 passed, 850 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