Skip to content

Resume a fiber whose captured async context can no longer be entered - #11013

Open
dv-waynehaffenden wants to merge 1 commit into
Effect-TS:mainfrom
dv-waynehaffenden:fix/fiber-unenterable-async-context
Open

dv-waynehaffenden wants to merge 1 commit into
Effect-TS:mainfrom
dv-waynehaffenden:fix/fiber-unenterable-async-context

Conversation

@dv-waynehaffenden

Copy link
Copy Markdown
Contributor

Fibers capture an AsyncResource when they suspend and resume inside it with runInAsyncScope. Cloudflare Workers (workerd) ties an async context to the request that created it, and refuses to enter it from a later request:

Cannot call this AsyncLocalStorage bound function outside of the request in which it was created.

A ManagedRuntime built while serving one request keeps its long-lived fibers, so any of them resumed by a later request throws while resuming. OtlpExporter's export loop is one: its export fails with this error, it disables itself, and telemetry from every later request (and every Durable Object alarm) is lost.

This resumes the fiber without its captured context when entering it fails before the fiber's code runs. An error raised once the context has been entered still propagates, and propagation within a single request is unchanged.

The test stubs node:async_hooks with an AsyncResource whose runInAsyncScope throws, re-imports effect, and checks a fiber that suspends still resumes. Without the change it never resumes and times out.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e55b39f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-amazon-bedrock Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/chat-discord Patch
@effect/chat-slack Patch
@effect/chat-teams Patch
@effect/chat-telegram Patch
@effect/chat-whatsapp Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-cloudflare Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Nov 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 40.29 KB 40.28 KB +0.01 KB (+0.03%)
basic.ts 6.62 KB 6.60 KB +0.02 KB (+0.29%)
batching.ts 11.67 KB 11.65 KB +0.02 KB (+0.14%)
brand.ts 7.17 KB 7.17 KB 0.00 KB (0.00%)
cache.ts 11.84 KB 11.83 KB +0.01 KB (+0.11%)
config.ts 23.76 KB 23.75 KB +0.02 KB (+0.07%)
differ.ts 22.57 KB 22.55 KB +0.02 KB (+0.07%)
http-client.ts 28.42 KB 28.40 KB +0.02 KB (+0.06%)
http-router.ts 39.12 KB 39.10 KB +0.02 KB (+0.05%)
logger.ts 12.27 KB 12.26 KB +0.01 KB (+0.11%)
metric.ts 9.93 KB 9.91 KB +0.02 KB (+0.18%)
optic.ts 7.43 KB 7.43 KB 0.00 KB (0.00%)
pubsub.ts 16.57 KB 16.55 KB +0.01 KB (+0.08%)
queue.ts 13.46 KB 13.44 KB +0.01 KB (+0.10%)
schedule.ts 12.29 KB 12.27 KB +0.02 KB (+0.13%)
schema-bigdecimal.ts 14.34 KB 14.32 KB +0.01 KB (+0.09%)
schema-binary.ts 43.18 KB 43.17 KB +0.01 KB (+0.02%)
schema-class.ts 22.33 KB 22.31 KB +0.01 KB (+0.05%)
schema-codegen.ts 33.69 KB 33.66 KB +0.02 KB (+0.07%)
schema-fromJsonSchemaDocument.ts 30.77 KB 30.76 KB +0.01 KB (+0.04%)
schema-representation-roundtrip.ts 28.50 KB 28.49 KB +0.01 KB (+0.04%)
schema-string-transformation.ts 16.07 KB 16.06 KB +0.01 KB (+0.09%)
schema-string.ts 12.62 KB 12.60 KB +0.01 KB (+0.11%)
schema-template-literal.ts 16.64 KB 16.62 KB +0.01 KB (+0.08%)
schema-toArbitrary.ts 39.83 KB 39.82 KB +0.01 KB (+0.03%)
schema-toCodecJson.ts 21.46 KB 21.44 KB +0.01 KB (+0.07%)
schema-toEquivalence.ts 21.63 KB 21.62 KB +0.01 KB (+0.05%)
schema-toFormatter.ts 21.72 KB 21.71 KB +0.01 KB (+0.07%)
schema-toJsonSchemaDocument.ts 26.76 KB 26.75 KB +0.01 KB (+0.06%)
schema-toRepresentation.ts 21.78 KB 21.77 KB +0.01 KB (+0.06%)
schema.ts 21.42 KB 21.41 KB +0.01 KB (+0.07%)
stm.ts 14.79 KB 14.77 KB +0.01 KB (+0.09%)
stream.ts 10.58 KB 10.56 KB +0.01 KB (+0.14%)
supervisor.ts 11.86 KB 11.85 KB +0.02 KB (+0.14%)

This branch is waiting to be deployed

1 waiting deployment
fork — e55b39fa Waiting Nov 27, 2026 by dv-waynehaffenden via approval-gate #27809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant