{"record":{"id":"26da303036efeb50","repo":"musistudio/claude-code-router","slug":"the-ccr-artifact-endpoint-returned-http-response","errorCode":null,"errorMessage":"The CCR artifact endpoint returned HTTP ${response.status}.","messagePattern":"The CCR artifact endpoint returned HTTP (.+?)\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agents/codex/media-preview-bridge.ts","lineNumber":304,"sourceCode":"  const token = url.searchParams.get(\"token\") || \"\";\n  if (keys.length !== 1 || keys[0] !== \"token\" || !/^[A-Za-z0-9_-]{32}$/.test(token)) {\n    throw new Error(\"Artifact URL contains an invalid access token.\");\n  }\n  return { artifactId, url };\n}\n\nasync function loadCodexMediaArtifact(validated: ValidatedArtifactUrl, signal: AbortSignal): Promise<LoadedMediaArtifact> {\n  let response: Response;\n  try {\n    response = await fetch(validated.url, {\n      headers: { accept: \"image/*, video/*\" },\n      redirect: \"error\",\n      signal\n    });\n  } catch {\n    throw new Error(\"The CCR artifact request failed.\");\n  }\n  if (!response.ok) throw new Error(`The CCR artifact endpoint returned HTTP ${response.status}.`);\n  if (response.redirected) throw new Error(\"The CCR artifact endpoint attempted a redirect.\");\n  const declaredMimeType = (response.headers.get(\"content-type\") || \"\").split(\";\", 1)[0].trim().toLowerCase();\n  const declaredKind = mediaKind(declaredMimeType);\n  if (!declaredKind) throw new Error(\"The CCR artifact endpoint returned a non-media content type.\");\n  const maxBytes = declaredKind === \"video\" ? codexMediaPreviewMaxVideoBytes : codexMediaPreviewMaxImageBytes;\n  const declaredLength = Number(response.headers.get(\"content-length\") || \"0\");\n  if (declaredLength && (!Number.isSafeInteger(declaredLength) || declaredLength < 1 || declaredLength > maxBytes)) {\n    throw new Error(\"The CCR media artifact exceeds the inline preview size limit.\");\n  }\n  if (response.headers.get(\"content-encoding\") && response.headers.get(\"content-encoding\") !== \"identity\") {\n    throw new Error(\"Compressed CCR media artifacts are not accepted for inline preview.\");\n  }\n  if (!response.body) throw new Error(\"The CCR artifact response had no body.\");\n  const reader = response.body.getReader();\n  const chunks: Buffer[] = [];\n  let total = 0;\n  while (true) {\n    const part = await reader.read();","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/core/src/agents/codex/media-preview-bridge.ts#L286-L322","documentation":"The HTTP response from the CCR artifact endpoint had a non-2xx status. loadCodexMediaArtifact checks response.ok after a successful fetch and rejects with the concrete status code so callers can distinguish auth failures (401/403), missing artifacts (404), and server errors (5xx).","triggerScenarios":"artifact() request returns 401/403 (expired or invalid session token), 404 (artifact deleted or unknown id), 410 (expired artifact URL), or 5xx from the CCR server.","commonSituations":"The CCR session token expired between conversation start and artifact fetch; the artifact was garbage-collected on the server; the wrong artifact URL was stored in the reference; or the endpoint is behind a gateway returning 502/503 during deployments.","solutions":["Match the status in the message: 401/403 → refresh/re-establish the CCR session and retry; 404/410 → the artifact no longer exists, drop the preview; 5xx → retry with backoff","Confirm the artifact reference and URL stored in the bridge still correspond to a live session","Check CCR server health/logs if the status is consistently 5xx"],"exampleFix":"// before\nconst media = await bridge.artifact(ref);\n\n// after\ntry {\n  const media = await bridge.artifact(ref);\n} catch (e) {\n  if (/HTTP 4\\d\\d/.test(e.message)) { /* artifact unavailable; skip preview */ }\n  else if (/HTTP 5\\d\\d/.test(e.message)) { /* retry with backoff */ }\n  else throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isArtifactHttpError(e: unknown): number | null {\n  const m = e instanceof Error ? e.message.match(/HTTP (\\d{3})/) : null;\n  return m ? Number(m[1]) : null;\n}","tryCatchPattern":"try {\n  const media = await bridge.artifact(ref);\n} catch (e) {\n  const status = isArtifactHttpError(e);\n  if (status && status >= 500) return retryWithBackoff(() => bridge.artifact(ref));\n  if (status === 401 || status === 403) await refreshSession();\n  if (status === 404 || status === 410) return renderPlaceholder(ref);\n  throw e;\n}","preventionTips":["Refresh session tokens before they expire","Persist accurate artifact URLs in references","Distinguish 4xx (permanent) from 5xx (retryable) in handling"],"tags":["http","status-code","codex","media-artifact"],"backgroundTag":"http-error-response-status","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}