#4062·Nuitka

Compiled coroutine drops the original exception traceback when awaiting a pending asyncio task

Author: h3harCreated Sep 24, 2026Updated Oct 1, 2026

Bug description

When a compiled coroutine awaits a pending asyncio.Task that raises an exception, the exception propagates to the caller but loses the traceback frame where it was originally raised. The equivalent interpreted coroutine preserves that frame.

This reproduces with Nuitka 4.2, 4.2.1, and develop at commit 4506e7927f39e4c58146ee5906c8f10c579f1729 (4.3rc3). The reproducer uses only the Python standard library at runtime.

Environment

  • OS: Windows 11, x86-64.
  • Python: official CPython 3.14.5, 3.14.5 (tags/v3.14.5:5607950, May 10 2026, 10:43:50) [MSC v.1944 64 bit (AMD64)], GIL enabled.
  • C compiler: MSVC 14.3, selected with --msvc=latest.
  • Nuitka: installed into isolated environments using uv run --with, with PyPI versions for 4.2 and 4.2.1 and the GitHub source archive for the develop revision.
  • Compilation mode: --module; only waiter.py is compiled. The driver remains interpreted.

Minimal reproducer

Save these two files in the same directory.

waiter.py:

python
import asyncio


async def wait(task: asyncio.Task[None]):
    await task

repro.py:

python
import asyncio
import traceback

from waiter import wait


async def origin():
    raise RuntimeError('original error')


async def main():
    task = asyncio.create_task(origin())
    try:
        await wait(task)
    except RuntimeError as exc:
        names = [frame.name for frame in traceback.extract_tb(exc.__traceback__)]
        print(names)
        assert 'origin' in names, 'The original exception traceback was lost'


asyncio.run(main())

Run the interpreted control from that directory:

powershell
uv run --no-project --python 3.14.5 python repro.py

Compile the wrapper, then run the same driver with the compiled module first on the import path:

powershell
uv run --no-project --python 3.14.5 --with Nuitka==4.2.1 python -m nuitka --module --msvc=latest --output-dir=compiled.build waiter.py
uv run --no-project --python 3.14.5 python -c "import sys; sys.path.insert(0, 'compiled.build'); import repro"

The output directory keeps the compiled module separate from the source, so the interpreted control can still be run afterward.

Expected behavior

Both runs should print the original raise location among the traceback frames and exit successfully, as the interpreted control does:

['main', 'wait', 'origin']

Actual behavior

The compiled run prints:

['main', 'wait']

It then exits with code 1 and AssertionError: The original exception traceback was lost. The RuntimeError shown as the assertion's context also lacks the origin frame.

The reproducer inspects the exception's __traceback__ directly; the missing frame is already absent before formatting or logging.

Await wrapper Observed frames Exit code
Interpreted Python main, wait, origin 0
Nuitka 4.2 main, wait 1
Nuitka 4.2.1 main, wait 1
Develop, 4.3rc3, commit 4506e7927f39e4c58146ee5906c8f10c579f1729 main, wait 1

The develop build was tested using:

powershell
uv run --no-project --python 3.14.5 --with https://github.com/Nuitka/Nuitka/archive/4506e7927f39e4c58146ee5906c8f10c579f1729.zip python -m nuitka --module --msvc=latest --output-dir=develop.build waiter.py
uv run --no-project --python 3.14.5 python -c "import sys; sys.path.insert(0, 'develop.build'); import repro"

Additional observation

Inserting await asyncio.wait([task]) immediately after task creation makes the develop build preserve origin and pass the assertion. That call waits for completion without propagating the task's exception, so the compiled wrapper subsequently awaits an already-finished task. This suggests the loss occurs when the compiled coroutine resumes from a suspended await.

Related issue

I searched open and closed issues and found #3878, concerning exception-state preservation during async logging. That issue was reported fixed in 4.1.1.

This reproducer has no exception handler in the compiled coroutine and still fails on 4.2.1 and the develop revision above. I am referencing #3878 for context rather than assuming the same underlying cause.

I have not established the first affected Nuitka version or tested other Python versions or operating systems.