Skip to content

Add a Cloudflare scheduler for cross-request fibers - #10662

Open
tim-smart wants to merge 2 commits into
v4/next-minorfrom
agent/bob/16dfbfd9703c
Open

tim-smart wants to merge 2 commits into
v4/next-minorfrom
agent/bob/16dfbfd9703c

Conversation

@tim-smart

@tim-smart tim-smart commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add CloudflareScheduler for Worker applications that share fibers across requests. It uses synchronous scheduling and disables native async-context capture. The module documents runner and shared ManagedRuntime installation, plus the async-context, CPU, and request-owned I/O limitations.

A platform-only scheduler could not bypass the unconditional captures in core. After discussing that constraint with Team Lead, this adds the optional Scheduler.preserveAsyncContext flag at both suspension and deferred-fork capture sites. Omission preserves existing behavior; there is no runtime detection or catch-and-retry.

Review follow-up: TestClock forwards the parent scheduler’s context policy. The ManagedRuntime recipe now requires runner options as well as the layer, covering callers waiting on lazy initialization; both review failures were reproduced before fixing them.

Validation

  • 374 tests passed across Effect.test.ts, TestClock.test.ts, and CloudflareScheduler.test.ts, including inherited fork behavior, default native-context propagation, and TestClock forwarding the opt-out.
  • Real cross-request reproduction on workerd 1.20260925.1 with nodejs_compat: restoring capture produces the reported request-bound AsyncLocalStorage error and HTTP 500; the Cloudflare scheduler completes both a shared fiber and lazy ManagedRuntime initialization across requests.
  • pnpm check, pnpm lint-fix, pnpm lint, and pnpm jsdocs --check passed (all via nix develop -c).

The regression uses a test-only Miniflare v5 alias matching the version already used by core and SQL tests. Existing Cloudflare integration tests retain their v4 dependency and API.

Both packages have minor changesets because these are additive stable APIs.

Closes EFF-3794

@changeset-bot

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 029d10a

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

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

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-bot
effect-bot changed the base branch from main to v4/next-minor November 16, 2026 02:06
@effect-janitor effect-janitor Bot added 4.0 and removed 4.0 labels Nov 16, 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.19 KB 40.18 KB +0.01 KB (+0.02%)
basic.ts 7.36 KB 7.35 KB +0.01 KB (+0.12%)
batching.ts 11.32 KB 11.30 KB +0.02 KB (+0.19%)
brand.ts 7.00 KB 7.00 KB 0.00 KB (0.00%)
cache.ts 11.85 KB 11.83 KB +0.02 KB (+0.18%)
config.ts 23.20 KB 23.18 KB +0.02 KB (+0.08%)
differ.ts 22.32 KB 22.30 KB +0.02 KB (+0.08%)
http-client.ts 27.72 KB 27.70 KB +0.02 KB (+0.07%)
http-router.ts 37.71 KB 37.70 KB +0.02 KB (+0.05%)
logger.ts 12.31 KB 12.28 KB +0.02 KB (+0.19%)
metric.ts 9.75 KB 9.74 KB +0.02 KB (+0.17%)
optic.ts 7.21 KB 7.21 KB 0.00 KB (0.00%)
pubsub.ts 16.36 KB 16.34 KB +0.02 KB (+0.15%)
queue.ts 13.23 KB 13.20 KB +0.02 KB (+0.17%)
schedule.ts 12.10 KB 12.07 KB +0.02 KB (+0.17%)
schema-bigdecimal.ts 14.36 KB 14.33 KB +0.02 KB (+0.17%)
schema-binary.ts 42.59 KB 42.58 KB +0.02 KB (+0.04%)
schema-class.ts 22.08 KB 22.06 KB +0.02 KB (+0.09%)
schema-codegen.ts 30.83 KB 30.80 KB +0.03 KB (+0.09%)
schema-fromJsonSchemaDocument.ts 30.69 KB 30.67 KB +0.02 KB (+0.07%)
schema-representation-roundtrip.ts 28.37 KB 28.35 KB +0.02 KB (+0.06%)
schema-string-transformation.ts 15.66 KB 15.64 KB +0.02 KB (+0.14%)
schema-string.ts 12.56 KB 12.53 KB +0.02 KB (+0.19%)
schema-template-literal.ts 16.53 KB 16.51 KB +0.02 KB (+0.13%)
schema-toArbitrary.ts 39.76 KB 39.75 KB +0.02 KB (+0.04%)
schema-toCodecJson.ts 21.23 KB 21.21 KB +0.02 KB (+0.09%)
schema-toEquivalence.ts 21.40 KB 21.38 KB +0.02 KB (+0.09%)
schema-toFormatter.ts 21.49 KB 21.47 KB +0.02 KB (+0.09%)
schema-toJsonSchemaDocument.ts 26.53 KB 26.51 KB +0.02 KB (+0.06%)
schema-toRepresentation.ts 21.56 KB 21.55 KB +0.02 KB (+0.08%)
schema.ts 21.16 KB 21.14 KB +0.02 KB (+0.09%)
stm.ts 14.58 KB 14.56 KB +0.02 KB (+0.14%)
stream.ts 10.68 KB 10.66 KB +0.02 KB (+0.17%)
supervisor.ts 11.63 KB 11.61 KB +0.02 KB (+0.18%)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants