Repository navigation
docs(async): record the to_thread worker-exception seam (#400) - #1382
Merged
Merged
Conversation
`asyncio.to_thread` lowers to a synthesized coroutine frame (issue #400, merged in #1352), so `create_task`, `gather` and `wait_for` take it. The value path is byte-identical to CPython 3.14, but the worker record carries the result value and a done flag and no exception slot, so a raise inside the worker does not reach the awaiter: CPython hands the exception to the awaiting task and the `except` clause runs, while the lowered program prints the exception on stderr and exits 1. Divergence 100 records that seam, with a probe that pins both sides' bytes, so the numbered list keeps its promise that anything unlisted is identical. The ledger generator also drifted from the numbered list: it carried a duplicate D93 and D94 and no D97, so regenerating it dropped the D97 row and renumbered D98 and D99 onto D93 and D94. The rows are fixed to their numbered entries, the missing D97 row is added, and D97's status moves from the off-vocabulary "differs" to "divergent".
Deploying pyscriptc with
|
| Latest commit: |
73da59b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9b3b24d4.pyscriptc.pages.dev |
| Branch Preview URL: | https://work-400-to-thread-frame.pyscriptc.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #400
Summary
The implementation for this issue landed upstream in #1352 (
feat(async): lower asyncio.to_thread as a synthesized coroutine frame, commitc0e13d59), which is already on master. This PR closes the remaining gap: the user-facing divergence entry and the ledger row for the seam the frame lowering leaves open.asyncio.to_thread(...)lowers to a synthesized coroutine frame (coro.ps_to_thread_<digest>), the same shapeasync deflowers to, socreate_task,gatherandwait_forcompose with it through the existing task machinery. The value path is byte-identical to CPython 3.14 on the host. The worker record (PsThreadCall) carries the result value and a done flag and no exception slot, so an exception raised inside the worker does not reach the awaiter:exceptclause runs, the program continues (exit 0).The numbered divergences list claims that anything unlisted is identical to CPython, so this seam needs an entry. Divergence 100 records it, with a probe that pins both sides' bytes.
The ledger generator drift
scripts/gen_divergence_ledger.pyhad drifted from the numbered list: it carried a duplicateD93(the compare-dispatch row and the subprocess row) and a duplicateD94(the hash row and the argparse row), and no row forD97at all. Regenerating it therefore dropped theD97row and renumbered the compare and hash rows ontoD93andD94, somise run divergence:ledger -- --checkfailed on master and the committed ledger was not reproducible.The rows are fixed to their numbered entries (
D98for the compare dispatch,D99for the hash rules,D93for the subprocess handle,D94for the argparse subparsers), the missingD97row is added, andD97's status moves from the off-vocabularydiffersto the generator'sdivergent.Verification
tests/test_divergence_ledger.py: 77 passed (the ledger replays every row against the pinned CPython and the current compiler).mise run divergence:ledger -- --check: exit 0, the committed ledger is reproducible.uv run pytest tests/test_divergence_ledger.py tests/test_coro_asyncio_sync.py tests/test_probe_guard.py: 108 passed.uv run ruff checkanduv run ruff format --check: clean.uv run pytest tests/ -n auto -m "not linux_container" --ignore=tests/compat2: 4215 passed, 4 failed. The 4 failures reproduce on a clean master checkout and are unrelated to this diff (tests/test_compat_site.pyreads files the sparse checkout leaves out, andtests/test_stdlib_ndarray.py::test_demo_program_matches_cpythonfails on the numpy value shape).mise run checkalso fails ontests/compat2/test_verdict_replay.py::test_macos_arm64_reference_is_a_separate_sloton a clean master checkout: the host runs CPython 3.14.10 and the baseline recording wants 3.14.9.The #400 acceptance criteria were checked against the merged implementation on this branch:
create_task(to_thread(...)),gather(to_thread(...))andwait_for(to_thread(...))compile and run, and their output matches the pinned CPython byte for byte; cancelling a task that wraps ato_threadcall hands the awaiter aCancelledErrorwhile the thread runs to completion, matching CPython; the oldcreate_task takes a coroutine, not another valuefence is gone for the frame case, and the non-frame uses still fence precisely.Owned files
docs/reference/divergences.md,docs/reference/divergence-ledger.json(generated, never hand-merged),scripts/gen_divergence_ledger.py,probes/divergences/d100_to_thread_worker_exception.py,.agents/docs/design/async-lowering-plan.md.