Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/v1/[...route]/route.ts
Original file line number Diff line number Diff line change
@@ -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.

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 👍 / 👎.

import { Hono } from "hono";
import { handle } from "hono/vercel";
import { registerCors } from "@/app/v1/_lib/cors";
Expand Down
1 change: 1 addition & 0 deletions src/app/v1beta/[...route]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "@/lib/polyfills/file";
import "@/lib/polyfills/worker-threads";
import { Hono } from "hono";
import { handle } from "hono/vercel";
import { registerCors } from "@/app/v1/_lib/cors";
Expand Down
13 changes: 13 additions & 0 deletions src/lib/polyfills/worker-threads.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createRequire } from "node:module";

const nodeRequire = createRequire(import.meta.url);
const workerThreads = nodeRequire("node:worker_threads") as {
markAsUncloneable?: (...args: unknown[]) => void;
};

// undici >= 8 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.
if (typeof workerThreads.markAsUncloneable !== "function") {
workerThreads.markAsUncloneable = function markAsUncloneable() {};
}