Skip to content

fix(api): bound /api/grade on slow or failing Gemini calls - #36

Merged
lautaropaske merged 2 commits into
mainfrom
lautaropaske/dash0-diagnose-issues
Oct 5, 2026
Merged

lautaropaske merged 2 commits into
mainfrom
lautaropaske/dash0-diagnose-issues

Conversation

@lautaropaske

Copy link
Copy Markdown
Contributor

Summary

Fixes found in 7 days of open-silver logs in Dash0: a /api/grade call that ran 235s, a Gemini gateway 503 reported as our own 500, pdf.js warnings logged as INFO, and Vercel installing with npm.

 POST /api/grade
+  deadline = AbortSignal.timeout(60s)
-  pdf(buffer)
+  parseResume(buffer)            # pdf.js "Warning: …" → console.warn
-  generateObject(...)
+  generateObject(..., abortSignal: deadline)
   catch
     ResumeFetchError      → 4xx
     invalid PDF           → 400
+    deadline.aborted      → 504 GradingTimeout
+    gateway 5xx           → 503 GradingUnavailable
     anything else         → 500 GradingError
  • The AI SDK only retries APICallError, and GatewayError isn't one. So a gateway 503 failed on the first attempt.
  • A timed-out request comes back from the gateway as a GatewayResponseError with status 500. That's why the timeout check runs before the gateway-5xx check.
  • The client shows Spanish messages for both new codes.
  • package-lock.json is deleted, so Vercel builds with bun the same way CI does. @ai-sdk/gateway is now a direct dependency so the route can check GatewayError.isInstance.

Evidence

  • Before (Dash0, last 7 days): POST /api/grade took 235s, 96s and 61s on its slowest calls. On Oct 3 20:33 a GatewayInternalServerError (503) was returned to the user as 500 GradingError. Warning: TT: undefined function was logged about 100 times at INFO. Vercel build logs show npm warn ERESOLVE for typescript.
    After (local dev server):
    deadline set to 1ms + fake gateway key  → 504 {"error":"GradingTimeout"}
    PDF with corrupted xref                 → "Warning: Indexing all PDF objects" on stderr, nothing on stdout
    no gateway key (401)                    → 500 GradingError (unchanged; a 4xx is a config problem)
    
  • Tests: 73 pass (bun run test), plus bun tsc and lint.
    gateway 503 rejection        → 503 GradingUnavailable
    gateway 429 rejection        → 500 GradingError
    deadline already aborted     → 504 GradingTimeout, signal passed to generateObject
    parseResume                  → "Warning: …" goes to console.warn, other output stays on console.log
    concurrent parses            → console.log restored only after the last one finishes
    
  • I didn't check the error message in a browser: the connected Chrome couldn't reach the local dev server.

Merge Danger

Door: two-way

Revert the commits to undo everything. Restoring package-lock.json on its own would put Vercel back on npm.

Blast Radius: resume-checker

  • Gradings that used to finish between 60s and 300s now return 504. In the last 7 days that was 3 of 618 requests.
  • The first Vercel build after merge installs with bun instead of npm. Watch that deploy.
  • While a resume is being parsed, console.log is patched for the whole process. Only lines starting with Warning: are redirected.

🤖 Generated with Claude Code

lautaropaske and others added 2 commits October 5, 2026 09:51
Vercel picked npm because both lockfiles were committed, while CI installs
with bun --frozen-lockfile. Builds logged ERESOLVE peer warnings for
typescript and could drift from what CI tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Give generateObject a 60s deadline and answer 504 GradingTimeout, so a
  stuck call no longer holds the function for up to 300s (one took 235s).
- Answer gateway 5xx with 503 GradingUnavailable instead of 500: the SDK
  never retries GatewayError, so an outage hit users on the first attempt.
- Route pdf.js "Warning: ..." lines from console.log to console.warn so
  they land as WARN in Dash0 instead of INFO.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
open-silver Ready Ready Preview Oct 5, 2026 12:52pm UTC

Request Review

@lautaropaske
lautaropaske merged commit a540e0d into main Oct 5, 2026
3 checks passed
@lautaropaske
lautaropaske deleted the lautaropaske/dash0-diagnose-issues branch October 5, 2026 14:48

This branch was successfully deployed

1 active deployment
Preview — 3dadc54d Deployed Oct 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant