{"record":{"id":"705c7820bcf4cb08","repo":"JuliusBrussee/caveman","slug":"sync-import-failed-response-status","errorCode":null,"errorMessage":"sync import failed (${response.status})","messagePattern":"sync import failed \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":10011,"sourceCode":"    const ts = typeof r.ts === \"string\" ? r.ts : \"\";\n    // The proxy writes ClickHouse-layout UTC timestamps (\"YYYY-MM-DD HH:MM:SS.mmm\").\n    const ms = Date.parse(ts.includes(\"T\") ? ts : ts.replace(\" \", \"T\") + \"Z\");\n    if (!Number.isFinite(ms)) return [];\n    return directiveInstalls.filter((d) => ms >= d.installedAtMs).map((d) => d.id);\n  };\n  const body = rows.map((r) => syncRequestSpan(r, rowDirectives(r))).join(\"\\n\") + \"\\n\";\n  const response = await fetch(`${cfg.baseURL}/api/v1/imports?format=caveman-jsonl`, {\n    method: \"POST\",\n    headers: {\n      authorization: `Bearer ${cfg.token}`,\n      \"content-type\": \"application/octet-stream\",\n      \"x-cave-csrf\": \"cli\",\n    },\n    body,\n  });\n  const result = (await response.json().catch(() => ({}))) as { status?: string; error?: { message?: string } };\n  if (!response.ok || result.status !== \"completed\") {\n    throw new Error(result.error?.message ?? `sync import failed (${response.status})`);\n  }\n\n  const num = (v: unknown) => (typeof v === \"bigint\" ? Number(v) : typeof v === \"number\" && Number.isFinite(v) ? v : 0);\n  const maxId = rows.reduce((m, r) => Math.max(m, num(r.id)), since);\n  writeSyncWatermark(key, maxId);\n  const tokensSaved = rows.reduce((sum, r) => sum + Math.max(0, num(r.compression_tokens_before) - num(r.compression_tokens_after)), 0);\n  const tokenBases = new Set(rows.map((r) => (typeof r.compression_token_count_basis === \"string\" ? r.compression_token_count_basis : \"\")).filter(Boolean));\n  const tokenCountBasis = tokenBases.size === 0 ? \"unavailable\" : tokenBases.size === 1 ? [...tokenBases][0] ?? \"unavailable\" : \"mixed\";\n  const cachedInputTokens = rows.reduce((sum, r) => sum + Math.max(0, num(r.cached_input_tokens)), 0);\n  const cacheCreationInputTokens = rows.reduce((sum, r) => sum + Math.max(0, num(r.cache_creation_input_tokens)), 0);\n  const headlineCompressionRefused = cacheCreationInputTokens > cachedInputTokens;\n  const savingsUSD = rows.reduce((sum, r) => sum + num(r.savings_usd), 0);\n  return {\n    kind: \"synced\",\n    spans: rows.length,\n    tokensSaved,\n    tokenCountBasis,\n    cachedInputTokens,","sourceCodeStart":9993,"sourceCodeEnd":10029,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/5184b3d11ac6a1acb7d44b9bfaa31698157cff97/packages/cli/src/index.ts#L9993-L10029","documentation":"The post-login sync that imports local spans into the dashboard got a non-2xx from the /imports endpoint. The login itself succeeded; only the one-time backfill of already-measured spans failed, with the HTTP status included.","triggerScenarios":"Thrown at packages/cli/src/index.ts:9166 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry `caveman sync` — the pass is idempotent via the watermark","Check auth token and server health if the status persists (401/5xx)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5184b3d11ac6a1acb7d44b9bfaa31698157cff97","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}