Compare commits

...

1 Commits

Author SHA1 Message Date
claude[bot] 6719e054c3 Switch edge runtime to Node.js to avoid Vercel 5-minute timeout
This patch moves the Big-AGI edge router from Vercel Edge runtime to
Node.js runtime to avoid the 5-minute hard timeout affecting slower
models like GPT-5 Pro.

Changes:
- Set runtime='nodejs' with maxDuration=600 (10 minutes)
- Added enhanced error handling matching cloud router
- Updated router documentation

Trade-offs:
- Slower cold starts (~250ms vs ~50ms)
- Single region instead of global edge distribution
- Higher costs on Vercel
- But: Reliable for slow models, 10min vs 5min timeout

For deployments needing >10 minutes, consider:
- Vercel Enterprise (15min max)
- Alternative hosting (Cloudflare, Railway, self-hosted)
- OpenAI Responses API with reconnection

Fixes #857

Co-authored-by: Enrico Ros <enricoros@users.noreply.github.com>
2025-10-28 01:42:18 +00:00
2 changed files with 31 additions and 6 deletions
+28 -5
View File
@@ -2,17 +2,40 @@ import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { appRouterEdge } from '~/server/trpc/trpc.router-edge';
import { createTRPCFetchContext } from '~/server/trpc/trpc.server';
import { posthogCaptureServerException } from '~/server/posthog/posthog.server';
const handlerEdgeRoutes = (req: Request) => fetchRequestHandler({
endpoint: '/api/edge',
router: appRouterEdge,
req,
createContext: createTRPCFetchContext,
onError:
process.env.NODE_ENV === 'development'
? ({ path, error }) => console.error(`❌ tRPC-edge failed on ${path ?? 'unk-path'}: ${error.message}`)
: undefined,
onError: async function({ path, error, type, ctx }) {
// -> DEV error logging
if (process.env.NODE_ENV === 'development')
console.error(`❌ tRPC-edge failed on ${path ?? 'unk-path'}: ${error.message}`);
// -> Capture node errors
await posthogCaptureServerException(error, {
domain: 'trpc-onerror',
runtime: 'nodejs',
endpoint: path ?? 'unknown',
method: req.method,
url: req.url,
additionalProperties: {
errorCode: error.code,
errorType: type,
},
});
},
});
export const runtime = 'edge';
// PATCH: Switch from edge to nodejs runtime to avoid Vercel's 5-minute timeout
// This sacrifices edge performance (speed, global distribution) for reliability
// with slower models like GPT-5 Pro that can take >5 minutes to respond.
// maxDuration: 600 seconds (10 minutes) - maximum for Vercel Pro plans
// For longer durations, consider Vercel Enterprise or alternative hosting.
export const maxDuration = 600;
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
export { handlerEdgeRoutes as GET, handlerEdgeRoutes as POST };
+3 -1
View File
@@ -11,7 +11,9 @@ import { llmOpenAIRouter } from '~/modules/llms/server/openai/openai.router';
import { youtubeRouter } from '~/modules/youtube/youtube.router';
/**
* Primary rooter, and will be sitting on an Edge Runtime.
* Primary router, originally designed for Edge Runtime.
* NOTE: Currently configured to run on Node.js runtime (see app/api/edge/[trpc]/route.ts)
* to avoid Vercel's 5-minute Edge timeout affecting slower models like GPT-5 Pro.
*/
export const appRouterEdge = createTRPCRouter({
aix: aixRouter,