{"record":{"id":"fd05eb821257f33a","repo":"nexu-io/open-design","slug":"grok-video-fetch-dlresp-status","errorCode":null,"errorMessage":"grok video fetch ${dlResp.status}","messagePattern":"grok video fetch (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/media/index.ts","lineNumber":2426,"sourceCode":"        + `(last status: ${lastStatus || 'pending'}, ceiling ${ceilingSec}s). `\n        + `If your jobs legitimately need longer, raise OD_GROK_VIDEO_MAX_POLL_MS.`,\n      );\n    }\n  }\n\n  if (!videoUrl) {\n    // Submit returned neither an inline video.url nor a request_id —\n    // upstream broke its own contract. Surfacing the last status helps\n    // pinpoint whether it was a transient API blip or a malformed\n    // response we should add a parser branch for.\n    throw new Error(\n      `grok video submit returned no inline video and no request_id to poll `\n      + `(status=${lastStatus || 'unknown'})`,\n    );\n  }\n\n  const dlResp = await fetch(videoUrl, withMediaRequestInit(ctx));\n  if (!dlResp.ok) throw new Error(`grok video fetch ${dlResp.status}`);\n  const arr = await dlResp.arrayBuffer();\n  const bytes = Buffer.from(arr);\n\n  return {\n    bytes,\n    providerNote: `grok/${ctx.wireModel} · ${aspectRatio} · ${durationSec}s · ${bytes.length} bytes`,\n    suggestedExt: '.mp4',\n  };\n}\n\nfunction grokAspectFor(aspect?: string): string {\n  // xAI accepts a wide list (1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1,\n  // 1:2, 19.5:9, 9:19.5, 20:9, 9:20, auto). Our MEDIA_ASPECTS subset\n  // is a strict subset — pass through known values, otherwise 16:9.\n  if (\n    aspect === '1:1'\n    || aspect === '16:9'\n    || aspect === '9:16'","sourceCodeStart":2408,"sourceCodeEnd":2444,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/media/index.ts#L2408-L2444","documentation":"Thrown after Grok returns a video URL (either inline or after polling) but the subsequent GET to download the binary from videoUrl returned a non-2xx status. The download path uses withMediaRequestInit(ctx) without an auth header (xAI's CDN URLs are typically signed). The message reports the raw HTTP status so you can distinguish 403 (signed URL expired/auth) from 404/410 (gone) from 5xx (CDN fault).","triggerScenarios":"renderGrokVideo reaches the final fetch(videoUrl, ...) and dlResp.ok is false. Happens when the signed CDN URL expired between completion and download, when the CDN has a transient 5xx, or when egress to the CDN host is blocked.","commonSituations":"Daemon paused (queue/backpressure) long enough that the signed xAI CDN URL expired; xAI CDN 5xx maintenance; firewall blocking the video CDN host; transient 503/504; URL was for a region the daemon can't reach.","solutions":["Retry the render — expired signed URLs and CDN 5xx usually resolve on a second attempt.","If 403/410: the signed URL expired or was revoked — re-run the whole job to get a fresh URL.","Verify the daemon host can reach the xAI video CDN (network egress/firewall rules).","If persistent, capture videoUrl and status; file an xAI support ticket — video lost between generation and storage is an upstream defect."],"exampleFix":"// before\nconst dlResp = await fetch(videoUrl, withMediaRequestInit(ctx));\nif (!dlResp.ok) throw new Error(`grok video fetch ${dlResp.status}`);\n\n// after — retry transient CDN failures before throwing\nasync function fetchVideoBytes(url: string, attempts = 3): Promise<Buffer> {\n  let last: Error | null = null;\n  for (let i = 0; i < attempts; i++) {\n    const r = await fetch(url);\n    if (r.ok) return Buffer.from(await r.arrayBuffer());\n    last = new Error(`grok video fetch ${r.status}`);\n    if (r.status >= 500 && i < attempts - 1) { await new Promise(res => setTimeout(res, 1500 * (i + 1))); continue; }\n    throw last;\n  }\n  throw last!;\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Video fetch failures are dominated by transient CDN 5xx and expired signed\n// URLs — retry with backoff, bail on 4xx that won't self-heal.\nasync function fetchGrokVideo(url: string, attempts = 3): Promise<Buffer> {\n  let last: Error | null = null;\n  for (let i = 0; i < attempts; i++) {\n    const r = await fetch(url);\n    if (r.ok) return Buffer.from(await r.arrayBuffer());\n    last = new Error(`grok video fetch ${r.status}`);\n    if (r.status >= 500 && i < attempts - 1) { await new Promise(res => setTimeout(res, 1500 * (i + 1))); continue; }\n    break;\n  }\n  throw last!;\n}","preventionTips":["Download video bytes immediately after the poll reports done — do not queue or pause, signed URLs expire.","Whitelist xAI's video CDN host in daemon egress rules, not just api.x.ai.","Log the videoUrl host on fetch failure so you can correlate which CDN region is failing."],"tags":["grok","xai","download","http-status","cdn"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}