Title: `_remote_debugging`: Impossible stack traces (cross calls, orphans, wrong lines) with `cache_frames=True` · Issue #151424 · python/cpython · GitHub
Open Graph Title: `_remote_debugging`: Impossible stack traces (cross calls, orphans, wrong lines) with `cache_frames=True` · Issue #151424 · python/cpython
X Title: `_remote_debugging`: Impossible stack traces (cross calls, orphans, wrong lines) with `cache_frames=True` · Issue #151424 · python/cpython
Description: Bug report Bug description: Basically, when profiling with Tachyon I'm seeing stack traces that are just impossible. Truth to be told, this is an absolutely pathological script with completely unstable (flutter frames) stack traces. That...
Open Graph Description: Bug report Bug description: Basically, when profiling with Tachyon I'm seeing stack traces that are just impossible. Truth to be told, this is an absolutely pathological script with completely unst...
X Description: Bug report Bug description: Basically, when profiling with Tachyon I'm seeing stack traces that are just impossible. Truth to be told, this is an absolutely pathological script with completely ...
Opengraph URL: https://github.com/python/cpython/issues/151424
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`_remote_debugging`: Impossible stack traces (cross calls, orphans, wrong lines) with `cache_frames=True`","articleBody":"# Bug report\n\n### Bug description:\n\nBasically, when profiling with Tachyon I'm seeing stack traces that are just impossible.\n\nTruth to be told, this is an absolutely pathological script with _completely_ unstable (flutter frames) stack traces. That said, I'd expect them to be rejected (thus increasing the error rate), not corrupted.\n\nAs before, I've spotted this issue - albeit not that catastrophically - while observing my [vm_remap](https://github.com/maurycy/cpython/pull/3) runs.\n\n# Reproduction\n\n```python\ndef leaf_a(): return sum(range(50))\ndef leaf_b(): return sum(range(50))\ndef hot_a(): return leaf_a()\ndef hot_b(): return leaf_b()\nwhile True:\n hot_a(); hot_b();\n```\n\nThen:\n\n```bash\n2026-06-12T20:56:38.335765000+0200 maurycy@gimel /Users/maurycy/work/cpython (main f4f1020?) % sudo ./python.exe -m profiling.sampling run --collapsed -o /tmp/stacks.txt -d 10 repro.py\nCaptured 10,000 samples in 10.00 seconds\nSample rate: 999.99 samples/sec\nError rate: 16.50\nCollapsed stack output written to /tmp/stacks.txt\n2026-06-12T20:56:48.704707000+0200 maurycy@gimel /Users/maurycy/work/cpython (main f4f1020?) % cat /tmp/stacks.txt\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:4;repro.py:leaf_a:1 1721\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:4;repro.py:leaf_b:2 1436\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:3;repro.py:leaf_b:2 1430\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6 1170\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:3;repro.py:leaf_a:1 1075\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:3 413\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:4 396\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:leaf_a:1 262\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:leaf_b:2 207\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:-1;repro.py:leaf_b:2 75\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:-1;repro.py:leaf_a:1 69\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:-1;repro.py:leaf_b:2 41\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:-1;repro.py:leaf_a:1 31\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:3;repro.py:leaf_b:-1 11\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:4;repro.py:leaf_a:-1 9\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:leaf_a:-1 2\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:5;repro.py:hot_a:-1;repro.py:leaf_b:2 1\ntid:12100288;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:3;repro.py:leaf_a:-1 1\n2026-06-12T20:58:42.867874000+0200 maurycy@gimel /Users/maurycy/work/cpython (main f4f1020?) %\n```\n\nMore precisely, **out of 8476 successful stacks, 4316 (50.9%) are impossible**.\n\nCross:\n\n```\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:hot_b:4;repro.py:leaf_a:1 1736\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:hot_a:3;repro.py:leaf_b:2 1584\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:hot_b:-1;repro.py:leaf_a:1 23\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:hot_a:-1;repro.py:leaf_b:2 14\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:hot_a:3;repro.py:leaf_b:-1 7\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:hot_b:4;repro.py:leaf_a:-1 4\ntid:12252325;...;repro.py:\u003cmodule>:5;repro.py:hot_a:3;repro.py:leaf_b:2 2\ntid:12252325;...;repro.py:\u003cmodule>:5;repro.py:hot_b:4;repro.py:leaf_a:1 2\n```\n\nOrphans:\n\n```\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:leaf_b:2 464\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:leaf_a:1 462\ntid:12252325;...;repro.py:\u003cmodule>:5;repro.py:leaf_b:2 1\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:leaf_a:-1 1\n```\n\nWrong lines:\n\n```\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:hot_a:-1;repro.py:leaf_a:1 7\ntid:12252325;...;repro.py:\u003cmodule>:6;repro.py:hot_b:-1;repro.py:leaf_b:2 4\ntid:12252325;...;repro.py:\u003cmodule>:5;repro.py:hot_b:4;repro.py:leaf_b:2 4\ntid:12252325;...;repro.py:\u003cmodule>:5;repro.py:hot_a:3;repro.py:leaf_a:1 1\n```\n\nVery important caveat here is that it's just 1 level deep, there are no generators etc.,\n\n# Isolation to `cache_frames=True`\n\n```patch\ndiff --git i/Lib/profiling/sampling/sample.py w/Lib/profiling/sampling/sample.py\nindex 50ccc57566d..16de26b2dc5 100644\n--- i/Lib/profiling/sampling/sample.py\n+++ w/Lib/profiling/sampling/sample.py\n@@ -110,7 +110,7 @@ def _new_unwinder(self, native, gc, opcodes, skip_non_matching_threads):\n gc=gc,\n opcodes=opcodes,\n skip_non_matching_threads=skip_non_matching_threads,\n- cache_frames=True,\n+ cache_frames=os.environ.get(\"PROFILING_CACHE_FRAMES\", \"1\") != \"0\",\n stats=self.collect_stats,\n **kwargs\n )\n```\n\n```bash\n2026-06-13T02:57:07.911742000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main f4f1020*?) % sudo PROFILING_CACHE_FRAMES=0\n./python.exe -m profiling.sampling run --collapsed -o /tmp/stacks.txt -d 10 repro.py\nCaptured 10,000 samples in 10.00 seconds\nSample rate: 999.99 samples/sec\nError rate: 15.09\nCollapsed stack output written to /tmp/stacks.txt\n2026-06-13T02:57:18.021250000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main f4f1020*?) % cat /tmp/stacks.txt\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:4;repro.py:leaf_b:2 3337\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:3;repro.py:leaf_a:1 3257\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6 1264\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:3 332\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:4 282\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_a:3;repro.py:leaf_a:-1 9\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:4;repro.py:leaf_b:-1 5\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:5 2\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:leaf_b:2 2\ntid:13147584;\u003cfrozen runpy>:_run_module_as_main:201;\u003cfrozen runpy>:_run_code:87;repro.py:\u003cmodule>:6;repro.py:hot_b:4;repro.py:leaf_a:1 1\n```\n\n...so now it's only 0,20% impossible stack traces (leaving figuring out which as a trivial excercise to the reader.) \n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-151426\n* gh-151459\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/maurycy","@type":"Person","name":"maurycy"},"datePublished":"2026-06-13T01:06:34Z","url":"https://github.com/python/cpython/issues/151424"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f050d62c-54b4-b711-5a2b-3c913c4df16a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C9A6:153FFA:40FE68:556867:6B023AC4 |
| html-safe-nonce | 521c38d8c4d59687db3896515aded80e7c2a7b4997d2ef465eb140b9649a21bf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUE2OjE1M0ZGQTo0MEZFNjg6NTU2ODY3OjZCMDIzQUM0IiwidmlzaXRvcl9pZCI6Ijg3NjkyNjAyNzU5NTEwOTAzNzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 003775cf7e3ef1d136c875618cc0f63f196d230194123538e95a9bcd483b5f03 |
| hovercard-subject-tag | issue:4653682823 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/151424/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a79a5241c679ca25a46935982efe4e16a371c06fa567f0108f58d79d0759c750/python/cpython/issues/151424 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a79a5241c679ca25a46935982efe4e16a371c06fa567f0108f58d79d0759c750/python/cpython/issues/151424 |
| og:image:alt | Bug report Bug description: Basically, when profiling with Tachyon I'm seeing stack traces that are just impossible. Truth to be told, this is an absolutely pathological script with completely unst... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | maurycy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width