diff --git a/apps/web-evals/src/app/api/runs/[id]/stream/route.ts b/apps/web-evals/src/app/api/runs/[id]/stream/route.ts index 732ec0f10d..2c4226dc6c 100644 --- a/apps/web-evals/src/app/api/runs/[id]/stream/route.ts +++ b/apps/web-evals/src/app/api/runs/[id]/stream/route.ts @@ -13,15 +13,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{ const requestId = crypto.randomUUID() const stream = new SSEStream() const run = await findRun(Number(id)) - if (!run) { - return new Response(`Run ${id} not found`, { status: 404 }) - } - const redis = await redisClient() - if (!redis) { - console.error(`[stream#${requestId}] Redis client not available`); - return new Response("Internal server error", { status: 500 }) - } let isStreamClosed = false const channelName = `evals:${run.id}` @@ -32,22 +24,19 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{ } try { - const parsedData = JSON.parse(data) - const taskEvent = taskEventSchema.parse(parsedData) + const taskEvent = taskEventSchema.parse(JSON.parse(data)) console.log(`[stream#${requestId}] task event -> ${taskEvent.eventName}`) const writeSuccess = await stream.write(JSON.stringify(taskEvent)) if (!writeSuccess) { - console.error(`[stream#${requestId}] failed to write to stream, disconnecting`); await disconnect() } - } catch (error) { - console.error(`[stream#${requestId}] invalid task event:`, data, 'Error:', error); + } catch (_error) { + console.error(`[stream#${requestId}] invalid task event:`, data) } } const disconnect = async () => { - console.log(`YO YO YO - [stream#${requestId}] disconnecting from channel ${channelName}`); if (isStreamClosed) { return } @@ -56,24 +45,19 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{ try { await redis.unsubscribe(channelName) - console.log(`YO YO YO - [stream#${requestId}] unsubscribed from ${channelName}`); + console.log(`[stream#${requestId}] unsubscribed from ${channelName}`) } catch (error) { - console.error(`YO YO YO - [stream#${requestId}] error unsubscribing:`, error); + console.error(`[stream#${requestId}] error unsubscribing:`, error) } try { await stream.close() } catch (error) { - console.error(`Error closing stream:`, error); + console.error(`[stream#${requestId}] error closing stream:`, error) } } - try { - await redis.subscribe(channelName, onMessage) - } catch (error) { - console.error(`Error subscribing to Redis:`, error); - return new Response("Internal server error", { status: 500 }) - } + await redis.subscribe(channelName, onMessage) // Add a timeout to close the stream after a period of inactivity or errors const timeoutDuration = 300000; // 5 minutes