fix(async): linearize await inside an async-generator finally; fix aliased native-class new - #8739
Merged
Conversation
…iased native-class new Lands #8736 and #8738. #8736 (fixes #8715) closes the `finally` analog of the #8681 `await`-in-`catch` deadlock that #8707 fixed. This is the exact gap #8707's own new test surfaced when it was rebased -- it reported "await-in-finally: 2 raw await(s) survived" -- so the two land as a pair. An `await` inside a `finally` of a real `async function*` compiled to a blocking busy-wait rather than an async suspend; the linearizer already splits the finally into its own dispatch states with a `finally_entry_state`, and the async-step driver now routes through them. #8738 (fixes #8730) stops an aliased ESM named import of a Node built-in class throwing `ReferenceError: identifier is not defined` when constructed at module init -- `import { BlockList as Wj4 } from "net"; new Wj4()` and the same shape for `AsyncLocalStorage` and `PassThrough`. `lower_new`'s alias-rewrite block rewrites the callee from the local import name to the class's export name so the construction path matches the un-aliased form that codegen's builtin-`New` dispatch recognizes. This broke the natively-compiled Claude Code cli.js 2.1.112 bundle, which constructs all three at module init, so nearly every command crashed. No version bump.
This was referenced Aug 24, 2026
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe PR fixes async-generator ChangesAsync-generator finally suspension
Aliased native constructor resolution
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant AsyncGenerator
participant __agstep
participant FinallyAwait
Caller->>AsyncGenerator: call .return()
AsyncGenerator->>__agstep: route pending return as non-error resume
__agstep->>FinallyAwait: execute finally state
FinallyAwait-->>__agstep: suspend await on microtask queue
__agstep-->>AsyncGenerator: complete or re-raise pending return
AsyncGenerator-->>Caller: resolve .return()
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Lands #8736 and #8738.
#8736 — linearize
awaitinside an async-generatorfinally(fixes #8715)This closes the
finallyanalog of the #8681await-in-catchdeadlock that #8707 fixed — and it is precisely the gap #8707's own new test surfaced when it was rebased ontomain, which reported:At the time I held #8707 and flagged that resolving it meant deciding whether
finallyshould route through its entry state the waycatchnow does. This is that decision, made properly: the linearizer already splits the finally into its own dispatch states with afinally_entry_state, and the async-step driver now routes through them, so a finallyawaitlowers to a real microtask suspend rather than a blocking busy-wait.async_generator_linearizes_every_await_positionpasses on the merged result — verified explicitly, since that test is what named the gap.#8738 — aliased native-class import
newno longer throws (fixes #8730)An aliased ESM named import of a Node built-in class threw
ReferenceError: identifier is not definedwhen constructed at module init:lower_new's alias-rewrite block rewrites the callee from the local import name to the class's export name, so the construction path matches the un-aliased form that codegen's builtin-Newdispatch recognizes. This broke the natively-compiled Claude Code cli.js 2.1.112 bundle, which constructs all three at module init, so nearly every command crashed with an uncaughtReferenceError.Validation (on the merged result)
lint-job checkers passperry-transform --lib: 93 passed, 0 failedperry-hir --lib: 334 passed, 0 failedperry-runtime --lib(RUST_TEST_THREADS=1): 2669 passed, 0 failedperry-codegen --lib: 1222 passed, 0 failedBoth PRs carried their own
changelog.d/fragments. No version bump.Summary by CodeRabbit
Bug Fixes
awaitis used inside afinallyblock during.return()or early loop termination.BlockList,AsyncLocalStorage, andPassThroughwork correctly.Tests