Skip to content

Commit 2b3d027

Browse files
committed
fix: resolve compiled binary crashes from circular dep and Bun CJS splitting bug
1 parent ce209e2 commit 2b3d027

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

packages/opencode/src/cli/cmd/serve.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { Installation } from "../../installation"
1313
import { PushRelay } from "../../server/push-relay"
1414
import { Log } from "../../util"
1515
import { Global } from "../../global"
16-
import * as QRCode from "qrcode"
16+
// dynamic import: static `import * as` of CJS package triggers Bun bundler splitting bug
17+
import type * as QRCodeType from "qrcode"
1718

1819
const log = Log.create({ service: "serve" })
1920

@@ -184,6 +185,7 @@ async function printPairQR(pair: PairPayload) {
184185
linkLength: link.length,
185186
qr: qrConfig,
186187
})
188+
const QRCode: typeof QRCodeType = await import("qrcode")
187189
const code = await QRCode.toString(link, {
188190
...qrConfig,
189191
})

packages/opencode/src/server/routes/instance/experimental.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { errors } from "../../error"
1717
import { lazy } from "@/util/lazy"
1818
import { Effect, Option } from "effect"
1919
import { PushRelay } from "../../push-relay"
20-
import * as QRCode from "qrcode"
20+
// dynamic import: static `import * as` of CJS package triggers Bun bundler splitting bug
21+
import type * as QRCodeType from "qrcode"
2122
import { Agent } from "@/agent/agent"
2223
import { jsonRequest, runRequest } from "./trace"
2324

@@ -60,6 +61,7 @@ function pushPairLink(input: { relaySecret: string; hosts: string[] }) {
6061
}
6162

6263
async function pushPairQRCode(input: { relaySecret: string; hosts: string[] }) {
64+
const QRCode: typeof QRCodeType = await import("qrcode")
6365
return QRCode.toDataURL(pushPairLink(input), pushPairQROptions)
6466
}
6567

packages/opencode/src/session/session.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ export const Event = {
246246
"session.error",
247247
z.object({
248248
sessionID: SessionID.zod.optional(),
249-
error: MessageV2.Assistant.shape.error,
249+
// z.lazy defers access to break circular dep: session → message-v2 → provider → plugin → session
250+
error: z.lazy(() => MessageV2.Assistant.shape.error),
250251
}),
251252
),
252253
}

0 commit comments

Comments
 (0)