fix: #775 — emit shim note when async_hooks is imported#787
Merged
Conversation
The `node:async_hooks` stub added in PR #754 is structural: it gives NestJS bootstrap enough shape (`AsyncResource`, `AsyncLocalStorage`, `executionAsyncId`, `createHook`) to compile, but does NOT track async context across `await` / `setImmediate` / `process.nextTick`. Anything that relies on `AsyncLocalStorage` for context propagation — Sentry request scopes, OpenTelemetry trace propagation, NestJS request-scoped providers, pino child loggers — compiles, runs, and silently loses context. Mirror the reflect-metadata 2a mitigation: emit a one-shot `[perry] note:` to stderr at compile time when `async_hooks` (or `node:async_hooks`) is imported, listing the implemented surface and the silent-failure boundary. Same `AtomicBool::swap` pattern as `emit_reflect_metadata_shim_note()`. Unlike reflect-metadata, the import still falls through so `AsyncLocalStorage` / `AsyncResource` keep binding against the structural stub.
This was referenced May 15, 2026
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.
Summary
Closes #775.
The
node:async_hooksstub added in #754 is structural — it providesAsyncResource,AsyncLocalStorage,executionAsyncId, andcreateHookshapes so NestJS bootstrap compiles, but it does not track async context acrossawait/setImmediate/process.nextTick. Anything that relies onAsyncLocalStoragefor context propagation (Sentry request scopes, OpenTelemetry trace propagation, NestJS request-scoped providers, pino child loggers) compiles, runs, and silently loses context.This PR mirrors the reflect-metadata 2a mitigation: a one-shot
[perry] note:to stderr at compile time whenasync_hooks(ornode:async_hooks) is imported.emit_async_hooks_shim_note()in crates/perry-hir/src/lower.rs, sameAtomicBool::swapone-shot pattern asemit_reflect_metadata_shim_note().lower_module_declnext to the reflect-metadata branch. Source is already normalized to strip thenode:prefix, so a singlesource == "async_hooks"check covers both spellings.return Ok(())) — the import still needs to bindAsyncLocalStorage/AsyncResourceagainst the existing structural stub.Real async-context tracking via tokio
task_local!(or via Perry's promise/microtask scheduler) is the proper long-term fix; this is the minimum-viable mitigation so the silent-failure surface doesn't grow.Test plan
cargo build --release -p perry-hir— clean.cargo build --release -p perry— clean.import { AsyncLocalStorage } from "node:async_hooks"and confirmed the[perry] note: ...line prints once to stderr during the compile.lint,cargo-test,parity,compile-smoke,api-docs-drift,security-audit.