Repository navigation
fix(runtime): let the v2 runtime start on Cloudflare Workers - #7609
Merged
Merged
Conversation
The v2 runtime imported its own package.json for the version string. The bundler compiles a JSON import into a CommonJS wrapper, and that wrapper imports the shared helper module, which runs createRequire(import.meta.url) at load. Cloudflare Workers leave import.meta.url undefined, so the Worker failed to start before it served a request. The version is now a build-time constant: tsdown and vitest define it. Source that runs with neither (the ts-node schema generator) gets a placeholder. The packed-runtime check now asserts that VERSION matches package.json in both published formats, so a build without the define cannot ship. Refs #6919 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A new check-dts validator walks each ESM entry's eager module graph and fails on a createRequire(import.meta.url) call that runs at module load. Cloudflare Workers leave import.meta.url undefined, so such a call stops the Worker from starting. A call inside a function, such as the lazy Express loader, is allowed. The v1 root is exempt: its deprecated service adapters need the bundler's require helper, and it is not a Workers target. The graph walk is shared with validate-optional-peer-entries.ts, which now exports it. On the build before the previous commit, the validator reports all four v2 entries. Refs #6919 Co-Authored-By: Claude Opus 5.5 <[email protected]>
An agent generates a thread ID when it is constructed, and Workers forbid random values in global scope, so a module-scope agent stops the Worker from starting. The callout names the error and shows the agents factory form, which lets the runtime itself live at module scope. Refs #6919 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (13)
✨ 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 |
Contributor
Production Digest-Pinning AuditAll 42 services digest-pinned. Run 2026-10-03 16:26:57 PDT — 0 finding(s). |
Contributor
|
Size Change: 0 B Total Size: 1.77 MB ℹ️ View Unchanged
|
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/intelligence-langgraph
@copilotkit/intelligence-mastra
@copilotkit/learning
@copilotkit/mcp-apps-renderer
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
The check-dts cache inputs listed the other three validators but not the new one, so an edit to it could replay a cached pass without running. Refs #6919 Co-Authored-By: Claude Opus 5.5 <[email protected]>
BenTaylorDev
added a commit
that referenced
this pull request
Oct 5, 2026
…policy error (#7612) Refs #5930. This does not implement the per-tool filter. It corrects the error that #6292 added for it. ## Problem Setting `includeTools` or `excludeTools` on an `mcpApps.servers` entry raises a configuration error. That error says `@ag-ui/[email protected]` owns per-server tool policy. The runtime moved to `^0.1.0` in 8454999 and now depends on `^0.1.1` (`packages/runtime/package.json`). The `McpAppsServerConfig` doc comment and the docs page `backend/copilot-runtime.mdx` also name `0.0.3`. ## Change The error, the doc comment and the docs sentence now refer to "the release the runtime depends on" instead of a version number. A hard-coded number goes stale at every bump, and reading the installed version at runtime would mean a JSON import, which #7609 removes from the v2 runtime for Cloudflare Workers. The error still names the package, the offending key and server, and links #5930. Example message: ``` Unsupported MCP Apps tool policy: includeTools at server[0] (weather). @ag-ui/mcp-apps-middleware owns per-server tool policy, and the release the runtime depends on does not support these keys; see #5930. ``` The docs page also told readers to "use a compatible middleware release" once the upstream policy exists. That advice could not work, because the runtime rejects the keys whatever middleware is installed. The second commit says the runtime has to adopt the policy first and links #5930. Not changed: `packages/runtime-dotnet/src/McpAppsAgent.cs:20` mentions "MCP Apps middleware 0.0.3 HTTP config hashing". That comment is about the hashing scheme, which 0.1.1 keeps, and it lives in the .NET runtime. Not changed: `showcase/shell-docs/src/content/doctest.json` pins `@ag-ui/[email protected]` alongside `@copilotkit/[email protected]`. That pin is a matched set for compiling doc snippets, not a statement about the current runtime. ## Testing - `mcp-apps-servers.test.ts` asserts the new wording. Run against the **old** source, it fails: ``` Tests 6 failed | 4 passed (10) ``` On this branch: ``` Tests 10 passed (10) ``` - `vitest run` in `packages/runtime` (full suite): 194 files, 2803 tests, all pass. - `nx run @copilotkit/runtime:check-types --skip-nx-cache`: pass. - `oxfmt` on the changed files: clean. - The pre-commit hook (`lint-fix`, `test`, `publint`, `attw` on affected projects): pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BenTaylorDev
marked this pull request as ready for review
October 5, 2026 05:02
BenTaylorDev
requested review from
jpr5,
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
October 5, 2026 05:02
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.
Refs #6919. This fixes the first of the two Cloudflare Workers blockers that remain open on the issue. The second blocker belongs upstream, and this PR documents its workaround.
Problem
On
@copilotkit/[email protected], a Worker that imports@copilotkit/runtime/v2fails to start:The v2 runtime imported its own
package.jsonto read the version string (runtime.ts,telemetry-client.ts). tsdown compiles a JSON import into a CommonJS wrapper. That wrapper imports the shared helper moduledist/_virtual/_rolldown/runtime.mjs, which runscreateRequire(import.meta.url)at load. Workers leaveimport.meta.urlundefined. Until now, users had to add adefineforimport.meta.urlto theirwrangler.json.Changes
package-info.tsreplaces both JSON imports with constants. tsdown and vitest inject the version withdefine. Code that runs the source without the define (the ts-node GraphQL schema generator) gets the placeholder0.0.0-unbuilt. As a side effect,package.jsonno longer reaches the v2 graph.scripts/validate-module-scope-create-require.tsruns in the runtime'scheck-dts. It walks the eager module graph of each ESM entry, using the walker now exported fromvalidate-optional-peer-entries.ts. It fails on acreateRequire(import.meta.url)call that runs at load. A call inside a function, such asloadExpress, is allowed. The v1 root (.) is exempt: its deprecated adapters need the helper, and it is not a Workers target.nx.jsonadds the validator to thecheck-dtscache inputs, so editing it re-runs the check.verify-runtime-package.tsnow checks that the packed runtime'sVERSIONequalspackage.json, through bothrequireandimport. A build that loses thedefinetherefore cannot ship the placeholder.AbstractAgentconstructor generates a UUID. The callout shows theagents: () => ({...})factory form as the alternative.Not in this PR
Blocker 2 at its source. The UUID is generated in the upstream
@ag-ui/clientconstructor. The fix there is to createthreadIdlazily. It needs its own ag-ui PR.@copilotkit/channels-core.create-channel.tsalso callscreateRequire(import.meta.url)at top level. No v2 entry reaches it, and it is not in the Worker bundle (checked below), so it does not block this repro.Dependencies are outside the validator's walk. It follows only the runtime's own files. A load-time
createRequireinside a dependency such as@copilotkit/sharedwould pass it.sharedemits plain ESM today, with nocreateRequire.Testing
Real Worker, before and after. The repro is the issue's own Worker: wrangler 4.147.0,
nodejs_compat, noimport.meta.urldefine,CopilotRuntimeat module scope with anagentsfactory, andcreateCopilotHonoHandler.On published 1.77.0:
On this branch (
pnpm pack, installed into the same project):In the
wrangler deploy --dry-runbundle of 1.77.0,createRequire(import.meta.url)occurs once, from@copilotkit/runtime/dist/_virtual/_rolldown/runtime.mjs. No@copilotkit/channels-*module is in the bundle.The docs callout, checked in the same Worker on this branch:
agents: () => ({ default: new BuiltInAgent(...) })at module scope:/info200.agents: { default: new BuiltInAgent(...) }at module scope:Uncaught Error: Disallowed operation called within global scope, thrownin BuiltInAgent.new StubAgent({ threadId: "default" })at module scope also starts, because an explicitthreadIdskips the UUID.Validator against the unfixed source. I reverted
runtime.tsandtelemetry-client.ts, rebuilt, and ran the validator:On this branch:
Version assertion against a build without the
define:On this branch:
Mutation checks on the validator tests:
import.meta.urlmatch fails 4 of 10 tests.A mutation check also showed that an earlier separate parameter-default rule was dead code, so I removed it. Skipping the function node already skips its parameters.
Package gates:
nx run @copilotkit/runtime:build: pass.nx run @copilotkit/runtime:check-types: pass.nx run @copilotkit/runtime:test: 194 files, 2803 tests, all pass.vitest runon both validator test files: 26 tests, all pass.oxlinton the changed files: 0 warnings, 0 errors.oxfmt --check: clean.test,publint,attwon affected projects): pass.🤖 Generated with Claude Code