From 04c0ccd30457297e0154a4035e13401b0bc1521b Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Sun, 27 Sep 2026 15:01:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(AI):=20Bun.serve=20=E7=A9=BA=E9=97=B2?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E8=B0=83=E5=88=B0=2060=20=E7=A7=92=EF=BC=8CA?= =?UTF-8?q?I=20=E6=B5=81=E4=B8=8D=E5=86=8D=E5=9C=A8=2010=20=E7=A7=92?= =?UTF-8?q?=E9=9D=99=E9=BB=98=E5=90=8E=E8=A2=AB=E6=8E=90=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bun.serve 默认 idleTimeout 是 10 秒:连接上 10 秒没有字节往来就直接断开,不报任何错。 AI 的两条 SSE 都会静默超过 10 秒 —— streamWhole(AI 提示)在 produce 期间每 15 秒 才发一次心跳,一次生成加过滤重生成常常超过 10 秒;streamChat 等首 token 也常过 10 秒。 学生看到的就是「AI 提示生成失败」。 对齐反代链上最短的一环(NPM proxy_read_timeout 60s)。实测:provider 挂住时原来 10 秒整连接被断、客户端收不到 error 事件;改后按 streamChat 自己的 45 秒空闲超时收尾。 Co-Authored-By: Claude Opus 5.5 --- apps/api/src/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 2f70f87..02574f5 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -86,6 +86,11 @@ async function serveUpload( const server = Bun.serve({ port: config.port, + // Bun 默认 10 秒没有字节往来就掐连接,而且不报任何错。AI 的 SSE 两条路都会静默 + // 超过 10 秒:streamWhole 在 produce 期间每 15 秒才发一次心跳,streamChat 等首 + // token 也常过 10 秒 —— 学生看到的就是「AI 提示生成失败」。对齐反代链上最短的 + // 那一环(NPM 的 proxy_read_timeout 60s),两边的心跳 / 空闲超时都在它之内。 + idleTimeout: 60, async fetch(request, bunServer) { const url = new URL(request.url) if (url.pathname.startsWith(`${config.avatarUriPrefix}/`)) {