Repository navigation
fix(deps): patch eventsource so Bun stops breaking the runtime integration job - #6334
Merged
Merged
Conversation
@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/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: |
Contributor
|
Size Change: 0 B Total Size: 1.22 MB ℹ️ View Unchanged
|
jpr5
force-pushed
the
fix/lazy-sse-transport-import
branch
from
August 3, 2026 17:27
5456e30 to
c4afe19
Compare
`bun-version: latest` let a Bun release change module-resolution behaviour between runs. 1.3.14 is the version the recent passing and failing runs both resolved, so pin it and make the job reproducible.
eventsource maps its `bun` export condition to the ESM build, and Bun resolves
`bun` before `require`. So a CJS require("eventsource") under Bun receives an
async ESM module and throws "require() async module ... is unsupported". The
package ships a real CJS build behind `require`, but Bun never reaches it.
Two CJS consumers in our graph hit this: the MCP SDK's own dist/cjs/client/sse.js,
and @ag-ui/mcp-apps-middleware, which requires that SDK path unconditionally at
module load. It surfaced as an intermittent failure of the runtime bun
integration job -- intermittent because it is a load-order race, where the run
only passes if the ESM graph happens to evaluate eventsource first.
Dropping the `bun` key makes Bun fall through to `import` for ESM consumers
(same file as before) and `require` for CJS consumers (the CJS build they need).
Takes the bun integration test from 5/20 to 20/20 locally. A version bump is not
an alternative: eventsource 4.1.0 still ships the same mapping.
Module-graph hygiene, not a behaviour fix -- the preceding eventsource patch is what fixes the bun failure. The SDK's SSE transport was imported at the top of the agent module but is only constructed inside the `type === "sse"` branch ~1300 lines below, so `eventsource` was pulled into the module graph of every non-SSE path, including every test that merely touches the agent module. Move it to an `await import()` at the point of use. `transport` and `mcpClient` gain explicit annotations so they keep real types instead of the bare `let` declarations they had before.
jpr5
force-pushed
the
fix/lazy-sse-transport-import
branch
from
August 3, 2026 17:48
c4afe19 to
67ec66b
Compare
jpr5
marked this pull request as ready for review
August 3, 2026 17:51
jpr5
requested review from
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
August 3, 2026 17:51
jpr5
marked this pull request as draft
August 3, 2026 17:59
jpr5
marked this pull request as ready for review
August 3, 2026 17:59
ranst91
added a commit
that referenced
this pull request
Aug 5, 2026
Root package.json pins patchedDependencies ([email protected] -> patches/[email protected], added in #6334). The harness Dockerfile selectively copies root manifests but omitted patches/, so the frozen install hashes the patch file, ENOENTs, and exits 254. Broke the showcase-harness build-check for any PR rebased onto post-#6334 main. Copy patches/ before the install. Verified: image builds clean locally.
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.
What
Fixes the intermittently-red
test / integration / runtimebun leg. Three commits, smallest blast radius first:ci(runtime)— pinbun-versionfromlatestto1.3.14so a Bun release can't change module-resolution behaviour between runs. (Onlybun-version: latestin the repo.)fix(deps)— this is the actual fix. Patch[email protected]to drop itsbunexport condition, viapnpm patch+patchedDependencies.refactor(runtime)— module-graph hygiene: load the MCP SSE transport lazily. Explicitly not a behaviour fix; commit 2 is.Root cause
[email protected]maps itsbunexport condition to the ESM build (dist/index.js). Bun resolvesbunbeforerequire, so a CJSrequire("eventsource")receives an async ESM module and throws. The package ships a real CJS build (dist/index.cjs) behindrequire, but Bun never reaches it.dist/cjs/client/sse.js, and@ag-ui/[email protected]— a CJS-only package (main: ./dist/index.js, noexports, notype: module) thatrequires that SDK path unconditionally at module load.eventsourcefirst, the later CJSrequirecan be served synchronously and the run passes; otherwise it throws.Dropping the
bunkey makes Bun fall through toimportfor ESM consumers (samedist/index.jsas before — no behaviour change) and torequirefor CJS consumers (dist/index.cjs, which is what they need). Onlybunis touched;deno/source/import/require/defaultare left alone.A version bump is not an alternative:
[email protected]still ships the samebun→ ESM mapping.Patch diff
patches/[email protected](header abridged — the file carries the full rationale and an explicit deletion criterion so it doesn't become permanent by accident):Root
package.jsongains:This repo had no
patches/precedent (it usespnpm.overrides), so this sets one — hence the minimal one-line patch and the documented removal criterion.Red-green proof
All four states. Local runs are the same command on the same machine, differing only by whether the patch is applied. Bun 1.3.14, macOS arm64, run from
packages/runtime:bun test src/v2/runtime/__tests__/integration/bun/bun-servers.integration.test.tsA single green run proves nothing here — it's a race — so both local states are N=20.
1. CI-RED
5456e308b9—runtime / nodesuccess,runtime / bunfailure:main@26a23bbf3a, run 30825667393 — same leg, same failure.2. LOCAL-RED (eventsource UNPATCHED, N=20)
3. LOCAL-GREEN (eventsource PATCHED, N=20)
5/20 → 20/20.
4. CI-GREEN
The
test / integration / runtimebun leg on this PR is the load-bearing evidence. See checks below.Clean-install verification
A patch that only works incrementally is worthless in CI, so this was verified from scratch — every
node_modulesin the workspace deleted, thenpnpm install --frozen-lockfile:--frozen-lockfile(lockfile is self-consistent; no drift).eventsourceentry in the store, and it is the patched one:node_modules/.pnpm/[email protected]_patch_hash=427032a8df76e38f39988ff5fb919a02ccb70eb8a235e2b484007e4bebb1e67e/package.jsonin the store after clean install:{"deno":"./dist/index.js","source":"./src/index.ts","import":"./dist/index.js","require":"./dist/index.cjs","default":"./dist/index.js"}—bunabsent, everything else intact.[email protected]withhash: 427032a8...andpath: patches/[email protected], and the dependency edge resolves as[email protected](patch_hash=427032a8...).--frozen-lockfileaccepted the lockfile verbatim (it does not rewrite), so the lockfile is self-consistent with the manifests.vue-component-type-helpers3.3.8→3.3.9 and avitepeer-range narrowing) picked up by a non-frozen install; that has been reverted so the diff contains only the patch wiring.Tests
All from
packages/runtime, with the patch applied:pnpm exec vitest runpnpm exec vitest run src/v2/runtime/__tests__/integration/node-servers.integration.test.tspnpm exec vitest run src/agent/__tests__/mcp-servers-integration.test.ts src/agent/__tests__/mcp-clients.test.ts src/v2/runtime/__tests__/mcp-apps-middleware-integration.test.tsbun test .../bun-servers.integration.test.tsNon-Bun consumers are unaffected by construction — Node never reads the
bunexport condition — and the Node suites above confirm it. The SSE path stays covered:mcp-servers-integration.test.tsexercisesmcpServers: [{ type: "sse", url }], so it executes the newawait import(), which sits outside thetry/catchthat swallows per-server connection failures.Module-graph proof for commit 3
Commit 3 is hygiene, so it gets its own narrower proof. Probe: Bun populates
require.cachewith the resolved path of every module actually loaded, so importing one module and inspecting that cache shows whethereventsourceentered the graph. Two controls run every time so it can't pass vacuously.@copilotkit/shared(negative control)@modelcontextprotocol/sdk/client/sse.js(positive control)../src/agent/index.ts(subject, non-SSE path)Both controls hold steady; only the subject flips. Measured on its own, commit 3 does not move the bun pass rate (5/20 before, 3/20 after within noise) — which is exactly why commit 2 exists.
Typing
No
as any, no@ts-ignore.const { SSEClientTransport } = await import(...)keeps the class fully typed — TypeScript resolves dynamic-import types statically.packages/runtime/tsconfig.jsonalready sets"module": "es2022"with the comment "so dynamic import() typechecks", so the pattern is anticipated.Two adjacent bare
letdeclarations (transport,mcpClient) gained explicit annotations (MCPTransport | undefined,MCPClient) because editors surface them as implicit-any suggestions. Both pre-existed onmain. Verified:tsc --noEmitclean;tsc --noEmit --stricterror set identical to baseline (3 pre-existing unrelatedTS2769s);oxlintwarnings unchanged from baseline (2, both pre-existing).SSEClientTransportis@deprecatedin SDK 1.29.0 in favour ofStreamableHTTPClientTransport. That deprecation pre-exists onmainand is left alone:type: "sse"is documented public config, SSE and Streamable HTTP are different wire protocols, and the SDK's own note says clients "may need to support both transports during the migration period." Migrating is a user-facing change for its own PR.Gates run
pnpm exec oxfmt --check packages/runtime/src/agent/index.ts— cleanpnpm exec oxlint packages/runtime/src/agent/index.ts— 0 errors, 2 warnings (both pre-existing onmain)pnpm nx run @copilotkit/runtime:check-types— passpnpm exec commitlint --from HEAD~3 --to HEAD— passpnpm install --frozen-lockfilefrom a fully wiped workspace — exit 0