Skip to content

fix: track recorder ownership so trace/profiler stop don't cross-stop#1457

Open
LukeTheoJohnson wants to merge 1 commit into
vercel-labs:mainfrom
LukeTheoJohnson:fix/trace-profiler-stop-ownership
Open

fix: track recorder ownership so trace/profiler stop don't cross-stop#1457
LukeTheoJohnson wants to merge 1 commit into
vercel-labs:mainfrom
LukeTheoJohnson:fix/trace-profiler-stop-ownership

Conversation

@LukeTheoJohnson

Copy link
Copy Markdown

Summary

trace and profiler both drive Chrome's CDP Tracing domain. The daemon tracked only whether a recording was active, not which command started it, so a stop issued by the other command ended the wrong recording. The owner's own stop then failed and its data was lost.

Current behavior

agent-browser --session s trace start            # ok
agent-browser --session s profiler start         # "Profiling/tracing already active" (correctly blocked)
agent-browser --session s profiler stop p.json   # ok  <- but this stops the TRACE recording
agent-browser --session s trace stop t.zip       # "No tracing in progress"  <- trace data lost

The symmetric case (profiler start then trace stop) fails the same way: trace stop consumes the profiler recording and profiler stop then reports "No profiling in progress". Both repros are in #1313.

Root cause

TracingState held a single active: bool. trace_stop and profiler_stop both guarded only on active, then issued Tracing.end unconditionally, so either command could stop a recording started by the other.

Fix

Record which command owns the active recording (TracingOwner::Trace / TracingOwner::Profiler) when it starts, and check it on stop through a small ensure_stoppable helper. A stop from the other command returns a clear error before Tracing.end is sent, so the real recorder keeps running:

  • trace start + profiler stop -> Cannot stop profiler: a trace recording is active. Use 'trace stop' instead.
  • profiler start + trace stop -> Cannot stop trace: a profiler recording is active. Use 'profiler stop' instead.

The existing idle messages (No tracing in progress / No profiling in progress) are unchanged for the genuine "nothing running" case.

Tests

ensure_stoppable is a pure function, so the regression is pinned with deterministic unit tests that need no Chrome: both cross-stop directions, the owner stopping its own recording, and the idle case. cargo test --profile ci passes.

Scope

Ownership tracking is the minimal change that fixes the reported bug. The single shared TracingState still means trace and profiler cannot run at the same time (a second start is rejected); this PR preserves that and only corrects which command may stop. No CLI, MCP, or flag surface changes, so no docs updates are needed. CHANGELOG.md is left to the maintainer per AGENTS.md.

Fixes #1313

`trace` and `profiler` share the CDP Tracing domain, but `TracingState`
only tracked a single `active` flag. Neither stop command recorded which
command owned the active recording, so a `profiler stop` would issue
`Tracing.end` against a recording started by `trace start` (and vice
versa): the wrong command consumed the recording and the owner's own
stop then failed with "No tracing in progress".

Track the owner on start and reject a stop from the other command before
issuing `Tracing.end`, so the real recorder keeps running. Adds unit
tests covering both cross-stop directions.

Fixes vercel-labs#1313
@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@LukeTheoJohnson is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@LukeTheoJohnson LukeTheoJohnson marked this pull request as ready for review June 17, 2026 09:03
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.

trace stop and profiler stop can stop the other recorder type

1 participant