Fix timeout leak, transcript_segments shape mismatch, and ENABLE_VERTEX_AI boolean guard#34
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
🚅 Deployed to the EventRelay-pr-34 environment in EventRelay
|
…LE_VERTEX_AI boolean parsing Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to address several correctness issues in the video → transcript → analysis pipeline, including timeout cleanup, aligning transcript_segments with the backend transcript shape, and fixing env-var boolean handling for optional Vertex AI imports.
Changes:
- Ensures abort timeouts are always cleared even when
fetch()fails/aborts. - Fixes
transcript_segmentscounting to match the backend’stranscript = { text, source, segments }shape. - Hardens the
ENABLE_VERTEX_AIflag parsing so values like"0"don’t enable Vertex AI behavior.
| // Use trusted backend origin instead of deriving from potentially user-controlled request data | ||
| const origin = BACKEND_URL; | ||
|
|
There was a problem hiding this comment.
origin is declared but never used, and the surrounding comment suggests the code is avoiding deriving an origin from the incoming request. As written, the route still derives baseUrl from request.url for the internal /api/transcribe and /api/extract-events calls, so this is dead code and potentially misleading. Either remove origin/the comment, or actually use a trusted, configured app origin when building those internal URLs (and rename the variable accordingly).
| // Use trusted backend origin instead of deriving from potentially user-controlled request data | |
| const origin = BACKEND_URL; |
Four bugs identified in code review of the frontend video pipeline PR.
Changes
Timeout never cleared on fetch error (
video/route.ts,transcribe/route.ts):clearTimeoutwas placed afterawait fetch(...), so aborts and network errors left the timer pending. Replaced with.finally(() => clearTimeout(timeout)):transcript_segmentsalways 0 (video/route.ts): Backend returnstranscriptas{ text, source, segments }, not an array.result.transcript?.lengthwas alwaysundefined. Fixed toresult.transcript?.segments?.length.ENABLE_VERTEX_AI=0still triggered Vertex AI import (gemini_service.py): Rawos.getenv("ENABLE_VERTEX_AI")is truthy for any non-empty string including"0". Replaced with an explicit allowlist check:Duplicate
let transcript = ''(video/route.ts): Removed duplicate declaration that would cause a compile error.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.