Title: JIT: assertion failure in pycore_backoff.h · Issue #141786 · python/cpython · GitHub
Open Graph Title: JIT: assertion failure in pycore_backoff.h · Issue #141786 · python/cpython
X Title: JIT: assertion failure in pycore_backoff.h · Issue #141786 · python/cpython
Description: Crash report What happened? It's possible to trigger an assertion failure in a patched (diff follows) JIT build by running the code below. It's a finicky issue to reproduce, so the MRE isn't as compact as I'd like and requires a special ...
Open Graph Description: Crash report What happened? It's possible to trigger an assertion failure in a patched (diff follows) JIT build by running the code below. It's a finicky issue to reproduce, so the MRE isn't as com...
X Description: Crash report What happened? It's possible to trigger an assertion failure in a patched (diff follows) JIT build by running the code below. It's a finicky issue to reproduce, so the MRE isn&...
Opengraph URL: https://github.com/python/cpython/issues/141786
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"JIT: assertion failure in pycore_backoff.h","articleBody":"# Crash report\n\n### What happened?\n\nIt's possible to trigger an assertion failure in a patched (diff follows) JIT build by running the code below. It's a finicky issue to reproduce, so the MRE isn't as compact as I'd like and requires a special environment, but changing minor details stops reproducing the abort.\n\nTo prepare the environment, run:\n```sh\n# Create a venv, then:\ngit clone https://github.com/devdanzin/lafleur.git\ngit clone https://github.com/devdanzin/fusil.git\npip install -e lafleur\npip install -e fusil\n```\n\nAlso, the way the script is invoked interferes with reproduction: calling it with `python`inside the active venv or with `path/to/venv/bin/python` works, while `path/to/built/python` doesn't work.\n\nGiven the sensitivity of the MRE to small changes, please let me know whether you can reproduce this issue.\n\nThe diff applied was (it might be possible to reduce this diff and keep reproducing):\n```diff\ndiff --git a/Include/internal/pycore_backoff.h b/Include/internal/pycore_backoff.h\nindex 71066f1bd9f..e4a31f76ff2 100644\n--- a/Include/internal/pycore_backoff.h\n+++ b/Include/internal/pycore_backoff.h\n@@ -112,8 +112,8 @@ trigger_backoff_counter(void)\n // For example, 4095 does not work for the nqueens benchmark on pyperformance\n // as we always end up tracing the loop iteration's\n // exhaustion iteration. Which aborts our current tracer.\n-#define JUMP_BACKWARD_INITIAL_VALUE 4000\n-#define JUMP_BACKWARD_INITIAL_BACKOFF 12\n+#define JUMP_BACKWARD_INITIAL_VALUE 63\n+#define JUMP_BACKWARD_INITIAL_BACKOFF 6\n static inline _Py_BackoffCounter\n initial_jump_backoff_counter(void)\n {\n@@ -125,8 +125,8 @@ initial_jump_backoff_counter(void)\n * Must be larger than ADAPTIVE_COOLDOWN_VALUE,\n * otherwise when a side exit warms up we may construct\n * a new trace before the Tier 1 code has properly re-specialized. */\n-#define SIDE_EXIT_INITIAL_VALUE 4000\n-#define SIDE_EXIT_INITIAL_BACKOFF 12\n+#define SIDE_EXIT_INITIAL_VALUE 63\n+#define SIDE_EXIT_INITIAL_BACKOFF 6\n\n static inline _Py_BackoffCounter\n initial_temperature_backoff_counter(void)\ndiff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h\nindex e7177552cf6..0d76a5a3df0 100644\n--- a/Include/internal/pycore_optimizer.h\n+++ b/Include/internal/pycore_optimizer.h\n@@ -86,7 +86,7 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);\n // Used as the threshold to trigger executor invalidation when\n // executor_creation_counter is greater than this value.\n // This value is arbitrary and was not optimized.\n-#define JIT_CLEANUP_THRESHOLD 1000\n+#define JIT_CLEANUP_THRESHOLD 10000\n\n int _Py_uop_analyze_and_optimize(\n PyFunctionObject *func,\n@@ -118,7 +118,7 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)\n }\n\n // Holds locals, stack, locals, stack ... co_consts (in that order)\n-#define MAX_ABSTRACT_INTERP_SIZE 4096\n+#define MAX_ABSTRACT_INTERP_SIZE 8192\n\n #define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)\n\n@@ -129,7 +129,7 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)\n // progress (and inserting a new ENTER_EXECUTOR instruction). In practice, this\n // is the \"maximum amount of polymorphism\" that an isolated trace tree can\n // handle before rejoining the rest of the program.\n-#define MAX_CHAIN_DEPTH 4\n+#define MAX_CHAIN_DEPTH 16\n\n /* Symbols */\n /* See explanation in optimizer_symbols.c */\ndiff --git a/Python/optimizer.c b/Python/optimizer.c\nindex 9db894f0bf0..14cbf670dec 100644\n--- a/Python/optimizer.c\n+++ b/Python/optimizer.c\n@@ -509,7 +509,7 @@ guard_ip_uop[MAX_UOP_ID + 1] = {\n\n\n #define CONFIDENCE_RANGE 1000\n-#define CONFIDENCE_CUTOFF 333\n+#define CONFIDENCE_CUTOFF 100\n\n #ifdef Py_DEBUG\n #define DPRINTF(level, ...) \\\n ```\n \n\nThe admitedly large, but much reduced, MRE is:\n```python\nimport builtins\nimport gc\nimport math # Not used\n\n\ndef g():\n gc.set_threshold(5)\n original_len = builtins.len\n try:\n builtins.len = lambda x: 'evil_string'\n _ = len([])\n except Exception:\n pass\n finally:\n builtins.len = original_len\n\nTHRESHOLD = 300\n\ndef f1():\n\n class Base1:\n def __init__(self):\n pass\n\n class Sub1(Base1):\n def __init__(self):\n super().__init__()\n def f(self):\n super().f()\n if False:\n Sub1.__bases__ = (object,)\n\n instance_1 = Sub1()\n for _ in range(THRESHOLD):\n try:\n _ = instance_1.f()\n except AttributeError:\n pass\n Sub1.__bases__ = (object,)\n\n g()\n\n\n class Dummy1:\n def __init__(self):\n pass\n def f(self):\n pass\n\n class Sub2(Base1):\n def __init__(self):\n super().__init__()\n def f(self):\n super().f()\n if False:\n Sub2.__bases__ = (object,)\n\n instance_2 = Sub2()\n for _ in range(THRESHOLD):\n try:\n _ = instance_2.f()\n except AttributeError:\n pass\n Sub2.__bases__ = (object,)\n\n class Base2:\n def __init__(self):\n pass\n def f(self):\n pass\n\n class Dummy2:\n def __init__(self):\n pass\n def f(self):\n pass\n\n class Sub4(Base1):\n def __init__(self):\n super().__init__()\n def f(self):\n super().f()\n if False:\n Sub4.__bases__ = (object,)\n\n instance_4 = Sub4()\n for _ in range(THRESHOLD):\n try:\n _ = instance_4.f()\n except AttributeError:\n pass\n Sub4.__bases__ = (object,)\n\n class Sub3(Base2):\n def __init__(self):\n pass\n def f(self):\n super().f()\n if self.non_existing_attribute:\n Sub3.__bases__ = (object,)\n\n\n instance_3 = Sub3()\n for _ in range(THRESHOLD):\n try:\n _ = instance_3.f()\n except AttributeError:\n pass\n Sub3.__bases__ = (object,)\n for _ in range(50):\n try:\n _ = instance_3.f()\n except AttributeError:\n pass\n\nfor i_f1 in range(300):\n print(i_f1)\n f1()\n```\n\nThe backtrace (with printing of iteration number) is:\n```\n1\n[...]\n64\n65\npython: ./Include/internal/pycore_backoff.h:65: _Py_BackoffCounter restart_backoff_counter(_Py_BackoffCounter): Assertion `!is_unreachable_backoff_counter(counter)' failed.\n\nProgram received signal SIGABRT, Aborted.\n\n#0 __pthread_kill_implementation (threadid=\u003coptimized out>, signo=6, no_tid=0) at ./nptl/pthread_kill.c:44\n#1 __pthread_kill_internal (threadid=\u003coptimized out>, signo=6) at ./nptl/pthread_kill.c:89\n#2 __GI___pthread_kill (threadid=\u003coptimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:100\n#3 0x00007ffff7c45e2e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26\n#4 0x00007ffff7c28888 in __GI_abort () at ./stdlib/abort.c:77\n#5 0x00007ffff7c287f0 in __assert_fail_base (fmt=\u003coptimized out>, assertion=\u003coptimized out>, file=\u003coptimized out>, line=\u003coptimized out>, function=\u003coptimized out>) at ./assert/assert.c:118\n#6 0x00007ffff7c3c19f in __assert_fail (assertion=\u003coptimized out>, file=\u003coptimized out>, line=\u003coptimized out>, function=\u003coptimized out>) at ./assert/assert.c:127\n#7 0x0000555555ec14c5 in restart_backoff_counter (counter=...) at ./Include/internal/pycore_backoff.h:65\n#8 0x0000555555ec14c5 in stop_tracing_and_jit (tstate=0x555556aebf00 \u003c_PyRuntime+358560>, frame=frame@entry=0x7e8ff6de5298)\n#9 0x0000555555e6e4f3 in _PyEval_EvalFrameDefault (tstate=\u003coptimized out>, frame=\u003coptimized out>, throwflag=\u003coptimized out>) at Python/generated_cases.c.h:11712\n#10 0x0000555555e4a67b in _PyEval_EvalFrame (tstate=0x555556aebf00 \u003c_PyRuntime+358560>, frame=0x7e8ff6de5220, throwflag=0) at ./Include/internal/pycore_ceval.h:121\n#11 _PyEval_Vector (tstate=\u003coptimized out>, func=\u003coptimized out>, locals=\u003coptimized out>, args=\u003coptimized out>, argcount=\u003coptimized out>, kwnames=0x0) at Python/ceval.c:2159\n#12 0x0000555555e4a095 in PyEval_EvalCode (co=\u003coptimized out>, globals=\u003coptimized out>, locals=0x7c7ff6e871c0) at Python/ceval.c:995\n#13 0x00005555561bbc6f in run_eval_code_obj (tstate=tstate@entry=0x555556aebf00 \u003c_PyRuntime+358560>, co=co@entry=0x7d2ff6e36c10, globals=globals@entry=0x7c7ff6e871c0,\n locals=locals@entry=0x7c7ff6e871c0) at Python/pythonrun.c:1372\n#14 0x00005555561bae3c in run_mod (mod=\u003coptimized out>, filename=\u003coptimized out>, globals=\u003coptimized out>, locals=\u003coptimized out>, flags=\u003coptimized out>, arena=\u003coptimized out>,\n interactive_src=\u003coptimized out>, generate_new_source=\u003coptimized out>) at Python/pythonrun.c:1475\n```\n\nOutput from running with `PYTHON_LLTRACE=4`:\n[89_abort_lltrace.txt](https://github.com/user-attachments/files/23653742/89_abort_lltrace.txt)\n\nOutput from running with `PYTHON_OPT_DEBUG=4`:\n[89_abort_opt_debug.txt](https://github.com/user-attachments/files/23653741/89_abort_opt_debug.txt)\n\nSorry for the convoluted repro steps, I've been trying to make it work with a simpler setup for many days, without success. \n\nFound using [lafleur](https://github.com/devdanzin/lafleur/).\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.15.0a2+ (heads/main-dirty:41b9ad5b38e, Nov 20 2025, 08:38:13) [Clang 21.1.2 (2ubuntu6)]\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-142286\n* gh-142344\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2025-11-20T13:01:16Z","url":"https://github.com/python/cpython/issues/141786"}
| 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:e659ca45-f165-e311-c417-ab9214d3d8fe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 85E0:293912:5F76C9:7D3FBE:6B02471F |
| html-safe-nonce | f23289d227d8ce0dbddd9dff893922e09b5fc597d5d781de699da688cfab89af |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUUwOjI5MzkxMjo1Rjc2Qzk6N0QzRkJFOjZCMDI0NzFGIiwidmlzaXRvcl9pZCI6IjYyNDAxNDg1MjQzNDA3NTgzMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 71bc1169dd3f711fa3e527730f9b59955dc84ad17f9f7572605423d226fe8979 |
| hovercard-subject-tag | issue:3647194772 |
| 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/141786/issue_layout |
| twitter:image | https://opengraph.githubassets.com/665d4c807986af7132fcaaca31372b94b81749197e9f7bc72b0ecadb8acbae81/python/cpython/issues/141786 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/665d4c807986af7132fcaaca31372b94b81749197e9f7bc72b0ecadb8acbae81/python/cpython/issues/141786 |
| og:image:alt | Crash report What happened? It's possible to trigger an assertion failure in a patched (diff follows) JIT build by running the code below. It's a finicky issue to reproduce, so the MRE isn't as com... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devdanzin |
| 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