Skip to content

Fix duplicate caller frames and initial stack ordering in trace writer - #392

Open
lixin-wei wants to merge 1 commit into
janestreet:masterfrom
lixin-wei:fix/trace-writer-stack-reconstruction
Open

lixin-wei wants to merge 1 commit into
janestreet:masterfrom
lixin-wei:fix/trace-writer-stack-reconstruction

Conversation

@lixin-wei

@lixin-wei lixin-wei commented Sep 24, 2026 •

Copy link
Copy Markdown

hi, thank you for making such an amazing tool! I really enjoy using it!

today I met an issue and fixed it using AI. I wonder whether I fix it the right way? would be grateful if you can have a look, thanks!

summary

Magic-trace could build an invalid call stack when optimized code jumped back to an existing caller: it left the current frame open and added a duplicate caller frame. It could also emit the first traced function before its inferred callers, putting begin events in the wrong order. These errors made some scopes appear to run until the trace ended.

The trace writer now treats a jump to an existing caller as a return and defers the first frame’s begin event until inferred callers are emitted. The change includes regression tests, updated expected traces, and the C++ link flag needed for the native build.

effect

before fix:
image

after fix:
image

Signed-off-by: Lixin Wei <wlx65005@gmail.com>
@lixin-wei
lixin-wei force-pushed the fix/trace-writer-stack-reconstruction branch from 1820c49 to 4e4b3a2 Compare September 24, 2026 14:26
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.

1 participant