{"record":{"id":"7e27d5be459f4d31","repo":"musistudio/claude-code-router","slug":"request-log-failed-to-backfill-usage-costs-fo","errorCode":null,"errorMessage":"[request-log] Failed to backfill usage costs: ${formatError(error)}","messagePattern":"\\[request-log\\] Failed to backfill usage costs: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/src/observability/request-log-worker.ts","lineNumber":144,"sourceCode":"  if (shuttingDown || (pricingBackfillActive && beforeId === undefined)) return;\n  pricingBackfillActive = true;\n  chain = chain.then(async () => {\n    if (shuttingDown) {\n      pricingBackfillActive = false;\n      return;\n    }\n    const page = await store.backfillMissingUsageCostsPage({ beforeId });\n    if (page.updated > 0) parentPort?.postMessage({ type: \"maintenance\", updated: page.updated });\n    if (page.nextBeforeId === undefined) {\n      pricingBackfillActive = false;\n      return;\n    }\n    // Yield between pages so normal log writes already queued by the parent can\n    // run before the next maintenance batch.\n    setImmediate(() => schedulePricingBackfillPage(page.nextBeforeId));\n  }).catch((error) => {\n    pricingBackfillActive = false;\n    console.warn(`[request-log] Failed to backfill usage costs: ${formatError(error)}`);\n  });\n}\n\nfunction reviveCommand(command: RequestLogStoreWriteCommand): RequestLogStoreWriteCommand {\n  if (command.kind === \"raw-trace-update\") {\n    const input = { ...command.input };\n    const maxBodyBytes = resolveRawTraceBodyLimit(command.rawTraceFiles?.maxBodyBytes);\n    const rawTraceFiles: RequestLogRawTraceFiles | undefined = command.rawTraceFiles\n      ? {\n          cleanupDirectory: command.rawTraceFiles.cleanupDirectory,\n          maxBodyBytes: command.rawTraceFiles.maxBodyBytes\n        }\n      : undefined;\n    if (command.rawTraceFiles?.requestBody) {\n      const body = readRawTraceBody(command.rawTraceFiles.requestBody, maxBodyBytes);\n      if (body) {\n        if (rawTraceFiles) rawTraceFiles.requestBody = fileMetadataFromRawTraceBody(body);\n        input.requestBodyContentType = body.contentType ?? input.requestBodyContentType;","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/core/src/observability/request-log-worker.ts#L126-L162","documentation":"This warning is emitted by the request-log worker when a background page of stored requests fails to have usage costs backfilled (pricing refresh). It comes from schedulePricingBackfillPage in packages/core/src/observability/request-log-worker.ts: the promise chain that processes a page of logs rejects, pricingBackfillActive is reset to false, and the paged backfill loop stops. It is non-fatal: normal request logging continues, only historical cost columns stay stale/unpriced.","triggerScenarios":"Calling schedulePricingRefresh (or triggering schedulePricingBackfillPage directly) after pricing data changes; the page query or update on the request-log store rejects — e.g. corrupted log database, a malformed record that fails cost calculation, missing pricing model data for a logged model, or an unavailable/locked store.","commonSituations":"Log store schema mismatch after upgrading the core package while keeping old request logs; a logged model id that has no entry in the pricing table; the SQLite/file store being locked or deleted mid-backfill.","solutions":["Check the formatted error text — an 'unknown model' pricing error means you must refresh pricing data or add a price entry for the offending model id.","If the store is locked or corrupted, stop the gateway, back up and remove/repair the request-log database, then restart to let backfill start over.","Upgrade to the matching core package version so the log store schema matches what the backfill writer expects.","If stale historical costs are acceptable, ignore the warning — new log writes still get priced correctly."],"exampleFix":"// before: logged model has no pricing entry\nawait schedulePricingRefresh(); // warns: Failed to backfill usage costs: no price for model 'vendor/unknown-model'\n\n// after: ensure pricing data covers the model before refreshing\nawait ensureModelPricingExists('vendor/unknown-model');\nawait schedulePricingRefresh();","handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Keep pricing data refreshed before long backfills","Keep the request-log store on a healthy writable disk","Upgrade core and log-store schema together"],"tags":["observability","pricing","background-job","request-log"],"backgroundTag":"background-job-failed","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}