Skip to content

fix: polyfill markAsUncloneable for Bun build compatibility - #1380

Closed
github-actions[bot] wants to merge 1 commit into
provider-racing-stacking-reasoning-uifrom
claude-fix-pr-1379-30714202270
Closed

fix: polyfill markAsUncloneable for Bun build compatibility#1380
github-actions[bot] wants to merge 1 commit into
provider-racing-stacking-reasoning-uifrom
claude-fix-pr-1379-30714202270

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

CI Auto-Fix

Original PR: #1379
Failed CI Run: PR Build Check - Docker Build Test

Root Cause

The dev branch upgraded undici to ^8.9.0. When this PR is merged into dev, the CI merge picks up dev's undici version. Undici 8.x unconditionally destructures markAsUncloneable from node:worker_threads (removed the runtime feature detection fallback that undici 7.x had):

// undici 8.9.0 - lib/web/webidl/index.js
const { markAsUncloneable } = require('node:worker_threads')  // undefined on Bun!
webidl.util.markAsUncloneable = markAsUncloneable

The Docker build stage uses oven/bun:debian, and Bun does not implement markAsUncloneable (a Node.js 23+ API). This causes next build to crash during page data collection for /v1beta/[...route] (and /v1/[...route]).

This also affects dev directly - the latest dev Docker build (run 30712055253) also fails.

Fixes Applied

File Fix Type
src/lib/polyfills/worker-threads.ts (new) No-op polyfill for markAsUncloneable on node:worker_threads when the runtime lacks it build compatibility
src/app/v1/[...route]/route.ts Import polyfill before undici-dependent modules wiring
src/app/v1beta/[...route]/route.ts Import polyfill before undici-dependent modules wiring

Verification

  • bun run build passes with undici@8.9.0 installed (previously crashed with TypeError: s.util.markAsUncloneable is not a function)
  • bun run typecheck passes
  • bun run lint passes
  • No logic changes made - polyfill is a no-op on Node.js (where markAsUncloneable already exists)

Auto-generated by Claude AI

Greptile Summary

The PR adds a Bun compatibility shim for the missing worker_threads.markAsUncloneable API and loads it from the /v1 and /v1beta proxy routes.

  • Adds a no-op export only when the runtime does not provide the API.
  • Adds side-effect imports before the proxy routes' Undici-dependent modules.
  • The route-local wiring does not cover another independently evaluated Undici import chain.

Confidence Score: 4/5

This should be fixed before merging because another independently evaluated route can still load Undici before the compatibility shim and fail the Bun-based build.

The shim itself is conditional and preserves native behavior, but importing it only from two proxy routes does not cover the existing /api/actions route chain that statically reaches Undici.

Files Needing Attention: src/app/v1/[...route]/route.ts and src/app/v1beta/[...route]/route.ts

Important Files Changed

Filename Overview
src/lib/polyfills/worker-threads.ts Adds a conditional no-op markAsUncloneable compatibility shim without replacing native implementations.
src/app/v1/[...route]/route.ts Loads the shim before this proxy route's dependencies, but route-local initialization does not protect other Undici entrypoints.
src/app/v1beta/[...route]/route.ts Mirrors the /v1 route wiring and has the same application-wide coverage limitation.
Prompt To Fix All With AI
### Issue 1
src/app/v1/[...route]/route.ts:2
**Route-local shim leaves Undici exposed**

When Next.js evaluates `/api/actions` before these proxy routes, its static `actions/providers``gemini/auth` chain loads Undici without this route-local shim, causing the Bun build to encounter the same missing `markAsUncloneable` failure. Initialize the shim from an application-wide server entrypoint that runs before every Undici import.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix: polyfill markAsUncloneable for Bun ..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used:

undici >= 8 (introduced on dev) unconditionally destructures
markAsUncloneable from node:worker_threads without a fallback.
Bun (Docker build stage) does not implement this Node.js 23+ API,
so next build crashes during page data collection for proxy routes.

Added a no-op polyfill imported before undici-dependent modules.

CI Run: https://github.com/ding113/claude-code-hub/actions/runs/30714125452

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@@ -1,4 +1,5 @@
import "@/lib/polyfills/file";
import "@/lib/polyfills/worker-threads";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Route-local shim leaves Undici exposed

When Next.js evaluates /api/actions before these proxy routes, its static actions/providersgemini/auth chain loads Undici without this route-local shim, causing the Bun build to encounter the same missing markAsUncloneable failure. Initialize the shim from an application-wide server entrypoint that runs before every Undici import.

Knowledge Base Used: Proxy request pipeline

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/v1/[...route]/route.ts
Line: 2

Comment:
**Route-local shim leaves Undici exposed**

When Next.js evaluates `/api/actions` before these proxy routes, its static `actions/providers``gemini/auth` chain loads Undici without this route-local shim, causing the Bun build to encounter the same missing `markAsUncloneable` failure. Initialize the shim from an application-wide server entrypoint that runs before every Undici import.

**Knowledge Base Used:** [Proxy request pipeline](https://app.greptile.com/ygxz/-/custom-context/knowledge-base/ding113/claude-code-hub/-/docs/proxy-pipeline.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b173aa9ef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@@ -1,4 +1,5 @@
import "@/lib/polyfills/file";
import "@/lib/polyfills/worker-threads";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply the worker shim before every undici entrypoint

In Bun Docker builds with undici 8, this side-effect import only protects the v1/v1beta route modules. I checked the retained /api/actions/[...route] legacy management route: it still statically imports @/actions/providers, which imports @/lib/proxy-agent and therefore undici at module load before any worker-threads shim runs, so Next's route/page data collection can hit the same markAsUncloneable crash after these two routes are fixed. Move the shim to a global server entrypoint or import it before every server entrypoint that can load undici.

Useful? React with 👍 / 👎.

@ding113 ding113 closed this Aug 2, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Claude Code Hub Roadmap Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant