fix: profile transactions that start while the final chunks are being sent

BI
1d ago
+70-15

I ran into this while adding continuous profiling to Hypervel. With profile_lifecycle set to trace, the SDK stops recording when the last sampled transaction finishes and sends the remaining profile chunks.

In an async server, request A can finish and still be waiting for its profile to send when request B starts a sampled transaction. B picks up A’s profiler ID even though A’s timer has already stopped. When the send returns, A clears the profiler state. B’s transaction still points to A’s profiler ID, but B’s work was never recorded.

This PR has stop() take the completed chunks and clear the old recording before sending them. B can then start a fresh recording with its own profiler ID while A’s chunks are on their way.

The regression test starts a new root span inside the client’s captureEvent() to reproduce that timing without Swoole.