musistudio/claude-code-router · warning

[request-log] Failed to backfill usage costs: ${formatError(

Error message

[request-log] Failed to backfill usage costs: ${formatError(error)}

What it means

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.

Source

Thrown at packages/core/src/observability/request-log-worker.ts:144

  if (shuttingDown || (pricingBackfillActive && beforeId === undefined)) return;
  pricingBackfillActive = true;
  chain = chain.then(async () => {
    if (shuttingDown) {
      pricingBackfillActive = false;
      return;
    }
    const page = await store.backfillMissingUsageCostsPage({ beforeId });
    if (page.updated > 0) parentPort?.postMessage({ type: "maintenance", updated: page.updated });
    if (page.nextBeforeId === undefined) {
      pricingBackfillActive = false;
      return;
    }
    // Yield between pages so normal log writes already queued by the parent can
    // run before the next maintenance batch.
    setImmediate(() => schedulePricingBackfillPage(page.nextBeforeId));
  }).catch((error) => {
    pricingBackfillActive = false;
    console.warn(`[request-log] Failed to backfill usage costs: ${formatError(error)}`);
  });
}

function reviveCommand(command: RequestLogStoreWriteCommand): RequestLogStoreWriteCommand {
  if (command.kind === "raw-trace-update") {
    const input = { ...command.input };
    const maxBodyBytes = resolveRawTraceBodyLimit(command.rawTraceFiles?.maxBodyBytes);
    const rawTraceFiles: RequestLogRawTraceFiles | undefined = command.rawTraceFiles
      ? {
          cleanupDirectory: command.rawTraceFiles.cleanupDirectory,
          maxBodyBytes: command.rawTraceFiles.maxBodyBytes
        }
      : undefined;
    if (command.rawTraceFiles?.requestBody) {
      const body = readRawTraceBody(command.rawTraceFiles.requestBody, maxBodyBytes);
      if (body) {
        if (rawTraceFiles) rawTraceFiles.requestBody = fileMetadataFromRawTraceBody(body);
        input.requestBodyContentType = body.contentType ?? input.requestBodyContentType;

View on GitHub (pinned to 99f24806c6)

Solutions

  1. 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.
  2. 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.
  3. Upgrade to the matching core package version so the log store schema matches what the backfill writer expects.
  4. If stale historical costs are acceptable, ignore the warning — new log writes still get priced correctly.

Example fix

// before: logged model has no pricing entry
await schedulePricingRefresh(); // warns: Failed to backfill usage costs: no price for model 'vendor/unknown-model'

// after: ensure pricing data covers the model before refreshing
await ensureModelPricingExists('vendor/unknown-model');
await schedulePricingRefresh();
Defensive patterns

Strategy: fallback

Validate before calling

null

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27). Data as JSON: /api/errors/7e27d5be459f4d31. Report an issue: GitHub.